src/Controller/Applicant/ItemController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Applicant;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use App\Util\EntityUtil;
  8. /**
  9.  *
  10.  * @author "wendell.zheng <wxzheng@ustc.edu.cn>"
  11.  */
  12. class ItemController extends AbstractController
  13. {
  14.     const COMMON_TYPES = [
  15.         'research',
  16.         'politics',
  17.         'other',
  18.         'book',
  19.         'achievement',
  20.         'excellent_book',
  21.         'hospital'
  22.     ];
  23.     /**
  24.      *
  25.      * @Route("/applicant/items/{type}", name="applicant_items")
  26.      */
  27.     public function index($type 'research'EntityManagerInterface $em): Response
  28.     {
  29.         $name 'Item' EntityUtil::camel($type);
  30.         $entityName EntityUtil::getEntityClassName($name);
  31.         $re $em->getRepository($entityName);
  32.         $reflectClass = new \ReflectionClass($entityName);
  33.         $titles $reflectClass->getConstant('TITLES');
  34.         $columns $reflectClass->getConstant('COLUMNS');
  35.         if (in_array($typeself::COMMON_TYPES)) {
  36.             $js 'applicant_item_common';
  37.         } else {
  38.             $js 'applicant_item_' $type;
  39.         }
  40.         return $this->render('applicant/item/index.html.twig', [
  41.             'current' => $type,
  42.             'items' => $re->findAll(),
  43.             'titles' => $titles,
  44.             'columns' => $columns,
  45.             'js' => $js
  46.         ]);
  47.     }
  48. }