$line) {
$li[] = sprintf('
%s %s (%s)', $k, $line['author'], $line['count']);
}
# Display
$__dashboard_items[0][] = '' .
'
' . html::escapeHTML(__('Top writer: entries')) . '
' .
'
' .
'
';
}
}
# top comments
if ($pref['topWriterCommentsItems']) {
$lines = Utils::comments($pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']);
if (!empty($lines)) {
$li = [];
foreach ($lines as $k => $line) {
$li[] = sprintf('%s %s (%s)', $k, $line['author'], $line['count']);
}
# Display
$__dashboard_items[0][] = '';
}
}
}
public static function adminDashboardOptionsFormV2(): void
{
$pref = self::setDefaultPref();
echo
'' .
'
' . __('Top writer: entries') . '
' .
'
' .
'
' .
form::combo('topWriterPostsPeriod', Utils::periods(), $pref['topWriterPostsPeriod']) . '
' .
'
' .
form::number('topWriterPostsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterPostsLimit']]) . '
' .
'
' .
'' .
'
' . __('Top writer: comments') . '
' .
'
' .
'
' .
form::combo('topWriterCommentsPeriod', Utils::periods(), $pref['topWriterCommentsPeriod']) . '
' .
'
' .
form::number('topWriterCommentsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterCommentsLimit']]) . '
' .
'
';
}
public static function adminAfterDashboardOptionsUpdate(?string $user_id): void
{
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsItems',
!empty($_POST['topWriterPostsItems']),
'boolean'
);
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsPeriod',
(string) $_POST['topWriterPostsPeriod'],
'string'
);
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsLimit',
(int) $_POST['topWriterPostsLimit'],
'integer'
);
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterCommentsItems',
!empty($_POST['topWriterCommentsItems']),
'boolean'
);
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterCommentsPeriod',
(string) $_POST['topWriterCommentsPeriod'],
'string'
);
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterCommentsLimit',
(int) $_POST['topWriterCommentsLimit'],
'integer'
);
}
private static function setDefaultPref(): array
{
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsItems')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsItems',
false,
'boolean'
);
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsPeriod')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsPeriod',
'month',
'string'
);
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsLimit')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsLimit',
10,
'integer'
);
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterCommentsItems')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterCommentsItems',
false,
'boolean'
);
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterCommentsPeriod')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterCommentsPeriod',
'month',
'string'
);
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterCommentsLimit')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterCommentsLimit',
10,
'integer'
);
}
return [
'topWriterPostsItems' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterPostsItems'),
'topWriterPostsPeriod' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterPostsPeriod'),
'topWriterPostsLimit' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterPostsLimit') ?? 10,
'topWriterCommentsItems' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterCommentsItems'),
'topWriterCommentsPeriod' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterCommentsPeriod'),
'topWriterCommentsLimit' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterCommentsLimit') ?? 10,
];
}
}