2021-09-02 22:04:20 +00:00
|
|
|
<?php
|
2023-10-17 20:47:35 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
declare(strict_types=1);
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
namespace Dotclear\Plugin\activityReport;
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
use ArrayObject;
|
2023-10-17 20:47:35 +00:00
|
|
|
use Dotclear\App;
|
2023-08-17 14:25:19 +00:00
|
|
|
use Dotclear\Core\Backend\Filter\Filters;
|
|
|
|
use Dotclear\Core\Backend\{
|
|
|
|
Notices,
|
|
|
|
Page
|
|
|
|
};
|
|
|
|
use Dotclear\Core\Process;
|
2023-04-20 12:22:43 +00:00
|
|
|
use Dotclear\Helper\Html\Form\{
|
|
|
|
Form,
|
|
|
|
Hidden,
|
|
|
|
Para,
|
|
|
|
Submit,
|
|
|
|
Text
|
|
|
|
};
|
|
|
|
use Exception;
|
2021-09-03 19:08:44 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
/**
|
2023-10-17 20:47:35 +00:00
|
|
|
* @brief activityReport manage class.
|
|
|
|
* @ingroup activityReport
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis (author)
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
2023-04-20 12:22:43 +00:00
|
|
|
*/
|
2023-08-17 14:25:19 +00:00
|
|
|
class Manage extends Process
|
2023-04-20 12:22:43 +00:00
|
|
|
{
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
2023-08-17 14:25:19 +00:00
|
|
|
return self::status(My::checkContext(My::MANAGE));
|
2021-09-03 19:08:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
public static function process(): bool
|
|
|
|
{
|
2023-08-17 14:25:19 +00:00
|
|
|
if (!self::status()) {
|
2023-04-20 12:22:43 +00:00
|
|
|
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();
|
2023-04-20 12:22:43 +00:00
|
|
|
} catch (Exception $e) {
|
2023-10-17 20:47:35 +00:00
|
|
|
App::error()->add($e->getMessage());
|
2023-04-20 12:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-09-03 19:08:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
public static function render(): void
|
|
|
|
{
|
2023-08-17 14:25:19 +00:00
|
|
|
if (!self::status()) {
|
2023-04-20 12:22:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$logs = $counter = $list = null;
|
2023-08-17 14:25:19 +00:00
|
|
|
$filter = new Filters(My::id());
|
2023-04-20 12:22:43 +00:00
|
|
|
$params = new ArrayObject($filter->params());
|
2021-09-03 19:08:44 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
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));
|
2023-04-20 12:22:43 +00:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2023-10-17 20:47:35 +00:00
|
|
|
App::error()->add($e->getMessage());
|
2021-09-03 19:08:44 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 14:25:19 +00:00
|
|
|
Page::openModule(
|
2023-04-20 12:22:43 +00:00
|
|
|
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') .
|
2023-04-20 12:22:43 +00:00
|
|
|
|
|
|
|
# --BEHAVIOR-- activityReportListHeader --
|
2023-10-17 20:47:35 +00:00
|
|
|
App::behavior()->callBehavior('activityReportListHeader')
|
2021-09-03 19:08:44 +00:00
|
|
|
);
|
2023-04-20 12:22:43 +00:00
|
|
|
|
|
|
|
echo
|
2023-08-17 14:25:19 +00:00
|
|
|
Page::breadcrumb([
|
2023-04-20 12:22:43 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
My::name() => '',
|
|
|
|
]) .
|
2023-08-17 14:25:19 +00:00
|
|
|
Notices::getNotices();
|
2023-04-20 12:22:43 +00:00
|
|
|
|
|
|
|
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
|
2023-10-17 20:47:35 +00:00
|
|
|
(new Form('form-logs'))->method('post')->action(App::backend()->getPageURL())->fields([
|
2023-04-20 12:22:43 +00:00
|
|
|
(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(),
|
2023-04-20 12:22:43 +00:00
|
|
|
]),
|
|
|
|
])->render();
|
2021-09-03 19:08:44 +00:00
|
|
|
}
|
2023-04-20 12:22:43 +00:00
|
|
|
|
2023-08-17 14:25:19 +00:00
|
|
|
Page::closeModule();
|
2021-09-03 19:08:44 +00:00
|
|
|
}
|
|
|
|
}
|