src/Controller/Rest/CourseOccurrenceRestController.php line 71

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Rest;
  3. use App\Entity\CourseOccurrence;
  4. use App\Repository\CourseOccurrenceRepository;
  5. use FOS\RestBundle\Controller\Annotations\View;
  6. use Nelmio\ApiDocBundle\Annotation\Model;
  7. use Swagger\Annotations as SWG;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. /**
  11.  * @Route("/rest/course-occurrence")
  12.  */
  13. class CourseOccurrenceRestController extends AbstractRestController
  14. {
  15.     /**
  16.      * @Route("/", name="rest_course-occurrence", methods="GET")
  17.      * @SWG\Get(
  18.      *     produces={"application/json"},
  19.      * )
  20.      * @SWG\Response(
  21.      *     response=200,
  22.      *     description="Returns the courses for each available occurrence",
  23.      *     @Model(type=Course::class, groups={"public", "detail"})
  24.      * )
  25.      * @SWG\Tag(name="rest")
  26.      * @View(serializerGroups={"public", "detail"})
  27.      */
  28.     public function index(CourseOccurrenceRepository $courseOccurrenceRepository) {
  29.         $queryBuilder $courseOccurrenceRepository->getQueryBuilderByClient($this->getCurrentClient());
  30.         $queryBuilder->leftJoin('co.times''cot');
  31.         $queryBuilder->andWhere('cot.start > :startMin');
  32.         $queryBuilder->setParameter('startMin', new \DateTime());
  33.         $queryBuilder->andWhere('co.published = 1');
  34.           
  35.         $result $queryBuilder->getQuery()->getResult();
  36.         $list = [];
  37.         foreach ($result as $occurrence) {
  38.             $course $occurrence->getCourse();
  39.             $xcourse = clone $course;
  40.             $xcourse->setOccurrences(new ArrayCollection([$occurrence]));
  41.             $list[] = $xcourse;
  42.         }
  43.         return $list;
  44.     }
  45.     /**
  46.      * @Route("/{id}", name="rest_course-occurrence_show", methods="GET", requirements={"id"="\d+"})
  47.      * @SWG\Get(
  48.      *     produces={"application/json"},
  49.      * )
  50.      * @SWG\Parameter(name="id", in="path", required=true, type="integer")
  51.      * @SWG\Response(
  52.      *     response=200,
  53.      *     description="Returns the occurrence of given course id as json.",
  54.      *     @Model(type=CourseOccurrence::class, groups={"public", "detail"})
  55.      * )
  56.      * @SWG\Tag(name="rest")
  57.      * @View(serializerGroups={"public",  "detail"})
  58.      */
  59.     public function show(CourseOccurrence $courseOccurrence)
  60.     {
  61.         #$this->denyAccessUnlessGranted('frontend_client_allowed', $courseOccurrence);
  62.         return $courseOccurrence;
  63.     }
  64. }