summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/hooks
diff options
context:
space:
mode:
authorSimon Rettberg2021-11-30 15:27:59 +0100
committerSimon Rettberg2022-03-09 15:06:54 +0100
commit41612c4481111969367d1a228ad4875d781558a2 (patch)
treed59bc50a3a2822faa6b800bd1f74f97c5ca692b3 /modules-available/serversetup-bwlp-ipxe/hooks
parent[permissionmanager] Fix for PHP 8 (diff)
downloadslx-admin-41612c4481111969367d1a228ad4875d781558a2.tar.gz
slx-admin-41612c4481111969367d1a228ad4875d781558a2.tar.xz
slx-admin-41612c4481111969367d1a228ad4875d781558a2.zip
[locations] Modularize additional column handling
Additional columns are now added through a hook, moving specialized code where it belongs.
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/hooks')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/hooks/locations-column.inc.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/hooks/locations-column.inc.php b/modules-available/serversetup-bwlp-ipxe/hooks/locations-column.inc.php
new file mode 100644
index 00000000..d3290b62
--- /dev/null
+++ b/modules-available/serversetup-bwlp-ipxe/hooks/locations-column.inc.php
@@ -0,0 +1,57 @@
+<?php
+
+if (!User::hasPermission('.serversetup.ipxe.menu.assign')
+ || !Module::isAvailable('serversetup')
+ || !class_exists('IPxe')) {
+ return null;
+}
+
+class IpxeLocationColumn extends AbstractLocationColumn
+{
+
+ private $lookup = [];
+
+ public function __construct(array $allowedLocationIds)
+ {
+ $res = Database::simpleQuery("SELECT ml.locationid, m.title, ml.defaultentryid FROM serversetup_menu m
+ INNER JOIN serversetup_menu_location ml USING (menuid)
+ WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds'));
+ foreach ($res as $row) {
+ $lid = (int)$row['locationid'];
+ if ($row['defaultentryid'] !== null) {
+ $row['title'] .= '(*)';
+ }
+ $this->lookup[$lid] = $row['title'];
+ }
+ }
+
+ public function getColumnHtml(int $locationId): string
+ {
+ return htmlspecialchars($this->lookup[$locationId] ?? '');
+ }
+
+ public function getEditUrl(int $locationId): string
+ {
+ if (!User::hasPermission('.serversetup.ipxe.menu.assign', $locationId))
+ return '';
+ return '?do=serversetup&show=assignlocation&locationid=' . $locationId;
+ }
+
+ public function header(): string
+ {
+ return Dictionary::translateFileModule('serversetup', 'module', 'location-column-header');
+ }
+
+ public function priority(): int
+ {
+ return 3000;
+ }
+
+ public function propagateColumn(): bool
+ {
+ return true;
+ }
+
+}
+
+return new IpxeLocationColumn($allowedLocationIds); \ No newline at end of file