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

StockImagesIndex.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.
    StockImagesIndex.php 1008 B
    <?php
    
    namespace JsonApi\Routes\StockImages;
    
    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 stock images.
     */
    class StockImagesIndex extends JsonApiController
    {
        protected $allowedPagingParameters = ['offset', 'limit'];
    
        /**
         * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         */
        public function __invoke(Request $request, Response $response): Response
        {
            if (!Authority::canIndexStockImages($this->getUser($request))) {
                throw new AuthorizationFailedException();
            }
    
            list($offset, $limit) = $this->getOffsetAndLimit();
            $total = \StockImage::countBySQL('1');
            $stockImages = \StockImage::findBySQL("1 ORDER BY title ASC LIMIT {$offset}, {$limit}");
    
            return $this->getPaginatedContentResponse($stockImages, $total);
        }
    }