summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php86
1 files changed, 31 insertions, 55 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
index f87d15c2..15766227 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
@@ -4,23 +4,35 @@ class IPxeMenu
{
protected $menuid;
- protected $timeoutMs;
- protected $title;
- protected $defaultEntryId;
+ public $timeoutMs;
+ public $title;
+ public $defaultEntryId;
/**
* @var MenuEntry[]
*/
- protected $items = [];
+ public $items = [];
+ /**
+ * @param int $menuId
+ */
+ public static function get($menuId, $emptyFallback = false)
+ {
+ $menu = Database::queryFirst("SELECT menuid, timeoutms, title, defaultentryid FROM serversetup_menu
+ WHERE menuid = :menuid LIMIT 1", ['menuid' => $menuId]);
+ if ($menu !== false)
+ return new IPxeMenu($menu);
+ if (!$emptyFallback)
+ return null;
+ return new EmptyIPxeMenu();
+ }
+
+ /**
+ * IPxeMenu constructor.
+ *
+ * @param array $menu array for according menu row
+ */
public function __construct($menu)
{
- if (!is_array($menu)) {
- $menu = Database::queryFirst("SELECT menuid, timeoutms, title, defaultentryid FROM serversetup_menu
- WHERE menuid = :menuid LIMIT 1", ['menuid' => $menu]);
- if (!is_array($menu)) {
- $menu = ['menuid' => 'foo', 'title' => 'Invalid Menu ID: ' . (int)$menu];
- }
- }
$this->menuid = (int)$menu['menuid'];
$this->timeoutMs = (int)$menu['timeoutms'];
$this->title = $menu['title'];
@@ -40,41 +52,6 @@ class IPxeMenu
}
}
- public function getMenuDefinition($targetVar, $mode, $slxExtensions)
- {
- $str = "menu -- {$this->title}\n";
- foreach ($this->items as $item) {
- $str .= $item->getMenuItemScript("m_{$this->menuid}", $this->defaultEntryId, $mode, $slxExtensions);
- }
- if ($this->defaultEntryId === null) {
- $defaultLabel = "mx_{$this->menuid}_poweroff";
- } else {
- $defaultLabel = "m_{$this->menuid}_{$this->defaultEntryId}";
- }
- $str .= "choose";
- if ($this->timeoutMs > 0) {
- $str .= " --timeout {$this->timeoutMs}";
- }
- $str .= " $targetVar || goto $defaultLabel || goto fail\n";
- if ($this->defaultEntryId === null) {
- $str .= "goto skip_{$defaultLabel}\n"
- . ":{$defaultLabel}\n"
- . "poweroff || goto fail\n"
- . ":skip_{$defaultLabel}\n";
- }
- return $str;
- }
-
- public function getItemsCode($mode)
- {
- $str = '';
- foreach ($this->items as $item) {
- $str .= $item->getBootEntryScript("m_{$this->menuid}", 'fail', $mode);
- $str .= "goto slx_menu\n";
- }
- return $str;
- }
-
public function title()
{
return $this->title;
@@ -94,13 +71,11 @@ class IPxeMenu
}
/**
- * @return string|false Return script label of default entry, false if not set
+ * @return string|null Return script label of default entry, null if not set
*/
- public function getDefaultScriptLabel()
+ public function getDefaultEntryId()
{
- if ($this->defaultEntryId !== null)
- return "m_{$this->menuid}_{$this->defaultEntryId}";
- return false;
+ return $this->defaultEntryId;
}
/**
@@ -126,10 +101,11 @@ class IPxeMenu
$chain = Location::getLocationRootChain($locationId);
}
if (!empty($chain)) {
- $res = Database::simpleQuery("SELECT m.menuid, m.timeoutms, m.title, IFNULL(ml.defaultentryid, m.defaultentryid) AS defaultentryid, ml.locationid
- FROM serversetup_menu m
- INNER JOIN serversetup_menu_location ml USING (menuid)
- WHERE ml.locationid IN (:chain)", ['chain' => $chain]);
+ $res = Database::simpleQuery("SELECT m.menuid, m.timeoutms, m.title,
+ IFNULL(ml.defaultentryid, m.defaultentryid) AS defaultentryid, ml.locationid
+ FROM serversetup_menu m
+ INNER JOIN serversetup_menu_location ml USING (menuid)
+ WHERE ml.locationid IN (:chain)", ['chain' => $chain]);
if ($res->rowCount() > 0) {
// Make the location id key, preserving order (closest location is first)
$chain = array_flip($chain);