<?php
namespace App\Controller\Rest;
use App\Entity\CourseOccurrence;
use App\Repository\CourseOccurrenceRepository;
use FOS\RestBundle\Controller\Annotations\View;
use Nelmio\ApiDocBundle\Annotation\Model;
use Swagger\Annotations as SWG;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Route("/rest/course-occurrence")
*/
class CourseOccurrenceRestController extends AbstractRestController
{
/**
* @Route("/", name="rest_course-occurrence", methods="GET")
* @SWG\Get(
* produces={"application/json"},
* )
* @SWG\Response(
* response=200,
* description="Returns the courses for each available occurrence",
* @Model(type=Course::class, groups={"public", "detail"})
* )
* @SWG\Tag(name="rest")
* @View(serializerGroups={"public", "detail"})
*/
public function index(CourseOccurrenceRepository $courseOccurrenceRepository) {
$queryBuilder = $courseOccurrenceRepository->getQueryBuilderByClient($this->getCurrentClient());
$queryBuilder->leftJoin('co.times', 'cot');
$queryBuilder->andWhere('cot.start > :startMin');
$queryBuilder->setParameter('startMin', new \DateTime());
$queryBuilder->andWhere('co.published = 1');
$result = $queryBuilder->getQuery()->getResult();
$list = [];
foreach ($result as $occurrence) {
$course = $occurrence->getCourse();
$xcourse = clone $course;
$xcourse->setOccurrences(new ArrayCollection([$occurrence]));
$list[] = $xcourse;
}
return $list;
}
/**
* @Route("/{id}", name="rest_course-occurrence_show", methods="GET", requirements={"id"="\d+"})
* @SWG\Get(
* produces={"application/json"},
* )
* @SWG\Parameter(name="id", in="path", required=true, type="integer")
* @SWG\Response(
* response=200,
* description="Returns the occurrence of given course id as json.",
* @Model(type=CourseOccurrence::class, groups={"public", "detail"})
* )
* @SWG\Tag(name="rest")
* @View(serializerGroups={"public", "detail"})
*/
public function show(CourseOccurrence $courseOccurrence)
{
#$this->denyAccessUnlessGranted('frontend_client_allowed', $courseOccurrence);
return $courseOccurrence;
}
}