<?php
namespace App\Controller\Front;
use App\Entity\Contract;
use App\Entity\Course;
use App\Entity\Director;
use App\Entity\FeaturedModule;
use App\Entity\Job;
use App\Entity\Live;
use App\Entity\Module;
use App\Entity\ModuleItem;
use App\Entity\NotificationReceiver;
use App\Entity\Office;
use App\Entity\Program;
use App\Entity\Quiz;
use App\Entity\Quote;
use App\Entity\SubsidiaryCompany;
use App\Entity\User;
use App\Entity\Partenaire;
use App\Form\ChangePasswordType;
use App\Form\CourseType;
use App\Form\DirectorType;
use App\Form\FeaturedModuleType;
use App\Form\JobType;
use App\Form\LiveType;
use App\Form\ModuleType;
use App\Form\ProgramType;
use App\Form\QuizType;
use App\Form\QuoteType;
use App\Form\PartenaireType;
use App\Form\RegistrationFormType;
use App\Helper\ControllerHelper;
use App\Message\Notification;
use App\Entity\Notification as NotificationEntity;
use App\Event\PreExecutionEvent;
use App\Repository\CourseRepository;
use App\Repository\DirectorRepository;
use App\Repository\FeaturedModuleRepository;
use App\Repository\JobRepository;
use App\Repository\LiveRepository;
use App\Repository\ModuleItemRepository;
use App\Repository\ModuleNoticeRepository;
use App\Repository\ModuleParticipationRepository;
use App\Repository\ModuleRepository;
use App\Repository\ModuleViewRepository;
use App\Repository\OfficeRepository;
use App\Repository\ProgramParticipationRepository;
use App\Repository\ProgramRepository;
use App\Repository\QuizRepository;
use App\Repository\QuoteRepository;
use App\Repository\SubsidiaryCompanyRepository;
use App\Repository\UserRepository;
use App\Repository\ModuleObjectiveRepository;
use App\Repository\NotificationReceiverRepository;
use App\Repository\NotificationRepository;
use App\Repository\PartenaireRepository;
use App\Repository\SubjectRepository;
use App\Repository\CommentRepository;
use App\Schedule\AppScheduleBuilder;
use App\Service\HelperService;
use App\Service\PushNotification;
use App\Utils\Constants;
use DateInterval;
use DateTime;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use Kreait\Firebase\Contract\Messaging;
use LogicException;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\String\Slugger\SluggerInterface;
use Symfony\Component\Workflow\WorkflowInterface;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use Knp\Component\Pager\Paginator;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Zenstruck\ScheduleBundle\Schedule;
/**
* Require ROLE_EMPLOYEE for all the actions of this controller
*
* @IsGranted("ROLE_EMPLOYEE")
*
* @Route("/dashboard")
*/
class DashboardController extends AbstractController
{
use ControllerHelper;
private $helperService;
private $courseWorkflow;
private $liveWorkflow;
private $quizWorkflow;
private $doctrine;
private $mailer;
private $messaging;
private $pushNotification;
private $slugger;
private $hub;
private $bus;
private $paginator;
public function __construct(
HelperService $helperService,
WorkflowInterface $coursePublishingStateMachine,
WorkflowInterface $livePublishingStateMachine,
WorkflowInterface $quizPublishingStateMachine,
MailerInterface $mailer,
ManagerRegistry $doctrine,
Messaging $messaging,
PushNotification $pushNotification,
SluggerInterface $slugger,
HubInterface $hub,
MessageBusInterface $bus,
PaginatorInterface $paginator)
{
$this->helperService = $helperService;
$this->courseWorkflow = $coursePublishingStateMachine;
$this->liveWorkflow = $livePublishingStateMachine;
$this->quizWorkflow = $quizPublishingStateMachine;
$this->doctrine = $doctrine;
$this->mailer = $mailer;
$this->messaging = $messaging;
$this->pushNotification = $pushNotification;
$this->slugger = $slugger;
$this->hub = $hub;
$this->bus = $bus;
$this->paginator = $paginator;
}
/**
* @Route("/{profil}/password", name="app_front_dashboard_update_password_page")
*/
public function updatePassword(Request $request, UserRepository $userRepository, UserPasswordHasherInterface $userPasswordHasher, String $profil): Response
{
/** @var User */
$user = $this->getUser();
$form = $this->createForm(ChangePasswordType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$oldPassword = $form->get('oldPassword')->getData();
if (!$userPasswordHasher->isPasswordValid($user, $oldPassword)) {
$this->addFlash('user_password_update_error', 'Mot de passe incorrect');
return $this->redirectToRoute('app_front_dashboard_update_password_page', ['profil' => $profil]);
}
$user->setPassword(
$userPasswordHasher->hashPassword(
$user,
$form->get('newPassword')->getData()
)
);
$userRepository->add($user, true);
$mail = (new TemplatedEmail())
->from(new Address($this->getParameter('cofina_sender_mail'), 'Cofina Academy'))
->to($user->getEmail())
->subject('Changement de mot de passe au Programme')
->htmlTemplate('security/change-password-email.html.twig')
->context([]);
try {
$this->mailer->send($mail);
} catch (TransportExceptionInterface $e) {
// dump($e->getMessage()); die;
}
$this->addFlash('user_password_updated', 'Mot de passe mis à jour');
return $this->redirectToRoute('app_front_dashboard_update_password_page', ['profil' => $profil]);
}
return $this->render('front/pages/dashboard/password.html.twig', [
'form' => $form->createView(),
]);
}
/**
* @Route("/apprenant/profil/{id}", name="app_learner_dashboard_page")
* @Route("/apprenant", name="app_front_learner_dashboard_page")
*/
public function learner(Request $request, ProgramRepository $programRepository, ModuleRepository $moduleRepository, NotificationRepository $notificationRepository, User $learner = null): Response
{
// $programs = $programRepository->findAll();
// foreach ($programs as $program) {
// $slug = $this->slugger->slug($program->getLabel());
// $program->setSlug($slug);
// $programRepository->add($program, true);
// }
// die("ok");
$followedModulesPage = (int)$request->query->get('followedModulesPage', 1);
$allModulesPage = (int)$request->query->get('allModulesPage', 1);
$terminatedModulesPage = (int)$request->query->get('terminatedModulesPage', 1);
$notificationPage = (int)$request->query->get('notificationPage', 1);
$session = $request->getSession();
/** @var User */
$user = $this->getUser();
$refererProfile = null;
if ($learner !== null) {
$user = $learner;
$refererProfile = $session->has('__profile') ? $session->get('__profile') : null;
}
$followedProgramCount = $programRepository->getFollowedProgramCount($user);
$terminatedProgramCount = $programRepository->getTerminatedProgramCount($user);
$limit = Constants::PAGINATION_LIMIT;
// $allModulesQb = $moduleRepository->findAllModuleQueryBuilder($user, $allModulesPage, $limit);
// $allModules = $moduleRepository->findAllModule($allModulesQb);
$allModulesCountQb = $moduleRepository->findAllModuleQueryBuilder($user);
$allModuleCount = $moduleRepository->findAllModule($allModulesCountQb)->count();
//$followedModules = $moduleRepository->findFollowedModules($user, $followedModulesPage, Constants::PAGINATION_LIMIT);
$followedModuleCount = $moduleRepository->getFollowedModuleCount($user, true);
//$followedModuleCountHist = $moduleRepository->getFollowedModuleCount($user, false);
$terminatedModules = $moduleRepository->findTerminatedModules($user, $terminatedModulesPage, $limit);
$terminatedModuleCount = $moduleRepository->getTerminatedModuleCount($user);
//$modulesObjectives = $moduleObjectiveRepository->findBy(array('module' => $allModules->getIterator()->getArrayCopy()));
//dd($allModules->getIterator()->getArrayCopy());
$programParticipationWithCertificate = $user->getProgramParticipations()->filter(function($programParticipation) {
return ($programParticipation->getCertificate() !== null);
});
$programs = $programRepository->findActivePrograms($user);
$modules = $moduleRepository->searchModule(null, null, $user);
// Filter form
$form = $this->createFormBuilder()
->add('program', EntityType::class, [
'class' => Program::class,
'label' => false,
'choice_label' => 'label',
'placeholder' => 'Choisir un programme',
'required' => false,
'choices' => $programs,
'attr' => [
// 'class' => 'form-select select-2-tags',
'class' => 'select-2-tags custom-dash-select shadow-sm me-0 me-md-4 custom-dash-select-w bg-white',
'data-placeholder' => 'Choisir un programme'
],
])
->add('module', EntityType::class, [
'class' => Module::class,
'label' => false,
'choice_label' => 'name',
'placeholder' => 'Choisir un module',
'required' => false,
'choices' => $modules,
'attr' => [
// 'class' => 'form-select select-2-tags',
'class' => 'select-2-tags custom-dash-select shadow-sm custom-dash-select-w bg-white',
'data-placeholder' => 'Choisir un module'
],
])
->add('filter', SubmitType::class, [
'label' => 'Filtrer',
// 'attr' => ['class' => 'btn btn-danger opificio rounded-4 px-5 fw-bold fs-5']
'attr' => ['class' => 'custom-dash-select shadow-sm bg-white']
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$programData = $form->get('program')->getData();
$moduleData = $form->get('module')->getData();
if ($programData !== null) $session->set('__program', $programData->getId());
if ($moduleData !== null) $session->set('__module', $moduleData->getId());
}
$current_role = $this->helperService->getUserCurrentRole();
$unreadNotifications = $notificationRepository->findUnreadNotifications($user, $notificationPage, Constants::PAGINATION_LIMIT);
$unreadNotificationCount = $notificationRepository->getUnreadNotificationCount($user);
$notificationCount = $notificationRepository->findNotificationCount($user);
// $notifications = $notificationRepository->findBy(
// array('receiver' => $user),
// array('createdAt' => 'DESC'),
// Constants::PAGINATION_LIMIT,
// $notificationPage-1
// );
$notifications = $notificationRepository->findNotifications($user, $notificationPage, Constants::PAGINATION_LIMIT);
// return $this->render('front/pages/dashboard/learner.html.twig', [
return $this->render('front/pages/dashboard/index.html.twig', [
'followed_program_count' => $followedProgramCount,
'terminated_program_count' => $terminatedProgramCount,
'followed_module_count' => $followedModuleCount,
'terminated_module_count' => $terminatedModuleCount,
//'followed_module_count_hist' => $followedModuleCountHist,
//'terminatedModuleCount' => $terminatedModuleCount,
//'followedModules' => $followedModules,
//'allModules' => $allModules,
'terminated_modules' => $terminatedModules,
'program_participation_with_certificate' => $programParticipationWithCertificate,
'limit' => Constants::PAGINATION_LIMIT,
'allModulesPage' => $allModulesPage,
'allModuleCount' => $allModuleCount,
'followedModulesPage' => $followedModulesPage,
//'followedModuleCount' => $followedModuleCount,
'terminatedModulesPage' => $terminatedModulesPage,
//'terminatedModuleCount' => $terminatedModuleCount,
'program' => ($session->has('__program') ? $programRepository->findOneById($session->get('__program')) : null),
'module' => ($session->has('__module') ? $moduleRepository->findOneById($session->get('__module')) : null),
//'programs' => $programs,
//'modules' => $modules,
'form' => $form->createView(),
'user' => $user,
'learner' => $learner,
'referer_profile' => $refererProfile,
'current_role' => $current_role,
'unreadNotifications' => $unreadNotifications,
'unreadNotificationCount' => $unreadNotificationCount,
'notificationPage' => $notificationPage,
'notifications' => $notifications,
'notificationCount' => $notificationCount
]);
}
/**
* @Route("/apprenant/training-history/user/{id}", name="app_front_learner_training_history_for_user")
* @Route("/apprenant/training-history", name="app_front_learner_training_history")
* @Route("/apprenant/training-history/{id}", name="app_front_learner_training__history")
*/
public function training_history(Request $request, ModuleRepository $moduleRepository, User $learner = null): Response
{
$type = $request->get('type', 'all');
$page = (int) $request->get('page', 1);
$followedModulesPage = 1;
$allModulesPage = 1;
$terminatedModulesPage = 1;
if ($type == 'followed') {
$followedModulesPage = $page;
} else if($type == 'terminated') {
$terminatedModulesPage = $page;
} else {
$allModulesPage = $page;
}
// dd($allModulesPage);
// $session = $request->getSession();
// dd($learner);
/** @var User */
$user = ($learner !== null) ? $learner : $this->getUser();
// $refererProfile = null;
// if ($learner !== null) {
// $user = $learner;
// //$refererProfile = $session->has('__profile') ? $session->get('__profile') : null;
// }
// $followedProgramCount = $programRepository->getFollowedProgramCount($user);
// $terminatedProgramCount = $programRepository->getTerminatedProgramCount($user);
$allModulesQb = $moduleRepository->findAllModuleQueryBuilder($user, $allModulesPage, Constants::PAGINATION_LIMIT);
$allModules = $moduleRepository->findAllModule($allModulesQb);
$allModulesCountQb = $moduleRepository->findAllModuleQueryBuilder($user);
$allModuleCount = $moduleRepository->findAllModule($allModulesCountQb)->count();
$followedModules = $moduleRepository->findFollowedModules($user, $followedModulesPage, Constants::PAGINATION_LIMIT, false);
$followedModuleCount = $moduleRepository->getFollowedModuleCount($user, true);
$followedModuleCountHist = $moduleRepository->getFollowedModuleCount($user, false);
// dump($followedModuleCount);
// dump($followedModuleCountHist);
// die;
$terminatedModules = $moduleRepository->findTerminatedModules($user, $terminatedModulesPage, Constants::PAGINATION_LIMIT);
$terminatedModuleCount = $moduleRepository->getTerminatedModuleCount($user);
$allModulesPagination = $this->paginator->paginate(
$allModulesQb,
$allModulesPage,
Constants::PAGINATION_LIMIT
);
return $this->render('front/layouts/partials/training-history.html.twig', [
'followedModules' => $followedModules,
'allModules' => $allModules,
'terminatedModules' => $terminatedModules,
'limit' => Constants::PAGINATION_LIMIT,
'allModulesPage' => $allModulesPage,
'all_module_count' => $allModuleCount,
'followedModulesPage' => $followedModulesPage,
'followedModuleCount' => $followedModuleCount,
'terminatedModulesPage' => $terminatedModulesPage,
//'terminatedModuleCount' => $terminatedModuleCount,
'terminated_module_count' => $terminatedModuleCount,
'followed_module_count_hist' => $followedModuleCountHist,
'user' => $user,
'learner' => $learner,
// 'allModulesPage' => $allModulesPage,
'followedModulesPage' => $followedModulesPage,
'terminatedModulesPage' => $terminatedModulesPage,
'type' => $type,
'allModulesPagination' => $allModulesPagination
]);
}
/**
* @Route("/apprenant/all-certificates", name="app_front_learner_all_certificates")
*/
public function allCertificates(Request $request, ProgramRepository $programRepository, ModuleRepository $moduleRepository, User $learner = null): Response
{
$followedModulesPage = (int)$request->query->get('followedModulesPage', 1);
$allModulesPage = (int)$request->query->get('allModulesPage', 1);
$session = $request->getSession();
/** @var User */
$user = $this->getUser();
$refererProfile = null;
if ($learner !== null) {
$user = $learner;
$refererProfile = $session->has('__profile') ? $session->get('__profile') : null;
}
$allModules = $moduleRepository->findAllModule($user, $allModulesPage, Constants::PAGINATION_LIMIT);
$allModuleCount = $moduleRepository->findAllModule($user)->count();
$programParticipationWithCertificate = $user->getProgramParticipations()->filter(function($programParticipation) {
return ($programParticipation->getCertificate() !== null);
});
return $this->render('front/layouts/partials/all-certificates-dashboard.html.twig', [
'allModules' => $allModules,
'program_participation_with_certificate' => $programParticipationWithCertificate,
'user' => $user
]);
}
/**
* @Route("/{profil}/list-apprenants", name="app_front_learner_page")
*/
public function learnerPage(Request $request, UserRepository $userRepository, ProgramRepository $programRepository, ModuleRepository $moduleRepository, String $profil): Response
{
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
$programs = $programRepository->findActivePrograms($this->getUser());
$modules = $moduleRepository->searchModule(null, null, $this->getUser());
$session = $request->getSession();
// Filter form
$form = $this->createFormBuilder()
->add('program', EntityType::class, [
'class' => Program::class,
'label' => false,
'choice_label' => 'label',
'attr' => ['class' => 'form-select fw-bold border-0 shadow-sm height-50'],
'placeholder' => 'Choisir un programme',
'required' => false,
'choices' => $programs,
])
->add('module', EntityType::class, [
'class' => Module::class,
'label' => false,
'choice_label' => 'name',
'attr' => ['class' => 'form-select fw-bold border-0 shadow-sm height-50'],
'placeholder' => 'Choisir un module',
'required' => false,
'choices' => $modules
])
->add('filter', SubmitType::class, [
'label' => 'Filtrer',
'attr' => ['class' => 'custom-dash-select shadow-sm bg-white']
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$programData = $form->get('program')->getData();
$module = $form->get('module')->getData();
$session->set('__program', $programData->getId());
$session->set('__module', $module->getId());
}
$current_role = $this->helperService->getUserCurrentRole();
$learners = $userRepository->findLearners($page, Constants::PAGINATION_LIMIT, $this->getUser(), $current_role);
// $learnerWithCertificateCount = $userRepository->getLearnerWithCertificateCount();
$learnerCount = $this->getLearnerCount();
return $this->render('front/pages/dashboard/learners/learners.html.twig', [
'learners' => $learners,
'total_learner' => $learnerCount,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'program' => ($session->has('__program') ? $programRepository->findOneById($session->get('__program')) : null),
'module' => ($session->has('__module') ? $moduleRepository->findOneById($session->get('__module')) : null),
'user' => ($profil === 'integrateur' || $profil === 'administrateur') ? null : $this->getUser(),
'programs' => $programs,
'modules' => $modules,
'form' => $form->createView(),
'current_role' => $current_role
// 'success_rate' => ($learnerWithCertificateCount / $learnerCount) * 100,
]);
}
/**
* @Route("/{profil}/utilisateurs", name="app_front_user_page")
*/
public function utilisateurPage(): Response
{
return $this->render('front/pages/dashboard/users/users.html.twig', [
'controller_name' => 'users',
]);
}
/**
* @Route("/{profil}/programmes", name="app_front_program_page")
* @Route("/{profil}/programmes-termines", name="app_front_terminated_program_page")
* @Route("/{profil}/{id}/programmes", name="app_front_learner_program_page")
* @Route("/{profil}/{id}/programmes-termines", name="app_front_learner_terminated_program_page")
*/
public function programPage(Request $request, ProgramRepository $programRepository, PaginatorInterface $paginator, User $learner = null): Response
{
$session = $request->getSession();
if ($request->query->get('page') === null) $session->remove('program_search_key');
$program = new Program();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
// Search form
$searchKey = $session->has('program_search_key') ? $session->get('program_search_key') : null;
$form = $this->createFormBuilder()
->add('searchKey', TextType::class, [
'label' => 'Rechercher: ',
'label_attr' => ['class' => 'text-grey'],
'attr' => [
'style' => 'border: 1px solid transparent !important'
],
'required' => false,
'data' => $session->has('program_search_key') ? $session->get('program_search_key') : ''
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchKey = $form->get('searchKey')->getData();
$session->remove('program_search_key');
if ($searchKey !== null) $session->set('program_search_key', $searchKey);
}
$user = ($learner !== null) ? $learner : $this->getUser();
// $programs = $programRepository->findPrograms($user, $page, Constants::PAGINATION_LIMIT, $searchKey);
$programs = $programRepository->findProgramsQuery($user, true, $searchKey);
// $totalProgram = $programRepository->getTotalProgram($user, $searchKey);
$pagination = $paginator->paginate(
$programs,
$page,
10
);
return $this->renderForm('front/pages/dashboard/program/program.html.twig', [
'program' => $program,
'programs' => $pagination,
//'totalProgram' => $totalProgram,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'form' => $form
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR')")
*
* @Route("/{profil}/programmes/creer-un-programme", name="app_front_create_program_page")
*/
public function createProgram(Request $request, ProgramRepository $programRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR')) throw $this->createNotFoundException("La page demandée n'existe pas");
// if (!in_array($this->helperService->getUserCurrentRole(), Constants::MANAGER_ROLES)) throw $this->createNotFoundException("La page demandée n'existe pas");
$program = new Program();
$form = $this->createForm(ProgramType::class, $program);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$programRepository->add($program, true);
$subsidiaryCompanies = ($program->isIsAllSubsidiaryCompanies()) ? "Toutes les filiales" : $program->getSubsidiaryCompanies()->toArray();
$jobs = ($program->isIsAllJobs()) ? "Tous les métiers" : $program->getJobs()->toArray();
$offices = ($program->isIsAllOffices()) ? "Toutes les fonctions" : $program->getOffices()->toArray();
$contracts = ($program->isIsAllContracts()) ? "Tous les types de contrat" : $program->getContracts()->toArray();
$toAddresses = [];
$topics = [];
if (is_array($subsidiaryCompanies)) {
foreach ($subsidiaryCompanies as $subsidiaryCompany) {
$toAddresses [] = $subsidiaryCompany->getMailingListAllStaff();
}
} else {
$toAddresses [] = $this->getParameter('cofina_all_subsidiary_companies_recipient_mail');
$topics [] = Constants::DEFAULT_TOPIC;
}
$deviceTokens = [];
foreach ($program->getUsers() as $user) {
$toAddresses [] = $user->getEmail();
$deviceTokens = array_diff($deviceTokens, ($user->getDeviceTokens() ?? []));
}
if ($toAddresses !== null && count($toAddresses) > 0) {
$okUrl = $_ENV['SECURE_SCHEME'].':'.$this->generateUrl('app_admin_program_participation_page', ['id' => $program->getId()], UrlGeneratorInterface::NETWORK_PATH);
$nokUrl = $_ENV['SECURE_SCHEME'].':'.$this->generateUrl('app_admin_program_participant_unavailable_page', ['id' => $program->getId()], UrlGeneratorInterface::NETWORK_PATH);
$mail = (new TemplatedEmail())
->from(new Address($this->getParameter('cofina_sender_mail'), 'Cofina Academy'))
->to(...$toAddresses)
->subject('Invitation au Programme')
->htmlTemplate('front/pages/dashboard/program/mail.html.twig')
->context([
'subsidiaryCompanies' => $subsidiaryCompanies,
'jobs' => $jobs,
'offices' => $offices,
'contracts' => $contracts,
'objective' => $program->getObjective(),
'name' => $program->getLabel(),
'startAt' => $program->getStartAt(),
'endAt' => $program->getEndAt(),
'program_participation_url' => $okUrl,
'nok_url' => $nokUrl
]);
try {
$this->mailer->send($mail);
} catch (TransportExceptionInterface $e) {
// dump($e->getMessage()); die;
}
}
try {
$this->bus->dispatch(new Notification($program->getId(), 'Program', 'new_program', $program->getCreatedBy()->getId()));
} catch (Exception $e) {
// dump($e->getMessage()); die;
}
return $this->redirectToRoute('app_front_program_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/program/create_program.html.twig', [
'program' => $program,
'form' => $form,
'profil' => $profil
]);
}
/**
* @Route("/{profil}/modules", name="app_front_module_page")
* @Route("/{profil}/modules-termines", name="app_front_terminated_module_page")
* @Route("/{profil}/{id}/modules", name="app_front_learner_module_page")
* @Route("/{profil}/{id}/modules-termines", name="app_front_learner_terminated_module_page")
*/
public function modulePage(Request $request, ModuleRepository $moduleRepository, PaginatorInterface $paginator, User $learner = null): Response
{
$session = $request->getSession();
if ($request->query->get('page') === null) $session->remove('module_search_key');
// $module = new Module();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
// Search form
$searchKey = $session->has('module_search_key') ? $session->get('module_search_key') : null;
$form = $this->createFormBuilder()
->add('searchKey', TextType::class, [
'label' => 'Rechercher: ',
'label_attr' => ['class' => 'text-grey'],
'attr' => [
'style' => 'border: 1px solid transparent !important'
],
'required' => false,
'data' => $session->has('module_search_key') ? $session->get('module_search_key') : ''
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchKey = $form->get('searchKey')->getData();
$session->remove('module_search_key');
if ($searchKey !== null) $session->set('module_search_key', $searchKey);
}
//$modules = $moduleRepository->findPaginateModule($page, Constants::PAGINATION_LIMIT);
$user = ($learner !== null) ? $learner : $this->getUser();
$modules = $moduleRepository->findModulesQuery($user, true, $searchKey);
//$totalModule = $moduleRepository->findModules($this->getUser(), false, null, null, $searchKey);
//$totalModule = $moduleRepository->getTotalModule($this->getUser());
//dd($totalModule);
$pagination = $paginator->paginate(
$modules,
$page,
10
);
return $this->renderForm('front/pages/dashboard/modules/modules.html.twig', [
//'module' => $module,
'modules' => $pagination,
// 'totalModule' => $totalModule,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'form' => $form
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR')")
*
* @Route("/{profil}/modules/creer-un-module", name="app_front_create_module_page")
*/
public function createModule(Request $request, ModuleRepository $moduleRepository, ModuleItemRepository $moduleItemRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR')) throw $this->createNotFoundException("La page demandée n'existe pas");
if (!in_array($this->helperService->getUserCurrentRole(), Constants::MANAGER_ROLES)) throw $this->createNotFoundException("La page demandée n'existe pas");
$module = new Module();
$form = $this->createForm(ModuleType::class, $module);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($module->isIsPublished()) $module->setPublishedAt(new DateTime());
$moduleRepository->add($module, true);
$courses = $module->getCourses();
foreach ($courses as $course) {
// $moduleItem = $moduleItemRepository->findOneBy(['module' => $module, 'course' => $course]);
// if ($moduleItem === null) {
$moduleItem = new ModuleItem();
$moduleItem->setModule($module);
$moduleItem->setCourse($course);
$moduleItem->setType('course');
$moduleItemRepository->add($moduleItem, true);
// }
}
$_quiz = $module->getQuiz();
foreach ($_quiz as $quiz) {
// $moduleItem = $moduleItemRepository->findOneBy(['module' => $module, 'quiz' => $quiz]);
// if ($moduleItem === null) {
$moduleItem = new ModuleItem();
$moduleItem->setModule($module);
$moduleItem->setQuiz($quiz);
$moduleItem->setType('quiz');
$moduleItemRepository->add($moduleItem, true);
// }
}
return $this->redirectToRoute('app_front_module_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/modules/create_module.html.twig', [
'module' => $module,
'form' => $form,
'profil' => $profil
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR')")
*
* @Route("/{profil}/modules/organiser-le-module/{slug}", name="app_front_module_arrange_page")
*/
public function arrangeModulePage(ModuleItemRepository $moduleItemRepository, Module $module): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR')) throw $this->createNotFoundException("La page demandée n'existe pas");
// if (!in_array($this->helperService->getUserCurrentRole(), Constants::MANAGER_ROLES)) throw $this->createNotFoundException("La page demandée n'existe pas");
$items = $moduleItemRepository->findItems($module);
// dump($items); die;
return $this->renderForm('front/pages/dashboard/modules/arrange.html.twig', [
'items' => $items,
'module' => $module
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR') or is_granted('ROLE_COACH') or is_granted('ROLE_TUTOR') or is_granted('ROLE_ADVISE')")
*
* @Route("/{profil}/quiz", name="app_front_quiz_page")
*/
public function quizPage(Request $request, QuizRepository $quizRepository, String $profil = null): Response
{
$session = $request->getSession();
if ($request->query->get('page') === null) $session->remove('quiz_search_key');
$userRole = $this->getUserActivedRole($profil);
if ($userRole === null) throw $this->createNotFoundException("La page demandée n'existe pas");
$quiz = new Quiz();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
// Search form
$searchKey = $session->has('quiz_search_key') ? $session->get('quiz_search_key') : null;
$form = $this->createFormBuilder()
->add('searchKey', TextType::class, [
'label' => 'Rechercher: ',
'label_attr' => ['class' => 'text-grey'],
'attr' => [
'style' => 'border: 1px solid transparent !important'
],
'required' => false,
'data' => $session->has('quiz_search_key') ? $session->get('quiz_search_key') : ''
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchKey = $form->get('searchKey')->getData();
$session->remove('quiz_search_key');
if ($searchKey !== null) $session->set('quiz_search_key', $searchKey);
}
$quizs = $quizRepository->findQuiz($this->getUser(), $page, Constants::PAGINATION_LIMIT, $searchKey);
$totalQuiz = $quizRepository->findQuiz($this->getUser(), null, null, $searchKey);
// $totalQuiz = $quizRepository->getTotalQuiz($this->getUser());
return $this->renderForm('front/pages/dashboard/quiz/quiz.html.twig', [
'quizs' => $quizs,
'quiz' => $quiz,
'totalQuiz' => $totalQuiz,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'form' => $form
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR') or is_granted('ROLE_COACH') or is_granted('ROLE_TUTOR') or is_granted('ROLE_ADVISE')")
*
* @Route("/{profil}/quiz/creer-un-quiz", name="app_front_create_quiz_page")
*/
public function createQuiz(Request $request, QuizRepository $quizRepository, ModuleItemRepository $moduleItemRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR') && !$this->isGranted('ROLE_COACH')) throw $this->createNotFoundException("La page demandée n'existe pas");
$quiz = new Quiz();
$form = $this->createForm(QuizType::class, $quiz);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $hour = (int)$quiz->getTime()->format('H');
// $minute = (int)$quiz->getTime()->format('i');
// $second = (int)$quiz->getTime()->format('s');
// $curentDate = clone (new DateTime());
// $endAt = $curentDate->add(new DateInterval('PT'.$hour.'H'.$minute.'M'.$second.'S'));
// $quiz->setAutomaticEndAt($endAt);
try {
if ($form->has('saveAndSentToReview') && $form->get('saveAndSentToReview')->isClicked()) {
$this->quizWorkflow->apply($quiz, 'to_review');
$this->addFlash('quiz_added_and_sent_to_review', 'Quiz créé et envoyé à validation');
} elseif ($form->has('saveAndPublished') && $form->get('saveAndPublished')->isClicked()) {
$this->quizWorkflow->apply($quiz, 'publish');
$quiz->setIsPublished(true);
$this->addFlash('quiz_added_and_published', 'Quiz créé et publié');
} else {
$message = 'Quiz crée';
if ($quiz->isIsPublished()) $message .= ' et publié';
$this->addFlash('quiz_added', $message);
}
$quizRepository->add($quiz, true);
$modules = $quiz->getModules();
foreach ($modules as $module) {
$moduleItem = new ModuleItem();
$moduleItem->setModule($module);
$moduleItem->setQuiz($quiz);
$moduleItem->setType('quiz');
$moduleItemRepository->add($moduleItem, true);
}
} catch (LogicException $exception) {
$this->addFlash('quiz_no_sent_to_review', "Erreur survenue lors de l'envoie du quiz à la validation. Veuillez contacter l'administrateur");
}
return $this->redirectToRoute('app_front_quiz_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/quiz/create_quiz.html.twig', [
'quiz' => $quiz,
'form' => $form,
'profil' => $profil,
]);
}
/**
* @Route("/{profil}/cours", name="app_front_course_page")
*/
public function coursePage(Request $request, CourseRepository $courseRepository, String $profil = null): Response
{
// $userRole = $this->getUserActivedRole($profil);
// if ($userRole === null) throw $this->createNotFoundException("La page demandée n'existe pas");
$session = $request->getSession();
if ($request->query->get('page') === null) $session->remove('course_search_key');
$course = new Course();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
// Search form
$searchKey = $session->has('course_search_key') ? $session->get('course_search_key') : null;
$form = $this->createFormBuilder()
->add('searchKey', TextType::class, [
'label' => 'Rechercher: ',
'label_attr' => ['class' => 'text-grey'],
'attr' => [
'style' => 'border: 1px solid transparent !important'
],
'required' => false,
'data' => $session->has('course_search_key') ? $session->get('course_search_key') : ''
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchKey = $form->get('searchKey')->getData();
$session->remove('course_search_key');
if ($searchKey !== null) $session->set('course_search_key', $searchKey);
}
$courses = $courseRepository->findCourses($this->getUser(), $page, Constants::PAGINATION_LIMIT, $searchKey);
$totalCourse = $courseRepository->findCourses($this->getUser(), null, null, $searchKey);
// $totalCourse = $courseRepository->getTotalCourse($this->getUser());
return $this->renderForm('front/pages/dashboard/courses/courses.html.twig', [
'course' => $course,
'courses' => $courses,
'totalCourse' => $totalCourse,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'form' => $form
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR') or is_granted('ROLE_COACH')")
*
* @Route("/{profil}/cours/creer-un-cours", name="app_front_create_course_page")
*/
public function createCourse(Request $request, CourseRepository $courseRepository, ModuleItemRepository $moduleItemRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR') && !$this->isGranted('ROLE_COACH')) throw $this->createNotFoundException("La page demandée n'existe pas");
$course = new Course();
$form = $this->createForm(CourseType::class, $course);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
if ($form->has('saveAndSentToReview') && $form->get('saveAndSentToReview')->isClicked()) {
$this->courseWorkflow->apply($course, 'to_review');
$this->addFlash('course_added_and_sent_to_review', 'Cours créé et envoyé à validation');
} elseif ($form->has('saveAndPublished') && $form->get('saveAndPublished')->isClicked()) {
$this->courseWorkflow->apply($course, 'publish');
$course->setIsPublished(true);
$this->addFlash('course_added_and_published', 'Cours créé et publié');
} else {
$message = 'Cours crée';
if ($course->isIsPublished()) $message .= ' et publié';
$this->addFlash('course_added', $message);
}
$courseRepository->add($course, true);
$modules = $course->getModules();
foreach ($modules as $module) {
$moduleItem = new ModuleItem();
$moduleItem->setModule($module);
$moduleItem->setCourse($course);
$moduleItem->setType('course');
$moduleItemRepository->add($moduleItem, true);
}
} catch (LogicException $exception) {
$this->addFlash('course_no_sent_to_review', "Erreur survenue lors de l'envoie du cours à la validation. Veuillez contacter l'administrateur");
}
return $this->redirectToRoute('app_front_course_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/courses/create_course.html.twig', [
'course' => $course,
'form' => $form,
'profil' => $profil,
]);
}
/**
* @Route("/{profil}/lives", name="app_dashboard_live_page")
*/
public function livePage(Request $request, LiveRepository $liveRepository, String $profil = null): Response
{
$session = $request->getSession();
if ($request->query->get('page') === null) $session->remove('live_search_key');
$userRole = $this->getUserActivedRole($profil);
if ($userRole === null) throw $this->createNotFoundException("La page demandée n'existe pas");
$live = new Live();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
// Search form
$searchKey = $session->has('live_search_key') ? $session->get('live_search_key') : null;
$form = $this->createFormBuilder()
->add('searchKey', TextType::class, [
'label' => 'Rechercher: ',
'label_attr' => ['class' => 'text-grey'],
'attr' => [
'style' => 'border: 1px solid transparent !important'
],
'required' => false,
'data' => $session->has('live_search_key') ? $session->get('live_search_key') : ''
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchKey = $form->get('searchKey')->getData();
$session->remove('live_search_key');
if ($searchKey !== null) $session->set('live_search_key', $searchKey);
}
$lives = $liveRepository->findLives($this->getUser(), $page, Constants::PAGINATION_LIMIT, $searchKey);
$totalLive = $liveRepository->findLives($this->getUser(), null, null, $searchKey);
// $totalLive = $liveRepository->getTotalLive($this->getUser(), $userRole);
foreach($lives as $live) {
$records = $live->getLiveRecords();
foreach($records as $record) {
if(!$record->isIsAlreadyDownloaded()) {
$live->removeLiveRecord($record);
}
}
}
return $this->renderForm('front/pages/dashboard/lives/lives.html.twig', [
'live' => $live,
'lives' => $lives,
'totalLive' => $totalLive,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'form' => $form
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR') or is_granted('ROLE_COACH')")
*
* @Route("/{profil}/lives/creer-un-live", name="app_front_create_live_page")
*/
public function createLive(Request $request, LiveRepository $liveRepository, ModuleItemRepository $moduleItemRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR') && !$this->isGranted('ROLE_COACH')) throw $this->createNotFoundException("La page demandée n'existe pas");
$live = new Live();
$form = $this->createForm(LiveType::class, $live);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
if ($form->has('saveAndSentToReview') && $form->get('saveAndSentToReview')->isClicked()) {
$this->liveWorkflow->apply($live, 'to_review');
$this->addFlash('live_added_and_sent_to_review', 'Live créé et envoyé à validation');
} elseif ($form->has('saveAndPublished') && $form->get('saveAndPublished')->isClicked()) {
$this->liveWorkflow->apply($live, 'publish');
$live->setIsPublished(true);
$this->addFlash('live_added_and_published', 'Live créé et publié');
} else {
$message = 'Live crée';
if ($live->isIsPublished()) $message .= ' et publié';
$this->addFlash('live_added', $message);
}
if ($live->getTime() !== null) {
$hour = (int)$live->getTime()->format('H');
$minute = (int)$live->getTime()->format('i');
$second = (int)$live->getTime()->format('s');
$startDate = clone $live->getStartAt();
$endAt = $startDate->add(new DateInterval('PT'.$hour.'H'.$minute.'M'.$second.'S'));
$live->setEndAt($endAt);
}
$liveRepository->add($live, true);
$modules = $live->getModules();
foreach ($modules as $module) {
$moduleItem = new ModuleItem();
$moduleItem->setModule($module);
$moduleItem->setLive($live);
$moduleItem->setType('live');
$moduleItemRepository->add($moduleItem, true);
}
// /** @var DateTime $startAt */
// $startAt = $live->getStartAt();
// if ($startAt !== null && $live->isIsPublished()) {
// $interval = new DateInterval('PT' . Constants::TIME_BEFORE_LIVE_SESSION_STARTING . 'M');
// $notificationDateBeforeLiveStarting = clone $startAt;
// $notificationDateBeforeLiveStarting->sub($interval);
// $minutes = $notificationDateBeforeLiveStarting->format('i');
// $hour = $notificationDateBeforeLiveStarting->format('H');
// $atExpression = sprintf("%s:%s", $hour, $minutes);
// // /** @var User $user The user object */
// // $schedule = new \Zenstruck\ScheduleBundle\Schedule();
// // $schedule->addCommand('app:live-session-starting:notification '.$live->getId())
// // ->description('Send notification to live ('.$live->getTitle().') participants')
// // ->at($atExpression)
// // ;
// // /** @var \Zenstruck\ScheduleBundle\Schedule $this->schedule */
// // $this->schedule->addCommand('app:test-mail:sending')
// // ->description('Send mail test 2.')
// // ->everyMinute()
// // ;
// }
} catch (LogicException $exception) {
$this->addFlash('live_no_sent_to_review', "Erreur survenue lors de l'envoie du live à la validation. Veuillez contacter l'administrateur");
}
return $this->redirectToRoute('app_dashboard_live_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
// return $this->redirectToRoute('app_front_lives_page', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/lives/create_live.html.twig', [
'live' => $live,
'form' => $form,
'profil' => $profil
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR')")
*
* @Route("/{profil}/parametre/citations", name="app_front_quote_page")
*/
public function quotePage(Request $request, QuoteRepository $quoteRepository, String $profil): Response
{
$quote = new Quote();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
$quotes = $quoteRepository->findPaginateQuote($page, Constants::PAGINATION_LIMIT);
$totalQuote = $quoteRepository->getTotalQuote();
return $this->renderForm('front/pages/dashboard/quotes/quotes.html.twig', [
'quote' => $quote,
'quotes' => $quotes,
'totalQuote' => $totalQuote,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
]);
}
/**
* @Security("is_granted('ROLE_ADMIN')")
*
* @Route("/{profil}/parametre/creer-une-citation", name="app_front_create_quote_page")
*/
public function createQuote(Request $request, QuoteRepository $quoteRepository, String $profil): Response
{
if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR')) throw $this->createNotFoundException("La page demandée n'existe pas");
$quote = new Quote();
$form = $this->createForm(QuoteType::class, $quote);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$quoteRepository->add($quote, true);
return $this->redirectToRoute('app_front_quote_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/quotes/create_quote.html.twig', [
'quote' => $quote,
'form' => $form,
]);
}
/**
* @Security("is_granted('ROLE_ADMIN')")
*
* @Route("/{profil}/parametre/ajouter-un-mot-du-directeur", name="app_front_create_director_page")
*/
public function createDirectorWord(Request $request, DirectorRepository $directorRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR')) throw $this->createNotFoundException("La page demandée n'existe pas");
$director = new Director();
$form = $this->createForm(DirectorType::class, $director);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$directorRepository->add($director, true);
return $this->redirectToRoute('app_front_director_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/directors/create_director.html.twig', [
'director' => $director,
'form' => $form,
'profil' => $profil
]);
}
/**
* @Security("is_granted('ROLE_ADMIN')")
*
* @Route("/{profil}/parametre/mots-du-directeur", name="app_front_director_page")
*/
public function directorPage(Request $request, DirectorRepository $directorRepository, String $profil): Response
{
$director = new Director();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
$directors = $directorRepository->findPaginateDirector($page, Constants::PAGINATION_LIMIT);
$totalDirector = $directorRepository->getTotalDirector();
return $this->renderForm('front/pages/dashboard/directors/directors.html.twig', [
'director' => $director,
'directors' => $directors,
'totalDirector' => $totalDirector,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'profil' => $profil
]);
}
/**
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_INTEGRATOR')")
*
* @Route("/{profil}/parametre/module-vedettes", name="app_front_featured_module_page")
*/
public function featured(Request $request, FeaturedModuleRepository $featuredModuleRepository, String $profil): Response
{
$featuredModules = $featuredModuleRepository->findBy([], ['id' => 'DESC'], 1, 0);
$featuredModule = (empty($featuredModules)) ? new FeaturedModule() : $featuredModules[0];
$form = $this->createForm(FeaturedModuleType::class, $featuredModule);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$featuredModuleRepository->add($featuredModule, true);
return $this->redirectToRoute('app_front_featured_module_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/modules/featured_module.html.twig', [
'featured_module' => $featuredModule,
'form' => $form,
]);
}
/**
* @Route("/job/offices/{id}", name="job_offices")
* @param Request $request
* @param Job $job
* @return JsonResponse
*/
public function jobOffice(Request $request, Job $job)
{
$output = [];
if ($job !== null) {
$offices = $job->getOffices();
foreach ($offices as $key => $office) {
$output[] = [
'id' => $office->getId(),
'name' => $office->getName()
];
}
}
return $this->json($output);
}
/**
* @Route("/job/offices", name="jobs_offices")
* @param Request $request
* @return JsonResponse
*/
public function jobsOffice(Request $request, OfficeRepository $officeRepository)
{
$output = [];
$ids = $request->get('ids');
if ($ids !== null && !empty($ids)) {
$offices = $officeRepository->findOffices($ids);
foreach ($offices as $key => $office) {
$output[] = [
'id' => $office->getId(),
'text' => $office->getName()
];
}
}
return $this->json($output);
}
public function getUserActivedRole(String $profil = null): String
{
$userRoles = $this->skipDefaultRole($this->getUser()->getRoles());
if ($profil === null) {
$userRole = (!empty($userRoles)) ? $userRoles[0] : null;
} else $userRole = $this->getRoleByProfil($profil);
return $userRole;
}
/**
* @Route("/{profil}", name="app_front_dashboard_kpi_page")
*/
public function kpiPage(Request $request, UserRepository $userRepository, ProgramRepository $programRepository, ModuleRepository $moduleRepository, PaginatorInterface $paginator, String $profil): Response
{
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
if ($profil === 'apprenant') return $this->redirectToRoute('app_front_learner_dashboard_page');
$user = $this->getUser();
$programs = $programRepository->findPrograms($user);
$modules = $moduleRepository->findModules($user, true);
$program = null;
$module = null;
$session = $request->getSession();
// Filter form
$form = $this->createFormBuilder()
->add('program', EntityType::class, [
'class' => Program::class,
'label' => false,
'choice_label' => 'label',
'attr' => ['class' => 'form-select select-2-tags'],
'placeholder' => 'Choisir un programme',
'required' => false,
'choices' => $programs,
])
->add('module', EntityType::class, [
'class' => Module::class,
'label' => false,
'choice_label' => 'name',
'attr' => ['class' => 'form-select select-2-tags'],
'placeholder' => 'Choisir un module',
'required' => false,
'choices' => $modules
])
->add('filter', SubmitType::class, [
'label' => 'Filtrer',
'attr' => ['class' => 'custom-dash-select shadow-sm bg-white']
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$program = $form->get('program')->getData();
$module = $form->get('module')->getData();
// if ($programData !== null) $session->set('__program', $programData->getId());
// if ($moduleData !== null) $session->set('__module', $moduleData->getId());
}
// dump($this->getCompletionRate($program, $module, null)); die;
$session->set('__profile', $profil);
$currentRole = $this->helperService->getUserCurrentRole();
// $learners = $userRepository->findLearners($page, Constants::PAGINATION_LIMIT, $this->getUser(), $current_role);
// $learnerWithCertificateCount = $userRepository->getLearnerWithCertificateCount();
// $learnerCount = $this->getLearnerCount();
// $learnerCount = count($userRepository->findLearners(null, null, $this->getUser(), $currentRole));
//$em = $this->getDoctrine()->getRepository('App\Entity\UserModuleParticipation');
//dd($em->getUserModuleItemCount());
$learners = $userRepository->findLearnersQuery($this->getUser(), $currentRole);
// $learnerCount = $userRepository->getLearnersCount($this->getUser(), $currentRole);
$pagination = $paginator->paginate(
$learners,
$page,
Constants::PAGINATION_LIMIT
);
return $this->render('front/pages/dashboard/kpi/index.html.twig', [
// 'learners' => $learners,
// 'total_learner' => $learnerCount,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'program' => $program,
'module' => $module,
//'user' => ($profil === 'integrateur' || $profil === 'administrateur') ? null : $this->getUser(),
'user' => $this->getUser(),
'programs' => $programs,
'modules' => $modules,
'form' => $form->createView(),
'current_role' => $currentRole,
'learners' => $pagination,
// 'success_rate' => ($learnerWithCertificateCount / $learnerCount) * 100,
]);
}
/**
* @Security("is_granted('ROLE_ADMIN')")
*
* @Route("/{profil}/parametre/creer-un-partenaire", name="app_front_create_partenaire_page")
*/
public function createPartenaire(Request $request, PartenaireRepository $partenaireRepository, String $profil): Response
{
// if (!$this->isGranted('ROLE_ADMIN') && !$this->isGranted('ROLE_INTEGRATOR')) throw $this->createNotFoundException("La page demandée n'existe pas");
$partenaire = new Partenaire();
$form = $this->createForm(PartenaireType::class, $partenaire);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$partenaireRepository->add($partenaire, true);
return $this->redirectToRoute('app_dashboard_partner_page', ['profil' => $profil], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('front/pages/dashboard/partenaires/create_partenaire.html.twig', [
'partenaire' => $partenaire,
'form' => $form,
'profil' => $profil
]);
}
/**
* @Security("is_granted('ROLE_ADMIN')")
*
* @Route("/{profil}/parametre/partenaires", name="app_dashboard_partner_page")
*/
public function partenairePage(Request $request, PartenaireRepository $partenaireRepository, String $profil): Response
{
$partenaire = new Partenaire();
$page = (int)$request->query->get('page', 1);
if ($page <= 0) throw $this->createNotFoundException("La page demandée n'existe pas");
$partenaires = $partenaireRepository->findPaginatePartenaire($page, Constants::PAGINATION_LIMIT);
$totalPartenaire = $partenaireRepository->getTotalPartenaire();
return $this->renderForm('front/pages/dashboard/partenaires/partenaires.html.twig', [
'partenaire' => $partenaire,
'partenaires' => $partenaires,
'totalPartenaire' => $totalPartenaire,
'limit' => Constants::PAGINATION_LIMIT,
'page' => $page,
'profil' => $profil
]);
}
/**
* @Route("/notification/as-read", name="notification_as_read")
* @param Request $request
* @return JsonResponse
*/
public function notificationStatus(NotificationRepository $notificationRepository, NotificationReceiverRepository $notificationReceiverRepository)
{
$notifications = $notificationRepository->findUnreadNotifications($this->getUser());
foreach ($notifications as $notification) {
$notification->setIsRead(true);
$notificationRepository->add($notification, true);
$notificationReceivers = $notification->getNotificationReceivers();
foreach ($notificationReceivers as $notificationReceiver) {
$notificationReceiver->setIsRead(true);
$notificationReceiverRepository->add($notificationReceiver, true);
}
}
return $this->json(['OK']);
}
/**
* @Route("/apprenant/notifications", name="app_get_user_notifications")
*/
public function getNotifications(Request $request, NotificationRepository $notificationRepository, SerializerInterface $serializer): Response
{
$notificationPage = (int)$request->query->get('notificationPage', 1);
$user = $this->getUser();
// $unreadNotifications = $notificationRepository->findUnreadNotifications($user, $notificationPage, Constants::PAGINATION_LIMIT);
$unreadNotificationCount = $notificationRepository->getUnreadNotificationCount($user);
// $notificationCount = $notificationRepository->findNotificationCount($user);
$notifications = $notificationRepository->findNotifications($user, $notificationPage, Constants::PAGINATION_LIMIT);
$context = new SerializationContext();
$context->setSerializeNull(true);
// $output = $serializer->serialize($notifications, 'json', $context);
//return $this->json(json_decode($output, true));
return $this->json(['unreadNotificationCount' => $unreadNotificationCount, 'html' => $this->render('front/layouts/partials/notifications-response.html.twig', ['notifications' => $notifications])->getContent()]);
// return $this->renderForm('front/layouts/partials/notifications-response.html.twig', ['notifications' => $notification]);
}
/**
* @Route("/apprenant/notifications/redirect/{id}", name="app_redirect_user_notifications")
*/
public function redirectNotification(Request $request, NotificationEntity $notification, NotificationRepository $notificationRepository, SubjectRepository $subjectRepository, ProgramRepository $programRepository, ModuleRepository $moduleRepository, CommentRepository $commentRepository): Response
{
if($notification->getObjectType() == 'program') {
return $this->redirectToRoute('app_front_program_module', ['id' => $notification->getObjectId()]);
} else if($notification->getObjectType() == 'subject') {
$subject = $subjectRepository->find($notification->getObjectId());
if($subject != null) {
return $this->redirectToRoute('app_front_forum_page', ['module_slug' => $subject->getModule()->getSlug(), 'subject_slug' => $subject->getSlug()]);
}
return $this->redirectToRoute('app_front_forum_charter_page');
} else if($notification->getObjectType() == 'module') {
$module = $moduleRepository->find($notification->getObjectId());
return $this->redirectToRoute('app_front_library_module_details_page', ['slug' => $module->getSlug()]);
} else if($notification->getObjectType() == 'comment') {
$comment = $commentRepository->find($notification->getObjectId());
if($comment != null) {
$subject = $comment->getSubject();
$url = $this->generateUrl('app_front_forum_page', ['module_slug' => $subject->getModule()->getSlug(), 'subject_slug' => $subject->getSlug()]);
if($notification->getComment()) {
$url .= '#comment-ref_'.$notification->getComment()->getId();
}
return $this->redirect($url);
}
} else if($notification->getObjectType() == 'live') {
$routeName = 'app_front_live_meet_page';
$parameters = ['id' => $notification->getObjectId()];
if ($notification->getModule() !== null) {
$module = $notification->getModule();
$routeName = 'app_front_live_module_meet_page';
$parameters['module_slug'] = $module->getSlug();
}
return $this->redirectToRoute($routeName, $parameters);
} else if($notification->getObjectType() == 'quiz') {
if ($notification->getModule() !== null) {
$module = $notification->getModule();
return $this->redirectToRoute('app_front_library_module_details_page', ['slug' => $module->getSlug()]);
}
} else if($notification->getObjectType() == 'quote') {
return $this->redirectToRoute('app_front_homepage');
}
return $this->redirectToRoute('app_front_learner_dashboard_page');
}
/**
* @Route("/v2", name="app_front_dashboard_v2_page")
*/
public function new_dash(): Response
{
return $this->render('front/pages/dashboard/new_dash.html.twig', [
'user' => $this->getUser()
]);
}
/**
* @Route("/apprenant/historique-notifications", name="app_front_dashboard_notification_page")
*/
public function notification(NotificationRepository $notificationRepository): Response
{
$unreadNotificationCount = $notificationRepository->getUnreadNotificationCount($this->getUser());
return $this->render('front/pages/dashboard/notification.html.twig', [
'unreadNotificationCount' => $unreadNotificationCount
]);
}
/**
* @Route("/{profil}/badges", name="app_front_dashboard_badge_block")
*/
public function badge(ModuleRepository $moduleRepository): Response
{
$terminatedModules = $moduleRepository->findTerminatedModules($this->getUser());
return $this->render('front/pages/dashboard/components/badge-block.html.twig', [
'terminated_modules' => $terminatedModules,
]);
}
}