summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-08 10:34:49 +0200
committerSimon Rettberg2016-09-08 10:34:49 +0200
commit161923c1d461ab933d5218c1ecffb6d143e6ea95 (patch)
tree7eba648d33e24730850fce499f50bdfeeb63fe42
parent[roomplanner] Fix formatting (diff)
downloadslx-admin-161923c1d461ab933d5218c1ecffb6d143e6ea95.tar.gz
slx-admin-161923c1d461ab933d5218c1ecffb6d143e6ea95.tar.xz
slx-admin-161923c1d461ab933d5218c1ecffb6d143e6ea95.zip
[roomplanner] Move pvs generator to api; skip empty rooms; add phpdoc
-rw-r--r--modules-available/roomplanner/api.inc.php3
-rw-r--r--modules-available/roomplanner/inc/pvsgenerator.inc.php55
2 files changed, 39 insertions, 19 deletions
diff --git a/modules-available/roomplanner/api.inc.php b/modules-available/roomplanner/api.inc.php
new file mode 100644
index 00000000..29c34747
--- /dev/null
+++ b/modules-available/roomplanner/api.inc.php
@@ -0,0 +1,3 @@
+<?php
+
+die(PvsGenerator::generate());
diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php
index 228426c8..d7f96106 100644
--- a/modules-available/roomplanner/inc/pvsgenerator.inc.php
+++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php
@@ -27,29 +27,33 @@ class PvsGenerator
$rooms[] = $row;
}
}
- /* collect names */
- $roomNames = array();
+ /* collect names and build room blocks - filter empty rooms while at it */
+ $roomNames = array();
+ $roomBlocks = '';
foreach ($rooms as $room) {
+ $roomBlock = PvsGenerator::generateRoomBlock($room);
+ if ($roomBlock === false)
+ continue; // Room nonexistent or empty
$roomNames[] = $room['locationname'];
+ $roomBlocks .= $roomBlock;
}
- /* add [General]-block */
- $config = "[General]\n";
- $config .= 'rooms=' . implode(', ', $roomNames) . "\n";
- $config .= "allowClientQuit=True\n"; // TODO: remove this
- $config .= "showLockDesktopButton=True\n"; // TODO: Make this configurable (or not)
- $config .= "\n\n";
-
- /* foreach room generate room-block */
- foreach ($rooms as $room) {
- $config .= PvsGenerator::generateRoomBlock($room);
- $config .= "\n";
- }
-
- return $config;
+ /* output room plus [General]-block */
+ return "[General]\n"
+ . 'rooms=' . implode(', ', $roomNames) . "\n"
+ . "allowClientQuit=False\n" // TODO: configurable
+ . "showLockDesktopButton=True\n" // TODO: Make this configurable (or not)
+ . "\n\n"
+ . $roomBlocks;
}
+ /**
+ * Generate .ini section for specific room.
+ *
+ * @param $room array room/location data as fetched from db
+ * @return string|bool .ini section for room, or false if room is empty
+ */
private static function generateRoomBlock($room)
{
$out = '[' . $room['locationname'] . "]\n";
@@ -57,6 +61,9 @@ class PvsGenerator
/* find all clients in that room */
$machines = PvsGenerator::getMachines($room['locationid']);
+ if (empty($machines))
+ return false;
+
/* manager */
$mgr = $room['managerip'];
$tutor = $room['tutorip'];
@@ -71,9 +78,15 @@ class PvsGenerator
/* grid */
$out .= PvsGenerator::generateGrid($machines);
- return $out;
+ return $out . "\n";
}
+ /**
+ * Generate grid size information and client position data for given clients.
+ *
+ * @param $machines array list of clients
+ * @return string grid and position data as required for a room's .ini section
+ */
private static function generateGrid($machines)
{
$out = "";
@@ -112,7 +125,12 @@ class PvsGenerator
}
-
+ /**
+ * Get all clients for given room with IP and position.
+ *
+ * @param $roomid int locationid of room
+ * @return array
+ */
private static function getMachines($roomid)
{
$ret = Database::simpleQuery(
@@ -154,4 +172,3 @@ class PvsGenerator
}
}
-