aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/StudyAreas/ParentOfStudyAreas.php
blob: e37d11080e0493f46322cd111a168f09a1347bc2 (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
<?php

namespace JsonApi\Routes\StudyAreas;

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

class ParentOfStudyAreas extends JsonApiController
{
    protected $allowedIncludePaths = [
        'children',
        'courses',
        'institute',
        'parent',
    ];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameters)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        if (!$studyArea = \StudipStudyArea::find($args['id'])) {
            throw new RecordNotFoundException();
        }

        return $this->getContentResponse($studyArea->getParent());
    }
}