diff options
author | Simon Rettberg | 2022-04-29 17:38:00 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-04-29 17:38:00 +0200 |
commit | 140062e0b606495f90fd77b8f290987844c79cab (patch) | |
tree | ad32ce72580fa898f447c66316587ee7404e9854 /modules-available/locations/inc | |
parent | [baseconfig_bwlp] Add more HDMI outputs for sound card (diff) | |
download | slx-admin-140062e0b606495f90fd77b8f290987844c79cab.tar.gz slx-admin-140062e0b606495f90fd77b8f290987844c79cab.tar.xz slx-admin-140062e0b606495f90fd77b8f290987844c79cab.zip |
[locations/remoteaccess] Add option to veto remoteaccess mode
Remoteaccess mode can now be forced to be disabled for individual
locations in locations module, either unconditionally, or whenever the
openingtimes schedule says the room is open. A reboot will be triggered
whenever the room opens/closes to force clients into the proper runmode.
Diffstat (limited to 'modules-available/locations/inc')
-rw-r--r-- | modules-available/locations/inc/openingtimes.inc.php | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/modules-available/locations/inc/openingtimes.inc.php b/modules-available/locations/inc/openingtimes.inc.php index 72ce92f4..18e25063 100644 --- a/modules-available/locations/inc/openingtimes.inc.php +++ b/modules-available/locations/inc/openingtimes.inc.php @@ -6,11 +6,12 @@ class OpeningTimes /** * Get opening times for given location. * Format is the decoded JSON from DB column, i.e. currently a list of entries: - * { + * <pre>{ * "days": ["Monday", "Tuesday", ...], * "openingtime": "8:00", * "closingtime": "20:00" - * } + * }</pre> + * @return array|null */ public static function forLocation(int $locationId) { @@ -31,4 +32,32 @@ class OpeningTimes return null; } + /** + * Check whether given location is open according to openingtimes. + * @param int $locationId location + * @param int $openOffsetMin offset to apply to opening times when checking. this is subtracted from opening time + * @param int $closeOffsetMin offset to apply to closing times when checking. this is added to closing time + */ + public static function isRoomOpen(int $locationId, int $openOffsetMin = 0, int $closeOffsetMin = 0): bool + { + $openingTimes = self::forLocation($locationId); + if ($openingTimes === null) + return true; // No opening times should mean room is always open + $now = time(); + $today = date('l', $now); + foreach ($openingTimes as $row) { + foreach ($row['days'] as $day) { + if ($day !== $today) + continue; // Not today! + if (strtotime("today {$row['openingtime']} -$openOffsetMin minutes") > $now) + continue; + if (strtotime("today {$row['closingtime']} +$closeOffsetMin minutes") < $now) + continue; + // Bingo! + return true; + } + } + return false; + } + }
\ No newline at end of file |