121 lines
3.3 KiB
PHP
121 lines
3.3 KiB
PHP
<?php
|
|
/*****************************************************************************
|
|
* ManageTags.php
|
|
* Contains the controller with the admin's list of tags.
|
|
*
|
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
|
*****************************************************************************/
|
|
|
|
class ManageTags extends HTMLController
|
|
{
|
|
public function __construct()
|
|
{
|
|
// Ensure it's just admins at this point.
|
|
if (!Registry::get('user')->isAdmin())
|
|
throw new NotAllowedException();
|
|
|
|
Session::resetSessionToken();
|
|
|
|
$options = [
|
|
'form' => [
|
|
'action' => BASEURL . '/edittag/',
|
|
'method' => 'get',
|
|
'class' => 'col-md-6 text-end',
|
|
'buttons' => [
|
|
'add' => [
|
|
'type' => 'submit',
|
|
'caption' => 'Add new tag',
|
|
],
|
|
],
|
|
],
|
|
'columns' => [
|
|
'id_tag' => [
|
|
'value' => 'id_tag',
|
|
'header' => 'ID',
|
|
'is_sortable' => true,
|
|
],
|
|
'tag' => [
|
|
'header' => 'Tag',
|
|
'is_sortable' => true,
|
|
'parse' => [
|
|
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
|
'data' => 'tag',
|
|
],
|
|
],
|
|
'slug' => [
|
|
'header' => 'Slug',
|
|
'is_sortable' => true,
|
|
'parse' => [
|
|
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
|
'data' => 'slug',
|
|
],
|
|
],
|
|
'id_user_owner' => [
|
|
'header' => 'Owning user',
|
|
'is_sortable' => true,
|
|
'parse' => [
|
|
'type' => 'function',
|
|
'data' => function($row) {
|
|
if (!empty($row['id_user']))
|
|
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
|
$row['first_name'] . ' ' . $row['surname']);
|
|
else
|
|
return 'n/a';
|
|
},
|
|
],
|
|
],
|
|
'count' => [
|
|
'header' => 'Cardinality',
|
|
'is_sortable' => true,
|
|
'value' => 'count',
|
|
],
|
|
],
|
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : null,
|
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : null,
|
|
'title' => 'Manage tags',
|
|
'no_items_label' => 'No tags meet the requirements of the current filter.',
|
|
'items_per_page' => 30,
|
|
'index_class' => 'col-md-6',
|
|
'base_url' => BASEURL . '/managetags/',
|
|
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'up') {
|
|
if (!in_array($order, ['id_tag', 'tag', 'slug', 'kind', 'count']))
|
|
$order = 'tag';
|
|
if (!in_array($direction, ['up', 'down']))
|
|
$direction = 'up';
|
|
|
|
$data = Registry::get('db')->queryAssocs('
|
|
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 != {string:album}
|
|
ORDER BY {raw:order}
|
|
LIMIT {int:offset}, {int:limit}',
|
|
[
|
|
'order' => $order . ($direction == 'up' ? ' ASC' : ' DESC'),
|
|
'offset' => $offset,
|
|
'limit' => $limit,
|
|
'album' => 'Album',
|
|
]);
|
|
|
|
return [
|
|
'rows' => $data,
|
|
'order' => $order,
|
|
'direction' => ($direction == 'up' ? 'up' : 'down'),
|
|
];
|
|
},
|
|
'get_count' => function() {
|
|
return Registry::get('db')->queryValue('
|
|
SELECT COUNT(*)
|
|
FROM tags
|
|
WHERE kind != {string:album}',
|
|
['album' => 'Album']);
|
|
}
|
|
];
|
|
|
|
$table = new GenericTable($options);
|
|
parent::__construct('Tag management - Page ' . $table->getCurrentPage() .' - ' . SITE_TITLE);
|
|
$this->page->adopt(new TabularData($table));
|
|
}
|
|
}
|