aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Mvv/VersionsByCourseOfStudyComponentsIndex.php
blob: 9d321b9789e3677a286b3d8a80a3344d168f098d (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
<?php

namespace JsonApi\Routes\Mvv;

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

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

    protected $allowedIncludePaths = [
        ComponentVersion::REL_SECTIONS,
        ComponentVersion::REL_START_SEMESTER,
        ComponentVersion::REL_END_SEMESTER,
    ];

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

        return $this->getPaginatedContentResponse(
            $component->versionen->limit($offset, $limit),
            count($component->versionen)
        );
    }
}