generic filter (dc 2.20)
This commit is contained in:
parent
fbda59abe3
commit
e7f00b41e4
31
_admin.php
31
_admin.php
@ -34,8 +34,8 @@ $core->addBehavior(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminSortsLists',
|
'adminFiltersLists',
|
||||||
['cinecturlink2AdminBehaviors', 'adminSortsLists']
|
['cinecturlink2AdminBehaviors', 'adminFiltersLists']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminDashboardFavorites',
|
'adminDashboardFavorites',
|
||||||
@ -44,6 +44,19 @@ $core->addBehavior(
|
|||||||
|
|
||||||
class cinecturlink2AdminBehaviors
|
class cinecturlink2AdminBehaviors
|
||||||
{
|
{
|
||||||
|
public static function adminSortbyCombo()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
__('Date') => 'link_upddt',
|
||||||
|
__('Title') => 'link_title',
|
||||||
|
__('Category') => 'cat_id',
|
||||||
|
__('Author') => 'link_author',
|
||||||
|
__('Description') => 'link_desc',
|
||||||
|
__('Link') => 'link_url',
|
||||||
|
__('Rating') => 'link_note'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public static function adminColumnsLists($core, $cols)
|
public static function adminColumnsLists($core, $cols)
|
||||||
{
|
{
|
||||||
$cols['c2link'] = [
|
$cols['c2link'] = [
|
||||||
@ -59,22 +72,14 @@ class cinecturlink2AdminBehaviors
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function adminSortsLists($core, $sorts)
|
public static function adminFiltersLists($core, $sorts)
|
||||||
{
|
{
|
||||||
$sorts['c2link'] = [
|
$sorts['c2link'] = [
|
||||||
__('Cinecturlink'),
|
__('Cinecturlink'),
|
||||||
[
|
self::adminSortbyCombo(),
|
||||||
__('Date') => 'link_upddt',
|
|
||||||
__('Title') => 'link_title',
|
|
||||||
__('Category') => 'cat_id',
|
|
||||||
__('Author') => 'link_author',
|
|
||||||
__('Description') => 'link_desc',
|
|
||||||
__('Link') => 'link_url',
|
|
||||||
__('Rating') => 'link_note'
|
|
||||||
],
|
|
||||||
'link_upddt',
|
'link_upddt',
|
||||||
'desc',
|
'desc',
|
||||||
null
|
[__('Links per page'), 30]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
121
index.php
121
index.php
@ -32,6 +32,7 @@ $catdesc = $_POST['catdesc'] ?? '';
|
|||||||
$redir = $_REQUEST['redir'] ?? '';
|
$redir = $_REQUEST['redir'] ?? '';
|
||||||
$part = $_REQUEST['part'] ?? 'links';
|
$part = $_REQUEST['part'] ?? 'links';
|
||||||
$entries = $_POST['entries'] ?? [];
|
$entries = $_POST['entries'] ?? [];
|
||||||
|
$page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1;
|
||||||
$headers = '';
|
$headers = '';
|
||||||
$breadcrumb = [
|
$breadcrumb = [
|
||||||
html::escapeHTML($core->blog->name) => '',
|
html::escapeHTML($core->blog->name) => '',
|
||||||
@ -136,65 +137,39 @@ if ($part == 'updlinkscat') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($part == 'links') {
|
if ($part == 'links') {
|
||||||
$sortby_combo = [
|
|
||||||
__('Date') => 'link_upddt',
|
|
||||||
__('Title') => 'link_title',
|
|
||||||
__('Category') => 'cat_id',
|
|
||||||
__('Author') => 'link_author',
|
|
||||||
__('Description') => 'link_desc',
|
|
||||||
__('Liens') => 'link_url',
|
|
||||||
__('Rating') => 'link_note'
|
|
||||||
];
|
|
||||||
$order_combo = [
|
|
||||||
__('Descending') => 'desc',
|
|
||||||
__('Ascending') => 'asc'
|
|
||||||
];
|
|
||||||
$action_combo = [
|
$action_combo = [
|
||||||
__('Delete') => 'dellinks',
|
__('Delete') => 'dellinks',
|
||||||
__('Change category') => 'updlinkscat',
|
__('Change category') => 'updlinkscat',
|
||||||
__('Change rating') => 'updlinksnote'
|
__('Change rating') => 'updlinksnote'
|
||||||
];
|
];
|
||||||
|
|
||||||
$show_filters = false;
|
$c2link_filter = new adminGenericFilter($core, 'c2link');
|
||||||
$page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1;
|
|
||||||
|
|
||||||
$core->auth->user_prefs->addWorkspace('interface');
|
$sortby = $c2link_filter->getFilter('sortby');
|
||||||
$sorts_user = @$core->auth->user_prefs->interface->sorts;
|
$order = $c2link_filter->getFilter('order');
|
||||||
$default_sortby = $sorts_user['c2link'][0] ?? 'link_upddt';
|
$nb = $c2link_filter->getFilter('nb');
|
||||||
$default_order = $sorts_user['c2link'][1] ?? 'desc';
|
|
||||||
$nb_per_page = !empty($sorts_user['c2link'][2]) ? $sorts_user['c2link'][2] : 30;
|
|
||||||
|
|
||||||
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby;
|
$c2link_filter->setFilter('page', $page);
|
||||||
$order = !empty($_GET['order']) ? $_GET['order'] : $default_order;
|
$c2link_filter->setFilter('part', 'links');
|
||||||
|
|
||||||
if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
|
|
||||||
if ($nb_per_page != (integer) $_GET['nb']) {
|
|
||||||
$show_filters = true;
|
|
||||||
}
|
|
||||||
$nb_per_page = (integer) $_GET['nb'];
|
|
||||||
}
|
|
||||||
if (!in_array($sortby, $sortby_combo)) {
|
|
||||||
$sortby = $default_sortby;
|
|
||||||
}
|
|
||||||
if (!in_array($order, $order_combo)) {
|
|
||||||
$order = $default_order;
|
|
||||||
}
|
|
||||||
if ($sortby != $default_sortby || $order != $default_order) {
|
|
||||||
$show_filters = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
$params['link_type'] = 'cinecturlink';
|
$params['link_type'] = 'cinecturlink';
|
||||||
$params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page];
|
$params['limit'] = [(($page - 1) * $nb), $nb];
|
||||||
$params['no_content'] = true;
|
$params['no_content'] = true;
|
||||||
$params['order'] = $sortby . ' ' . $order;
|
$params['order'] = $sortby . ' ' . $order;
|
||||||
|
|
||||||
if ($catid !== '' && in_array($catid, $categories_combo)) {
|
if ($catid === '' || !in_array($catid, $categories_combo)) {
|
||||||
$params['cat_id'] = $catid;
|
|
||||||
$show_filters = true;
|
|
||||||
} else {
|
|
||||||
$catid = '';
|
$catid = '';
|
||||||
}
|
}
|
||||||
|
$catid = $c2link_filter->setFilter([
|
||||||
|
'id' => 'catid',
|
||||||
|
'value' => $catid,
|
||||||
|
'title' => __('Category:'),
|
||||||
|
'combo' => $categories_combo
|
||||||
|
]);
|
||||||
|
if ($catid != '') {
|
||||||
|
$params['cat_id'] = $catid;
|
||||||
|
}
|
||||||
|
|
||||||
$links_list = null;
|
$links_list = null;
|
||||||
|
|
||||||
@ -209,7 +184,7 @@ if ($part == 'links') {
|
|||||||
$breadcrumb[__('My cinecturlink')] = '';
|
$breadcrumb[__('My cinecturlink')] = '';
|
||||||
$headers .=
|
$headers .=
|
||||||
dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links'])]) .
|
dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links'])]) .
|
||||||
dcPage::jsFilterControl($show_filters) .
|
dcPage::jsFilterControl($c2link_filter->show()) .
|
||||||
dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/c2links.js'));
|
dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/c2links.js'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,17 +498,8 @@ if ($part == 'updlinkscat') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($part == "links") {
|
if ($part == "links") {
|
||||||
$links_redir = $core->adminurl->get(
|
$links_redir = $core->adminurl->get('admin.plugin.cinecturlink2', $c2link_filter->getFilters());
|
||||||
'admin.plugin.cinecturlink2',
|
|
||||||
[
|
|
||||||
'part' => 'links',
|
|
||||||
'catid' => $catid,
|
|
||||||
'sortby' => $sortby,
|
|
||||||
'order' => $order,
|
|
||||||
'page' => $page,
|
|
||||||
'nb' => $nb_per_page
|
|
||||||
]
|
|
||||||
);
|
|
||||||
echo
|
echo
|
||||||
'<p>' .
|
'<p>' .
|
||||||
'<a class="button" href="' .
|
'<a class="button" href="' .
|
||||||
@ -549,41 +515,11 @@ if ($part == "links") {
|
|||||||
if ($links->isEmpty()) {
|
if ($links->isEmpty()) {
|
||||||
echo '<p>'.__('There is no link').'</p>';
|
echo '<p>'.__('There is no link').'</p>';
|
||||||
} else {
|
} else {
|
||||||
echo
|
$c2link_filter->display('admin.plugin.cinecturlink2',
|
||||||
'<form action="' . $core->adminurl->get('admin.plugin.cinecturlink2') . '" method="get" id="filters-form">' .
|
form::hidden('p', 'cinecturlink2') . form::hidden('part', 'links')
|
||||||
'<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>' .
|
);
|
||||||
|
|
||||||
'<div class="table">' .
|
$links_list->display($page, $nb,
|
||||||
|
|
||||||
'<div class="cell">' .
|
|
||||||
'<h4>' . __('Filters') . '</h4>' .
|
|
||||||
'<p><label for="cat_id" class="ib">' . __('Category:') . '</label> ' .
|
|
||||||
form::combo('catid', $categories_combo, $catid) . '</p>' .
|
|
||||||
'</div>'.
|
|
||||||
|
|
||||||
'<div class="cell filters-options">' .
|
|
||||||
'<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' .
|
|
||||||
form::combo('sortby', $sortby_combo, $sortby) . '</p>' .
|
|
||||||
'</div><div class="cell">' .
|
|
||||||
'<p><label for="order" class="ib">' . __('Sort:') . '</label> ' .
|
|
||||||
form::combo('order', $order_combo, $order) . '</p>' .
|
|
||||||
'</div><div class="cell">' .
|
|
||||||
'<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">'.
|
|
||||||
form::field('nb', 0, 999, $nb_per_page) . ' ' .
|
|
||||||
__('entries per page') . '</label></p>' .
|
|
||||||
form::hidden('p', 'cinecturlink2') .
|
|
||||||
form::hidden('part', 'links') .
|
|
||||||
form::hidden('filters-options-id', 'c2link') .
|
|
||||||
'<p class="hidden-if-no-js"><a href="#" id="filter-options-save">' . __('Save current options') . '</a></p>' .
|
|
||||||
'</div>' .
|
|
||||||
|
|
||||||
'</div>' .
|
|
||||||
|
|
||||||
'<p><input type="submit" value="' . __('Apply filters and display options') . '" />' .
|
|
||||||
'<br class="clear" /></p>' . //Opera sucks
|
|
||||||
'</form>';
|
|
||||||
|
|
||||||
$links_list->display($page, $nb_per_page,
|
|
||||||
'<form action="' . $core->adminurl->get('admin.plugin.cinecturlink2') . '" method="post" id="form-entries">' .
|
'<form action="' . $core->adminurl->get('admin.plugin.cinecturlink2') . '" method="post" id="form-entries">' .
|
||||||
|
|
||||||
'%s' .
|
'%s' .
|
||||||
@ -594,15 +530,12 @@ if ($part == "links") {
|
|||||||
'<p class="col right"><label for="action" class="classic">' . __('Selected links action:') . '</label> ' .
|
'<p class="col right"><label for="action" class="classic">' . __('Selected links action:') . '</label> ' .
|
||||||
form::combo('part', $action_combo) .
|
form::combo('part', $action_combo) .
|
||||||
'<input id="do-action" type="submit" value="' . __('ok') . '" disabled /></p>' .
|
'<input id="do-action" type="submit" value="' . __('ok') . '" disabled /></p>' .
|
||||||
form::hidden(['sortby'], $sortby) .
|
$core->adminurl->getHiddenFormFields('admin.plugin.cinecturlink2', $c2link_filter->getFilters(true)) .
|
||||||
form::hidden(['order'], $order) .
|
|
||||||
form::hidden(['page'], $page) .
|
|
||||||
form::hidden(['nb'], $nb_per_page) .
|
|
||||||
form::hidden(['redir'], $links_redir) .
|
form::hidden(['redir'], $links_redir) .
|
||||||
$core->formNonce() .
|
$core->formNonce() .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
'</form>',
|
'</form>',
|
||||||
$show_filters,
|
$c2link_filter->show(),
|
||||||
$links_redir
|
$links_redir
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user