<?php
namespace App\Controller\Super;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Notice;
use App\Entity\NoticeAttachment;
use App\Form\AttachmentType;
/**
*
* @Route("/super/notice-attachment/", name="super_notice_attachment_")
* @author "wendell.zheng <wxzheng@ustc.edu.cn>"
*/
class NoticeAttachmentController extends BaseController
{
/**
*
* @Route("list/{id}", name="list", requirements={"id"="\d+"})
*/
public function list(Notice $notice): Response
{
return $this->render('super/notice_attachment/list.html.twig', [
'name' => $this->getLowerName(),
'title' => $notice->getName() . ' - 附件列表',
'notice' => $notice,
'entities' => $notice->getAttachments()
]);
}
/**
*
* @Route("new/{id}", name="new", requirements={"id"="\d+"})
*/
public function new(Notice $notice, Request $request): Response
{
$attachment = new NoticeAttachment();
$attachment->setNotice($notice);
$form = $this->createForm(AttachmentType::class, $attachment);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($attachment);
$this->em->flush();
$this->addFlash('notice', '操作成功');
return $this->redirectToRoute($this->getListRoute(), [
'id' => $notice->getId()
]);
}
return $this->render('super/notice_attachment/edit.html.twig', [
'name' => $this->getLowerName(),
'title' => $notice->getName() . ' - 新建附件',
'notice' => $notice,
'form' => $form->createView()
]);
}
/**
*
* @Route("delete/{id}", name="delete", requirements={"id"="\d+"})
*/
public function delete(NoticeAttachment $attachment): Response
{
return $this->doDelete($attachment, 'super_notice_attachment_list', [
'id' => $attachment->getNotice()
->getId()
]);
}
}