aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/SemestersIndex.php
blob: ffa1d4c0f7b4737b730d34ae6cd86e2008f6cd96 (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
<?php

namespace JsonApi\Routes;

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use JsonApi\JsonApiController;

/**
 * List all the semesters.
 */
class SemestersIndex extends JsonApiController
{
    protected $allowedPagingParameters = ['offset', 'limit'];

    public function __invoke(Request $request, Response $response, $args)
    {
        list($offset, $limit) = $this->getOffsetAndLimit();
        $semesters = \Semester::getAll();

        return $this->getPaginatedContentResponse(
            array_slice($semesters, $offset, $limit),
            count($semesters)
        );
    }
}