From 1aac7d146864a303e40db7e2bfe1c00a713e0140 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Sep 2016 11:10:40 +0200 Subject: [roomplanner] Filter non-leaf locations without extra query per location --- modules-available/roomplanner/inc/pvsgenerator.inc.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'modules-available/roomplanner/inc/pvsgenerator.inc.php') 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 -- cgit v1.2.3-55-g7522