diff --git a/src/Backend.php b/src/Backend.php index 1e80a62..45ccba2 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -62,6 +62,7 @@ class Backend extends dcNsProcess dcCore::app()->addBehaviors([ // user pref 'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'], + 'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'], 'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'], 'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'], // post diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index d9fa50f..d34a49a 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -42,6 +42,11 @@ class BackendBehaviors ]; } + /** + * User pref widget text filters options. + * + * @param ArrayObject $sorts Sort options + */ public static function adminFiltersListsV2(ArrayObject $sorts): void { $sorts['pwt'] = [ @@ -53,6 +58,25 @@ class BackendBehaviors ]; } + /** + * User pref for widget text columns lists. + * + * @param ArrayObject $cols Columns + */ + public static function adminColumnsListsV2(ArrayObject $cols): void + { + $cols[My::id()] = [ + My::name(), + [ + 'post_dt' => [true, __('Entry date')], + 'option_title' => [true, __('Widget title')], + 'option_creadt' => [true, __('Widget date')], + 'user_id' => [true, __('Author')], + 'post_type' => [true, __('Entry type')], + ], + ]; + } + public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void { echo ' diff --git a/src/Manage.php b/src/Manage.php index 6840b0c..4c7ac0b 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -87,6 +87,9 @@ class Manage extends dcNsProcess # filters $filter = new adminGenericFilterV2('pwt'); $filter->add(dcAdminFilters::getPageFilter()); + $filter->add(dcAdminFilters::getInputFilter('search_post_title', __('Entry:'))); + $filter->add(dcAdminFilters::getInputFilter('search_widget_title', __('Widget:'))); + $filter->add(dcAdminFilters::getInputFilter('user_id', __('User:'))); $params = $filter->params(); # Get posts with text widget @@ -118,14 +121,13 @@ class Manage extends dcNsProcess $filter->display('admin.plugin.' . My::id(), form::hidden('p', My::id())); $posts_list->display( - (int) $filter->value('page'), - (int) $filter->value('nb'), + $filter, '
' . '%s' . '
' . '

' . '

' . - '

' . + '

' . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $filter->values(true))) . dcCore::app()->formNonce() . '
' . diff --git a/src/ManageList.php b/src/ManageList.php index cf52dd4..c21e9ad 100644 --- a/src/ManageList.php +++ b/src/ManageList.php @@ -14,15 +14,16 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; +use ArrayObject; +use adminGenericFilterV2; use adminGenericListV2; use context; use dcCore; use dcPager; use Dotclear\Helper\Date; +use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Html; -use form; - /** * @ingroup DC_PLUGIN_POSTWIDGETTEXT * @brief postWidgetText - admin list methods. @@ -30,28 +31,40 @@ use form; */ class ManageList extends adminGenericListV2 { - public function display(int $page, int $nb_per_page, string $enclose = ''): void + public function display(adminGenericFilterV2 $filter, string $enclose = '',): void { if ($this->rs->isEmpty()) { - echo '

' . __('No widget') . '

'; + echo '

' . ($filter->show() ? + __('No widgets matching the filter.') : __('No widget') + ) . '

'; + + return; } - $pager = new dcPager($page, (int) $this->rs_count, $nb_per_page, 10); - $pager->html_prev = $this->html_prev; - $pager->html_next = $this->html_next; - $pager->var_page = 'page'; + $pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); - $content = '
' . + $content = + '
' . '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - ''; + '' . + ''; + + $cols = new ArrayObject([ + 'name' => '', + 'post_dt' => '', + 'option_title' => '', + 'option_creadt' => '', + 'user_id' => '', + 'post_type' => '', + ]); + + $this->userColumns(My::id(), $cols); + + $content .= implode(iterator_to_array($cols)) . ''; while ($this->rs->fetch()) { $w_title = Html::escapeHTML($this->rs->option_title); @@ -66,38 +79,25 @@ class ManageList extends adminGenericListV2 ) . ''; } - $content .= '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . + $cols = new ArrayObject([ + 'check' => '', + 'name' => '', + 'post_dt' => '', + 'option_title' => '', + 'option_creadt' => '', + 'user_id' => '', + 'post_type' => '', + + ]); + + $this->userColumns(My::id(), $cols); + + $content .= + '' . + implode(iterator_to_array($cols)) . ''; + } $content .= '
' . __('Post title') . '' . __('Post date') . '' . __('Widget title') . '' . __('Widget date') . '' . __('Author') . '' . __('Type') . '
' . ( + $filter->show() ? + sprintf(__('List of %s widgets matching the filter.'), $this->rs_count) : + sprintf(__('List of widgets (%s)'), $this->rs_count) + ) . '
' . __('Post title') . '' . __('Post date') . '' . __('Widget title') . '' . __('Widget date') . '' . __('Author') . '' . __('Type') . '
' . - form::checkbox( - ['widgets[]'], - $this->rs->option_id, - '', - '', - '', - !$this->rs->isEditable() - ) . '' . - Html::escapeHTML($this->rs->post_title) . - '' . Date::dt2str( - __('%Y-%m-%d %H:%M'), - $this->rs->post_dt - ) . '' . $w_title . '' . Date::dt2str( - __('%Y-%m-%d %H:%M'), - $this->rs->option_upddt - ) . '' . $this->rs->user_id . '' . $this->rs->post_type . '' . (new Checkbox(['widgets[]'], (bool) $this->rs->f('option_id')))->value($this->rs->f('periodical_id'))->disabled(!$this->rs->isEditable())->render() . '' . + Html::escapeHTML($this->rs->f('post_title')) . '' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt'), $tz ?? 'UTC') . '' . $w_title . '' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('option_upddt'), $tz ?? 'UTC') . '' . $this->rs->f('user_id') . '' . $this->rs->f('post_type') . '
'; diff --git a/src/Utils.php b/src/Utils.php index 6d06f48..5c7502b 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -24,6 +24,7 @@ use Dotclear\Database\Statement\{ JoinStatement, SelectStatement }; +use Dotclear\Helper\Text; use Exception; /** @@ -87,6 +88,32 @@ class Utils $sql->and('option_type = ' . $sql->quote(My::id())); } + // search post title + if (!empty($params['search_post_title'])) { + $words = Text::splitWords($params['search_post_title']); + + if (!empty($words)) { + foreach ($words as $i => $w) { + $words[$i] = $sql->like('post_title', '%' . $sql->escape($w) . '%'); + } + $sql->and($words); + } + unset($params['search_post_title']); + } + + // search widget title + if (!empty($params['search_widget_title'])) { + $words = Text::splitWords($params['search_widget_title']); + + if (!empty($words)) { + foreach ($words as $i => $w) { + $words[$i] = $sql->like('option_title', '%' . $sql->escape($w) . '%'); + } + $sql->and($words); + } + unset($params['search_widget_title']); + } + // work on all post type by default if (!isset($params['post_type'])) { $params['post_type'] = '';