<?php
namespace App\Controller\Applicant;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManagerInterface;
use App\Util\EntityUtil;
/**
*
* @author "wendell.zheng <wxzheng@ustc.edu.cn>"
*/
class ItemController extends AbstractController
{
const COMMON_TYPES = [
'research',
'politics',
'other',
'book',
'achievement',
'excellent_book',
'hospital'
];
/**
*
* @Route("/applicant/items/{type}", name="applicant_items")
*/
public function index($type = 'research', EntityManagerInterface $em): Response
{
$name = 'Item' . EntityUtil::camel($type);
$entityName = EntityUtil::getEntityClassName($name);
$re = $em->getRepository($entityName);
$reflectClass = new \ReflectionClass($entityName);
$titles = $reflectClass->getConstant('TITLES');
$columns = $reflectClass->getConstant('COLUMNS');
if (in_array($type, self::COMMON_TYPES)) {
$js = 'applicant_item_common';
} else {
$js = 'applicant_item_' . $type;
}
return $this->render('applicant/item/index.html.twig', [
'current' => $type,
'items' => $re->findAll(),
'titles' => $titles,
'columns' => $columns,
'js' => $js
]);
}
}