Added booked (phpscheduleit) plugin to get reservation count in interval

master
Lukas Macura 2016-12-11 13:06:36 +01:00
parent 30cadc3bcd
commit 065feeec04
4 changed files with 1374 additions and 0 deletions

1218
booked/bookedapi.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
<?php
/**
* Title: booked-php-api-client
* Ver: 0.0.1 Beta
* By: Ryan C Crawford
* Email: ryan@mytrueserenity.com
*
* This file is part of Booked PHP Client Libary.
* There are other files that make up the whole libary
* and that are dependent on this file or that this file is dependent on.
*
*
*/
// Endpoints
const AUTHENTICATE = '/Authentication/Authenticate';
const GETRESOURCES = '/Resources/';
const GETRESERVATIONS ='/Reservations/';
const FILTERRESERVATION = '/Reservations';
const GETAVAILABILITY = '/Resources/Availability';
const GETACCESSORY = '/Accessories/';
const GETCATATTRIBUTE = '/Attributes/Category/';
const GETATTRIBUTE = '/Attributes/';
const GETGROUPS = '/Groups/';
const RESERVATIONS = '/Reservations/';
const SCHEDULES = '/Schedules/';
const SLOTS = '/Slots';
const STATUS = '/Status';
const STATUSREASONS = '/Reasons';
const RESOURCETYPES = '/Types';
const USERS = '/Users/';
const INTERVALHOURS = 'hours';
const INTERVALMINUTES = 'minutes';
const INTERVALDAYS = 'days';
// updateScope are this|full|future
const UPDATESCOPE_THIS = 'this';
const UPDATESCOPE_FULL = 'full';
const UPDATESCOPE_FUTURE = 'future';
// Recurrance Rule Const
//"recurrenceRule":{"type":"daily|monthly|none|weekly|yearly","interval":3,"monthlyType":"dayOfMonth|dayOfWeek|null","weekdays":[0,1,2,3,4,5,6],"repeatTerminationDate":"2015-09-16T20:51:36-0700"}
const RECURRENCETYPE_DAILY = 'daily';
const RECURRENCETYPE_MONTHLY = 'monthly';
const RECURRENCETYPE_NONE = 'none';
const RECURRENCETYPE_WEEKLY = 'weekly';
const RECURRENCETYPE_YEARLY = 'yearly';
const RECURRENCE_MONTHLY_TYPE_DAYOFMONTH = 'dayOfMonth';
const RECURRENCE_MONTHLY_TYPE_DAYOFWEEK = 'dayOfWeek';
const RECURRENCE_MONTHLY_TYPE_NULL = null;
const RECURRENCE_WEEKDAY_SUN = 0;
const RECURRENCE_WEEKDAY_MON = 1;
const RECURRENCE_WEEKDAY_TUE = 2;
const RECURRENCE_WEEKDAY_WED = 3;
const RECURRENCE_WEEKDAY_THR = 4;
const RECURRENCE_WEEKDAY_FRI = 5;
const RECURRENCE_WEEKDAY_SAT = 6;
// Attibute Categories
const ATT_CAT_RESERVATION = 1;
const ATT_CAT_USER = 2;
const ATT_CAT_RESOURCE = 4;
const ATT_CAT_RESOURCE_TYPE = 5;
// Attribute Types
const SINGLE_LINE_TEXT = 1;
const SELECT_LIST = 3;
const MULTI_LINE_TEXT = 2;
const CHECK_BOX = 4;
?>

38
booked/control.zaf Normal file
View File

@ -0,0 +1,38 @@
Plugin: booked
Description::
Plugin for booked PHP reservation system
::
Version: 0.1
Url: https://raw.githubusercontent.com/limosek/zaf-plugins/master/booked
Web: https://github.com/limosek/zaf-plugins
Parameters::
url http://localhost/booked/Services/index.php
timezone UTC
username zaf
password
::
# Dependencies
Depends-dpkg: php5-cli
Depends-opkg: php
Depends-bin: php
# Install
Install-files: bookedapi.php bookedapiconfig.php
Install-bin: getr.php
Item num_reservations:
Return: int
Parameters::
from 'now' ''
to '+1 hour' ''
::
Description::
Get number of reservations in given time range
::
Cmd: getr.php "$from" "$to"
/Item

46
booked/getr.php Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env php
<?php
error_reporting(0);
session_start();
$from=$argv[1];
$to=$argv[2];
define("YOURTIMEZONE",getenv("timezone"));
define("BOOKEDWEBSERVICESURL",getenv("url"));
require_once(__DIR__ . "/bookedapi.php");
if ($from) {
$from=New DateTime($from);
$from=$from->getTimestamp();
} else {
$from=time();
}
if ($to) {
$to=New DateTime($to);
$to=$to->getTimestamp();
} else {
$to=time()+3600;
}
$bookedapiclient = new bookedapiclient(getenv("username"), getenv("password"));
$bookedapiclient-> authenticate();
$reservations=$bookedapiclient->getReservation(null,null,null,date("c",$from),date("c",$to));
$cnt=0;
foreach ($reservations["reservations"] as $r) {
$start=New DateTime($r["startDate"]);
$start->setTimezone(New DateTimeZone(getenv("timezone")));
$end=New DateTime($r["endDate"]);
$end->setTimezone(New DateTimeZone(getenv("timezone")));
$sstart=$start->getTimestamp();
$send=$end->getTimestamp();
if ($sstart>=$from && $send<=$to) {
$cnt++;
}
}
echo $cnt;