add filters and columns user pref on list
This commit is contained in:
parent
fed7583470
commit
45c0b61bbe
5 changed files with 106 additions and 52 deletions
|
@ -62,6 +62,7 @@ class Backend extends dcNsProcess
|
||||||
dcCore::app()->addBehaviors([
|
dcCore::app()->addBehaviors([
|
||||||
// user pref
|
// user pref
|
||||||
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
|
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
|
||||||
|
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'],
|
||||||
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
|
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
|
||||||
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
|
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
|
||||||
// post
|
// post
|
||||||
|
|
|
@ -42,6 +42,11 @@ class BackendBehaviors
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User pref widget text filters options.
|
||||||
|
*
|
||||||
|
* @param ArrayObject $sorts Sort options
|
||||||
|
*/
|
||||||
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
||||||
{
|
{
|
||||||
$sorts['pwt'] = [
|
$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
|
public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void
|
||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
|
|
|
@ -87,6 +87,9 @@ class Manage extends dcNsProcess
|
||||||
# filters
|
# filters
|
||||||
$filter = new adminGenericFilterV2('pwt');
|
$filter = new adminGenericFilterV2('pwt');
|
||||||
$filter->add(dcAdminFilters::getPageFilter());
|
$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();
|
$params = $filter->params();
|
||||||
|
|
||||||
# Get posts with text widget
|
# Get posts with text widget
|
||||||
|
@ -118,14 +121,13 @@ class Manage extends dcNsProcess
|
||||||
$filter->display('admin.plugin.' . My::id(), form::hidden('p', My::id()));
|
$filter->display('admin.plugin.' . My::id(), form::hidden('p', My::id()));
|
||||||
|
|
||||||
$posts_list->display(
|
$posts_list->display(
|
||||||
(int) $filter->value('page'),
|
$filter,
|
||||||
(int) $filter->value('nb'),
|
|
||||||
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
|
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
|
||||||
'%s' .
|
'%s' .
|
||||||
'<div class="two-cols">' .
|
'<div class="two-cols">' .
|
||||||
'<p class="col checkboxes-helpers"></p>' .
|
'<p class="col checkboxes-helpers"></p>' .
|
||||||
'<p class="col right">' .
|
'<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()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $filter->values(true))) .
|
||||||
dcCore::app()->formNonce() .
|
dcCore::app()->formNonce() .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
|
|
|
@ -14,15 +14,16 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postWidgetText;
|
namespace Dotclear\Plugin\postWidgetText;
|
||||||
|
|
||||||
|
use ArrayObject;
|
||||||
|
use adminGenericFilterV2;
|
||||||
use adminGenericListV2;
|
use adminGenericListV2;
|
||||||
use context;
|
use context;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcPager;
|
use dcPager;
|
||||||
use Dotclear\Helper\Date;
|
use Dotclear\Helper\Date;
|
||||||
|
use Dotclear\Helper\Html\Form\Checkbox;
|
||||||
use Dotclear\Helper\Html\Html;
|
use Dotclear\Helper\Html\Html;
|
||||||
|
|
||||||
use form;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
|
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
|
||||||
* @brief postWidgetText - admin list methods.
|
* @brief postWidgetText - admin list methods.
|
||||||
|
@ -30,28 +31,40 @@ use form;
|
||||||
*/
|
*/
|
||||||
class ManageList extends adminGenericListV2
|
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()) {
|
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 = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
|
||||||
$pager->html_prev = $this->html_prev;
|
|
||||||
$pager->html_next = $this->html_next;
|
|
||||||
$pager->var_page = 'page';
|
|
||||||
|
|
||||||
$content = '<div class="table-outer">' .
|
$content =
|
||||||
|
'<div class="table-outer">' .
|
||||||
'<table class="clear">' .
|
'<table class="clear">' .
|
||||||
'<thead>' .
|
'<caption>' . (
|
||||||
'<tr>' .
|
$filter->show() ?
|
||||||
'<th colspan="2" class="nowrap">' . __('Post title') . '</th>' .
|
sprintf(__('List of %s widgets matching the filter.'), $this->rs_count) :
|
||||||
'<th class="nowrap">' . __('Post date') . '</th>' .
|
sprintf(__('List of widgets (%s)'), $this->rs_count)
|
||||||
'<th class="nowrap">' . __('Widget title') . '</th>' .
|
) . '</caption>' .
|
||||||
'<th class="nowrap">' . __('Widget date') . '</th>' .
|
'<thead><tr>';
|
||||||
'<th class="nowrap">' . __('Author') . '</th>' .
|
|
||||||
'<th class="nowrap">' . __('Type') . '</th>' .
|
$cols = new ArrayObject([
|
||||||
'</tr></thead><tbody>';
|
'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()) {
|
while ($this->rs->fetch()) {
|
||||||
$w_title = Html::escapeHTML($this->rs->option_title);
|
$w_title = Html::escapeHTML($this->rs->option_title);
|
||||||
|
@ -66,38 +79,25 @@ class ManageList extends adminGenericListV2
|
||||||
) . '</em>';
|
) . '</em>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$content .= '<tr class="line' . (
|
$cols = new ArrayObject([
|
||||||
$this->rs->post_status != 1 ?
|
'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>',
|
||||||
' offline' : ''
|
'name' => '<td class="maximal"><a href="' . dcCore::app()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '#post-wtext-form">' .
|
||||||
) . '" id="p' . $this->rs->post_id . '">' .
|
Html::escapeHTML($this->rs->f('post_title')) . '</a></td>',
|
||||||
'<td class="nowrap">' .
|
'post_dt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt'), $tz ?? 'UTC') . '</td>',
|
||||||
form::checkbox(
|
'option_title' => '<td class="nowrap">' . $w_title . '</td>',
|
||||||
['widgets[]'],
|
'option_creadt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('option_upddt'), $tz ?? 'UTC') . '</td>',
|
||||||
$this->rs->option_id,
|
'user_id' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>',
|
||||||
'',
|
'post_type' => '<td class="nowrap">' . $this->rs->f('post_type') . '</td>',
|
||||||
'',
|
|
||||||
'',
|
]);
|
||||||
!$this->rs->isEditable()
|
|
||||||
) . '</td>' .
|
$this->userColumns(My::id(), $cols);
|
||||||
'<td class="maximal"><a href="' .
|
|
||||||
dcCore::app()->getPostAdminURL(
|
$content .=
|
||||||
$this->rs->post_type,
|
'<tr class="line' . ($this->rs->f('post_status') == 1 ? '' : ' offline') . '" id="p' . $this->rs->f('post_id') . '">' .
|
||||||
$this->rs->post_id
|
implode(iterator_to_array($cols)) .
|
||||||
) . '#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>' .
|
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$content .= '</tbody></table></div>';
|
$content .= '</tbody></table></div>';
|
||||||
|
|
|
@ -24,6 +24,7 @@ use Dotclear\Database\Statement\{
|
||||||
JoinStatement,
|
JoinStatement,
|
||||||
SelectStatement
|
SelectStatement
|
||||||
};
|
};
|
||||||
|
use Dotclear\Helper\Text;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,6 +88,32 @@ class Utils
|
||||||
$sql->and('option_type = ' . $sql->quote(My::id()));
|
$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
|
// work on all post type by default
|
||||||
if (!isset($params['post_type'])) {
|
if (!isset($params['post_type'])) {
|
||||||
$params['post_type'] = '';
|
$params['post_type'] = '';
|
||||||
|
|
Loading…
Reference in a new issue