From 09785e4cf625892fa922ef95006084aa1448e78e Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Sun, 11 Dec 2016 20:58:36 +0100 Subject: [PATCH] Working on booked --- booked/control.zaf | 7 ++++--- booked/getr.php | 34 ++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/booked/control.zaf b/booked/control.zaf index c416d4a..7c366d3 100644 --- a/booked/control.zaf +++ b/booked/control.zaf @@ -4,7 +4,7 @@ Description:: Plugin for booked PHP reservation system :: -Version: 0.1 +Version: 0.2 Url: https://raw.githubusercontent.com/limosek/zaf-plugins/master/booked Web: https://github.com/limosek/zaf-plugins @@ -29,10 +29,11 @@ Return: int Parameters:: from 'now' '' to '+1 hour' '' + start_only 'no' '' :: Description:: - Get number of reservations in given time range + Get number of reservations in given time range. If start_only is not null, report even reservations which ends after to. :: -Cmd: php getr.php "$from" "$to" +Cmd: php getr.php "$from" "$to" "$start_only" /Item diff --git a/booked/getr.php b/booked/getr.php index 3055ae3..8118d04 100755 --- a/booked/getr.php +++ b/booked/getr.php @@ -1,23 +1,29 @@ getTimestamp(); + $tz=New DateTimeZone(getenv("timezone")); + + if ($from!="") { + $fromd=New DateTime(strtr($from,"_"," ")); + $fromd->setTimezone($tz); + $from=$fromd->getTimestamp(); } else { $from=time(); } - if ($to) { - $to=New DateTime(strtr($to,"_"," ")); - $to=$to->getTimestamp(); + if ($to!="") { + $tod=New DateTime(strtr($to,"_"," ")); + $tod->setTimezone($tz); + $to=$tod->getTimestamp(); } else { $to=time()+3600; } @@ -29,13 +35,21 @@ $cnt=0; foreach ($reservations["reservations"] as $r) { $start=New DateTime($r["startDate"]); - $start->setTimezone(New DateTimeZone(getenv("timezone"))); + $start->setTimezone($tz); $end=New DateTime($r["endDate"]); - $end->setTimezone(New DateTimeZone(getenv("timezone"))); + $end->setTimezone($tz); $sstart=$start->getTimestamp(); $send=$end->getTimestamp(); - if ($sstart>=$from && $send<=$to) { - $cnt++; + #echo $fromd->format("Y-m-d H:i") . "," . $start->format("Y-m-d H:i") . "," . $end->format("Y-m-d H:i") . "," . $tod->format("Y-m-d H:i"). "\n"; + #echo $from . "," . $start->getTimestamp() . "," . $end->getTimestamp() . "," . $to . "\n"; + if ($start_only=="yes") { + if ($sstart>=$from && $sstart<=$to) { + $cnt++; + } + } else { + if ($sstart>=$from && $send<=$to) { + $cnt++; + } } }