Compare commits
No commits in common. "generic-tables" and "master" have entirely different histories.
generic-ta
...
master
@ -35,14 +35,18 @@ class ManageAlbums extends HTMLController
|
|||||||
'tag' => [
|
'tag' => [
|
||||||
'header' => 'Album',
|
'header' => 'Album',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
'parse' => [
|
||||||
'value' => 'tag',
|
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
||||||
|
'data' => 'tag',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'slug' => [
|
'slug' => [
|
||||||
'header' => 'Slug',
|
'header' => 'Slug',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
'parse' => [
|
||||||
'value' => 'slug',
|
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
||||||
|
'data' => 'slug',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'count' => [
|
'count' => [
|
||||||
'header' => '# Photos',
|
'header' => '# Photos',
|
||||||
@ -50,21 +54,30 @@ class ManageAlbums extends HTMLController
|
|||||||
'value' => 'count',
|
'value' => 'count',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'default_sort_order' => 'tag',
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
||||||
'default_sort_direction' => 'up',
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : null,
|
||||||
'start' => $_GET['start'] ?? 0,
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : null,
|
||||||
'sort_order' => $_GET['order'] ?? '',
|
|
||||||
'sort_direction' => $_GET['dir'] ?? '',
|
|
||||||
'title' => 'Manage albums',
|
'title' => 'Manage albums',
|
||||||
'no_items_label' => 'No albums meet the requirements of the current filter.',
|
'no_items_label' => 'No albums meet the requirements of the current filter.',
|
||||||
'items_per_page' => 9999,
|
'items_per_page' => 9999,
|
||||||
'index_class' => 'col-md-6',
|
'index_class' => 'col-md-6',
|
||||||
'base_url' => BASEURL . '/managealbums/',
|
'base_url' => BASEURL . '/managealbums/',
|
||||||
'get_data' => function($offset, $limit, $order, $direction) {
|
'get_data' => function($offset = 0, $limit = 9999, $order = '', $direction = 'up') {
|
||||||
return Tag::getOffset($offset, $limit, $order, $direction, true);
|
if (!in_array($order, ['id_tag', 'tag', 'slug', 'count']))
|
||||||
|
$order = 'tag';
|
||||||
|
if (!in_array($direction, ['up', 'down']))
|
||||||
|
$direction = 'up';
|
||||||
|
|
||||||
|
$rows = PhotoAlbum::getHierarchy($order, $direction);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'rows' => $rows,
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => ($direction == 'up' ? 'up' : 'down'),
|
||||||
|
];
|
||||||
},
|
},
|
||||||
'get_count' => function() {
|
'get_count' => function() {
|
||||||
return Tag::getCount(false, 'Album', true);
|
return 9999;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -38,33 +38,40 @@ class ManageAssets extends HTMLController
|
|||||||
'checkbox' => [
|
'checkbox' => [
|
||||||
'header' => '<input type="checkbox" id="selectall">',
|
'header' => '<input type="checkbox" id="selectall">',
|
||||||
'is_sortable' => false,
|
'is_sortable' => false,
|
||||||
'format' => fn($row) =>
|
'parse' => [
|
||||||
'<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">',
|
'type' => 'function',
|
||||||
|
'data' => function($row) {
|
||||||
|
return '<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">';
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'thumbnail' => [
|
'thumbnail' => [
|
||||||
'header' => ' ',
|
'header' => ' ',
|
||||||
'is_sortable' => false,
|
'is_sortable' => false,
|
||||||
'cell_class' => 'text-center',
|
'cell_class' => 'text-center',
|
||||||
'format' => function($row) {
|
'parse' => [
|
||||||
$asset = Image::byRow($row);
|
'type' => 'function',
|
||||||
$width = $height = 65;
|
'data' => function($row) {
|
||||||
if ($asset->isImage())
|
$asset = Image::byRow($row);
|
||||||
{
|
$width = $height = 65;
|
||||||
if ($asset->isPortrait())
|
if ($asset->isImage())
|
||||||
$width = null;
|
{
|
||||||
|
if ($asset->isPortrait())
|
||||||
|
$width = null;
|
||||||
|
else
|
||||||
|
$height = null;
|
||||||
|
|
||||||
|
$thumb = $asset->getThumbnailUrl($width, $height);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$height = null;
|
$thumb = BASEURL . '/images/nothumb.svg';
|
||||||
|
|
||||||
$thumb = $asset->getThumbnailUrl($width, $height);
|
$width = isset($width) ? $width . 'px' : 'auto';
|
||||||
}
|
$height = isset($height) ? $height . 'px' : 'auto';
|
||||||
else
|
|
||||||
$thumb = BASEURL . '/images/nothumb.svg';
|
|
||||||
|
|
||||||
$width = isset($width) ? $width . 'px' : 'auto';
|
return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
|
||||||
$height = isset($height) ? $height . 'px' : 'auto';
|
},
|
||||||
|
],
|
||||||
return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
'id_asset' => [
|
'id_asset' => [
|
||||||
'value' => 'id_asset',
|
'value' => 'id_asset',
|
||||||
@ -80,42 +87,72 @@ class ManageAssets extends HTMLController
|
|||||||
'value' => 'filename',
|
'value' => 'filename',
|
||||||
'header' => 'Filename',
|
'header' => 'Filename',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
'parse' => [
|
||||||
'value' => 'filename',
|
'type' => 'value',
|
||||||
|
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
||||||
|
'data' => 'filename',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'id_user_uploaded' => [
|
'id_user_uploaded' => [
|
||||||
'header' => 'User uploaded',
|
'header' => 'User uploaded',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'format' => function($row) {
|
'parse' => [
|
||||||
if (!empty($row['id_user']))
|
'type' => 'function',
|
||||||
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
'data' => function($row) {
|
||||||
$row['first_name'] . ' ' . $row['surname']);
|
if (!empty($row['id_user']))
|
||||||
else
|
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
||||||
return 'n/a';
|
$row['first_name'] . ' ' . $row['surname']);
|
||||||
},
|
else
|
||||||
|
return 'n/a';
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'dimensions' => [
|
'dimensions' => [
|
||||||
'header' => 'Dimensions',
|
'header' => 'Dimensions',
|
||||||
'is_sortable' => false,
|
'is_sortable' => false,
|
||||||
'format' => function($row) {
|
'parse' => [
|
||||||
if (!empty($row['image_width']))
|
'type' => 'function',
|
||||||
return $row['image_width'] . ' x ' . $row['image_height'];
|
'data' => function($row) {
|
||||||
else
|
if (!empty($row['image_width']))
|
||||||
return 'n/a';
|
return $row['image_width'] . ' x ' . $row['image_height'];
|
||||||
},
|
else
|
||||||
|
return 'n/a';
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'default_sort_order' => 'id_asset',
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
||||||
'default_sort_direction' => 'down',
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
|
||||||
'start' => $_GET['start'] ?? 0,
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
|
||||||
'sort_order' => $_GET['order'] ?? '',
|
|
||||||
'sort_direction' => $_GET['dir'] ?? '',
|
|
||||||
'title' => 'Manage assets',
|
'title' => 'Manage assets',
|
||||||
'no_items_label' => 'No assets meet the requirements of the current filter.',
|
'no_items_label' => 'No assets meet the requirements of the current filter.',
|
||||||
'items_per_page' => 30,
|
'items_per_page' => 30,
|
||||||
'index_class' => 'col-md-6',
|
'index_class' => 'col-md-6',
|
||||||
'base_url' => BASEURL . '/manageassets/',
|
'base_url' => BASEURL . '/manageassets/',
|
||||||
'get_data' => 'Asset::getOffset',
|
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'down') {
|
||||||
|
if (!in_array($order, ['id_asset', 'id_user_uploaded', 'title', 'subdir', 'filename']))
|
||||||
|
$order = 'id_asset';
|
||||||
|
|
||||||
|
$data = Registry::get('db')->queryAssocs('
|
||||||
|
SELECT a.id_asset, a.subdir, a.filename,
|
||||||
|
a.image_width, a.image_height, a.mimetype,
|
||||||
|
u.id_user, u.first_name, u.surname
|
||||||
|
FROM assets AS a
|
||||||
|
LEFT JOIN users AS u ON a.id_user_uploaded = u.id_user
|
||||||
|
ORDER BY {raw:order}
|
||||||
|
LIMIT {int:offset}, {int:limit}',
|
||||||
|
[
|
||||||
|
'order' => $order . ($direction == 'up' ? ' ASC' : ' DESC'),
|
||||||
|
'offset' => $offset,
|
||||||
|
'limit' => $limit,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'rows' => $data,
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => $direction,
|
||||||
|
];
|
||||||
|
},
|
||||||
'get_count' => 'Asset::getCount',
|
'get_count' => 'Asset::getCount',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ class ManageErrors extends HTMLController
|
|||||||
if (!Registry::get('user')->isAdmin())
|
if (!Registry::get('user')->isAdmin())
|
||||||
throw new NotAllowedException();
|
throw new NotAllowedException();
|
||||||
|
|
||||||
// Clearing, are we?
|
// Flushing, are we?
|
||||||
if (isset($_POST['clear']) && Session::validateSession('get'))
|
if (isset($_POST['flush']) && Session::validateSession('get'))
|
||||||
{
|
{
|
||||||
ErrorLog::flush();
|
ErrorLog::flush();
|
||||||
header('Location: ' . BASEURL . '/manageerrors/');
|
header('Location: ' . BASEURL . '/manageerrors/');
|
||||||
@ -31,7 +31,7 @@ class ManageErrors extends HTMLController
|
|||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'class' => 'col-md-6 text-end',
|
'class' => 'col-md-6 text-end',
|
||||||
'buttons' => [
|
'buttons' => [
|
||||||
'clear' => [
|
'flush' => [
|
||||||
'type' => 'submit',
|
'type' => 'submit',
|
||||||
'caption' => 'Delete all',
|
'caption' => 'Delete all',
|
||||||
'class' => 'btn-danger',
|
'class' => 'btn-danger',
|
||||||
@ -39,23 +39,26 @@ class ManageErrors extends HTMLController
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
'columns' => [
|
'columns' => [
|
||||||
'id_entry' => [
|
'id' => [
|
||||||
'value' => 'id_entry',
|
'value' => 'id_entry',
|
||||||
'header' => '#',
|
'header' => '#',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
],
|
],
|
||||||
'message' => [
|
'message' => [
|
||||||
|
'parse' => [
|
||||||
|
'type' => 'function',
|
||||||
|
'data' => function($row) {
|
||||||
|
return $row['message'] . '<br>' .
|
||||||
|
'<div><a onclick="this.parentNode.childNodes[1].style.display=\'block\';this.style.display=\'none\';">Show debug info</a>' .
|
||||||
|
'<pre style="display: none">' . htmlspecialchars($row['debug_info']) .
|
||||||
|
'</pre></div>' .
|
||||||
|
'<small><a href="' . BASEURL .
|
||||||
|
htmlspecialchars($row['request_uri']) . '">' .
|
||||||
|
htmlspecialchars($row['request_uri']) . '</a></small>';
|
||||||
|
}
|
||||||
|
],
|
||||||
'header' => 'Message / URL',
|
'header' => 'Message / URL',
|
||||||
'is_sortable' => false,
|
'is_sortable' => false,
|
||||||
'format' => function($row) {
|
|
||||||
return $row['message'] . '<br>' .
|
|
||||||
'<div><a onclick="this.parentNode.childNodes[1].style.display=\'block\';this.style.display=\'none\';">Show debug info</a>' .
|
|
||||||
'<pre style="display: none">' . htmlspecialchars($row['debug_info']) .
|
|
||||||
'</pre></div>' .
|
|
||||||
'<small><a href="' . BASEURL .
|
|
||||||
htmlspecialchars($row['request_uri']) . '">' .
|
|
||||||
htmlspecialchars($row['request_uri']) . '</a></small>';
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
'file' => [
|
'file' => [
|
||||||
'value' => 'file',
|
'value' => 'file',
|
||||||
@ -68,10 +71,12 @@ class ManageErrors extends HTMLController
|
|||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
],
|
],
|
||||||
'time' => [
|
'time' => [
|
||||||
'format' => [
|
'parse' => [
|
||||||
'type' => 'timestamp',
|
'type' => 'timestamp',
|
||||||
'pattern' => 'long',
|
'data' => [
|
||||||
'value' => 'time',
|
'timestamp' => 'time',
|
||||||
|
'pattern' => 'long',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'header' => 'Time',
|
'header' => 'Time',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
@ -84,21 +89,41 @@ class ManageErrors extends HTMLController
|
|||||||
'uid' => [
|
'uid' => [
|
||||||
'header' => 'UID',
|
'header' => 'UID',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
'parse' => [
|
||||||
'value' => 'id_user',
|
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||||
|
'data' => 'id_user',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'default_sort_order' => 'id_entry',
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
||||||
'default_sort_direction' => 'down',
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
|
||||||
'start' => $_GET['start'] ?? 0,
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
|
||||||
'sort_order' => $_GET['order'] ?? '',
|
|
||||||
'sort_direction' => $_GET['dir'] ?? '',
|
|
||||||
'no_items_label' => "No errors to display -- we're all good!",
|
'no_items_label' => "No errors to display -- we're all good!",
|
||||||
'items_per_page' => 20,
|
'items_per_page' => 20,
|
||||||
'index_class' => 'col-md-6',
|
'index_class' => 'col-md-6',
|
||||||
'base_url' => BASEURL . '/manageerrors/',
|
'base_url' => BASEURL . '/manageerrors/',
|
||||||
'get_count' => 'ErrorLog::getCount',
|
'get_count' => 'ErrorLog::getCount',
|
||||||
'get_data' => 'ErrorLog::getOffset',
|
'get_data' => function($offset = 0, $limit = 20, $order = '', $direction = 'down') {
|
||||||
|
if (!in_array($order, ['id_entry', 'file', 'line', 'time', 'ipaddress', 'id_user']))
|
||||||
|
$order = 'id_entry';
|
||||||
|
|
||||||
|
$data = Registry::get('db')->queryAssocs('
|
||||||
|
SELECT *
|
||||||
|
FROM log_errors
|
||||||
|
ORDER BY {raw:order}
|
||||||
|
LIMIT {int:offset}, {int:limit}',
|
||||||
|
[
|
||||||
|
'order' => $order . ($direction === 'up' ? ' ASC' : ' DESC'),
|
||||||
|
'offset' => $offset,
|
||||||
|
'limit' => $limit,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'rows' => $data,
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => $direction,
|
||||||
|
];
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
$error_log = new GenericTable($options);
|
$error_log = new GenericTable($options);
|
||||||
|
@ -37,25 +37,32 @@ class ManageTags extends HTMLController
|
|||||||
'tag' => [
|
'tag' => [
|
||||||
'header' => 'Tag',
|
'header' => 'Tag',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
'parse' => [
|
||||||
'value' => 'tag',
|
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
||||||
|
'data' => 'tag',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'slug' => [
|
'slug' => [
|
||||||
'header' => 'Slug',
|
'header' => 'Slug',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
'parse' => [
|
||||||
'value' => 'slug',
|
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
||||||
|
'data' => 'slug',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'id_user_owner' => [
|
'id_user_owner' => [
|
||||||
'header' => 'Owning user',
|
'header' => 'Owning user',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'format' => function($row) {
|
'parse' => [
|
||||||
if (!empty($row['id_user']))
|
'type' => 'function',
|
||||||
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
'data' => function($row) {
|
||||||
$row['first_name'] . ' ' . $row['surname']);
|
if (!empty($row['id_user']))
|
||||||
else
|
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
||||||
return 'n/a';
|
$row['first_name'] . ' ' . $row['surname']);
|
||||||
},
|
else
|
||||||
|
return 'n/a';
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'count' => [
|
'count' => [
|
||||||
'header' => 'Cardinality',
|
'header' => 'Cardinality',
|
||||||
@ -63,21 +70,46 @@ class ManageTags extends HTMLController
|
|||||||
'value' => 'count',
|
'value' => 'count',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'default_sort_order' => 'tag',
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
||||||
'default_sort_direction' => 'up',
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : null,
|
||||||
'start' => $_GET['start'] ?? 0,
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : null,
|
||||||
'sort_order' => $_GET['order'] ?? '',
|
|
||||||
'sort_direction' => $_GET['dir'] ?? '',
|
|
||||||
'title' => 'Manage tags',
|
'title' => 'Manage tags',
|
||||||
'no_items_label' => 'No tags meet the requirements of the current filter.',
|
'no_items_label' => 'No tags meet the requirements of the current filter.',
|
||||||
'items_per_page' => 30,
|
'items_per_page' => 30,
|
||||||
'index_class' => 'col-md-6',
|
'index_class' => 'col-md-6',
|
||||||
'base_url' => BASEURL . '/managetags/',
|
'base_url' => BASEURL . '/managetags/',
|
||||||
'get_data' => function($offset, $limit, $order, $direction) {
|
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'up') {
|
||||||
return Tag::getOffset($offset, $limit, $order, $direction, false);
|
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() {
|
'get_count' => function() {
|
||||||
return Tag::getCount(false, null, false);
|
return Registry::get('db')->queryValue('
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM tags
|
||||||
|
WHERE kind != {string:album}',
|
||||||
|
['album' => 'Album']);
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -37,20 +37,26 @@ class ManageUsers extends HTMLController
|
|||||||
'surname' => [
|
'surname' => [
|
||||||
'header' => 'Last name',
|
'header' => 'Last name',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
'parse' => [
|
||||||
'value' => 'surname',
|
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||||
|
'data' => 'surname',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'first_name' => [
|
'first_name' => [
|
||||||
'header' => 'First name',
|
'header' => 'First name',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
'parse' => [
|
||||||
'value' => 'first_name',
|
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||||
|
'data' => 'first_name',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'slug' => [
|
'slug' => [
|
||||||
'header' => 'Slug',
|
'header' => 'Slug',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
'parse' => [
|
||||||
'value' => 'slug',
|
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||||
|
'data' => 'slug',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'emailaddress' => [
|
'emailaddress' => [
|
||||||
'value' => 'emailaddress',
|
'value' => 'emailaddress',
|
||||||
@ -58,10 +64,12 @@ class ManageUsers extends HTMLController
|
|||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
],
|
],
|
||||||
'last_action_time' => [
|
'last_action_time' => [
|
||||||
'format' => [
|
'parse' => [
|
||||||
'type' => 'timestamp',
|
'type' => 'timestamp',
|
||||||
'pattern' => 'long',
|
'data' => [
|
||||||
'value' => 'last_action_time',
|
'timestamp' => 'last_action_time',
|
||||||
|
'pattern' => 'long',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'header' => 'Last activity',
|
'header' => 'Last activity',
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
@ -74,21 +82,48 @@ class ManageUsers extends HTMLController
|
|||||||
'is_admin' => [
|
'is_admin' => [
|
||||||
'is_sortable' => true,
|
'is_sortable' => true,
|
||||||
'header' => 'Admin?',
|
'header' => 'Admin?',
|
||||||
'format' => fn($row) => $row['is_admin'] ? 'yes' : 'no',
|
'parse' => [
|
||||||
|
'type' => 'function',
|
||||||
|
'data' => function($row) {
|
||||||
|
return $row['is_admin'] ? 'yes' : 'no';
|
||||||
|
}
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'default_sort_order' => 'id_user',
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
||||||
'default_sort_direction' => 'down',
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
|
||||||
'start' => $_GET['start'] ?? 0,
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
|
||||||
'sort_order' => $_GET['order'] ?? '',
|
|
||||||
'sort_direction' => $_GET['dir'] ?? '',
|
|
||||||
'title' => 'Manage users',
|
'title' => 'Manage users',
|
||||||
'no_items_label' => 'No users meet the requirements of the current filter.',
|
'no_items_label' => 'No users meet the requirements of the current filter.',
|
||||||
'items_per_page' => 30,
|
'items_per_page' => 30,
|
||||||
'index_class' => 'col-md-6',
|
'index_class' => 'col-md-6',
|
||||||
'base_url' => BASEURL . '/manageusers/',
|
'base_url' => BASEURL . '/manageusers/',
|
||||||
'get_data' => 'Member::getOffset',
|
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'down') {
|
||||||
'get_count' => 'Member::getCount',
|
if (!in_array($order, ['id_user', 'surname', 'first_name', 'slug', 'emailaddress', 'last_action_time', 'ip_address', 'is_admin']))
|
||||||
|
$order = 'id_user';
|
||||||
|
|
||||||
|
$data = Registry::get('db')->queryAssocs('
|
||||||
|
SELECT *
|
||||||
|
FROM users
|
||||||
|
ORDER BY {raw:order}
|
||||||
|
LIMIT {int:offset}, {int:limit}',
|
||||||
|
[
|
||||||
|
'order' => $order . ($direction == 'up' ? ' ASC' : ' DESC'),
|
||||||
|
'offset' => $offset,
|
||||||
|
'limit' => $limit,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'rows' => $data,
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => $direction,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
'get_count' => function() {
|
||||||
|
return Registry::get('db')->queryValue('
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM users');
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
$table = new GenericTable($options);
|
$table = new GenericTable($options);
|
||||||
|
@ -680,23 +680,6 @@ class Asset
|
|||||||
FROM assets');
|
FROM assets');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getOffset($offset, $limit, $order, $direction)
|
|
||||||
{
|
|
||||||
return Registry::get('db')->queryAssocs('
|
|
||||||
SELECT a.id_asset, a.subdir, a.filename,
|
|
||||||
a.image_width, a.image_height, a.mimetype,
|
|
||||||
u.id_user, u.first_name, u.surname
|
|
||||||
FROM assets AS a
|
|
||||||
LEFT JOIN users AS u ON a.id_user_uploaded = u.id_user
|
|
||||||
ORDER BY {raw:order}
|
|
||||||
LIMIT {int:offset}, {int:limit}',
|
|
||||||
[
|
|
||||||
'order' => $order . ($direction == 'up' ? ' ASC' : ' DESC'),
|
|
||||||
'offset' => $offset,
|
|
||||||
'limit' => $limit,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
if (empty($this->id_asset))
|
if (empty($this->id_asset))
|
||||||
|
@ -24,7 +24,7 @@ class ErrorLog
|
|||||||
|
|
||||||
public static function flush()
|
public static function flush()
|
||||||
{
|
{
|
||||||
return Registry::get('db')->query('DELETE FROM log_errors');
|
return Registry::get('db')->query('TRUNCATE log_errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCount()
|
public static function getCount()
|
||||||
@ -33,20 +33,4 @@ class ErrorLog
|
|||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM log_errors');
|
FROM log_errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getOffset($offset, $limit, $order, $direction)
|
|
||||||
{
|
|
||||||
assert(in_array($order, ['id_entry', 'file', 'line', 'time', 'ipaddress', 'id_user']));
|
|
||||||
|
|
||||||
return Registry::get('db')->queryAssocs('
|
|
||||||
SELECT *
|
|
||||||
FROM log_errors
|
|
||||||
ORDER BY {raw:order}
|
|
||||||
LIMIT {int:offset}, {int:limit}',
|
|
||||||
[
|
|
||||||
'order' => $order . ($direction === 'up' ? ' ASC' : ' DESC'),
|
|
||||||
'offset' => $offset,
|
|
||||||
'limit' => $limit,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class GenericTable
|
|||||||
|
|
||||||
private $title;
|
private $title;
|
||||||
private $title_class;
|
private $title_class;
|
||||||
|
private $tableIsSortable = false;
|
||||||
|
|
||||||
public $form_above;
|
public $form_above;
|
||||||
public $form_below;
|
public $form_below;
|
||||||
@ -28,22 +29,58 @@ class GenericTable
|
|||||||
|
|
||||||
public function __construct($options)
|
public function __construct($options)
|
||||||
{
|
{
|
||||||
$this->initOrder($options);
|
// Make sure we're actually sorting on something sortable.
|
||||||
$this->initPagination($options);
|
if (!isset($options['sort_order']) || (!empty($options['sort_order']) && empty($options['columns'][$options['sort_order']]['is_sortable'])))
|
||||||
|
$options['sort_order'] = '';
|
||||||
|
|
||||||
$data = $options['get_data']($this->start, $this->items_per_page,
|
// Order in which direction?
|
||||||
$this->sort_order, $this->sort_direction);
|
if (!empty($options['sort_direction']) && !in_array($options['sort_direction'], ['up', 'down']))
|
||||||
|
$options['sort_direction'] = 'up';
|
||||||
|
|
||||||
|
// Make sure we know whether we can actually sort on something.
|
||||||
|
$this->tableIsSortable = !empty($options['base_url']);
|
||||||
|
|
||||||
|
// How much data do we have?
|
||||||
|
$this->recordCount = $options['get_count'](...(!empty($options['get_count_params']) ? $options['get_count_params'] : []));
|
||||||
|
|
||||||
|
// How much data do we need to retrieve?
|
||||||
|
$this->items_per_page = !empty($options['items_per_page']) ? $options['items_per_page'] : 30;
|
||||||
|
|
||||||
|
// Figure out where to start.
|
||||||
|
$this->start = empty($options['start']) || !is_numeric($options['start']) || $options['start'] < 0 || $options['start'] > $this->recordCount ? 0 : $options['start'];
|
||||||
|
|
||||||
|
// Figure out where we are on the whole, too.
|
||||||
|
$numPages = max(1, ceil($this->recordCount / $this->items_per_page));
|
||||||
|
$this->currentPage = min(ceil($this->start / $this->items_per_page) + 1, $numPages);
|
||||||
|
|
||||||
|
// Let's bear a few things in mind...
|
||||||
|
$this->base_url = $options['base_url'];
|
||||||
|
|
||||||
|
// Gather parameters for the data gather function first.
|
||||||
|
$parameters = [$this->start, $this->items_per_page, $options['sort_order'], $options['sort_direction']];
|
||||||
|
if (!empty($options['get_data_params']) && is_array($options['get_data_params']))
|
||||||
|
$parameters = array_merge($parameters, $options['get_data_params']);
|
||||||
|
|
||||||
|
// Okay, let's fetch the data!
|
||||||
|
$data = $options['get_data'](...$parameters);
|
||||||
|
|
||||||
|
// Extract data into local variables.
|
||||||
|
$rawRowData = $data['rows'];
|
||||||
|
$this->sort_order = $data['order'];
|
||||||
|
$this->sort_direction = $data['direction'];
|
||||||
|
unset($data);
|
||||||
|
|
||||||
// Okay, now for the column headers...
|
// Okay, now for the column headers...
|
||||||
$this->generateColumnHeaders($options);
|
$this->generateColumnHeaders($options);
|
||||||
|
|
||||||
// Should we create a page index?
|
// Should we create a page index?
|
||||||
if ($this->recordCount > $this->items_per_page)
|
$needsPageIndex = !empty($this->items_per_page) && $this->recordCount > $this->items_per_page;
|
||||||
|
if ($needsPageIndex)
|
||||||
$this->generatePageIndex($options);
|
$this->generatePageIndex($options);
|
||||||
|
|
||||||
// Process the data to be shown into rows.
|
// Process the data to be shown into rows.
|
||||||
if (!empty($data))
|
if (!empty($rawRowData))
|
||||||
$this->processAllRows($data, $options);
|
$this->processAllRows($rawRowData, $options);
|
||||||
else
|
else
|
||||||
$this->body = $options['no_items_label'] ?? '';
|
$this->body = $options['no_items_label'] ?? '';
|
||||||
|
|
||||||
@ -58,38 +95,6 @@ class GenericTable
|
|||||||
$this->form_below = $options['form_below'] ?? $options['form'] ?? null;
|
$this->form_below = $options['form_below'] ?? $options['form'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initOrder($options)
|
|
||||||
{
|
|
||||||
assert(isset($options['default_sort_order']));
|
|
||||||
assert(isset($options['default_sort_direction']));
|
|
||||||
|
|
||||||
// Validate sort order (column)
|
|
||||||
$this->sort_order = $options['sort_order'];
|
|
||||||
if (empty($this->sort_order) || empty($options['columns'][$this->sort_order]['is_sortable']))
|
|
||||||
$this->sort_order = $options['default_sort_order'];
|
|
||||||
|
|
||||||
// Validate sort direction
|
|
||||||
$this->sort_direction = $options['sort_direction'];
|
|
||||||
if (empty($this->sort_direction) || !in_array($this->sort_direction, ['up', 'down']))
|
|
||||||
$this->sort_direction = $options['default_sort_direction'];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function initPagination(array $options)
|
|
||||||
{
|
|
||||||
assert(isset($options['base_url']));
|
|
||||||
assert(isset($options['items_per_page']));
|
|
||||||
|
|
||||||
$this->base_url = $options['base_url'];
|
|
||||||
|
|
||||||
$this->recordCount = $options['get_count']();
|
|
||||||
$this->items_per_page = !empty($options['items_per_page']) ? $options['items_per_page'] : 30;
|
|
||||||
|
|
||||||
$this->start = empty($options['start']) || !is_numeric($options['start']) || $options['start'] < 0 || $options['start'] > $this->recordCount ? 0 : $options['start'];
|
|
||||||
|
|
||||||
$numPages = max(1, ceil($this->recordCount / $this->items_per_page));
|
|
||||||
$this->currentPage = min(ceil($this->start / $this->items_per_page) + 1, $numPages);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateColumnHeaders($options)
|
private function generateColumnHeaders($options)
|
||||||
{
|
{
|
||||||
foreach ($options['columns'] as $key => $column)
|
foreach ($options['columns'] as $key => $column)
|
||||||
@ -97,14 +102,14 @@ class GenericTable
|
|||||||
if (empty($column['header']))
|
if (empty($column['header']))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$isSortable = !empty($column['is_sortable']);
|
$isSortable = $this->tableIsSortable && !empty($column['is_sortable']);
|
||||||
$sortDirection = $key == $this->sort_order && $this->sort_direction === 'up' ? 'down' : 'up';
|
$sortDirection = $key == $this->sort_order && $this->sort_direction === 'up' ? 'down' : 'up';
|
||||||
|
|
||||||
$header = [
|
$header = [
|
||||||
'class' => isset($column['class']) ? $column['class'] : '',
|
'class' => isset($column['class']) ? $column['class'] : '',
|
||||||
'cell_class' => isset($column['cell_class']) ? $column['cell_class'] : null,
|
'cell_class' => isset($column['cell_class']) ? $column['cell_class'] : null,
|
||||||
'colspan' => !empty($column['header_colspan']) ? $column['header_colspan'] : 1,
|
'colspan' => !empty($column['header_colspan']) ? $column['header_colspan'] : 1,
|
||||||
'href' => $isSortable ? $this->getHeaderLink($this->start, $key, $sortDirection) : null,
|
'href' => $isSortable ? $this->getLink($this->start, $key, $sortDirection) : null,
|
||||||
'label' => $column['header'],
|
'label' => $column['header'],
|
||||||
'scope' => 'col',
|
'scope' => 'col',
|
||||||
'sort_mode' => $key == $this->sort_order ? $this->sort_direction : null,
|
'sort_mode' => $key == $this->sort_order ? $this->sort_direction : null,
|
||||||
@ -121,7 +126,7 @@ class GenericTable
|
|||||||
'base_url' => $this->base_url,
|
'base_url' => $this->base_url,
|
||||||
'index_class' => $options['index_class'] ?? '',
|
'index_class' => $options['index_class'] ?? '',
|
||||||
'items_per_page' => $this->items_per_page,
|
'items_per_page' => $this->items_per_page,
|
||||||
'linkBuilder' => [$this, 'getHeaderLink'],
|
'linkBuilder' => [$this, 'getLink'],
|
||||||
'recordCount' => $this->recordCount,
|
'recordCount' => $this->recordCount,
|
||||||
'sort_direction' => $this->sort_direction,
|
'sort_direction' => $this->sort_direction,
|
||||||
'sort_order' => $this->sort_order,
|
'sort_order' => $this->sort_order,
|
||||||
@ -129,7 +134,7 @@ class GenericTable
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeaderLink($start = null, $order = null, $dir = null)
|
public function getLink($start = null, $order = null, $dir = null)
|
||||||
{
|
{
|
||||||
if ($start === null)
|
if ($start === null)
|
||||||
$start = $this->start;
|
$start = $this->start;
|
||||||
@ -191,18 +196,12 @@ class GenericTable
|
|||||||
|
|
||||||
foreach ($options['columns'] as $column)
|
foreach ($options['columns'] as $column)
|
||||||
{
|
{
|
||||||
// Process formatting
|
// Process data for this particular cell.
|
||||||
if (isset($column['format']) && is_callable($column['format']))
|
if (isset($column['parse']))
|
||||||
$value = $column['format']($row);
|
$value = self::processCell($column['parse'], $row);
|
||||||
elseif (isset($column['format']))
|
|
||||||
$value = self::processFormatting($column['format'], $row);
|
|
||||||
else
|
else
|
||||||
$value = $row[$column['value']];
|
$value = $row[$column['value']];
|
||||||
|
|
||||||
// Turn value into a link?
|
|
||||||
if (!empty($column['link']))
|
|
||||||
$value = $this->processLink($column['link'], $value, $row);
|
|
||||||
|
|
||||||
// Append the cell to the row.
|
// Append the cell to the row.
|
||||||
$newRow['cells'][] = [
|
$newRow['cells'][] = [
|
||||||
'class' => $column['cell_class'] ?? '',
|
'class' => $column['cell_class'] ?? '',
|
||||||
@ -215,47 +214,68 @@ class GenericTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processFormatting($options, $rowData)
|
private function processCell($options, $rowData)
|
||||||
{
|
{
|
||||||
if ($options['type'] === 'timestamp')
|
if (!isset($options['type']))
|
||||||
|
$options['type'] = 'value';
|
||||||
|
|
||||||
|
// Parse the basic value first.
|
||||||
|
switch ($options['type'])
|
||||||
{
|
{
|
||||||
if (empty($options['pattern']) || $options['pattern'] === 'long')
|
// Basic option: simply take a use a particular data property.
|
||||||
$pattern = 'Y-m-d H:i';
|
case 'value':
|
||||||
elseif ($options['pattern'] === 'short')
|
$value = htmlspecialchars($rowData[$options['data']]);
|
||||||
$pattern = 'Y-m-d';
|
break;
|
||||||
else
|
|
||||||
$pattern = $options['pattern'];
|
|
||||||
|
|
||||||
assert(isset($rowData[$options['value']]));
|
// Processing via a lambda function.
|
||||||
if (!is_numeric($rowData[$options['value']]))
|
case 'function':
|
||||||
$timestamp = strtotime($rowData[$options['value']]);
|
$value = $options['data']($rowData);
|
||||||
else
|
break;
|
||||||
$timestamp = (int) $rowData[$options['value']];
|
|
||||||
|
|
||||||
if (isset($options['if_null']) && $timestamp == 0)
|
// Using sprintf to fill out a particular pattern.
|
||||||
$value = $options['if_null'];
|
case 'sprintf':
|
||||||
else
|
$parameters = [$options['data']['pattern']];
|
||||||
$value = date($pattern, $timestamp);
|
foreach ($options['data']['arguments'] as $identifier)
|
||||||
|
$parameters[] = $rowData[$identifier];
|
||||||
|
|
||||||
return $value;
|
$value = sprintf(...$parameters);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Timestamps get custom treatment.
|
||||||
|
case 'timestamp':
|
||||||
|
if (empty($options['data']['pattern']) || $options['data']['pattern'] === 'long')
|
||||||
|
$pattern = 'Y-m-d H:i';
|
||||||
|
elseif ($options['data']['pattern'] === 'short')
|
||||||
|
$pattern = 'Y-m-d';
|
||||||
|
else
|
||||||
|
$pattern = $options['data']['pattern'];
|
||||||
|
|
||||||
|
if (!isset($rowData[$options['data']['timestamp']]))
|
||||||
|
$timestamp = 0;
|
||||||
|
elseif (!is_numeric($rowData[$options['data']['timestamp']]))
|
||||||
|
$timestamp = strtotime($rowData[$options['data']['timestamp']]);
|
||||||
|
else
|
||||||
|
$timestamp = (int) $rowData[$options['data']['timestamp']];
|
||||||
|
|
||||||
|
if (isset($options['data']['if_null']) && $timestamp == 0)
|
||||||
|
$value = $options['data']['if_null'];
|
||||||
|
else
|
||||||
|
$value = date($pattern, $timestamp);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
throw ValueError('Unexpected formatter type: ' . $options['type']);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processLink($template, $value, array $rowData)
|
// Generate a link, if requested.
|
||||||
{
|
if (!empty($options['link']))
|
||||||
$href = $this->rowReplacements($template, $rowData);
|
{
|
||||||
return '<a href="' . $href . '">' . $value . '</a>';
|
// First, generate the replacement variables.
|
||||||
}
|
$keys = array_keys($rowData);
|
||||||
|
$values = array_values($rowData);
|
||||||
|
foreach ($keys as $keyKey => $keyValue)
|
||||||
|
$keys[$keyKey] = '{' . strtoupper($keyValue) . '}';
|
||||||
|
|
||||||
private function rowReplacements($template, array $rowData)
|
$value = '<a href="' . str_replace($keys, $values, $options['link']) . '">' . $value . '</a>';
|
||||||
{
|
}
|
||||||
$keys = array_keys($rowData);
|
|
||||||
$values = array_values($rowData);
|
|
||||||
foreach ($keys as $keyKey => $keyValue)
|
|
||||||
$keys[$keyKey] = '{' . strtoupper($keyValue) . '}';
|
|
||||||
|
|
||||||
return str_replace($keys, $values, $template);
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,22 +187,6 @@ class Member extends User
|
|||||||
FROM users');
|
FROM users');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getOffset($offset, $limit, $order, $direction)
|
|
||||||
{
|
|
||||||
assert(in_array($order, ['id_user', 'surname', 'first_name', 'slug', 'emailaddress', 'last_action_time', 'ip_address', 'is_admin']));
|
|
||||||
|
|
||||||
return Registry::get('db')->queryAssocs('
|
|
||||||
SELECT *
|
|
||||||
FROM users
|
|
||||||
ORDER BY {raw:order}
|
|
||||||
LIMIT {int:offset}, {int:limit}',
|
|
||||||
[
|
|
||||||
'order' => $order . ($direction === 'up' ? ' ASC' : ' DESC'),
|
|
||||||
'offset' => $offset,
|
|
||||||
'limit' => $limit,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getProps()
|
public function getProps()
|
||||||
{
|
{
|
||||||
// We should probably phase out the use of this function, or refactor the access levels of member properties...
|
// We should probably phase out the use of this function, or refactor the access levels of member properties...
|
||||||
|
76
models/PhotoAlbum.php
Normal file
76
models/PhotoAlbum.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
/*****************************************************************************
|
||||||
|
* PhotoAlbum.php
|
||||||
|
* Contains key class PhotoAlbum.
|
||||||
|
*
|
||||||
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
class PhotoAlbum extends Tag
|
||||||
|
{
|
||||||
|
public static function getHierarchy($order, $direction)
|
||||||
|
{
|
||||||
|
$db = Registry::get('db');
|
||||||
|
$res = $db->query('
|
||||||
|
SELECT *
|
||||||
|
FROM tags
|
||||||
|
WHERE kind = {string:album}
|
||||||
|
ORDER BY id_parent, {raw:order}',
|
||||||
|
[
|
||||||
|
'order' => $order . ($direction == 'up' ? ' ASC' : ' DESC'),
|
||||||
|
'album' => 'Album',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$albums_by_parent = [];
|
||||||
|
while ($row = $db->fetch_assoc($res))
|
||||||
|
{
|
||||||
|
if (!isset($albums_by_parent[$row['id_parent']]))
|
||||||
|
$albums_by_parent[$row['id_parent']] = [];
|
||||||
|
|
||||||
|
$albums_by_parent[$row['id_parent']][] = $row + ['children' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
$albums = self::getChildrenRecursively(0, 0, $albums_by_parent);
|
||||||
|
$rows = self::flattenChildrenRecursively($albums);
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getChildrenRecursively($id_parent, $level, &$albums_by_parent)
|
||||||
|
{
|
||||||
|
$children = [];
|
||||||
|
if (!isset($albums_by_parent[$id_parent]))
|
||||||
|
return $children;
|
||||||
|
|
||||||
|
foreach ($albums_by_parent[$id_parent] as $child)
|
||||||
|
{
|
||||||
|
if (isset($albums_by_parent[$child['id_tag']]))
|
||||||
|
$child['children'] = self::getChildrenRecursively($child['id_tag'], $level + 1, $albums_by_parent);
|
||||||
|
|
||||||
|
$child['tag'] = ($level ? str_repeat('—', $level * 2) . ' ' : '') . $child['tag'];
|
||||||
|
$children[] = $child;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $children;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function flattenChildrenRecursively($albums)
|
||||||
|
{
|
||||||
|
if (empty($albums))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
foreach ($albums as $album)
|
||||||
|
{
|
||||||
|
$rows[] = array_intersect_key($album, array_flip(['id_tag', 'tag', 'slug', 'count']));
|
||||||
|
if (!empty($album['children']))
|
||||||
|
{
|
||||||
|
$children = self::flattenChildrenRecursively($album['children']);
|
||||||
|
foreach ($children as $child)
|
||||||
|
$rows[] = array_intersect_key($child, array_flip(['id_tag', 'tag', 'slug', 'count']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
}
|
100
models/Tag.php
100
models/Tag.php
@ -24,11 +24,6 @@ class Tag
|
|||||||
$this->$attribute = $value;
|
$this->$attribute = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromId($id_tag, $return_format = 'object')
|
public static function fromId($id_tag, $return_format = 'object')
|
||||||
{
|
{
|
||||||
$db = Registry::get('db');
|
$db = Registry::get('db');
|
||||||
@ -414,98 +409,27 @@ class Tag
|
|||||||
['tags' => $tags]);
|
['tags' => $tags]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCount($only_used = true, $kind = '', $isAlbum = false)
|
public static function getCount($only_active = 1, $kind = '')
|
||||||
{
|
{
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($only_used)
|
if ($only_active)
|
||||||
$where[] = 'count > 0';
|
$where[] = 'count > 0';
|
||||||
if (empty($kind))
|
if (!empty($kind))
|
||||||
$kind = 'Album';
|
$where[] = 'kind = {string:kind}';
|
||||||
|
|
||||||
$where[] = 'kind {raw:operator} {string:kind}';
|
if (!empty($where))
|
||||||
$where = implode(' AND ', $where);
|
$where = 'WHERE ' . implode(' AND ', $where);
|
||||||
|
else
|
||||||
|
$where = '';
|
||||||
|
|
||||||
return Registry::get('db')->queryValue('
|
return Registry::get('db')->queryValue('
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM tags
|
FROM tags ' . $where,
|
||||||
WHERE ' . $where,
|
['kind' => $kind]);
|
||||||
[
|
|
||||||
'kind' => $kind,
|
|
||||||
'operator' => $isAlbum ? '=' : '!=',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getOffset($offset, $limit, $order, $direction, $isAlbum = false)
|
public function __toString()
|
||||||
{
|
{
|
||||||
assert(in_array($order, ['id_tag', 'tag', 'slug', 'count']));
|
return $this->tag;
|
||||||
|
|
||||||
$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 {raw:operator} {string:album}
|
|
||||||
ORDER BY id_parent, {raw:order}
|
|
||||||
LIMIT {int:offset}, {int:limit}',
|
|
||||||
[
|
|
||||||
'order' => $order . ($direction === 'up' ? ' ASC' : ' DESC'),
|
|
||||||
'offset' => $offset,
|
|
||||||
'limit' => $limit,
|
|
||||||
'album' => 'Album',
|
|
||||||
'operator' => $isAlbum ? '=' : '!=',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$albums_by_parent = [];
|
|
||||||
while ($row = $db->fetch_assoc($res))
|
|
||||||
{
|
|
||||||
if (!isset($albums_by_parent[$row['id_parent']]))
|
|
||||||
$albums_by_parent[$row['id_parent']] = [];
|
|
||||||
|
|
||||||
$albums_by_parent[$row['id_parent']][] = $row + ['children' => []];
|
|
||||||
}
|
|
||||||
|
|
||||||
$albums = self::getChildrenRecursively(0, 0, $albums_by_parent);
|
|
||||||
$rows = self::flattenChildrenRecursively($albums);
|
|
||||||
|
|
||||||
return $rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function getChildrenRecursively($id_parent, $level, &$albums_by_parent)
|
|
||||||
{
|
|
||||||
$children = [];
|
|
||||||
if (!isset($albums_by_parent[$id_parent]))
|
|
||||||
return $children;
|
|
||||||
|
|
||||||
foreach ($albums_by_parent[$id_parent] as $child)
|
|
||||||
{
|
|
||||||
if (isset($albums_by_parent[$child['id_tag']]))
|
|
||||||
$child['children'] = self::getChildrenRecursively($child['id_tag'], $level + 1, $albums_by_parent);
|
|
||||||
|
|
||||||
$child['tag'] = ($level ? str_repeat('—', $level * 2) . ' ' : '') . $child['tag'];
|
|
||||||
$children[] = $child;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $children;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function flattenChildrenRecursively($albums)
|
|
||||||
{
|
|
||||||
if (empty($albums))
|
|
||||||
return [];
|
|
||||||
|
|
||||||
$rows = [];
|
|
||||||
foreach ($albums as $album)
|
|
||||||
{
|
|
||||||
static $headers_to_keep = ['id_tag', 'tag', 'slug', 'count', 'id_user', 'first_name', 'surname'];
|
|
||||||
$rows[] = array_intersect_key($album, array_flip($headers_to_keep));
|
|
||||||
if (!empty($album['children']))
|
|
||||||
{
|
|
||||||
$children = self::flattenChildrenRecursively($album['children']);
|
|
||||||
foreach ($children as $child)
|
|
||||||
$rows[] = array_intersect_key($child, array_flip($headers_to_keep));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rows;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class MainNavBar extends NavBar
|
|||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>';
|
</button>';
|
||||||
|
|
||||||
if (Registry::has('user') && Registry::get('user')->isLoggedIn())
|
if (Registry::get('user')->isLoggedIn())
|
||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
<div class="collapse navbar-collapse justify-content-end" id="', $this->innerMenuId, '">
|
<div class="collapse navbar-collapse justify-content-end" id="', $this->innerMenuId, '">
|
||||||
|
Loading…
Reference in New Issue
Block a user