<?php
namespace App\Controller\Admin;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Vich\UploaderBundle\Handler\DownloadHandler;
use App\Entity\Project;
use App\Entity\ProjectAttachment;
use App\Security\ProjectVoter;
/**
*
* @Route("/admin/project-attachment/", name="admin_project_attachment_")
* @author "wendell.zheng <wxzheng@ustc.edu.cn>"
*/
class ProjectAttachmentController extends AbstractController
{
/**
*
* @Route("list/{id}", name="list", requirements={"id"="\d+"})
*/
public function list(Project $project): Response
{
$this->denyAccessUnlessGranted(ProjectVoter::COLLEGE_VIEW, $project);
return $this->render('admin/project_attachment/list.html.twig', [
'title' => $project->getName() . ' - 附件列表',
'project' => $project,
'entities' => $project->getAttachments()
]);
}
/**
*
* @Route("download/{id}", name="download", requirements={"id"="\d+"})
*/
public function download(ProjectAttachment $attachment, DownloadHandler $downloadHandler): Response
{
$project = $attachment->getProject();
$this->denyAccessUnlessGranted(ProjectVoter::COLLEGE_VIEW, $project);
return $downloadHandler->downloadObject($attachment, 'attachment', null, $attachment->getDownloadName());
}
}