summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 14:47:55 +0100
committerSimon Rettberg2023-11-14 14:47:55 +0100
commit06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch)
tree7e5493b102074672d8cfd8fe1a61e49f080edbe8 /modules-available/roomplanner/page.inc.php
parentUpdate phpstorm config (diff)
downloadslx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.gz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.xz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.zip
Add function param/return types, fix a lot more phpstorm complaints
Diffstat (limited to 'modules-available/roomplanner/page.inc.php')
-rw-r--r--modules-available/roomplanner/page.inc.php61
1 files changed, 27 insertions, 34 deletions
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 7ac6890d..53e8bf0b 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -82,22 +82,17 @@ class Page_Roomplanner extends Page
$config = Database::queryFirst('SELECT roomplan, managerip, tutoruuid
FROM location_roomplan
WHERE locationid = :locationid', ['locationid' => $this->locationid]);
+ if ($config === false) {
+ $config = ['dedicatedmgr' => false, 'managerip' => ''];
+ }
$runmode = RunMode::getForMode(Page::getModule(), $this->locationid, true);
- if (empty($runmode)) {
- $config['dedicatedmgr'] = false;
- } else {
+ if (!empty($runmode)) {
$runmode = array_pop($runmode);
$config['managerip'] = $runmode['clientip'];
$config['manageruuid'] = $runmode['machineuuid'];
$data = json_decode($runmode['modedata'], true);
$config['dedicatedmgr'] = (isset($data['dedicatedmgr']) && $data['dedicatedmgr']);
}
- if ($config !== false) {
- $managerIp = $config['managerip'] ?? '';
- $dediMgr = $config['dedicatedmgr'] ? 'checked' : '';
- } else {
- $dediMgr = $managerIp = '';
- }
$furniture = $this->getFurniture($config);
$subnetMachines = $this->getPotentialMachines();
$machinesOnPlan = $this->getMachinesOnPlan($config['tutoruuid'] ?? '');
@@ -105,8 +100,8 @@ class Page_Roomplanner extends Page
$canEdit = User::hasPermission('edit', $this->locationid);
$params = [
'location' => $this->location,
- 'managerip' => $managerIp,
- 'dediMgrChecked' => $dediMgr,
+ 'managerip' => $config['managerip'],
+ 'dediMgrChecked' => $config['dedicatedmgr'] ? 'checked' : '',
'subnetMachines' => json_encode($subnetMachines),
'locationid' => $this->locationid,
'roomConfiguration' => json_encode($roomConfig),
@@ -229,11 +224,9 @@ class Page_Roomplanner extends Page
if ($leaf !== $this->isLeaf) {
if ($isAjax) {
die('Leaf mode mismatch. Did you restructure locations while editing this room?');
- } else {
- Message::addError('leaf-mode-mismatch');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
- return;
+ Message::addError('leaf-mode-mismatch');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
if ($this->isLeaf) {
$this->saveLeafRoom($isAjax);
@@ -250,10 +243,9 @@ class Page_Roomplanner extends Page
if (!is_array($config) || !isset($config['furniture']) || !isset($config['computers'])) {
if ($isAjax) {
die('JSON data incomplete');
- } else {
- Message::addError('json-data-invalid');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Message::addError('json-data-invalid');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
$tutorUuid = Request::post('tutoruuid', '', 'string');
if (empty($tutorUuid)) {
@@ -263,10 +255,9 @@ class Page_Roomplanner extends Page
if ($ret === false) {
if ($isAjax) {
die('Invalid tutor UUID');
- } else {
- Message::addError('invalid-tutor-uuid');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Message::addError('invalid-tutor-uuid');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
}
$this->saveRoomConfig($config['furniture'], $tutorUuid);
@@ -282,10 +273,9 @@ class Page_Roomplanner extends Page
if ($res === false) {
if ($isAjax) {
die('Error writing config to DB');
- } else {
- Message::addError('db-error');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Message::addError('db-error');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
}
@@ -302,7 +292,7 @@ class Page_Roomplanner extends Page
* @param array $computers Deserialized json from browser with all the computers
* @param array $oldComputers Deserialized old roomplan from database, used to find removed computers
*/
- protected function saveComputerConfig($computers, $oldComputers)
+ protected function saveComputerConfig(array $computers, array $oldComputers)
{
$oldUuids = [];
@@ -323,12 +313,12 @@ class Page_Roomplanner extends Page
if (!isset($computer['gridRow'])) {
$computer['gridRow'] = 0;
} else {
- $this->sanitizeNumber($computer['gridRow'], 0, 32 * 4);
+ Util::clamp($computer['gridRow'], 0, 32 * 4);
}
if (!isset($computer['gridCol'])) {
$computer['gridCol'] = 0;
} else {
- $this->sanitizeNumber($computer['gridCol'], 0, 32 * 4);
+ Util::clamp($computer['gridCol'], 0, 32 * 4);
}
$position = json_encode(['gridRow' => $computer['gridRow'],
@@ -374,17 +364,20 @@ class Page_Roomplanner extends Page
}
}
- protected function getFurniture($config)
+ protected function getFurniture(array $config): array
{
- if ($config === false)
- return array();
- $config = json_decode($config['roomplan'] ?? '', true);
+ if (empty($config['roomplan']))
+ return [];
+ $config = json_decode($config['roomplan'], true);
if (!is_array($config))
- return array();
+ return [];
return $config;
}
- protected function getMachinesOnPlan($tutorUuid)
+ /**
+ * @return array{computers: array}
+ */
+ protected function getMachinesOnPlan(string $tutorUuid): array
{
$result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, position
FROM machine
@@ -418,7 +411,7 @@ class Page_Roomplanner extends Page
return ['computers' => $machines];
}
- protected function getPotentialMachines()
+ protected function getPotentialMachines(): array
{
$result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom, m.fixedlocationid
FROM machine m