Tag: invert behaviour of getCount and getOffset methods
This commit is contained in:
@@ -59,10 +59,10 @@ class ManageAlbums extends HTMLController
|
|||||||
'items_per_page' => 9999,
|
'items_per_page' => 9999,
|
||||||
'base_url' => BASEURL . '/managealbums/',
|
'base_url' => BASEURL . '/managealbums/',
|
||||||
'get_data' => function($offset, $limit, $order, $direction) {
|
'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() {
|
'get_count' => function() {
|
||||||
return Tag::getCount(false, 'Album', true);
|
return Tag::getCount(false, 'Album');
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ class ManageTags extends HTMLController
|
|||||||
'items_per_page' => 9999,
|
'items_per_page' => 9999,
|
||||||
'base_url' => BASEURL . '/managetags/',
|
'base_url' => BASEURL . '/managetags/',
|
||||||
'get_data' => function($offset, $limit, $order, $direction) {
|
'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() {
|
'get_count' => function() {
|
||||||
return Tag::getCount(false, null, false);
|
return Tag::getCount(false, null, true);
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class ViewPeople extends HTMLController
|
|||||||
|
|
||||||
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||||
$start = ($page - 1) * self::PER_PAGE;
|
$start = ($page - 1) * self::PER_PAGE;
|
||||||
$total_count = Tag::getCount(1, 'Person', true);
|
$total_count = Tag::getCount(1, 'Person');
|
||||||
|
|
||||||
// Fetch subalbums.
|
// Fetch subalbums.
|
||||||
$subalbums = Tag::getPeople(0, $start, self::PER_PAGE);
|
$subalbums = Tag::getPeople(0, $start, self::PER_PAGE);
|
||||||
|
|||||||
@@ -417,16 +417,17 @@ class Tag
|
|||||||
['tags' => $tags]);
|
['tags' => $tags]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCount($only_used = true, $kind = '', $isAlbum = false)
|
public static function getCount($only_used = true, $kind = '', $invert = false)
|
||||||
{
|
{
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($only_used)
|
|
||||||
$where[] = 'count > 0';
|
$where[] = 'kind ' . ($invert ? '!=' : '=' ) . ' :kind';
|
||||||
if (empty($kind))
|
if (empty($kind))
|
||||||
$kind = 'Album';
|
$kind = 'Album';
|
||||||
|
|
||||||
$operator = $isAlbum ? '=' : '!=';
|
if ($only_used)
|
||||||
$where[] = 'kind ' . $operator . ' :kind';
|
$where[] = 'count > 0';
|
||||||
|
|
||||||
$where = implode(' AND ', $where);
|
$where = implode(' AND ', $where);
|
||||||
|
|
||||||
return Registry::get('db')->queryValue('
|
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']));
|
assert(in_array($order, ['id_tag', 'tag', 'slug', 'count']));
|
||||||
$order = $order . ($direction === 'up' ? ' ASC' : ' DESC');
|
$order = $order . ($direction === 'up' ? ' ASC' : ' DESC');
|
||||||
|
|
||||||
$operator = $isAlbum ? '=' : '!=';
|
|
||||||
|
|
||||||
$db = Registry::get('db');
|
$db = Registry::get('db');
|
||||||
$res = $db->query('
|
$res = $db->query('
|
||||||
SELECT t.*, u.id_user, u.first_name, u.surname
|
SELECT t.*, u.id_user, u.first_name, u.surname
|
||||||
FROM tags AS t
|
FROM tags AS t
|
||||||
LEFT JOIN users AS u ON t.id_user_owner = u.id_user
|
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 . '
|
ORDER BY id_parent, ' . $order . '
|
||||||
LIMIT :offset, :limit',
|
LIMIT :offset, :limit',
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user