Skip to content
Snippets Groups Projects
Select Git revision
  • 54ff6f772744517a56528528ca35f9cb7d7af043
  • main default protected
  • v0.2.0
  • v0.1.4
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
8 results

GetCoursesByPerson.php

Blame
  • user avatar
    Tobias Gross-Vogt authored
    54ff6f77
    History
    GetCoursesByPerson.php 1.18 KiB
    <?php
    
    declare(strict_types=1);
    
    namespace Dbp\Relay\CourseBundle\Controller;
    
    use ApiPlatform\Core\DataProvider\PaginatorInterface;
    use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator;
    use Dbp\Relay\CourseBundle\API\CourseProviderInterface;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\HttpFoundation\Request;
    
    class GetCoursesByPerson extends AbstractController
    {
        public const ITEMS_PER_PAGE = 250;
    
        protected $coursesProvider;
    
        public function __construct(CourseProviderInterface $coursesProvider)
        {
            $this->coursesProvider = $coursesProvider;
        }
    
        public function __invoke(string $id, Request $request): PaginatorInterface
        {
            $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
    
            $page = (int) $request->query->get('page', 1);
            $perPage = (int) $request->query->get('perPage', self::ITEMS_PER_PAGE);
    
            $options = [];
            if ($request->query->has('lang')) {
                $options['lang'] = (string) $request->query->get('lang');
            }
    
            $courses = $this->coursesProvider->getCoursesByPerson($id, $options);
    
            return new ArrayFullPaginator($courses, $page, $perPage);
        }
    }