src/Controller/Website/CourseCertificateController.php line 33

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use EADPlataforma\Entity\CourseCertificate;
  7. use EADPlataforma\Enum\CourseCertificateEnum;
  8. use EADPlataforma\Enum\ClientEnum;
  9. /**
  10.  * @Route(
  11.  *      schemes         = {"http|https"}
  12.  * )
  13.  * @Cache(
  14.  *      maxage          = "0",
  15.  *      smaxage         = "0",
  16.  *      expires         = "now",
  17.  *      public          = false
  18.  * )
  19.  */
  20. class CourseCertificateController extends AbstractWebsiteController {
  21.     /**
  22.      * @Route(
  23.      *      path          = "/certificate/search",
  24.      *      name          = "certificateSearchPage",
  25.      *      methods       = {"GET"}
  26.      * )
  27.      */
  28.     public function courseCertificateSearchPage(Request $request) {
  29.         if(!$this->configuration->isModuleActive("course_certificate_module")){
  30.             return $this->redirectToRoute('notFound');
  31.         }
  32.         $code $request->get('certificate-code');
  33.         $date $request->get('certificate-date');
  34.         return $this->redirectToRoute('certificatePage', [ 
  35.             "type" => "certificate"
  36.             "code" => $code
  37.             "date" => $date 
  38.         ]);
  39.     }
  40.     /**
  41.      * @Route(
  42.      *      path          = "/certificate/{code}/{date}",
  43.      *      name          = "certificatePage",
  44.      *      methods       = {"GET"},
  45.      *      defaults      = { "code": null, "date": null }
  46.      * )
  47.      * @Route(
  48.      *      path          = "/certificado/{code}/{date}",
  49.      *      name          = "certificatePageOld",
  50.      *      methods       = {"GET"},
  51.      *      defaults      = { "code": null, "date": null },
  52.      * )
  53.      */
  54.     public function courseCertificatePage(Request $request) {
  55.         if(!$this->configuration->isModuleActive("course_certificate_module")){
  56.             return $this->redirectToRoute('notFound');
  57.         }
  58.         $code $request->get('code');
  59.         $date $request->get('date');
  60.         $certificateRepository $this->em->getRepository(CourseCertificate::class);
  61.         $courseCertificate $certificateRepository->getCourseCertificateByCode($code$date);
  62.         $this->data['courseCertificate'] = $courseCertificate;
  63.         $this->data['code'] = $code;
  64.         $this->data['date'] = $date;
  65.         return $this->renderEAD('certificate/certificate-detail.html.twig');
  66.     }
  67.     /**
  68.      * @Route(
  69.      *      path          = "/certificate/view/{code}/{date}",
  70.      *      name          = "viewCertificate",
  71.      *      methods       = {"GET"},
  72.      * )
  73.      */
  74.     public function viewCertificate(Request $request) {
  75.         if(!$this->configuration->isModuleActive("course_certificate_module")){
  76.             return $this->redirectToRoute('notFound');
  77.         }
  78.         $code $request->get('code');
  79.         $date $request->get('date');
  80.         $certificateRepository $this->em->getRepository(CourseCertificate::class);
  81.         $courseCertificate $certificateRepository->getCourseCertificateByCode($code$date);
  82.         if (!$courseCertificate) {
  83.             return $this->redirectToRoute('notFound');
  84.         }
  85.     
  86.         return $certificateRepository->generateCertificate($courseCertificate);
  87.     }
  88.     /**
  89.      * @Route(
  90.      *      path          = "/certificate/download/{code}/{date}",
  91.      *      name          = "downloadCertificate",
  92.      *      methods       = {"GET"},
  93.      * )
  94.      */
  95.     public function downloadCertificate(Request $request) {
  96.         if(!$this->configuration->isModuleActive("course_certificate_module")){
  97.             return $this->redirectToRoute('notFound');
  98.         }
  99.         $code $request->get('code');
  100.         $date $request->get('date');
  101.         $certificateRepository $this->em->getRepository(CourseCertificate::class);
  102.         $courseCertificate $certificateRepository->getCourseCertificateByCode($code$date);
  103.         if (!$courseCertificate) {
  104.             return $this->redirectToRoute('notFound');
  105.         }
  106.         return $certificateRepository->generateCertificate($courseCertificatetrue);
  107.     }
  108. }