src/Controller/Super/BatchController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Super;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Entity\Batch;
  7. /**
  8.  *
  9.  * @Route("/super/batch/", name="super_batch_")
  10.  * @author "wendell.zheng <wxzheng@ustc.edu.cn>"
  11.  */
  12. class BatchController extends BaseController
  13. {
  14.     /**
  15.      *
  16.      * @Route("list", name="list")
  17.      */
  18.     public function list(): Response
  19.     {
  20.         return $this->doList();
  21.     }
  22.     /**
  23.      *
  24.      * @Route("new", name="new")
  25.      */
  26.     public function new(Request $request): Response
  27.     {
  28.         return $this->doEdit($request);
  29.     }
  30.     /**
  31.      *
  32.      * @Route("edit/{id}", name="edit", requirements={
  33.      * "id": "\d+"
  34.      * })
  35.      */
  36.     public function edit(Request $requestBatch $batch): Response
  37.     {
  38.         return $this->doEdit($request$batch);
  39.     }
  40.     /**
  41.      *
  42.      * @Route("delete/{id}", name="delete", requirements={
  43.      * "id": "\d+"
  44.      * })
  45.      */
  46.     public function delete(Batch $batch): Response
  47.     {
  48.         $items = [
  49.             'Notices' => '通知',
  50.         ];
  51.         $message "批次下有";
  52.         $error false;
  53.         foreach ($items as $type => $name) {
  54.             $method "get{$type}";
  55.             if (count($batch->$method())) {
  56.                 $message .= $name '、';
  57.                 $error true;
  58.             }
  59.         }
  60.         if ($error) {
  61.             $message rtrim($message'、');
  62.             $message .= "。需先删除!";
  63.             $this->addFlash('notice'$message);
  64.             return $this->redirectToRoute($this->getListRoute());
  65.         }
  66.         return $this->doDelete($batch);
  67.     }
  68. }