<?php
namespace EADPlataforma\Controller\Website;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use EADPlataforma\Entity\CourseCertificate;
use EADPlataforma\Enum\CourseCertificateEnum;
use EADPlataforma\Enum\ClientEnum;
/**
* @Route(
* schemes = {"http|https"}
* )
* @Cache(
* maxage = "0",
* smaxage = "0",
* expires = "now",
* public = false
* )
*/
class CourseCertificateController extends AbstractWebsiteController {
/**
* @Route(
* path = "/certificate/search",
* name = "certificateSearchPage",
* methods = {"GET"}
* )
*/
public function courseCertificateSearchPage(Request $request) {
if(!$this->configuration->isModuleActive("course_certificate_module")){
return $this->redirectToRoute('notFound');
}
$code = $request->get('certificate-code');
$date = $request->get('certificate-date');
return $this->redirectToRoute('certificatePage', [
"type" => "certificate",
"code" => $code,
"date" => $date
]);
}
/**
* @Route(
* path = "/certificate/{code}/{date}",
* name = "certificatePage",
* methods = {"GET"},
* defaults = { "code": null, "date": null }
* )
* @Route(
* path = "/certificado/{code}/{date}",
* name = "certificatePageOld",
* methods = {"GET"},
* defaults = { "code": null, "date": null },
* )
*/
public function courseCertificatePage(Request $request) {
if(!$this->configuration->isModuleActive("course_certificate_module")){
return $this->redirectToRoute('notFound');
}
$code = $request->get('code');
$date = $request->get('date');
$certificateRepository = $this->em->getRepository(CourseCertificate::class);
$courseCertificate = $certificateRepository->getCourseCertificateByCode($code, $date);
$this->data['courseCertificate'] = $courseCertificate;
$this->data['code'] = $code;
$this->data['date'] = $date;
return $this->renderEAD('certificate/certificate-detail.html.twig');
}
/**
* @Route(
* path = "/certificate/view/{code}/{date}",
* name = "viewCertificate",
* methods = {"GET"},
* )
*/
public function viewCertificate(Request $request) {
if(!$this->configuration->isModuleActive("course_certificate_module")){
return $this->redirectToRoute('notFound');
}
$code = $request->get('code');
$date = $request->get('date');
$certificateRepository = $this->em->getRepository(CourseCertificate::class);
$courseCertificate = $certificateRepository->getCourseCertificateByCode($code, $date);
if (!$courseCertificate) {
return $this->redirectToRoute('notFound');
}
return $certificateRepository->generateCertificate($courseCertificate);
}
/**
* @Route(
* path = "/certificate/download/{code}/{date}",
* name = "downloadCertificate",
* methods = {"GET"},
* )
*/
public function downloadCertificate(Request $request) {
if(!$this->configuration->isModuleActive("course_certificate_module")){
return $this->redirectToRoute('notFound');
}
$code = $request->get('code');
$date = $request->get('date');
$certificateRepository = $this->em->getRepository(CourseCertificate::class);
$courseCertificate = $certificateRepository->getCourseCertificateByCode($code, $date);
if (!$courseCertificate) {
return $this->redirectToRoute('notFound');
}
return $certificateRepository->generateCertificate($courseCertificate, true);
}
}