diff --git a/src/Backend.php b/src/Backend.php index 8f479f0..ecfc6d5 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -21,16 +21,14 @@ use dcFavorites; use dcNsProcess; use dcPage; -/** - * Manage contributions list - */ class Backend extends dcNsProcess { public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth?->isSuperAdmin() - && My::phpCompliant(); + && My::phpCompliant() + && !is_null(dcCore::app()->auth) + && dcCore::app()->auth->isSuperAdmin(); return static::$init; } @@ -41,6 +39,7 @@ class Backend extends dcNsProcess return false; } + // backend sidebar menu icon dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem( My::name(), dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), @@ -50,6 +49,7 @@ class Backend extends dcNsProcess ); dcCore::app()->addBehaviors([ + // backend user preference for logs list columns 'adminColumnsListsV2' => function (ArrayObject $cols): void { $cols[My::BACKEND_LIST_ID] = [ My::name(), @@ -63,7 +63,7 @@ class Backend extends dcNsProcess ], ]; }, - + // backend filter for logs list sort 'adminFiltersListsV2' => function (ArrayObject $sorts): void { $sorts[My::BACKEND_LIST_ID] = [ My::name(), @@ -80,7 +80,7 @@ class Backend extends dcNsProcess [__('Logs per page'), 30], ]; }, - + // backend user preference for dashboard icon 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { $favs->register(My::BACKEND_LIST_ID, [ 'title' => My::name(), diff --git a/src/BackendList.php b/src/BackendList.php index 5895194..d9e43fb 100644 --- a/src/BackendList.php +++ b/src/BackendList.php @@ -21,8 +21,19 @@ use Dotclear\Helper\Date; use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Form\Checkbox; +/** + * Backend logs list helper. + */ class BackendList extends adminGenericListV2 { + /** + * Display logs record. + * + * @param int $page The current list page + * @param int $nb_per_page The record per page number + * @param string $enclose_block The enclose block + * @param bool $filter Filter is applied + */ public function display(int $page, int $nb_per_page, string $enclose_block = '', bool $filter = false): void { if ($this->rs->isEmpty()) { @@ -73,6 +84,11 @@ class BackendList extends adminGenericListV2 } } + /** + * Display a records line. + * + * @param bool $checked Selected line + */ private function logLine(bool $checked): void { $cols = [ @@ -105,8 +121,8 @@ class BackendList extends adminGenericListV2 $this->userColumns(My::BACKEND_LIST_ID, $cols); echo - '' . - implode(iterator_to_array($cols)) . - ''; + '' . + implode(iterator_to_array($cols)) . + ''; } } diff --git a/src/Manage.php b/src/Manage.php index 02eb8e3..634fcf5 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -35,8 +35,9 @@ class Manage extends dcNsProcess public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth?->isSuperAdmin() - && My::phpCompliant(); + && My::phpCompliant() + && !is_null(dcCore::app()->auth) + && dcCore::app()->auth->isSuperAdmin(); return static::$init; } @@ -49,7 +50,7 @@ class Manage extends dcNsProcess $current = ManageVars::init(); - # Delete logs + // Delete logs if ($current->selected_logs && !empty($current->entries) || $current->all_logs) { try { dcCore::app()->log->delLogs($current->entries, $current->all_logs); diff --git a/src/ManageVars.php b/src/ManageVars.php index 643877e..752e7a8 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -20,20 +20,35 @@ use dcCore; use Dotclear\Database\MetaRecord; use Exception; +/** + * Backend logs manage page vars container. + */ class ManageVars { - /** - * @var ManageVars self instance - */ + /** @var ManageVars $container self instance */ private static $container; + /** @var adminGenericFilterV2 $filter The filter instance */ public readonly adminGenericFilterV2 $filter; + + /** @var null|MetaRecord $logs The current records */ public readonly ?MetaRecord $logs; + + /** @var null|BackendList $list The records list form instance */ public readonly ?BackendList $list; + + /** @var array $entries The post form selected entries */ public readonly array $entries; + + /** @var bool $selected_logs The post form action */ public readonly bool $selected_logs; + + /** @var bool $all_logs The post form action */ public readonly bool $all_logs; + /** + * Constructor grabs post form value and sets properties. + */ protected function __construct() { $this->entries = !empty($_POST['entries']) && is_array($_POST['entries']) ? $_POST['entries'] : []; @@ -57,6 +72,11 @@ class ManageVars } } + /** + * Get instance. + * + * @return ManageVars The instance + */ public static function init(): ManageVars { if (!(self::$container instanceof self)) { diff --git a/src/My.php b/src/My.php index 72e6510..cc4921a 100644 --- a/src/My.php +++ b/src/My.php @@ -16,6 +16,9 @@ namespace Dotclear\Plugin\dcLog; use dcCore; +/** + * Module definition shortcut. + */ class My { /** @@ -29,7 +32,9 @@ class My public const BACKEND_LIST_ID = 'dcloglist'; /** - * This module id + * This module id. + * + * @return string The module id */ public static function id(): string { @@ -37,7 +42,9 @@ class My } /** - * This module name + * This module name. + * + * @return string The module translated name */ public static function name(): string { @@ -45,7 +52,9 @@ class My } /** - * Check php version + * Check php version. + * + * @return bool True on supported PHP version */ public static function phpCompliant(): bool {