code review
parent
e19032fac5
commit
320a1ed91c
|
@ -31,33 +31,30 @@ use Dotclear\Helper\Html\Html;
|
||||||
*/
|
*/
|
||||||
class ManageList extends adminGenericListV2
|
class ManageList extends adminGenericListV2
|
||||||
{
|
{
|
||||||
public function display(adminGenericFilterV2 $filter, string $enclose = ''): void
|
public function display(adminGenericFilterV2 $filter, string $enclose = '%s'): void
|
||||||
{
|
{
|
||||||
|
// nullsafe
|
||||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) {
|
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare page
|
||||||
|
$blocks = explode('%s', $enclose);
|
||||||
|
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
|
||||||
|
$tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC');
|
||||||
|
|
||||||
|
// no record
|
||||||
if ($this->rs->isEmpty()) {
|
if ($this->rs->isEmpty()) {
|
||||||
echo '<p><strong>' . (
|
echo sprintf(
|
||||||
$filter->show() ?
|
'<p><strong>%s</strong></p>',
|
||||||
__('No widgets matching the filter.') : __('No widget')
|
$filter->show() ? __('No widgets matching the filter.') : __('No widget')
|
||||||
) . '</strong></p>';
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
|
// table head line
|
||||||
|
$thead = new ArrayObject([
|
||||||
$content = '<div class="table-outer">' .
|
|
||||||
'<table class="clear">' .
|
|
||||||
'<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>',
|
'name' => '<th colspan="2" class="first">' . __('Post title') . '</th>',
|
||||||
'post_dt' => '<th scope="col" class="nowrap">' . __('Post date') . '</th>',
|
'post_dt' => '<th scope="col" class="nowrap">' . __('Post date') . '</th>',
|
||||||
'option_title' => '<th scope="col" class="nowrap">' . __('Widget title') . '</th>',
|
'option_title' => '<th scope="col" class="nowrap">' . __('Widget title') . '</th>',
|
||||||
|
@ -66,27 +63,43 @@ class ManageList extends adminGenericListV2
|
||||||
'post_type' => '<th scope="col" class="nowrap">' . __('Type') . '</th>',
|
'post_type' => '<th scope="col" class="nowrap">' . __('Type') . '</th>',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->userColumns(My::id(), $cols);
|
$this->userColumns(My::id(), $thead);
|
||||||
|
|
||||||
$content .= implode(iterator_to_array($cols)) . '</tr></thead><tbody>';
|
// display list header
|
||||||
|
echo
|
||||||
$tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC');
|
$pager->getLinks() .
|
||||||
|
($blocks[0] ?? '') .
|
||||||
|
sprintf(
|
||||||
|
'<div class="table-outer"><table class="clear"><caption>%s</caption><thead><tr>%s</tr></thead><tbody>',
|
||||||
|
$filter->show() ?
|
||||||
|
sprintf(__('List of %s widgets matching the filter.'), $this->rs_count) :
|
||||||
|
sprintf(__('List of widgets (%s)'), $this->rs_count),
|
||||||
|
implode(iterator_to_array($thead))
|
||||||
|
);
|
||||||
|
|
||||||
|
// parses lines
|
||||||
while ($this->rs->fetch()) {
|
while ($this->rs->fetch()) {
|
||||||
$w_title = Html::escapeHTML($this->rs->option_title);
|
$w_title = Html::escapeHTML($this->rs->option_title);
|
||||||
if ($w_title == '') {
|
if ($w_title == '') {
|
||||||
$w_title = '<em>' . context::global_filters(
|
// widget title can accept HTML, but backend table not
|
||||||
|
$w_title = context::global_filters(
|
||||||
$this->rs->option_content,
|
$this->rs->option_content,
|
||||||
[
|
[
|
||||||
'encode_xml',
|
'encode_xml',
|
||||||
'remove_html',
|
'remove_html',
|
||||||
'cut_string' => 80,
|
'cut_string' => 80,
|
||||||
]
|
]
|
||||||
) . '</em>';
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cols = new ArrayObject([
|
// table body line
|
||||||
'check' => '<td class="nowrap">' . (new Checkbox(['widgets[]'], (bool) $this->rs->f('option_id')))->value($this->rs->f('option_id'))->disabled(!$this->rs->isEditable())->render() . '</td>',
|
$tbody = new ArrayObject([
|
||||||
|
'check' => '<td class="nowrap">' .
|
||||||
|
(new Checkbox(['widgets[]'], (bool) in_array($this->rs->f('option_id'), $_REQUEST['widgets'] ?? [])))
|
||||||
|
->__call('value', [$this->rs->f('option_id')])
|
||||||
|
->__call('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">' .
|
'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>',
|
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) . '</td>',
|
'post_dt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt'), $tz) . '</td>',
|
||||||
|
@ -94,21 +107,21 @@ class ManageList extends adminGenericListV2
|
||||||
'option_creadt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('option_upddt'), $tz) . '</td>',
|
'option_creadt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('option_upddt'), $tz) . '</td>',
|
||||||
'user_id' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>',
|
'user_id' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>',
|
||||||
'post_type' => '<td class="nowrap">' . $this->rs->f('post_type') . '</td>',
|
'post_type' => '<td class="nowrap">' . $this->rs->f('post_type') . '</td>',
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->userColumns(My::id(), $cols);
|
$this->userColumns(My::id(), $tbody);
|
||||||
|
|
||||||
$content .= '<tr class="line' . ($this->rs->f('post_status') == 1 ? '' : ' offline') . '" id="p' . $this->rs->f('post_id') . '">' .
|
// display table body line
|
||||||
implode(iterator_to_array($cols)) .
|
echo
|
||||||
|
'<tr class="line' . ($this->rs->f('post_status') == 1 ? '' : ' offline') . '" id="p' . $this->rs->f('post_id') . '">' .
|
||||||
|
implode(iterator_to_array($tbody)) .
|
||||||
'</tr>';
|
'</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$content .= '</tbody></table></div>';
|
// display list footer
|
||||||
|
|
||||||
echo
|
echo
|
||||||
$pager->getLinks() .
|
'</tbody></table></div>' .
|
||||||
sprintf($enclose, $content) .
|
($blocks[1] ?? '').
|
||||||
$pager->getLinks();
|
$pager->getLinks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue