1
0
forked from Public/pics

3 Commits

Author SHA1 Message Date
b0ee3081a6 Tag: invert behaviour of getCount and getOffset methods 2026-02-14 12:56:50 +01:00
2cd2f472d0 Merge pull request 'ViewPeople: fix incorrect pagination count' (#55) from yorick/pics:fix/viewpeople-pagination-count into master
Reviewed-on: Public/pics#55
2026-02-14 12:43:56 +01:00
7f7067852a ViewPeople: fix incorrect pagination count
Tag::getCount was called without the third argument, causing it to
count tags where kind \!= 'Person' instead of kind = 'Person'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 11:19:04 +01:00
3 changed files with 12 additions and 13 deletions

View File

@@ -59,10 +59,10 @@ class ManageAlbums extends HTMLController
'items_per_page' => 9999,
'base_url' => BASEURL . '/managealbums/',
'get_data' => function($offset, $limit, $order, $direction) {
return Tag::getOffset($offset, $limit, $order, $direction, true);
return Tag::getOffset($offset, $limit, $order, $direction);
},
'get_count' => function() {
return Tag::getCount(false, 'Album', true);
return Tag::getCount(false, 'Album');
}
];

View File

@@ -72,10 +72,10 @@ class ManageTags extends HTMLController
'items_per_page' => 9999,
'base_url' => BASEURL . '/managetags/',
'get_data' => function($offset, $limit, $order, $direction) {
return Tag::getOffset($offset, $limit, $order, $direction, false);
return Tag::getOffset($offset, $limit, $order, $direction, true);
},
'get_count' => function() {
return Tag::getCount(false, null, false);
return Tag::getCount(false, null, true);
}
];

View File

@@ -417,16 +417,17 @@ class Tag
['tags' => $tags]);
}
public static function getCount($only_used = true, $kind = '', $isAlbum = false)
public static function getCount($only_used = true, $kind = '', $invert = false)
{
$where = [];
if ($only_used)
$where[] = 'count > 0';
$where[] = 'kind ' . ($invert ? '!=' : '=' ) . ' :kind';
if (empty($kind))
$kind = 'Album';
$operator = $isAlbum ? '=' : '!=';
$where[] = 'kind ' . $operator . ' :kind';
if ($only_used)
$where[] = 'count > 0';
$where = implode(' AND ', $where);
return Registry::get('db')->queryValue('
@@ -438,19 +439,17 @@ class Tag
]);
}
public static function getOffset($offset, $limit, $order, $direction, $isAlbum = false)
public static function getOffset($offset, $limit, $order, $direction, $invert = false)
{
assert(in_array($order, ['id_tag', 'tag', 'slug', 'count']));
$order = $order . ($direction === 'up' ? ' ASC' : ' DESC');
$operator = $isAlbum ? '=' : '!=';
$db = Registry::get('db');
$res = $db->query('
SELECT t.*, u.id_user, u.first_name, u.surname
FROM tags AS t
LEFT JOIN users AS u ON t.id_user_owner = u.id_user
WHERE kind ' . $operator . ' :album
WHERE kind ' . ($invert ? '!=' : '=') . ' :album
ORDER BY id_parent, ' . $order . '
LIMIT :offset, :limit',
[