add logic to filter tasks

This commit is contained in:
2018-05-07 22:06:34 +02:00
parent 38cc4f84c4
commit b856647b04
7 changed files with 144 additions and 90 deletions

View File

@@ -25,6 +25,7 @@ use Chill\TaskBundle\Event\TaskEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Translation\TranslatorInterface;
class SingleTaskController extends Controller
{
@@ -329,7 +330,8 @@ class SingleTaskController extends Controller
Request $request,
PaginatorFactory $paginatorFactory,
SingleTaskRepository $taskRepository,
PersonRepository $personRepository
PersonRepository $personRepository,
FormFactoryInterface $formFactory
) {
/* @var $viewParams array The parameters for the view */
/* @var $params array The parameters for the query */
@@ -340,10 +342,10 @@ class SingleTaskController extends Controller
$params['user'] = null;
$viewParams['center'] = null;
$params['center'] = null;
// Get parameters from url
if ($request->query->has('person_id')) {
$personId = $request->query->getInt('person_id', null);
if (!empty($request->query->get('person_id', NULL))) {
$personId = $request->query->getInt('person_id');
$person = $personRepository->find($personId);
if ($person === null) {
@@ -437,74 +439,22 @@ class SingleTaskController extends Controller
// total number of tasks
$viewParams['tasks_count'] = $tasks_count;
if ($request->query->has('person_id')){
if ($viewParams['person'] !== null){
$viewParams['layout'] = 'ChillPersonBundle::layout.html.twig';
} else {
$viewParams['layout'] = 'ChillMainBundle::layout.html.twig';
}
// Form for filtering tasks
$form = $this->createForm(SingleTaskListType::class, null, [
//'center' => $task->getCenter()
$form = $formFactory->createNamed(null, SingleTaskListType::class, null, [
'method' => Request::METHOD_GET,
'csrf_protection' => false
]);
$form->add('submit', SubmitType::class);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$formData = $form->getData();
$status = $statuses[$formData['status']];
$viewParamsForm['user'] = $formData['user'];
$viewParamsForm['isSingleStatus'] = $singleStatus = count($statuses) === 1;
// herit some parameters from the page
$viewParamsForm['person'] = $viewParams['person'];
$viewParamsForm['layout'] = $viewParams['layout'];
// different query if regarding to date or 'closed'
if (in_array($status, SingleTaskRepository::DATE_STATUSES)) {
$params['date_status'] = $status;
$params['is_closed'] = false;
} else {
$params['date_status'] = null;
$params['is_closed'] = true;
}
$count = $taskRepository
->countByParameters($params, $formData['user'])
;
$paginator = $paginatorFactory->create($count);
$viewParamsForm['single_task_'.$status.'_count'] = $count;
$viewParamsForm['single_task_'.$status.'_paginator'] = $paginator;
$viewParamsForm['single_task_'.$status.'_tasks'] = $taskRepository
->findByParameters($params, $formData['user'],
$singleStatus ? $paginator->getCurrentPage()->getFirstItemNumber() : 0,
$singleStatus ? $paginator->getItemsPerPage() : 10)
;
// total number of tasks
$viewParamsForm['tasks_count'] = $count;
return $this->render('ChillTaskBundle:SingleTask:index.html.twig', array(
'view' => $viewParamsForm,
'form' => $form->createView()
));
} else {
$this->addFlash('error', "wrong test");
}
}
dump($viewParams);
return $this->render('ChillTaskBundle:SingleTask:index.html.twig', array(
'view' => $viewParams,
'form' => $form->createView()
));
return $this->render('ChillTaskBundle:SingleTask:index.html.twig',
\array_merge($viewParams, [ 'form' => $form->createView() ]));
}