mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
65 lines
2.0 KiB
PHP
65 lines
2.0 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;
|
|
|
|
|
|
class TaskController extends Controller
|
|
{
|
|
public function applyTransitionAction(
|
|
$type,
|
|
$taskId,
|
|
$transition,
|
|
SingleTaskRepository $singleTaskRepository,
|
|
Registry $registry,
|
|
EntityManagerInterface $em,
|
|
Request $request
|
|
) {
|
|
switch ($type) {
|
|
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 '$type' 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($task, TaskVoter::SHOW);
|
|
|
|
$workflow = $registry->get($task);
|
|
|
|
if ($workflow->can($task, $transition)) {
|
|
$workflow->apply($task, $transition);
|
|
|
|
$em->flush();
|
|
|
|
$this->addFlash('success', 'The transition is sucessfully applyed');
|
|
|
|
} else {
|
|
$this->addFlash('error', 'The transition could not be applyed');
|
|
}
|
|
|
|
return $this->redirect($request->query->get('return_path', $defaultReturnPath));
|
|
}
|
|
}
|