src/Controller/DefaultController.php line 92

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\SMSSender;
  4. use App\Entity\User;
  5. use App\Entity\SchoolYear;
  6. use Informagenie\OrangeSDK;
  7. use App\Entity\TreasuryCashRegister;
  8. use App\Repository\SchoolYearRepository;
  9. use App\Repository\EstablishmentRepository;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use App\Repository\EstablishmentGroupRepository;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. class DefaultController extends AbstractController
  15. {
  16.     public const SENDER_ID = [
  17.         'client_id' => 'D7zEefSrAm3SF6D4NGlWWQl1Qojsy61R',
  18.         'client_secret' => 'uBrw9vRVGAoRsVQ9'
  19.     ];
  20.     /**
  21.      * @Route("/", name="default")
  22.      */
  23.     public function index(): Response
  24.     {
  25.         return $this->render('default/index.html.twig', [
  26.             'controller_name' => 'DefaultController',
  27.         ]);
  28.     }
  29.     /**
  30.      * @Route("/o-sms", name="api_or_sms")
  31.      */
  32.     public function or_sms(): Response
  33.     {
  34.         try {
  35.             $sms = new OrangeSDK(SMSSender::OCI_SENDER_ID);
  36.             $response $sms->balance();
  37.             dd($response);
  38.         } catch (\Throwable $th) {
  39.             dd($th);
  40.         }
  41.         return $this->render('default/index.html.twig', [
  42.             'controller_name' => 'DefaultController',
  43.         ]);
  44.     }
  45.     /**
  46.      * @Route("/change-syear/{id}", name="default_change_syear", methods={"GET"})
  47.     */
  48.     public function change_syear(SchoolYear $schoolYear): Response
  49.     {
  50.         if ($schoolYear->getIsArchived()) {
  51.             return $this->json(['code' => 500'message' => "Impossible, cette base de données est archivée"], 200);
  52.         }
  53.         /**@var User $user */
  54.         $user $this->getUser();
  55.         $entityManager $this->getDoctrine()->getManager();
  56.         $user->setSchoolYear($schoolYear);
  57.         try {
  58.             $entityManager->flush();
  59.             $this->addFlash('success'"success");
  60.             return $this->json(['code' => 200'message' => "Changement effectué :)"], 200);
  61.         } catch (\Throwable $th) {
  62.             //$th->getMessage()
  63.             $this->addFlash('warning'$th->getMessage());
  64.         }
  65.         
  66.         $this->addFlash('warning'"warning");
  67.         return $this->json(['code' => 500'message' => "warning"], 200);
  68.     }
  69.     public function _header(EstablishmentGroupRepository $establishmentGroupRepositoryEstablishmentRepository $establishmentRepositorySchoolYearRepository $schoolYearRepository): Response
  70.     {
  71.         /**@var User $user */
  72.         $user $this->getUser();
  73.         return $this->render('_header.html.twig', [
  74.             'establishmentGroups' => $establishmentGroupRepository->findBy([], ['id' => 'DESC']),
  75.             'establishments' => $establishmentRepository->findBy([], ['id' => 'DESC']),
  76.             'schoolYear' => $user->getSchoolYear(),
  77.             'schoolYears' => $schoolYearRepository->findBy([], ['id' => 'DESC'])
  78.         ]);
  79.     }
  80.     public function _footer(): Response
  81.     {
  82.         /**@var User $user */
  83.         $user $this->getUser();
  84.         return $this->render('_footer.html.twig', [
  85.             'schoolYear' => $user->getSchoolYear()
  86.         ]);
  87.     }
  88.     public function _sidebar(EstablishmentGroupRepository $establishmentGroupRepositoryEstablishmentRepository $establishmentRepository): Response
  89.     {
  90.         return $this->render('_sidebar.html.twig', [
  91.             'establishmentGroups' => $establishmentGroupRepository->findBy([], ['id' => 'DESC']),
  92.             'establishments' => $establishmentRepository->findBy([], ['id' => 'DESC']),
  93.         ]);
  94.     }
  95.     /**
  96.      * @Route("/preview/{file}/{dir}", name="preview", methods={"GET"})
  97.     */
  98.     public function preview($file$dir)
  99.     {
  100.         return $this->render('print/preview.html.twig', array(
  101.             'file' => $file,
  102.             'dir' => $dir,
  103.         ));
  104.     }
  105.     /**
  106.      * @Route("/previewPayment/{id}/{file}/{dir}", name="preview_payment", methods={"GET"})
  107.     */
  108.     public function previewPayment($file$dirTreasuryCashRegister $treasuryCashRegister)
  109.     {
  110.         return $this->render('print/previewPayment.html.twig', array(
  111.             'file' => $file,
  112.             'dir' => $dir,
  113.             'treasuryCashRegister' => $treasuryCashRegister,
  114.         ));
  115.     }
  116. }