src/HomeBundle/Controller/DefaultController.php line 35

Open in your IDE?
  1. <?php
  2. namespace HomeBundle\Controller;
  3. use CoreBundle\Entity\Branche;
  4. use CoreBundle\Entity\NewsFeed;
  5. use CoreBundle\Entity\NoteTest;
  6. use CoreBundle\Entity\NoteTestGroup;
  7. use CoreBundle\Entity\Periode;
  8. use CoreBundle\Entity\Post;
  9. use CoreBundle\Entity\Secteur;
  10. use CoreBundle\Entity\Tutor;
  11. use CoreBundle\Provider\DefaultValuesProvider;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use HomeBundle\Service\BoxImageByUser;
  14. use HomeBundle\Service\SchoolLifeBoxByUser;
  15. use QuestionnaireBundle\Service\QcmForStudent;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use CoreBundle\Entity\BoxText;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use CoreBundle\Entity\BoxImage;
  23. use CoreBundle\Entity\Student;
  24. use Symfony\Component\HttpFoundation\File\UploadedFile;
  25. use CoreBundle\S3;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. class DefaultController extends AbstractController
  28. {
  29.     /**
  30.      * @Route("/", name="app_home")
  31.      */
  32.     public function indexAction(
  33.         EntityManagerInterface $em,
  34.         DefaultValuesProvider $defaultValuesProvider,
  35.         BoxImageByUser $boxImageByUser,
  36.         SchoolLifeBoxByUser $schoolLifeBoxByUser,
  37.         QcmForStudent $qcmForStudent,
  38.     ) {
  39.         $user $this->getUser();
  40.         $periode $defaultValuesProvider->getPeriode();
  41.         // Emploi du temps
  42.         $boxImages $boxImageByUser->get();
  43.         // school life
  44.         $boxes $schoolLifeBoxByUser->get();
  45.         $forumUnreads $em->getRepository(NewsFeed::class)
  46.             ->getUnread($user'POST''-15days');
  47.         $qcmOnlineUnreads $em->getRepository(NewsFeed::class)
  48.             ->getUnread($user'QCM''-15days');
  49.         $documentUnreads $em->getRepository(NewsFeed::class)
  50.             ->getUnread($user'FILE''-15days');
  51.         $edtUnreads $em->getRepository(NewsFeed::class)
  52.             ->getUnread($user'EDT''-15days');
  53.         // qcm
  54.         $onlineQcms = [];
  55.         if ($user instanceof Student) {
  56.             $qcmForStudent->setSort('date''desc');
  57.             $onlineQcms $qcmForStudent->getOnlines();
  58.         }
  59.         if ($this->getUser()->getAdmin()) {
  60.             $branches $em->getRepository(Branche::class)
  61.                 ->findBy([], ['name' => 'asc']);
  62.         } elseif ($this->getUser() instanceof Student) {
  63.             $branches = [$this->getUser()->getBranche()];
  64.         } else {
  65.             $branches $em->getRepository(Branche::class)
  66.                 ->getByTutor($this->getUser());
  67.         }
  68.         $lastPosts $em->getRepository(Post::class)
  69.             ->getUserLastPosts($periode$this->getUser());
  70.         $openedTestGroups = [];
  71.         if ($this->getUser() instanceof Tutor) {
  72.             if ($this->getUser()->getAdmin()) {
  73.                 $openedTestGroups $em->getRepository(NoteTestGroup::class)
  74.                     ->getOpensByAdmin($this->getUser(), $periode);
  75.             } else {
  76.                 $openedTestGroups $em->getRepository(NoteTestGroup::class)
  77.                     ->getOpensByTutor($this->getUser(), $periode);
  78.             }
  79.         }
  80.         return $this->render('@HomeBundle/Default/index.html.twig', [
  81.             'branches' => $branches,
  82.             'boxImages' => $boxImages,
  83.             'boxes' => $boxes,
  84.             'lastPosts' => $lastPosts,
  85.             'openedTestGroups' => $openedTestGroups,
  86.             'onlineQcms' => $onlineQcms,
  87.             'forumUnreads' => $forumUnreads,
  88.             'qcmOnlineUnreads' => $qcmOnlineUnreads,
  89.             'documentUnreads' => $documentUnreads,
  90.             'edtUnreads' => $edtUnreads,
  91.         ]);
  92.     }
  93.     /**
  94.      * @Route("/text/{box_image_id}/{id}",
  95.      *      name="app_home_text",
  96.      *      requirements={"box_image_id": "\d+", "id": "\d+"},
  97.      *      defaults={"id": null},
  98.      *      options={"expose" : true})
  99.      * @ParamConverter("boxImage", options={"mapping"={"box_image_id": "id"}})
  100.      * @IsGranted("ROLE_ADMIN")
  101.      */
  102.     public function text(
  103.         EntityManagerInterface $em,
  104.         Request $request,
  105.         BoxImage $boxImage,
  106.         BoxText $boxText null
  107.     ) {
  108.         if (null === $boxText) {
  109.             $boxText = new BoxText();
  110.             $boxText->setBoxImage($boxImage);
  111.         }
  112.         $boxText->setContent($request->request->get('content'));
  113.         $em->persist($boxText);
  114.         $em->flush();
  115.         $formatter = new \IntlDateFormatter('fr'\IntlDateFormatter::FULL\IntlDateFormatter::SHORT);
  116.         return new JsonResponse([
  117.             'code' => 'success',
  118.             'id' => $boxText->getId(),
  119.             'date' => $formatter->format(new \DateTime())
  120.         ]);
  121.     }
  122.     /**
  123.      * @Route("/delete-text-box/{id}", name="app_home_delete_text_box", options={"expose" : true})
  124.      * @IsGranted("ROLE_ADMIN")
  125.      */
  126.     public function delTextBox(EntityManagerInterface $emBoxText $boxText)
  127.     {
  128.         $em->remove($boxText);
  129.         $em->flush();
  130.         return new JsonResponse(['code' => "success"]);
  131.     }
  132. }