src/Controller/Admin/ProjectAttachmentController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Vich\UploaderBundle\Handler\DownloadHandler;
  7. use App\Entity\Project;
  8. use App\Entity\ProjectAttachment;
  9. use App\Security\ProjectVoter;
  10. /**
  11.  *
  12.  * @Route("/admin/project-attachment/", name="admin_project_attachment_")
  13.  * @author "wendell.zheng <wxzheng@ustc.edu.cn>"
  14.  */
  15. class ProjectAttachmentController extends AbstractController
  16. {
  17.     /**
  18.      *
  19.      * @Route("list/{id}", name="list", requirements={"id"="\d+"})
  20.      */
  21.     public function list(Project $project): Response
  22.     {
  23.         $this->denyAccessUnlessGranted(ProjectVoter::COLLEGE_VIEW$project);
  24.         return $this->render('admin/project_attachment/list.html.twig', [
  25.             'title' => $project->getName() . ' - 附件列表',
  26.             'project' => $project,
  27.             'entities' => $project->getAttachments()
  28.         ]);
  29.     }
  30.     /**
  31.      *
  32.      * @Route("download/{id}", name="download", requirements={"id"="\d+"})
  33.      */
  34.     public function download(ProjectAttachment $attachmentDownloadHandler $downloadHandler): Response
  35.     {
  36.         $project $attachment->getProject();
  37.         $this->denyAccessUnlessGranted(ProjectVoter::COLLEGE_VIEW$project);
  38.         return $downloadHandler->downloadObject($attachment'attachment'null$attachment->getDownloadName());
  39.     }
  40. }