activityReport/src/Manage.php

119 lines
3.3 KiB
PHP
Raw Normal View History

<?php
2021-09-02 22:18:08 +00:00
/**
* @brief activityReport, a plugin for Dotclear 2
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @author Jean-Christian Denis and contributors
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\activityReport;
use ArrayObject;
use dcCore;
2023-08-17 14:25:19 +00:00
use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{
Form,
Hidden,
Para,
Submit,
Text
};
use Exception;
/**
* Manage process (admin logs list).
*/
2023-08-17 14:25:19 +00:00
class Manage extends Process
{
public static function init(): bool
{
2023-08-17 14:25:19 +00:00
return self::status(My::checkContext(My::MANAGE));
}
public static function process(): bool
{
2023-08-17 14:25:19 +00:00
if (!self::status()) {
return false;
}
if (!empty($_POST['delete_all_logs']) || !empty($_POST['delete_reported_logs'])) {
try {
ActivityReport::instance()->deleteLogs(!empty($_POST['delete_reported_logs']));
2023-08-17 14:25:19 +00:00
Notices::addSuccessNotice(__('Logs successfully deleted'));
My::redirect();
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
return true;
}
public static function render(): void
{
2023-08-17 14:25:19 +00:00
if (!self::status()) {
return;
}
$logs = $counter = $list = null;
2023-08-17 14:25:19 +00:00
$filter = new Filters(My::id());
$params = new ArrayObject($filter->params());
try {
$logs = ActivityReport::instance()->getLogs($params);
$counter = ActivityReport::instance()->getLogs($params, true);
if (!is_null($logs) && !is_null($counter)) {
2023-08-17 14:25:19 +00:00
$list = new ManageList($logs, $counter->f(0));
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
2023-08-17 14:25:19 +00:00
Page::openModule(
My::name(),
2023-08-17 14:25:19 +00:00
$filter->js((string) My::manageUrl()) .
Page::jsJson(My::id(), ['confirm_delete' => __('Are you sure you want to delete logs?')]) .
My::jsLoad('backend') .
# --BEHAVIOR-- activityReportListHeader --
dcCore::app()->callBehavior('activityReportListHeader')
);
echo
2023-08-17 14:25:19 +00:00
Page::breadcrumb([
__('Plugins') => '',
My::name() => '',
]) .
2023-08-17 14:25:19 +00:00
Notices::getNotices();
if (!is_null($list)) {
$filter->display('admin.plugin.' . My::id(), (new Hidden('p', My::id()))->render());
$list->logsDisplay($filter, '%s');
}
if (!is_null($logs) && !$logs->isEmpty()) {
echo
(new Form('form-logs'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([
(new Para())->class('right')->separator(' ')->items([
(new Submit('delete_all_logs'))->class('delete')->value(__('Delete all aticivity logs')),
(new Submit('delete_reported_logs'))->class('delete')->value(__('Delete all allready reported logs')),
2023-08-17 14:25:19 +00:00
... My::hiddenFields(),
]),
])->render();
}
2023-08-17 14:25:19 +00:00
Page::closeModule();
}
}