aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Courseware/ContainersShow.php
blob: 0e061a235a1a1cb6b326965f3deb68a0d24e0bc1 (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
<?php

namespace JsonApi\Routes\Courseware;

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

/**
 * Displays one Container.
 */
class ContainersShow extends JsonApiController
{
    protected $allowedIncludePaths = [
        'blocks',
        'blocks.edit-blocker',
        'blocks.editor',
        'blocks.owner',
        'blocks.user-data-field',
        'blocks.user-progress',
        'editor',
        'edit-blocker',
        'owner',
        'structural-element',
    ];

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

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

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