move sort options from blog pref to user pref
This commit is contained in:
parent
9ce7cdd237
commit
3ef8a1d395
@ -4,7 +4,7 @@
|
||||
- [ ] add auto-find post title in content
|
||||
- [ ] split filters into modules
|
||||
- [x] add autosubmit onadmin menu
|
||||
- [ ] move sort options from blog pref to user pref
|
||||
- [x] move sort options from blog pref to user pref
|
||||
|
||||
2021.09.05
|
||||
- fix duplicate records id
|
||||
|
41
_admin.php
41
_admin.php
@ -43,6 +43,10 @@ $core->addBehavior(
|
||||
'adminBeforeBlogSettingsUpdate',
|
||||
['epcAdminBehaviors', 'adminBeforeBlogSettingsUpdate']
|
||||
);
|
||||
$core->addBehavior(
|
||||
'adminFiltersLists',
|
||||
['epcAdminBehaviors', 'adminFiltersLists']
|
||||
);
|
||||
|
||||
class epcAdminBehaviors
|
||||
{
|
||||
@ -78,21 +82,9 @@ class epcAdminBehaviors
|
||||
];
|
||||
}
|
||||
|
||||
public static function orderCombo()
|
||||
{
|
||||
return [
|
||||
__('Ascending') => 'asc',
|
||||
__('Descending') => 'desc'
|
||||
];
|
||||
}
|
||||
|
||||
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings)
|
||||
{
|
||||
$active = (boolean) $blog_settings->enhancePostContent->enhancePostContent_active;
|
||||
$list_sortby = (string) $blog_settings->enhancePostContent->enhancePostContent_list_sortby;
|
||||
$list_order = (string) $blog_settings->enhancePostContent->enhancePostContent_list_order;
|
||||
$list_nb = (integer) $blog_settings->enhancePostContent->enhancePostContent_list_nb;
|
||||
$_filters = libEPC::blogFilters();
|
||||
$allowedtplvalues = libEPC::blogAllowedTplValues();
|
||||
$allowedpubpages = libEPC::blogAllowedPubPages();
|
||||
|
||||
@ -106,14 +98,6 @@ class epcAdminBehaviors
|
||||
'<p class="form-note">' .
|
||||
__('This enable public widgets and contents filter.') .
|
||||
'</p>' .
|
||||
'<h5>' . __('Record list') . '</h4>' .
|
||||
'<p class="form-note">' . __('This is the default order of records lists.') . '</p>' .
|
||||
'<p class="field"><label for="epc_list_sortby">' . __('Order by:') . '</label>' .
|
||||
form::combo('epc_list_sortby', self::sortbyCombo(), $list_sortby) . '</p>' .
|
||||
'<p class="field"><label for="epc_list_order">' . __('Sort:') . '</label>' .
|
||||
form::combo('epc_list_order', self::orderCombo(), $list_order) . '</p>' .
|
||||
'<p class="field"><label for="list_nb">' . __('Records per page:') . '</label>' .
|
||||
form::field('epc_list_nb', 3, 3, $list_nb) . '</p>' .
|
||||
'<p><a href="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '">' .
|
||||
__('Set content filters') . '</a></p>' .
|
||||
'</div>' .
|
||||
@ -135,17 +119,22 @@ class epcAdminBehaviors
|
||||
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
||||
{
|
||||
$active = !empty($_POST['epc_active']);
|
||||
$list_sortby = in_array($_POST['epc_list_sortby'], self::sortbyCombo()) ? $_POST['epc_list_sortby'] : 'epc_id';
|
||||
$list_order = in_array($_POST['epc_list_order'], self::orderCombo()) ? $_POST['epc_list_order'] : 'desc';
|
||||
$list_nb = isset($_POST['epc_list_nb']) && $_POST['epc_list_nb'] > 0 ? $_POST['epc_list_nb'] : 20;
|
||||
$allowedtplvalues = libEPC::explode($_POST['epc_allowedtplvalues']);
|
||||
$allowedpubpages = libEPC::explode($_POST['epc_allowedpubpages']);
|
||||
|
||||
$blog_settings->enhancePostContent->put('enhancePostContent_active', $active);
|
||||
$blog_settings->enhancePostContent->put('enhancePostContent_list_sortby', $list_sortby);
|
||||
$blog_settings->enhancePostContent->put('enhancePostContent_list_order', $list_order);
|
||||
$blog_settings->enhancePostContent->put('enhancePostContent_list_nb', $list_nb);
|
||||
$blog_settings->enhancePostContent->put('enhancePostContent_allowedtplvalues', serialize($allowedtplvalues));
|
||||
$blog_settings->enhancePostContent->put('enhancePostContent_allowedpubpages', serialize($allowedpubpages));
|
||||
}
|
||||
|
||||
public static function adminFiltersLists(dcCore $core, $sorts)
|
||||
{
|
||||
$sorts['epc'] = [
|
||||
__('Enhance post content'),
|
||||
self::sortbyCombo(),
|
||||
'epc_upddt',
|
||||
'desc',
|
||||
[__('records per page'), 20]
|
||||
];
|
||||
}
|
||||
}
|
59
index.php
59
index.php
@ -298,50 +298,28 @@ if (isset($filters_id[$default_part])) {
|
||||
|
||||
# Filter records list
|
||||
if ($filter['has_list']) {
|
||||
$sorts = new adminGenericFilter($core, 'epc');
|
||||
$sorts->add(dcAdminFilters::getPageFilter());
|
||||
|
||||
$sortby_combo = [
|
||||
'epc_upddt',
|
||||
'epc_key',
|
||||
'epc_value',
|
||||
'epc_id'
|
||||
];
|
||||
|
||||
$order_combo = [
|
||||
'asc',
|
||||
'desc'
|
||||
];
|
||||
|
||||
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : (string) $s->enhancePostContent_list_sortby;
|
||||
$order = !empty($_GET['order']) ? $_GET['order'] : (string) $s->enhancePostContent_list_order;
|
||||
$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
|
||||
$nb = !empty($_GET['nb']) && (integer) $_GET['nb'] > 0 ? (integer) $_GET['nb'] : (integer) $s->enhancePostContent_list_nb;
|
||||
|
||||
$params = [];
|
||||
$params = $sorts->params();
|
||||
$params['epc_filter'] = $name;
|
||||
$params['limit'] = [(($page - 1) * $nb), $nb];
|
||||
|
||||
if ($sortby !== '' && in_array($sortby, $sortby_combo)) {
|
||||
if ($order !== '' && in_array($order, $order_combo)) {
|
||||
$params['order'] = $sortby . ' ' . $order;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$list = $records->getRecords($params);
|
||||
$counter = $records->getRecords($params, true);
|
||||
|
||||
$pager_url = $p_url .
|
||||
'&nb=' . $nb .
|
||||
'&nb=' . $sorts->nb .
|
||||
'&sortby=%s' .
|
||||
'&order=%s' . //($order == 'desc' ? 'desc' : 'asc') .
|
||||
'&order=%s' .
|
||||
'&page=%s' .
|
||||
'&part=' . $default_part .
|
||||
'#record';
|
||||
|
||||
$pager = new pager($page, $counter->f(0), $nb, 10);
|
||||
$pager = new pager($sorts->page, $counter->f(0), $sorts->nb, 10);
|
||||
$pager->html_prev = __('«prev.');
|
||||
$pager->html_next = __('next»');
|
||||
$pager->base_url = sprintf($pager_url, $sortby, $order, '%s');
|
||||
$pager->base_url = sprintf($pager_url, $sorts->sortby, $sorts->order, '%s');
|
||||
$pager->var_page = 'page';
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
@ -354,17 +332,22 @@ if (isset($filters_id[$default_part])) {
|
||||
echo '<p>' . __('No record') . '</p>';
|
||||
} else {
|
||||
echo '
|
||||
<form action="' . sprintf($pager_url, 'epc_key', $order, $page) . '" method="post">
|
||||
<form action="' . sprintf($pager_url, $sorts->sortby, $sorts->order, $sorts->page) . '" method="post">
|
||||
<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>
|
||||
<div class="table-outer">
|
||||
<table><caption class="hidden">' . __('Records') . '</caption>
|
||||
<thead><tr>
|
||||
<th><a href="' . sprintf($pager_url, 'epc_key', $order, $page) . '">' .
|
||||
__('Key') . '</a></th>
|
||||
<th><a href="' . sprintf($pager_url, 'epc_value', $order, $page) . '">' .
|
||||
__('Value') . '</a></th>
|
||||
<th><a href="' . sprintf($pager_url, 'epc_upddt', $order, $page) . '">' .
|
||||
__('Date') . '</a></th>
|
||||
<thead><tr>';
|
||||
|
||||
$lines = [
|
||||
__('Key') => 'epc_key',
|
||||
__('Value') => 'epc_value',
|
||||
__('Date') => 'epc_date'
|
||||
];
|
||||
foreach($lines as $k => $v) {
|
||||
echo '<th><a href="' . sprintf($pager_url, $v, $sorts->sortby == $v ? $sorts->order == 'asc' ? 'desc' : 'asc' : $sorts->order, $sorts->page) . '">' .$k . '</a></th>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</tr></thead>
|
||||
<tbody>';
|
||||
|
||||
@ -392,7 +375,7 @@ if (isset($filters_id[$default_part])) {
|
||||
<div class="clear">
|
||||
<p>' .
|
||||
$core->formNonce() .
|
||||
form::hidden(['redir'], sprintf($pager_url, $sortby, $order, $page)) .
|
||||
form::hidden(['redir'], sprintf($pager_url, $sorts->sortby, $sorts->order, $sorts->page)) .
|
||||
form::hidden(['action'], 'saveupdaterecords') . '
|
||||
<input type="submit" name="save" value="' . __('Save') . '" />
|
||||
</p>
|
||||
|
Loading…
Reference in New Issue
Block a user