about summary refs log tree commit diff stats
path: root/classes/Handler/GetpaginationHandler.php
blob: 282c724e4a849f5fe43ef1f11890ca8683524fbe (plain) (blame)
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
<?php

namespace Handler;

use AuthRequired;
use ORM;
use Request;
use RequestHandlerInterface;
use Response;

class GetpaginationHandler implements RequestHandlerInterface, AuthRequired
{
    public function handle(Request $request): Response
    {
        $bookid = (int) $request->getAttribute('id');

        if ($bookid) {
            $pag = ORM::for_table('epube_pagination')
                ->where('bookid', $bookid)
                ->find_one();

            if ($pag) {
                return (new Response())->withBody($pag->pagination);
            }
        }

        return (new Response())
            ->withStatus(404)
            ->withBody("File not found.");
    }
}