aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Mvv/ComponentsByCoursesOfStudyIndex.php
blob: 17fbdcfc0c53f04398f439ba0a69800db50fca2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

namespace JsonApi\Routes\Mvv;

use JsonApi\Schemas\CourseOfStudyComponent;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;

class ComponentsByCoursesOfStudyIndex extends JsonApiController
{
    protected $allowedPagingParameters = [
        'offset',
        'limit'
    ];

    protected $allowedIncludePaths = [
        CourseOfStudyComponent::REL_SUBJECT,
        CourseOfStudyComponent::REL_VERSIONS,
    ];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameters)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        $course_of_study = \Studiengang::find($args['id']);
        if (!$course_of_study) {
            throw new RecordNotFoundException();
        }
        [$offset, $limit] = $this->getOffsetAndLimit();

        return $this->getPaginatedContentResponse(
            $course_of_study->studiengangteile->limit($offset, $limit),
            count($course_of_study->studiengangteile)
        );
    }
}