mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
83 lines
2.5 KiB
PHP
83 lines
2.5 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->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));
|
|
}
|
|
}
|