Skip to content
Snippets Groups Projects
Select Git revision
  • a3da1483a9e689846179159355badfec8073dbec
  • 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

BlocksIndex.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.
    BookmarkedStructuralElementsIndex.php 1.60 KiB
    <?php
    
    namespace JsonApi\Routes\Courseware;
    
    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 the user's bookmarked structural elements.
     */
    class BookmarkedStructuralElementsIndex extends JsonApiController
    {
        use CoursewareInstancesHelper;
    
        protected $allowedIncludePaths = [
            'ancestors',
            'containers',
            'containers.blocks',
            'containers.blocks.edit-blocker',
            'containers.blocks.editor',
            'containers.blocks.owner',
            'containers.blocks.user-data-field',
            'containers.blocks.user-progress',
            'course',
            'descendants',
            'descendants.containers',
            'descendants.containers.blocks',
            'editor',
            'owner',
            'parent',
        ];
    
        protected $allowedPagingParameters = ['offset', 'limit'];
    
        /**
         * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         */
        public function __invoke(Request $request, Response $response, $args)
        {
            $instance = $this->findInstanceWithRange($args['type'], $args['id']);
            if (!Authority::canIndexBookmarks($user = $this->getUser($request), $instance)) {
                throw new AuthorizationFailedException();
            }
            $resources = $instance->getUsersBookmarks($user);
            $total = count($resources);
            list($offset, $limit) = $this->getOffsetAndLimit();
    
            return $this->getPaginatedResponse(array_slice($resources, $offset, $limit), $total);
        }
    }