aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Feedback/FeedbackElementsShow.php
blob: 849e58a7ea9f2beed3627b81d3a7e240ed241345 (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
40
41
42
43
44
45
46
<?php

namespace JsonApi\Routes\Feedback;

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;
use JsonApi\Schemas\FeedbackElement as FeedbackElementSchema;

/**
 * Displays a certain feedback element.
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
class FeedbackElementsShow extends JsonApiController
{
    protected $allowedIncludePaths = [
        FeedbackElementSchema::REL_AUTHOR,
        FeedbackElementSchema::REL_COURSE,
        FeedbackElementSchema::REL_ENTRIES,
        FeedbackElementSchema::REL_RANGE,
    ];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     *
     * @param array $args
     *
     * @return Response
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        $resource = \FeedbackElement::find($args['id']);
        if (!$resource) {
            throw new RecordNotFoundException();
        }

        if (!Authority::canShowFeedbackElement($this->getUser($request), $resource)) {
            throw new AuthorizationFailedException();
        }

        return $this->getContentResponse($resource);
    }
}