Working on booked

master
Lukas Macura 2016-12-11 20:58:36 +01:00
parent 08875ed63c
commit 09785e4cf6
2 changed files with 28 additions and 13 deletions

View File

@ -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

View File

@ -1,23 +1,29 @@
<?php
error_reporting(0);
session_start();
$from=$argv[1];
$to=$argv[2];
$start_only=$argv[3];
define("YOURTIMEZONE",getenv("timezone"));
define("BOOKEDWEBSERVICESURL",getenv("url"));
require_once(__DIR__ . "/bookedapi.php");
if ($from) {
$from=New DateTime(strtr($from,"_"," "));
$from=$from->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++;
}
}
}