Implement pagination for people page.

This commit is contained in:
Aaron van Geffen 2016-09-01 23:47:34 +02:00
parent ab0e4efbcb
commit bfcbe5aa2e
2 changed files with 42 additions and 14 deletions

View File

@ -12,9 +12,12 @@ class ViewPeople extends HTMLController
public function __construct()
{
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$start = ($page - 1) * self::PER_PAGE;
$total_count = Tag::getCount(1, 'Person');
// Fetch subalbums.
// !!! TODO: pagination.
$subalbums = Tag::getPeople();
$subalbums = Tag::getPeople(0, $start, self::PER_PAGE);
// What assets are we using?
$id_assets = array_map(function($album) {
@ -36,10 +39,18 @@ class ViewPeople extends HTMLController
];
}
$index = new AlbumIndex($albums);
parent::__construct('People - ' . SITE_TITLE);
$this->page->adopt($index);
$this->page->setCanonicalUrl(BASEURL . '/people/');
$this->page->adopt(new AlbumIndex($albums));
$pagination = new PageIndex([
'recordCount' => $total_count,
'items_per_page' => self::PER_PAGE,
'start' => $start,
'base_url' => BASEURL . '/people/',
'page_slug' => 'page/%PAGE%/',
]);
$this->page->adopt(new Pagination($pagination));
$this->page->setCanonicalUrl(BASEURL . '/people/' . ($page > 1 ? 'page/' . $page . '/' : ''));
}
}

View File

@ -95,16 +95,19 @@ class Tag
return $rows;
}
public static function getAlbums($id_parent = 0, $return_format = 'array')
public static function getAlbums($id_parent = 0, $offset = 0, $limit = 24, $return_format = 'array')
{
$rows = Registry::get('db')->queryAssocs('
SELECT *
FROM tags
WHERE id_parent = {int:id_parent} AND kind = {string:kind}
ORDER BY tag ASC',
ORDER BY tag ASC
LIMIT {int:offset}, {int:limit}',
[
'id_parent' => $id_parent,
'kind' => 'Album',
'offset' => $offset,
'limit' => $limit,
]);
if ($return_format == 'object')
@ -118,16 +121,19 @@ class Tag
return $rows;
}
public static function getPeople($id_parent = 0, $return_format = 'array')
public static function getPeople($id_parent = 0, $offset = 0, $limit = 24, $return_format = 'array')
{
$rows = Registry::get('db')->queryAssocs('
SELECT *
FROM tags
WHERE id_parent = {int:id_parent} AND kind = {string:kind}
ORDER BY tag ASC',
ORDER BY tag ASC
LIMIT {int:offset}, {int:limit}',
[
'id_parent' => $id_parent,
'kind' => 'Person',
'offset' => $offset,
'limit' => $limit,
]);
if ($return_format == 'object')
@ -322,12 +328,23 @@ class Tag
['tags' => $tags]);
}
public static function getCount($only_active = 1)
public static function getCount($only_active = 1, $kind = '')
{
return $db->queryValue('
$where = [];
if ($only_active)
$where[] = 'count > 0';
if (!empty($kind))
$where[] = 'kind = {string:kind}';
if (!empty($where))
$where = 'WHERE ' . implode(' AND ', $where);
else
$where = '';
return Registry::get('db')->queryValue('
SELECT COUNT(*)
FROM tags' . ($only_active ? '
WHERE count > 0' : ''));
FROM tags ' . $where,
['kind' => $kind]);
}
public function __toString()