chill-bundles/Controller/TaskController.php
Julien Fastré eadaeaef35 add closed tasks
- the entity has a new column / property "closed" (boolean)
- An event listener in created during container compilation, which listen on tasks
  status changed
- The taskworkflow manager and task workflow definition indicate if the tasks is closed ;
- Add list for closed tasks in controller, and change parameter 'date_status' to 'status';
- and change query to allow to filter on closed tasks
2018-04-26 12:14:30 +02:00

83 lines
2.6 KiB
PHP

<?php
namespace Chill\TaskBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
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
* @param SingleTaskRepository $singleTaskRepository
* @param Registry $registry
* @param EntityManagerInterface $em
* @param Request $request
* @return Response
*/
public function applyTransitionAction(
$kind,
$taskId,
$transition,
SingleTaskRepository $singleTaskRepository,
Registry $registry,
EntityManagerInterface $em,
Request $request
) {
switch ($kind) {
case 'single-task':
$task = $singleTaskRepository
->find($taskId)
;
$defaultReturnPath = $this->generateUrl(
'chill_task_task_list_by_person',
[ 'personId' => $task->getPerson() ]
);
break;
default:
return new Response("The type '$kind' is not implemented",
Response::HTTP_BAD_REQUEST);
}
if (NULL === $task) {
$this->createHttpNotFoundException("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));
}
}