improve task list

This commit is contained in:
2018-04-20 21:55:56 +02:00
parent 9dfa39ff07
commit 196fc2c38f
4 changed files with 250 additions and 91 deletions

View File

@@ -9,29 +9,68 @@ use Chill\PersonBundle\Entity\Person;
use Chill\TaskBundle\Entity\SingleTask;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Symfony\Component\HttpFoundation\Response;
class TaskController extends Controller
{
/**
* @Route("/{_locale}/task/task/list/{personId}")
* @Route(
* "/{_locale}/task/task/list/{personId}",
* name="chill_task_task_list"
* )
*/
public function listAction(Request $request, Person $personId)
{
$person = $personId;
$em = $this->getDoctrine()
->getManager();
// collect parameters for filter
$params = [];
/* @var $taskRepository SingleTaskRepository */
$taskRepository = $this->get('chill_task.single_task_repository');
/* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory */
$paginatorFactory = $this->get('chill_main.paginator_factory');
/* @var $viewParams array The parameters for the view */
$viewParams['person'] = $person;
// collect parameters for filter
$params['person'] = $person;
$singleTasks = $this->get('chill_task.single_task_repository')
->findByParameters($params, $this->getUser());
if ($request->query->has('date_status')) {
$statuses = $request->query->get('date_status');
$singleStatus = count($statuses) === 1;
// check for invalid parameters
$diff = \array_diff(
$statuses,
SingleTaskRepository::DATE_STATUSES)
;
if (count($diff) > 0) {
return new Response(
'date_status not allowed: '. \implode(', ', $diff),
Response::HTTP_BAD_REQUEST
);
}
}
foreach(SingleTaskRepository::DATE_STATUSES as $type) {
if($request->query->has('date_status')
&& FALSE === \in_array($type, $statuses ?? [])) {
continue;
}
$params['date_status'] = $type;
$count = $taskRepository
->countByParameters($params, $this->getUser())
;
$paginator = $paginatorFactory->create($count);
$viewParams['single_task_'.$type.'_count'] = $count;
$viewParams['single_task_'.$type.'_paginator'] = $paginator;
$viewParams['single_task_'.$type.'_tasks'] = $taskRepository
->findByParameters($params, $this->getUser(),
$singleStatus ? $paginator->getCurrentPage()->getFirstItemNumber() : 0,
$singleStatus ? $paginator->getItemsPerPage() : 10)
;
}
return $this->render('ChillTaskBundle:Task:index.html.twig', [
'single_tasks' => $singleTasks,
'person' => $person
]);
return $this->render('ChillTaskBundle:Task:index.html.twig', $viewParams);
}
protected function getPersonParam(Request $request, EntityManagerInterface $em)