$calendars
$calendars : array<mixed,\MPorcheron\FreeBusyCal\Calendar>
FreeBusyCal generator - this is the main class used to generate a free busy calendar.
If you are loading an iCal file, use the Calendar
class:
$cal = (new MPorcheron\FreeBusyCal\Calendar())->setFile('calendar.ics');
Alternatively:
$iCloud = (new MPorcheron\FreeBusyCal\CalDAVCalendar())
->setUsername('my.apple.id@me.com')
->setPassword('application-specific-password')
->setPrincipalUrl('https://caldav.icloud.com/123456789876543/principal/');
Create the Generator
object and add one or more calendars:
$fbc = new \MPorcheron\FreeBusyCal\Generator($cal, $iCloud);
Set the date range to extract, e.g. start from this Monday, and run for 14 days (i.e. two weeks), but exclude weekends:
$fbc->setDateRange(new \DateTime('Monday this week'), 14, false);
Only generate a calendar between 9am (inclusive) and 5pm (exclusive), and show a slot every 30 minutes:
$fbc->setTimeRange(9, 17, 30);
Fetch the calendars and process them:
$fbc->fetchAndParse();
Print out the calendar table, with the class cal
, default date and time formats, the labels Free
and Busy
for
slots, and show times as ranges (i.e. start – end) as opposed to just start time:
$contents = $fbc->generate(function (Fbc\FreeBusyCalendar &$cal) {
$output = '<table class="cal">';
// Output table headers with days
$output .= '<tr><th></th>';
$days = [ 'S', 'M', 'T', 'W', 'T', 'F', 'S' ];
foreach ($cal->getCalendarDates(Fbc\FreeBusyCalendar::DATE_FORMAT) as $label => &$dt) {
$output .= '<th class="day">'. $days[$dt->format('N')] .'</th>';
}
$output .= '</tr>';
// Output table headers with dates
$output .= '<tr><th></th>';
foreach ($cal->getCalendarDates(Fbc\FreeBusyCalendar::DATE_FORMAT) as $label => &$dt) {
$output .= '<th class="date">'. $label .'</th>';
}
$output .= '</tr>';
// Iterate through each time and $output .= the availability
$times = $cal->getCalendarTimes(Fbc\FreeBusyCalendar::TIME_FORMAT);
foreach ($times as $hour => $temp) {
foreach ($temp as $minute => $labels) {
$output .= '<tr><td class="time">'. $labels[0];
if ($showRange) {
$output .= ' – ' . $labels[1];
}
$output .= '</td>';
foreach ($cal->getCalendarDates(Fbc\FreeBusyCalendar::DATE_FORMAT) as $dt) {
if ($cal->isFree($dt->format('Y-m-d'), $hour, $minute)) {
$output .= '<td class="avail free">Free</td>';
} else {
$output .= '<td class="avail busy">Busy</td>';
}
}
}
$output .= '</td>';
}
$output .= '</table>';
return $output;
});
Alternatively test if a specific time/date (i.e. 5pm on 4th May 2016) is available:
$cal = $fbc->getFreeBusyCalendar();
$free = $cal->isFree('2016-05-04', 17, 0);
$calendars : array<mixed,\MPorcheron\FreeBusyCal\Calendar>
$freeBusyCalendar : \MPorcheron\FreeBusyCal\FreeBusyCalendar
__construct(\MPorcheron\FreeBusyCal\Calendar $cal)
Construct the controller and populate it with the configuration values. Constructing this class sets the time limit for script execution to indefinite and the default timezone because of a PHP oddity.
Output buffering is started also.
\MPorcheron\FreeBusyCal\Calendar | $cal | (One or more) calendars to extract data from. |
addCalendar(\MPorcheron\FreeBusyCal\Calendar $cal)
Add a calendar to extract data from.
\MPorcheron\FreeBusyCal\Calendar | $cal | Calendar to also extact data from. |
setDateRange(\DateTime $startDate, integer $numDays = 7, boolean $includeWeekends = false) : \MPorcheron\FreeBusyCal\Calendar
Set the date range to generate data for.
\DateTime | $startDate | When to start the calendar from. |
integer | $numDays | Number of days from the start date to generate calendar for. |
boolean | $includeWeekends | Set to false to ignore weekends. Note weekennds still count in the number of days (i.e. 7 days, and
|
$this
.
setTimeRange(integer $startHour, integer $endHour, integer $interval = 60) : \MPorcheron\FreeBusyCal\Generator
Set the time range to generate data for.
integer | $startHour | First hour of the day to start output at (midnight = |
integer | $endHour | Last hour of the day print output for (midnight = 0). Minimum is |
integer | $interval | How many mniutes to break each slot in the calendar up by (60 = segment by hour). You should make this number
one of the following to fit evenly into the hour: 1,2,3,4,5,6,10,12,15,20,30,60. Minumum is |
$this
.
fetchAndParse(boolean $refetch = false) : \MPorcheron\FreeBusyCal\Generator
Fetch and parse the data needed to generate the availability calendar.
boolean | $refetch | Refetch iCal data if it has already been fetched once. |
$this
.
generate(\MPorcheron\FreeBusyCal\function $func) : \MPorcheron\FreeBusyCal\Generator
Generates the calendar and returs output.
\MPorcheron\FreeBusyCal\function | $func | Function that takes a single paramter of a \MPorcheron\FreeBusyCal\FreeBusyCalendar` and returns out the output as a string. |
If the calendar hasn't been fetched yet.
Output from the print function.
getFreeBusyCalendar() : \MPorcheron\FreeBusyCal\FreeBusyCalendar
Retrieve the calendar of availability.
If the calendar hasn't been fetched yet.
Calendar availability.