summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-08 11:10:40 +0200
committerSimon Rettberg2016-09-08 11:10:40 +0200
commit1aac7d146864a303e40db7e2bfe1c00a713e0140 (patch)
treeaed336337715ce32c0c81ac968973f8414e30ea7
parent[locations] Fix formatting (diff)
downloadslx-admin-1aac7d146864a303e40db7e2bfe1c00a713e0140.tar.gz
slx-admin-1aac7d146864a303e40db7e2bfe1c00a713e0140.tar.xz
slx-admin-1aac7d146864a303e40db7e2bfe1c00a713e0140.zip
[roomplanner] Filter non-leaf locations without extra query per location
-rw-r--r--modules-available/roomplanner/inc/pvsgenerator.inc.php18
1 files changed, 13 insertions, 5 deletions
diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php
index d7f96106..223b1bf4 100644
--- a/modules-available/roomplanner/inc/pvsgenerator.inc.php
+++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php
@@ -17,21 +17,29 @@ class PvsGenerator
/* get all rooms */
$rooms = array();
$ret = Database::simpleQuery(
- 'SELECT l.locationid, l.locationname, lr.managerip, lr.tutoruuid, m.clientip as tutorip '
+ 'SELECT l.locationid, l.parentlocationid, l.locationname, lr.locationid AS notnull, lr.managerip, lr.tutoruuid, m.clientip as tutorip '
. 'FROM location l '
- . 'INNER JOIN location_roomplan lr ON (l.locationid = lr.locationid)'
+ . 'LEFT JOIN location_roomplan lr ON (l.locationid = lr.locationid)'
. 'LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid)');
while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
- if (Location::isLeaf($row['locationid'])) { // TODO: This creates extra queries, optimize?
- $row['locationname'] = str_replace(',', ';', $row['locationname']); // comma probably not the best sep here
- $rooms[] = $row;
+ $row['locationname'] = str_replace(',', ';', $row['locationname']); // comma probably not the best sep here
+ settype($row['locationid'], 'int');
+ settype($row['parentlocationid'], 'int');
+ $rooms[$row['locationid']] = $row;
+ }
+ foreach ($rooms as &$room) {
+ if ($room['parentlocationid'] > 0 && isset($rooms[$room['parentlocationid']])) {
+ $rooms[$room['parentlocationid']]['skip'] = true; // Don't just unset, might be wrong order
}
}
+ unset($room); // refd!
/* collect names and build room blocks - filter empty rooms while at it */
$roomNames = array();
$roomBlocks = '';
foreach ($rooms as $room) {
+ if (is_null($room['notnull']) || isset($room['skip'])) // Not leaf
+ continue;
$roomBlock = PvsGenerator::generateRoomBlock($room);
if ($roomBlock === false)
continue; // Room nonexistent or empty