add filters and columns user pref on list

This commit is contained in:
Jean-Christian Denis 2023-04-25 00:34:28 +02:00
parent fed7583470
commit 45c0b61bbe
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 106 additions and 52 deletions

View file

@ -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

View file

@ -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 '

View file

@ -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,
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
'%s' .
'<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' .
'<input id="do-action" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' .
'<input id="do-action" class="delete" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $filter->values(true))) .
dcCore::app()->formNonce() .
'</div>' .

View file

@ -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 '<p><strong>' . __('No widget') . '</strong></p>';
echo '<p><strong>' . ($filter->show() ?
__('No widgets matching the filter.') : __('No widget')
) . '</strong></p>';
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 = '<div class="table-outer">' .
$content =
'<div class="table-outer">' .
'<table class="clear">' .
'<thead>' .
'<tr>' .
'<th colspan="2" class="nowrap">' . __('Post title') . '</th>' .
'<th class="nowrap">' . __('Post date') . '</th>' .
'<th class="nowrap">' . __('Widget title') . '</th>' .
'<th class="nowrap">' . __('Widget date') . '</th>' .
'<th class="nowrap">' . __('Author') . '</th>' .
'<th class="nowrap">' . __('Type') . '</th>' .
'</tr></thead><tbody>';
'<caption>' . (
$filter->show() ?
sprintf(__('List of %s widgets matching the filter.'), $this->rs_count) :
sprintf(__('List of widgets (%s)'), $this->rs_count)
) . '</caption>' .
'<thead><tr>';
$cols = new ArrayObject([
'name' => '<th colspan="2" class="first">' . __('Post title') . '</th>',
'post_dt' => '<th scope="col" class="nowrap">' . __('Post date') . '</th>',
'option_title' => '<th scope="col" class="nowrap">' . __('Widget title') . '</th>',
'option_creadt' => '<th scope="col" class="nowrap">' . __('Widget date') . '</th>',
'user_id' => '<th scope="col" class="nowrap">' . __('Author') . '</th>',
'post_type' => '<th scope="col" class="nowrap">' . __('Type') . '</th>',
]);
$this->userColumns(My::id(), $cols);
$content .= implode(iterator_to_array($cols)) . '</tr></thead><tbody>';
while ($this->rs->fetch()) {
$w_title = Html::escapeHTML($this->rs->option_title);
@ -66,38 +79,25 @@ class ManageList extends adminGenericListV2
) . '</em>';
}
$content .= '<tr class="line' . (
$this->rs->post_status != 1 ?
' offline' : ''
) . '" id="p' . $this->rs->post_id . '">' .
'<td class="nowrap">' .
form::checkbox(
['widgets[]'],
$this->rs->option_id,
'',
'',
'',
!$this->rs->isEditable()
) . '</td>' .
'<td class="maximal"><a href="' .
dcCore::app()->getPostAdminURL(
$this->rs->post_type,
$this->rs->post_id
) . '#post-wtext-form">' .
Html::escapeHTML($this->rs->post_title) .
'</a></td>' .
'<td class="nowrap">' . Date::dt2str(
__('%Y-%m-%d %H:%M'),
$this->rs->post_dt
) . '</td>' .
'<td class="nowrap">' . $w_title . '</td>' .
'<td class="nowrap">' . Date::dt2str(
__('%Y-%m-%d %H:%M'),
$this->rs->option_upddt
) . '</td>' .
'<td class="nowrap">' . $this->rs->user_id . '</td>' .
'<td class="nowrap">' . $this->rs->post_type . '</td>' .
$cols = new ArrayObject([
'check' => '<td class="nowrap">' . (new Checkbox(['widgets[]'], (bool) $this->rs->f('option_id')))->value($this->rs->f('periodical_id'))->disabled(!$this->rs->isEditable())->render() . '</td>',
'name' => '<td class="maximal"><a href="' . dcCore::app()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '#post-wtext-form">' .
Html::escapeHTML($this->rs->f('post_title')) . '</a></td>',
'post_dt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt'), $tz ?? 'UTC') . '</td>',
'option_title' => '<td class="nowrap">' . $w_title . '</td>',
'option_creadt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('option_upddt'), $tz ?? 'UTC') . '</td>',
'user_id' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>',
'post_type' => '<td class="nowrap">' . $this->rs->f('post_type') . '</td>',
]);
$this->userColumns(My::id(), $cols);
$content .=
'<tr class="line' . ($this->rs->f('post_status') == 1 ? '' : ' offline') . '" id="p' . $this->rs->f('post_id') . '">' .
implode(iterator_to_array($cols)) .
'</tr>';
}
$content .= '</tbody></table></div>';

View file

@ -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'] = '';