diff --git a/CHANGELOG.md b/CHANGELOG.md index a875dc8..ce35db9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/_admin.php b/_admin.php index a02d91f..f268727 100644 --- a/_admin.php +++ b/_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 '

' . __('This enable public widgets and contents filter.') . '

' . - '
' . __('Record list') . '
' . - '

' . __('This is the default order of records lists.') . '

' . - '

' . - form::combo('epc_list_sortby', self::sortbyCombo(), $list_sortby) . '

' . - '

' . - form::combo('epc_list_order', self::orderCombo(), $list_order) . '

' . - '

' . - form::field('epc_list_nb', 3, 3, $list_nb) . '

' . '

' . __('Set content filters') . '

' . '' . @@ -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] + ]; + } } \ No newline at end of file diff --git a/index.php b/index.php index 9c69eca..3666b68 100644 --- a/index.php +++ b/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 '

' . __('No record') . '

'; } else { echo ' -
+

' . __('Page(s)') . ' : ' . $pager->getLinks() . '

- - - - + '; + + $lines = [ + __('Key') => 'epc_key', + __('Value') => 'epc_value', + __('Date') => 'epc_date' + ]; + foreach($lines as $k => $v) { + echo ''; + } + + echo ' '; @@ -392,7 +375,7 @@ if (isset($filters_id[$default_part])) {

' . $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') . '

' . - __('Key') . '' . - __('Value') . '' . - __('Date') . '
' .$k . '