function availability_calendar_booking_formlet_extract_date in Availability Calendars 7.3
Same name and namespace in other branches
- 7.5 booking_formlet/availability_calendar_booking_formlet.inc \availability_calendar_booking_formlet_extract_date()
- 7.4 booking_formlet/availability_calendar_booking_formlet.module \availability_calendar_booking_formlet_extract_date()
Returns a date based on the settings and global context.
Parameters
array $settings:
string $date: Either 'preset_begin_date' or 'preset_end_date'
null|DateTime $offset: null or a date to use as offset if the source indicates a duration rather than a date on its own.
Return value
null|DateTime
1 call to availability_calendar_booking_formlet_extract_date()
File
- booking_formlet/
availability_calendar_booking_formlet.module, line 611 - Availability Calendar booking formlet module. This submdule of the Availability Calendar module defines a field that shows a small booking form that interacts with a calendar field. The form only has an arraival and departure date field and a submit…
Code
function availability_calendar_booking_formlet_extract_date($settings, $date, $offset = null) {
$source = $settings["{$date}_source"];
$global = substr($source, 0, strlen('get')) === 'get' ? $_GET : $_POST;
$key = $settings["{$date}_key"];
$result = null;
switch ($source) {
case 'today':
$result = new DateTime();
break;
case 'fixed_duration':
if ($offset instanceof DateTime) {
$result = clone $offset;
$duration = (int) $key;
// Adjust duration as to date is inclusive.
$duration--;
$result
->modify("+{$duration} days");
}
break;
case 'get':
case 'post':
case 'get1':
case 'post1':
$date = availability_calendar_booking_formlet_get_nested_array_value($global, $key);
if (is_string($date)) {
$date = availability_calendar_parse_entry_date($date);
if ($date instanceof DateTime) {
$result = $date;
// get1 and post1 are not inclusive: modify by 1 day.
if (substr($source, -strlen('1')) === '1') {
$result
->modify('-1 day');
}
}
}
break;
case 'get_duration':
case 'post_duration':
if ($offset instanceof DateTime) {
$duration = availability_calendar_booking_formlet_get_nested_array_value($global, $key);
if (is_int($duration) || ctype_digit($duration)) {
$result = clone $offset;
$duration = (int) $duration;
// Adjust duration as to date is inclusive.
$duration--;
$result
->modify("+{$duration} days");
}
}
break;
case 'none':
default:
break;
}
// Set time to noon to avoid timezone conversion rounding errors later.
if ($result instanceof DateTime) {
$result
->setTime(12, 0, 0);
}
return $result;
}