From f508096e53c631a124bda1de8f154ac8977d8cfc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 13 Feb 2017 15:48:30 +0100 Subject: [roomplanner] Make hiding of rooms in api more clever Don't hide a non-leaf room if at least one its leafs doesn't have a valid room plan (but the non-leaf in question does). --- .../roomplanner/inc/pvsgenerator.inc.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (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 c00d5439..d61e826b 100644 --- a/modules-available/roomplanner/inc/pvsgenerator.inc.php +++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php @@ -16,6 +16,8 @@ class PvsGenerator /* get all rooms */ $rooms = array(); + // Use left joins everywhere so we still have the complete list of locations below + // for figuring out which locations are leafs and which aren't $ret = Database::simpleQuery( 'SELECT l.locationid, l.parentlocationid, l.locationname, lr.locationid AS notnull, lr.managerip, lr.tutoruuid, m.clientip as tutorip ' . 'FROM location l ' @@ -27,12 +29,27 @@ class PvsGenerator settype($row['parentlocationid'], 'int'); $rooms[$row['locationid']] = $row; } + // Mark all non-leafs as skip 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! + // Now un-mark all where there's at least one child without valid room plan + foreach ($rooms as &$room) { + if (!isset($room['skip']) && (is_null($room['notnull']) || empty($room['managerip']))) { + $room['skip'] = true; + $r2 =& $room; + while ($r2['parentlocationid'] > 0) { + $r2 =& $rooms[$r2['parentlocationid']]; + if (!(is_null($room['notnull']) || empty($room['managerip']))) { + unset($r2['skip']); + break; + } + } + } + } + unset($room, $r2); // refd! /* collect names and build room blocks - filter empty rooms while at it */ $roomNames = array(); -- cgit v1.2.3-55-g7522