Skip to content

Commit 2cf69a2

Browse files
gagnieraytrasher
andauthored
Implement plugins interfaces
Co-authored-by: Johan Cwiklinski <johan@x-tnd.be>
1 parent 3128291 commit 2cf69a2

File tree

1 file changed

+29
-65
lines changed

1 file changed

+29
-65
lines changed

lib/GaletteLegalNotices/PluginGaletteLegalnotices.php

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323

2424
namespace GaletteLegalNotices;
2525

26+
use DI\Attribute\Inject;
2627
use Galette\Core\Db;
2728
use Galette\Core\Login;
28-
use Galette\Entity\Adherent;
29+
use Galette\Core\Plugins\MenuProviderInterface;
2930
use Galette\Core\GalettePlugin;
31+
use GaletteLegalNotices\Entity\Pages;
3032
use GaletteLegalNotices\Entity\Settings;
3133

3234
/**
@@ -36,19 +38,20 @@
3638
* @author Guillaume AGNIERAY <dev@agnieray.net>
3739
*/
3840

39-
class PluginGaletteLegalnotices extends GalettePlugin
41+
class PluginGaletteLegalnotices extends GalettePlugin implements MenuProviderInterface
4042
{
43+
#[Inject]
44+
private readonly Db $zdb; //@phpstan-ignore-line injected from DI
45+
4146
/**
42-
* Extra menus entries
47+
* Get plugins menus
4348
*
4449
* @return array<string, string|array<string,mixed>>
4550
*/
46-
public static function getMenusContents(): array
51+
public function getMenus(): array
4752
{
4853
/** @var Login $login */
4954
global $login;
50-
/** @var Db $zdb */
51-
global $zdb;
5255
$menus = [];
5356
$items = [];
5457

@@ -82,15 +85,13 @@ public static function getMenusContents(): array
8285
}
8386

8487
/**
85-
* Extra public menus entries
88+
* Get plugins public menus
8689
*
8790
* @return array<int, string|array<string,mixed>>
8891
*/
89-
public static function getPublicMenusItemsList(): array
92+
public function getPublicMenus(): array
9093
{
91-
/** @var Db $zdb */
92-
global $zdb;
93-
$settings = new Settings($zdb);
94+
$settings = new Settings($this->zdb);
9495
$items = [];
9596
$children = [];
9697

@@ -141,60 +142,6 @@ public static function getPublicMenusItemsList(): array
141142
return $items;
142143
}
143144

144-
/**
145-
* Get dashboards contents
146-
*
147-
* @return array<int, string|array<string,mixed>>
148-
*/
149-
public static function getDashboardsContents(): array
150-
{
151-
return [];
152-
}
153-
154-
/**
155-
* Get current logged-in user dashboards contents
156-
*
157-
* @return array<int, string|array<string,mixed>>
158-
*/
159-
public static function getMyDashboardsContents(): array
160-
{
161-
return [];
162-
}
163-
164-
/**
165-
* Get actions contents
166-
*
167-
* @param Adherent $member Member instance
168-
*
169-
* @return array<int, string|array<string,mixed>>
170-
*/
171-
public static function getListActionsContents(Adherent $member): array
172-
{
173-
return [];
174-
}
175-
176-
/**
177-
* Get detailed actions contents
178-
*
179-
* @param Adherent $member Member instance
180-
*
181-
* @return array<int, string|array<string,mixed>>
182-
*/
183-
public static function getDetailedActionsContents(Adherent $member): array
184-
{
185-
return static::getListActionsContents($member);
186-
}
187-
188-
/**
189-
* Get batch actions contents
190-
*
191-
* @return array<int, string|array<string,mixed>>
192-
*/
193-
public static function getBatchActionsContents(): array
194-
{
195-
return [];
196-
}
197-
198145
/**
199146
* Get plugin settings
200147
*
@@ -207,4 +154,21 @@ public static function getPluginSettings(): array
207154
$settings = new Settings($zdb);
208155
return $settings->getSettings();
209156
}
157+
158+
/**
159+
* Is the plugin fully installed (including database, extra configuration, etc.)?
160+
*/
161+
public function isInstalled(): bool
162+
{
163+
try {
164+
$this->zdb->execute($this->zdb->select(LEGALNOTICES_PREFIX . Pages::TABLE)->limit(1));
165+
$this->zdb->execute($this->zdb->select(LEGALNOTICES_PREFIX . Settings::TABLE)->limit(1));
166+
return true;
167+
} catch (\Throwable $e) {
168+
if (!$this->zdb->isMissingTableException($e)) {
169+
throw $e;
170+
}
171+
}
172+
return false;
173+
}
210174
}

0 commit comments

Comments
 (0)