<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Vich\UploaderBundle\Handler\DownloadHandler;
use App\Entity\AnnouncementAttachment;
use App\Entity\NoticeAttachment;
use App\Entity\Batch;
use App\Entity\Announcement;
use App\Entity\Notice;
use App\Entity\ReviewBatch;
/**
*
* @author "wendell.zheng <wxzheng@ustc.edu.cn>"
*/
class DefaultController extends AbstractController
{
/**
*
* @Route("/", name="homepage")
*/
public function homepage(EntityManagerInterface $em): Response
{
$batches = $em->getRepository(Batch::class)->getCurrents();
$announcements = $em->getRepository(Announcement::class)->last();
$currentReviewBatch = $em->getRepository(ReviewBatch::class)->findOneByCurrent(true);
return $this->render('default/homepage.html.twig', [
'batches' => $batches,
'announcements' => $announcements,
'currentReviewBatch' => $currentReviewBatch
]);
}
/**
*
* @Route("/announcement/{id}", name="announcement", requirements={"id"="\d+"})
*/
public function announcement(Announcement $announcement): Response
{
return $this->render('default/announcement.html.twig', [
'announcement' => $announcement
]);
}
/**
*
* @Route("/notice/{id}", name="notice", requirements={"id"="\d+"})
*/
public function notice(Notice $notice): Response
{
return $this->render('default/notice.html.twig', [
'notice' => $notice
]);
}
/**
*
* @Route("/announcement-attachment/download/{id}", name="announcement_attachment_download", requirements={"id"="\d+"})
*/
public function announcementAttachmentDownload(AnnouncementAttachment $attachment, DownloadHandler $downloadHandler): Response
{
return $this->attachmentDownload($attachment, $downloadHandler);
}
/**
*
* @Route("/notice-attachment/download/{id}", name="notice_attachment_download", requirements={"id"="\d+"})
*/
public function noticeAttachmentDownload(NoticeAttachment $attachment, DownloadHandler $downloadHandler): Response
{
return $this->attachmentDownload($attachment, $downloadHandler);
}
protected function attachmentDownload($attachment, DownloadHandler $downloadHandler): Response
{
return $downloadHandler->downloadObject($attachment, 'attachment', null, $attachment->getDownloadName());
}
}