Implement pagination for people page.
This commit is contained in:
parent
ab0e4efbcb
commit
bfcbe5aa2e
@ -12,9 +12,12 @@ class ViewPeople extends HTMLController
|
|||||||
|
|
||||||
public function __construct()
|
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.
|
// Fetch subalbums.
|
||||||
// !!! TODO: pagination.
|
$subalbums = Tag::getPeople(0, $start, self::PER_PAGE);
|
||||||
$subalbums = Tag::getPeople();
|
|
||||||
|
|
||||||
// What assets are we using?
|
// What assets are we using?
|
||||||
$id_assets = array_map(function($album) {
|
$id_assets = array_map(function($album) {
|
||||||
@ -36,10 +39,18 @@ class ViewPeople extends HTMLController
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$index = new AlbumIndex($albums);
|
|
||||||
|
|
||||||
parent::__construct('People - ' . SITE_TITLE);
|
parent::__construct('People - ' . SITE_TITLE);
|
||||||
$this->page->adopt($index);
|
$this->page->adopt(new AlbumIndex($albums));
|
||||||
$this->page->setCanonicalUrl(BASEURL . '/people/');
|
|
||||||
|
$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 . '/' : ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,16 +95,19 @@ class Tag
|
|||||||
return $rows;
|
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('
|
$rows = Registry::get('db')->queryAssocs('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM tags
|
FROM tags
|
||||||
WHERE id_parent = {int:id_parent} AND kind = {string:kind}
|
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,
|
'id_parent' => $id_parent,
|
||||||
'kind' => 'Album',
|
'kind' => 'Album',
|
||||||
|
'offset' => $offset,
|
||||||
|
'limit' => $limit,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($return_format == 'object')
|
if ($return_format == 'object')
|
||||||
@ -118,16 +121,19 @@ class Tag
|
|||||||
return $rows;
|
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('
|
$rows = Registry::get('db')->queryAssocs('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM tags
|
FROM tags
|
||||||
WHERE id_parent = {int:id_parent} AND kind = {string:kind}
|
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,
|
'id_parent' => $id_parent,
|
||||||
'kind' => 'Person',
|
'kind' => 'Person',
|
||||||
|
'offset' => $offset,
|
||||||
|
'limit' => $limit,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($return_format == 'object')
|
if ($return_format == 'object')
|
||||||
@ -322,12 +328,23 @@ class Tag
|
|||||||
['tags' => $tags]);
|
['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(*)
|
SELECT COUNT(*)
|
||||||
FROM tags' . ($only_active ? '
|
FROM tags ' . $where,
|
||||||
WHERE count > 0' : ''));
|
['kind' => $kind]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
|
Loading…
Reference in New Issue
Block a user