mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\CalendarBundle\Controller;
|
|
|
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use function count;
|
|
|
|
class CalendarRangeAPIController extends ApiController
|
|
{
|
|
/**
|
|
* @Route("/api/1.0/calendar/calendar-range-available.{_format}", name="chill_api_single_calendar_range_available")
|
|
*/
|
|
public function availableRanges(Request $request, string $_format): JsonResponse
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$sql = 'SELECT c FROM ChillCalendarBundle:CalendarRange c
|
|
WHERE NOT EXISTS (SELECT cal.id FROM ChillCalendarBundle:Calendar cal WHERE cal.calendarRange = c.id)';
|
|
|
|
if ($request->query->has('user')) {
|
|
$user = $request->query->get('user');
|
|
$sql = $sql . ' AND c.user = :user';
|
|
$query = $em->createQuery($sql)
|
|
->setParameter('user', $user);
|
|
} else {
|
|
$query = $em->createQuery($sql);
|
|
}
|
|
|
|
$results = $query->getResult();
|
|
|
|
return $this->json(['count' => count($results), 'results' => $results], Response::HTTP_OK, [], ['groups' => ['read']]);
|
|
//TODO use also the paginator, eg return $this->serializeCollection('get', $request, $_format, $paginator, $results);
|
|
}
|
|
}
|