add list by person, user and scope + formatting of submit button in edit

This commit is contained in:
nobohan
2018-04-26 21:54:49 +02:00
parent 4b391d03d5
commit bf0db0de3f
7 changed files with 243 additions and 130 deletions

View File

@@ -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)

View File

@@ -16,12 +16,12 @@ class TaskController extends Controller
{
/**
* Apply a transition to a task
*
*
* @Route(
* "/{_locale}/task/transition/{kind}/{taskId}/{transition}",
* name="chill_task_task_transition"
* )
*
*
* @param string $kind
* @param int $taskId
* @param string $transition
@@ -32,7 +32,7 @@ class TaskController extends Controller
* @return Response
*/
public function applyTransitionAction(
$kind,
$kind,
$taskId,
$transition,
SingleTaskRepository $singleTaskRepository,
@@ -51,32 +51,32 @@ class TaskController extends Controller
);
break;
default:
return new Response("The type '$kind' is not implemented",
return new Response("The type '$kind' is not implemented",
Response::HTTP_BAD_REQUEST);
}
if (NULL === $task) {
$this->createHttpNotFoundException("task with id '$taskId' and type "
$this->createNotFoundException("task with id '$taskId' and type "
. "'$type' does not exists");
}
// we simply check that the user can see the task. Other ACL checks
// should be performed using `guard` events.
$this->denyAccessUnlessGranted(TaskVoter::SHOW, $task);
$workflow = $registry->get($task);
if ($workflow->can($task, $transition)) {
$workflow->apply($task, $transition);
$em->flush();
$this->addFlash('success', 'The transition is sucessfully appliyed');
} else {
$this->addFlash('error', 'The transition could not be appliyed');
}
return $this->redirect($request->query->get('return_path', $defaultReturnPath));
}
}