diff --git a/lib/GaletteLegalNotices/PluginGaletteLegalnotices.php b/lib/GaletteLegalNotices/PluginGaletteLegalnotices.php index 977ae07..74c47d7 100644 --- a/lib/GaletteLegalNotices/PluginGaletteLegalnotices.php +++ b/lib/GaletteLegalNotices/PluginGaletteLegalnotices.php @@ -23,10 +23,14 @@ namespace GaletteLegalNotices; +use DI\Attribute\Inject; use Galette\Core\Db; use Galette\Core\Login; +use Galette\Core\Plugins\DashboardProviderInterface; +use Galette\Core\Plugins\MenuProviderInterface; use Galette\Entity\Adherent; use Galette\Core\GalettePlugin; +use GaletteLegalNotices\Entity\Pages; use GaletteLegalNotices\Entity\Settings; /** @@ -36,19 +40,20 @@ * @author Guillaume AGNIERAY */ -class PluginGaletteLegalnotices extends GalettePlugin +class PluginGaletteLegalnotices extends GalettePlugin implements MenuProviderInterface { + #[Inject] + private readonly Db $zdb; + /** - * Extra menus entries + * Get plugins menus * * @return array> */ - public static function getMenusContents(): array + public function getMenus(): array { /** @var Login $login */ global $login; - /** @var Db $zdb */ - global $zdb; $menus = []; $items = []; @@ -82,15 +87,13 @@ public static function getMenusContents(): array } /** - * Extra public menus entries + * Get plugins public menus * * @return array> */ - public static function getPublicMenusItemsList(): array + public function getPublicMenus(): array { - /** @var Db $zdb */ - global $zdb; - $settings = new Settings($zdb); + $settings = new Settings($this->zdb); $items = []; $children = []; @@ -141,60 +144,6 @@ public static function getPublicMenusItemsList(): array return $items; } - /** - * Get dashboards contents - * - * @return array> - */ - public static function getDashboardsContents(): array - { - return []; - } - - /** - * Get current logged-in user dashboards contents - * - * @return array> - */ - public static function getMyDashboardsContents(): array - { - return []; - } - - /** - * Get actions contents - * - * @param Adherent $member Member instance - * - * @return array> - */ - public static function getListActionsContents(Adherent $member): array - { - return []; - } - - /** - * Get detailed actions contents - * - * @param Adherent $member Member instance - * - * @return array> - */ - public static function getDetailedActionsContents(Adherent $member): array - { - return static::getListActionsContents($member); - } - - /** - * Get batch actions contents - * - * @return array> - */ - public static function getBatchActionsContents(): array - { - return []; - } - /** * Get plugin settings * @@ -207,4 +156,22 @@ public static function getPluginSettings(): array $settings = new Settings($zdb); return $settings->getSettings(); } + + /** + * Is the plugin fully installed (including database, extra configuration, etc.)? + */ + public function isInstalled(): bool + { + try { + $this->zdb->execute($this->zdb->select(LEGALNOTICES_PREFIX . Pages::TABLE)->limit(1)); + $this->zdb->execute($this->zdb->select(LEGALNOTICES_PREFIX . Settings::TABLE)->limit(1)); + return true; + } + catch (\Throwable $e) { + if (!$this->zdb->isMissingTableException($e)) { + throw $e; + } + } + return false; + } }