forked from Public/pics
ManageAssets: allow batch deletion of assets
This commit is contained in:
@@ -14,10 +14,37 @@ class ManageAssets extends HTMLController
|
||||
if (!Registry::get('user')->isAdmin())
|
||||
throw new NotAllowedException();
|
||||
|
||||
if (isset($_POST['deleteChecked'], $_POST['delete']) && Session::validateSession())
|
||||
$this->handleAssetDeletion();
|
||||
|
||||
Session::resetSessionToken();
|
||||
|
||||
$options = [
|
||||
'form' => [
|
||||
'action' => BASEURL . '/manageassets/?' . Session::getSessionTokenKey() . '=' . Session::getSessionToken(),
|
||||
'method' => 'post',
|
||||
'class' => 'col-md-6 text-end',
|
||||
'is_embed' => true,
|
||||
'buttons' => [
|
||||
'deleteChecked' => [
|
||||
'type' => 'submit',
|
||||
'caption' => 'Delete checked',
|
||||
'class' => 'btn-danger',
|
||||
'onclick' => 'return confirm(\'Are you sure you want to delete these items?\')',
|
||||
],
|
||||
],
|
||||
],
|
||||
'columns' => [
|
||||
'checkbox' => [
|
||||
'header' => '<input type="checkbox" id="selectall">',
|
||||
'is_sortable' => false,
|
||||
'parse' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
return '<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">';
|
||||
},
|
||||
],
|
||||
],
|
||||
'id_asset' => [
|
||||
'value' => 'id_asset',
|
||||
'header' => 'ID',
|
||||
@@ -71,6 +98,7 @@ class ManageAssets extends HTMLController
|
||||
'title' => 'Manage assets',
|
||||
'no_items_label' => 'No assets meet the requirements of the current filter.',
|
||||
'items_per_page' => 30,
|
||||
'index_class' => 'col-md-6',
|
||||
'base_url' => BASEURL . '/manageassets/',
|
||||
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'down') {
|
||||
if (!in_array($order, ['id_asset', 'id_user_uploaded', 'title', 'subdir', 'filename']))
|
||||
@@ -100,7 +128,25 @@ class ManageAssets extends HTMLController
|
||||
];
|
||||
|
||||
$table = new GenericTable($options);
|
||||
parent::__construct('Asset management - Page ' . $table->getCurrentPage() .'');
|
||||
$this->page->adopt(new TabularData($table));
|
||||
parent::__construct('Asset management - Page ' . $table->getCurrentPage());
|
||||
|
||||
$wrapper = new AssetManagementWrapper();
|
||||
$this->page->adopt($wrapper);
|
||||
$wrapper->adopt(new TabularData($table));
|
||||
}
|
||||
|
||||
private function handleAssetDeletion()
|
||||
{
|
||||
if (!isset($_POST['delete']) || !is_array($_POST['delete']))
|
||||
throw new UnexpectedValueException();
|
||||
|
||||
foreach ($_POST['delete'] as $id_asset)
|
||||
{
|
||||
$asset = Asset::fromId($id_asset);
|
||||
$asset->delete();
|
||||
}
|
||||
|
||||
header('Location: ' . BASEURL . '/manageassets/');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user