src/Controller/DefaultController.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Vich\UploaderBundle\Handler\DownloadHandler;
  8. use App\Entity\AnnouncementAttachment;
  9. use App\Entity\NoticeAttachment;
  10. use App\Entity\Batch;
  11. use App\Entity\Announcement;
  12. use App\Entity\Notice;
  13. use App\Entity\ReviewBatch;
  14. /**
  15.  *
  16.  * @author "wendell.zheng <wxzheng@ustc.edu.cn>"
  17.  */
  18. class DefaultController extends AbstractController
  19. {
  20.     /**
  21.      *
  22.      * @Route("/", name="homepage")
  23.      */
  24.     public function homepage(EntityManagerInterface $em): Response
  25.     {
  26.         $batches $em->getRepository(Batch::class)->getCurrents();
  27.         $announcements $em->getRepository(Announcement::class)->last();
  28.         $currentReviewBatch $em->getRepository(ReviewBatch::class)->findOneByCurrent(true);
  29.         return $this->render('default/homepage.html.twig', [
  30.             'batches' => $batches,
  31.             'announcements' => $announcements,
  32.             'currentReviewBatch' => $currentReviewBatch
  33.         ]);
  34.     }
  35.     /**
  36.      *
  37.      * @Route("/announcement/{id}", name="announcement", requirements={"id"="\d+"})
  38.      */
  39.     public function announcement(Announcement $announcement): Response
  40.     {
  41.         return $this->render('default/announcement.html.twig', [
  42.             'announcement' => $announcement
  43.         ]);
  44.     }
  45.     /**
  46.      *
  47.      * @Route("/notice/{id}", name="notice", requirements={"id"="\d+"})
  48.      */
  49.     public function notice(Notice $notice): Response
  50.     {
  51.         return $this->render('default/notice.html.twig', [
  52.             'notice' => $notice
  53.         ]);
  54.     }
  55.     /**
  56.      *
  57.      * @Route("/announcement-attachment/download/{id}", name="announcement_attachment_download", requirements={"id"="\d+"})
  58.      */
  59.     public function announcementAttachmentDownload(AnnouncementAttachment $attachmentDownloadHandler $downloadHandler): Response
  60.     {
  61.         return $this->attachmentDownload($attachment$downloadHandler);
  62.     }
  63.     /**
  64.      *
  65.      * @Route("/notice-attachment/download/{id}", name="notice_attachment_download", requirements={"id"="\d+"})
  66.      */
  67.     public function noticeAttachmentDownload(NoticeAttachment $attachmentDownloadHandler $downloadHandler): Response
  68.     {
  69.         return $this->attachmentDownload($attachment$downloadHandler);
  70.     }
  71.     protected function attachmentDownload($attachmentDownloadHandler $downloadHandler): Response
  72.     {
  73.         return $downloadHandler->downloadObject($attachment'attachment'null$attachment->getDownloadName());
  74.     }
  75. }