1: <?php
2:
3: namespace Charcoal\Source\Database;
4:
5: // Local parent namespace dependencies
6: use \Charcoal\Source\Pagination;
7:
8: /**
9: * The DatabasePagination makes a Pagination SQL-aware
10: */
11: class DatabasePagination extends Pagination
12: {
13: /**
14: * Get the pagination's SQL string (Full "LIMIT" subquery)
15: *
16: * For example, for the pagination `{page:3,num_per_page:50}` the result
17: * would be: `' LIMIT 100, 50'`.
18: *
19: * @return string
20: */
21: public function sql()
22: {
23: $sql = '';
24: $page = $this->page() ? $this->page() : 1;
25: $numPerPage = $this->numPerPage();
26:
27: if ($numPerPage) {
28: $first_page = max(0, (($page-1)*$numPerPage));
29: $sql = ' LIMIT '.$first_page.', '.$numPerPage;
30: }
31: return $sql;
32: }
33: }
34: