src/Controller/AdminApiController.php line 79

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Action;
  4. use App\Entity\ActionComment;
  5. use App\Entity\OrganizationUnit;
  6. use App\Repository\EventRepository;
  7. use FOS\RestBundle\Controller\AbstractFOSRestController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Serializer\SerializerInterface;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  13. /**
  14.  * @Route("/aapi")
  15.  * @Security("is_granted('ROLE_USER')")
  16.  */
  17. class AdminApiController extends AbstractFOSRestController
  18. {
  19.     /**
  20.      * @Route("/action/{id}/comment/list", name="api_admin_action_comment_new_n_list", methods={"POST"})
  21.      * @Security("is_granted('ROLE_USER')")
  22.      */
  23.     public function newNList(Request $requestAction $actionSerializerInterface $serializer): Response
  24.     {
  25.         if ($request->request->get('content')) {
  26.             $comment = new ActionComment();
  27.             $comment->setContent($request->request->get('content'));
  28.             $action->addComment($comment);
  29.             $this->getDoctrine()->getManager()->persist($action);
  30.             $this->getDoctrine()->getManager()->flush();
  31.         }
  32.         return new Response(
  33.             $serializer->serialize(
  34.                 $action->getComments(),
  35.                 'json',
  36.                 ['groups'=>['aapi','crLog']]
  37.             ),
  38.             RESPONSE::HTTP_OK
  39.         );
  40.     }
  41.     /**
  42.      * @Route("/action/{id}/complete", name="api_admin_action_complete", methods={"POST"})
  43.      * @Security("is_granted('ROLE_USER')")
  44.      */
  45.     public function completeTask(Request $requestAction $action): Response
  46.     {
  47.         if ( $action->canClose($this->getUser()) || $this->getUser()->hasRole('ROLE_ACTION_ADMIN')) {
  48.             $action->setCompleted(true);
  49.             $this->getDoctrine()->getManager()->persist($action);
  50.             $this->getDoctrine()->getManager()->flush();
  51.         } else {
  52.             return new Response(
  53.                 json_encode([]),
  54.                 RESPONSE::HTTP_BAD_REQUEST
  55.             );
  56.         }
  57.         return new Response(
  58.             json_encode([
  59.                 'newState' => $action->getTaskState(),
  60.                 'aid' => $action->getId(),
  61.             ]),
  62.             RESPONSE::HTTP_OK
  63.         );
  64.     }
  65.    /**
  66.      * @Route("/tasks", name="api_admin_tasks_list", methods={"GET"})
  67.      * @Security("is_granted('ROLE_USER')")
  68.      */
  69.     public function taskList(Request $requestSerializerInterface $serializer): Response
  70.     {
  71.         $tasks $this->getDoctrine()->getRepository(Action::class)->userTasks($this->getUser());
  72.         return new Response(
  73.             $serializer->serialize(
  74.                 $tasks,
  75.                 'json',
  76.                 ['groups'=>['aapi','crLog']]
  77.             ),
  78.             RESPONSE::HTTP_OK
  79.         );
  80.     }
  81.     /**
  82.      * @Route("/ou/{id}/events", name="api_admin_ou_events_list", methods={"GET"})
  83.      * @Security("is_granted('ROLE_EVENT_VENUE')")
  84.      */
  85.     public function eventsList(Request $requestSerializerInterface $serializerOrganizationUnit $ouEventRepository $er): Response
  86.     {
  87.         $qb=$er->createQueryBuilder('e')
  88.             ->where('e.organizationUnit = :ou' )
  89.             ->andWhere('e.date>=:start')
  90.             ->setParameter'ou'$ou )
  91.             ->setParameter'start', new \DateTime() )
  92.             ->orderBy('e.date''ASC');
  93.         return new Response(
  94.             $serializer->serialize(
  95.                 $qb->getQuery()->getResult(),
  96.                 'json',
  97.                 ['groups'=>['aapi']]
  98.             ),
  99.             RESPONSE::HTTP_OK
  100.         );
  101.     }
  102. }