Skip to content
Snippets Groups Projects
Select Git revision
  • 60080354dcc904e01f4ee88793d0e132afca8227
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

StandardFile.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ContainersIndex.php 1.41 KiB
    <?php
    
    namespace JsonApi\Routes\Courseware;
    
    use Courseware\StructuralElement;
    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 all containers of a structural element.
     */
    class ContainersIndex extends JsonApiController
    {
        protected $allowedPagingParameters = ['offset', 'limit'];
    
        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 = StructuralElement::find($args['id'])) {
                throw new RecordNotFoundException();
            }
    
            if (!Authority::canIndexContainers($this->getUser($request), $resource)) {
                throw new AuthorizationFailedException();
            }
    
            list($offset, $limit) = $this->getOffsetAndLimit();
    
            return $this->getPaginatedContentResponse(
                $resource->containers->limit($offset, $limit),
                count($resource->containers)
            );
        }
    }