<?php
namespace App\Controller;
use App\Service\SMSSender;
use App\Entity\User;
use App\Entity\SchoolYear;
use Informagenie\OrangeSDK;
use App\Entity\TreasuryCashRegister;
use App\Repository\SchoolYearRepository;
use App\Repository\EstablishmentRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\EstablishmentGroupRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
public const SENDER_ID = [
'client_id' => 'D7zEefSrAm3SF6D4NGlWWQl1Qojsy61R',
'client_secret' => 'uBrw9vRVGAoRsVQ9'
];
/**
* @Route("/", name="default")
*/
public function index(): Response
{
return $this->render('default/index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
/**
* @Route("/o-sms", name="api_or_sms")
*/
public function or_sms(): Response
{
try {
$sms = new OrangeSDK(SMSSender::OCI_SENDER_ID);
$response = $sms->balance();
dd($response);
} catch (\Throwable $th) {
dd($th);
}
return $this->render('default/index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
/**
* @Route("/change-syear/{id}", name="default_change_syear", methods={"GET"})
*/
public function change_syear(SchoolYear $schoolYear): Response
{
if ($schoolYear->getIsArchived()) {
return $this->json(['code' => 500, 'message' => "Impossible, cette base de données est archivée"], 200);
}
/**@var User $user */
$user = $this->getUser();
$entityManager = $this->getDoctrine()->getManager();
$user->setSchoolYear($schoolYear);
try {
$entityManager->flush();
$this->addFlash('success', "success");
return $this->json(['code' => 200, 'message' => "Changement effectué :)"], 200);
} catch (\Throwable $th) {
//$th->getMessage()
$this->addFlash('warning', $th->getMessage());
}
$this->addFlash('warning', "warning");
return $this->json(['code' => 500, 'message' => "warning"], 200);
}
public function _header(EstablishmentGroupRepository $establishmentGroupRepository, EstablishmentRepository $establishmentRepository, SchoolYearRepository $schoolYearRepository): Response
{
/**@var User $user */
$user = $this->getUser();
return $this->render('_header.html.twig', [
'establishmentGroups' => $establishmentGroupRepository->findBy([], ['id' => 'DESC']),
'establishments' => $establishmentRepository->findBy([], ['id' => 'DESC']),
'schoolYear' => $user->getSchoolYear(),
'schoolYears' => $schoolYearRepository->findBy([], ['id' => 'DESC'])
]);
}
public function _footer(): Response
{
/**@var User $user */
$user = $this->getUser();
return $this->render('_footer.html.twig', [
'schoolYear' => $user->getSchoolYear()
]);
}
public function _sidebar(EstablishmentGroupRepository $establishmentGroupRepository, EstablishmentRepository $establishmentRepository): Response
{
return $this->render('_sidebar.html.twig', [
'establishmentGroups' => $establishmentGroupRepository->findBy([], ['id' => 'DESC']),
'establishments' => $establishmentRepository->findBy([], ['id' => 'DESC']),
]);
}
/**
* @Route("/preview/{file}/{dir}", name="preview", methods={"GET"})
*/
public function preview($file, $dir)
{
return $this->render('print/preview.html.twig', array(
'file' => $file,
'dir' => $dir,
));
}
/**
* @Route("/previewPayment/{id}/{file}/{dir}", name="preview_payment", methods={"GET"})
*/
public function previewPayment($file, $dir, TreasuryCashRegister $treasuryCashRegister)
{
return $this->render('print/previewPayment.html.twig', array(
'file' => $file,
'dir' => $dir,
'treasuryCashRegister' => $treasuryCashRegister,
));
}
}