forked from Public/pics
Port basic asset management page from Kabuki.
This commit is contained in:
parent
12ea378b02
commit
f193b614b7
100
controllers/ManageAssets.php
Normal file
100
controllers/ManageAssets.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* ManageAssets.php
|
||||
* Contains the asset management controller.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2017, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class ManageAssets extends HTMLController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Ensure it's just admins at this point.
|
||||
if (!Registry::get('user')->isAdmin())
|
||||
throw new NotAllowedException();
|
||||
|
||||
Session::resetSessionToken();
|
||||
|
||||
$options = [
|
||||
'columns' => [
|
||||
'id_asset' => [
|
||||
'value' => 'id_asset',
|
||||
'header' => 'ID',
|
||||
'is_sortable' => true,
|
||||
],
|
||||
'subdir' => [
|
||||
'value' => 'subdir',
|
||||
'header' => 'Subdirectory',
|
||||
'is_sortable' => true,
|
||||
],
|
||||
'filename' => [
|
||||
'value' => 'filename',
|
||||
'header' => 'Filename',
|
||||
'is_sortable' => true,
|
||||
'parse' => [
|
||||
'type' => 'value',
|
||||
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
||||
'data' => 'filename',
|
||||
],
|
||||
],
|
||||
'title' => [
|
||||
'header' => 'Title',
|
||||
'is_sortable' => true,
|
||||
'parse' => [
|
||||
'type' => 'value',
|
||||
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
||||
'data' => 'title',
|
||||
],
|
||||
],
|
||||
'dimensions' => [
|
||||
'header' => 'Dimensions',
|
||||
'is_sortable' => false,
|
||||
'parse' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
if (!empty($row['image_width']))
|
||||
return $row['image_width'] . ' x ' . $row['image_height'];
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
||||
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
|
||||
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
|
||||
'title' => 'Manage assets',
|
||||
'no_items_label' => 'No assets meet the requirements of the current filter.',
|
||||
'items_per_page' => 30,
|
||||
'index_class' => 'pull_left',
|
||||
'base_url' => BASEURL . '/manageassets/',
|
||||
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'down') {
|
||||
if (!in_array($order, ['id_asset', 'title', 'subdir', 'filename']))
|
||||
$order = 'id_asset';
|
||||
|
||||
$data = Registry::get('db')->queryAssocs('
|
||||
SELECT id_asset, title, subdir, filename, image_width, image_height
|
||||
FROM assets
|
||||
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',
|
||||
];
|
||||
|
||||
$table = new GenericTable($options);
|
||||
parent::__construct('Asset management - Page ' . $table->getCurrentPage() .'');
|
||||
$this->page->adopt(new TabularData($table));
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ class Dispatcher
|
||||
'login' => 'Login',
|
||||
'logout' => 'Logout',
|
||||
'managealbums' => 'ManageAlbums',
|
||||
'manageassets' => 'ManageAssets',
|
||||
'manageerrors' => 'ManageErrors',
|
||||
'managetags' => 'ManageTags',
|
||||
'manageusers' => 'ManageUsers',
|
||||
|
@ -16,6 +16,7 @@ class AdminBar extends SubTemplate
|
||||
<div id="admin_bar">
|
||||
<ul>
|
||||
<li><a href="', BASEURL, '/managealbums/">Albums</a></li>
|
||||
<li><a href="', BASEURL, '/manageassets/">Assets</a></li>
|
||||
<li><a href="', BASEURL, '/managetags/">Tags</a></li>
|
||||
<li><a href="', BASEURL, '/manageusers/">Users</a></li>
|
||||
<li><a href="', BASEURL, '/manageerrors/">Errors [', ErrorLog::getCount(), ']</a></li>';
|
||||
|
Loading…
Reference in New Issue
Block a user