mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
action: confirm accompanying period + create workflow
This commit is contained in:
@@ -5,7 +5,6 @@ namespace Chill\PersonBundle\Controller;
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
@@ -18,6 +17,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
|
||||
class AccompanyingCourseApiController extends ApiController
|
||||
{
|
||||
@@ -25,10 +25,37 @@ class AccompanyingCourseApiController extends ApiController
|
||||
|
||||
protected ValidatorInterface $validator;
|
||||
|
||||
public function __construct(EventDispatcherInterface $eventDispatcher, $validator)
|
||||
{
|
||||
private Registry $registry;
|
||||
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
ValidatorInterface $validator,
|
||||
Registry $registry
|
||||
) {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->validator = $validator;
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function confirmApi($id, Request $request, $_format): Response
|
||||
{
|
||||
/** @var AccompanyingPeriod $accompanyingPeriod */
|
||||
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
||||
|
||||
$this->checkACL('confirm', $request, $_format, $accompanyingPeriod);
|
||||
$workflow = $this->registry->get($accompanyingPeriod);
|
||||
|
||||
if (FALSE === $workflow->can($accompanyingPeriod, 'confirm')) {
|
||||
throw new BadRequestException('It is not possible to confirm this period');
|
||||
}
|
||||
|
||||
$workflow->apply($accompanyingPeriod, 'confirm');
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->json($accompanyingPeriod, Response::HTTP_OK, [], [
|
||||
'groups' => [ 'read' ]
|
||||
]);
|
||||
}
|
||||
|
||||
public function participationApi($id, Request $request, $_format)
|
||||
|
Reference in New Issue
Block a user