mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
add list by person, user and scope + formatting of submit button in edit
This commit is contained in:
@@ -18,6 +18,8 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\PersonBundle\Entity\PersonRepository;
|
||||
use Chill\MainBundle\Entity\UserRepository;
|
||||
|
||||
class SingleTaskController extends Controller
|
||||
{
|
||||
@@ -41,7 +43,7 @@ class SingleTaskController extends Controller
|
||||
->find($personId);
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Invalid person id");
|
||||
$this->createNotFoundException("Invalid person id");
|
||||
}
|
||||
|
||||
$task = (new SingleTask())
|
||||
@@ -280,44 +282,96 @@ class SingleTaskController extends Controller
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{_locale}/task/task/list/person/{personId}",
|
||||
* name="chill_task_task_list_by_person"
|
||||
* "/{_locale}/task/singletask/list",
|
||||
* name="chill_task_singletask_list"
|
||||
* )
|
||||
*/
|
||||
public function listAction(
|
||||
Request $request,
|
||||
Person $personId,
|
||||
PaginatorFactory $paginatorFactory,
|
||||
SingleTaskRepository $taskRepository
|
||||
Request $request,
|
||||
PaginatorFactory $paginatorFactory,
|
||||
SingleTaskRepository $taskRepository,
|
||||
PersonRepository $personRepository
|
||||
) {
|
||||
$person = $personId;
|
||||
/* @var $viewParams array The parameters for the view */
|
||||
$viewParams['person'] = $person;
|
||||
/* @var $params array The parameters for the query */
|
||||
|
||||
$viewParams['person'] = null;
|
||||
$params['person'] = null;
|
||||
$viewParams['user'] = null;
|
||||
$params['user'] = null;
|
||||
$viewParams['center'] = null;
|
||||
$params['center'] = null;
|
||||
|
||||
// Get parameters from url
|
||||
if ($request->query->has('person_id')) {
|
||||
$personId = $request->query->get('person_id');
|
||||
$person = $personRepository->find($personId);
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("This person ' $personId ' does not exist.");
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||
|
||||
$viewParams['person'] = $person;
|
||||
$params['person'] = $person;
|
||||
}
|
||||
|
||||
if ($request->query->has('user_id')) {
|
||||
|
||||
$userId = $request->query->get('user_id');
|
||||
$user = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->find($userId);
|
||||
|
||||
if ($user === null) {
|
||||
throw $this->createNotFoundException("This user ' $userId ' does not exist.");
|
||||
}
|
||||
|
||||
$viewParams['user'] = $user;
|
||||
$params['user'] = $user;
|
||||
}
|
||||
|
||||
if ($request->query->has('scope_id')) {
|
||||
|
||||
$scopeId = $request->query->get('scope_id');
|
||||
$scope = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillMainBundle:Scope')
|
||||
->find($scopeId);
|
||||
|
||||
if ($scope === null) {
|
||||
throw $this->createNotFoundException("This scope' $scopeId 'does not exist.");
|
||||
}
|
||||
|
||||
$viewParams['scope'] = $scope;
|
||||
$params['scope'] = $scope;
|
||||
}
|
||||
|
||||
// collect parameters for filter
|
||||
$params['person'] = $person;
|
||||
$possibleStatuses = \array_merge(SingleTaskRepository::DATE_STATUSES, [ 'closed' ]);
|
||||
$statuses = $request->query->get('status', $possibleStatuses);
|
||||
|
||||
|
||||
// check for invalid statuses
|
||||
$diff = \array_diff($statuses, $possibleStatuses);
|
||||
if (count($diff) > 0) {
|
||||
return new Response(
|
||||
'date_status not allowed: '. \implode(', ', $diff),
|
||||
'date_status not allowed: '. \implode(', ', $diff),
|
||||
Response::HTTP_BAD_REQUEST
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$viewParams['isSingleStatus'] = $singleStatus = count($statuses) === 1;
|
||||
|
||||
|
||||
foreach($statuses as $status) {
|
||||
if($request->query->has('status')
|
||||
if($request->query->has('status')
|
||||
&& FALSE === \in_array($status, $statuses)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// different query if regarding to date or 'closed'
|
||||
if (in_array($status, SingleTaskRepository::DATE_STATUSES)) {
|
||||
$params['date_status'] = $status;
|
||||
@@ -326,23 +380,30 @@ class SingleTaskController extends Controller
|
||||
$params['date_status'] = null;
|
||||
$params['is_closed'] = true;
|
||||
}
|
||||
|
||||
|
||||
$count = $taskRepository
|
||||
->countByParameters($params, $this->getUser())
|
||||
;
|
||||
$paginator = $paginatorFactory->create($count);
|
||||
|
||||
$viewParams['single_task_'.$status.'_count'] = $count;
|
||||
$viewParams['single_task_'.$status.'_paginator'] = $paginator;
|
||||
$viewParams['single_task_'.$status.'_tasks'] = $taskRepository
|
||||
->findByParameters($params, $this->getUser(),
|
||||
$singleStatus ? $paginator->getCurrentPage()->getFirstItemNumber() : 0,
|
||||
->findByParameters($params, $this->getUser(),
|
||||
$singleStatus ? $paginator->getCurrentPage()->getFirstItemNumber() : 0,
|
||||
$singleStatus ? $paginator->getItemsPerPage() : 10)
|
||||
;
|
||||
}
|
||||
|
||||
return $this->render('ChillTaskBundle:Task:index.html.twig', $viewParams);
|
||||
|
||||
if ($request->query->has('person_id')){
|
||||
$viewParams['layout'] = 'ChillPersonBundle::layout.html.twig';
|
||||
} else {
|
||||
$viewParams['layout'] = 'ChillMainBundle::layout.html.twig';
|
||||
}
|
||||
|
||||
return $this->render('ChillTaskBundle:SingleTask:index.html.twig', $viewParams);
|
||||
}
|
||||
|
||||
|
||||
protected function getPersonParam(Request $request, EntityManagerInterface $em)
|
||||
{
|
||||
$person = $em->getRepository(Person::class)
|
||||
@@ -358,7 +419,7 @@ class SingleTaskController extends Controller
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
|
||||
protected function getUserParam(Request $request, EntityManagerInterface $em)
|
||||
{
|
||||
$user = $em->getRepository(User::class)
|
||||
|
Reference in New Issue
Block a user