function availability_calendar_get_availability in Availability Calendars 7.4
Same name and namespace in other branches
- 7.5 availability_calendar.inc \availability_calendar_get_availability()
- 7.3 availability_calendar.inc \availability_calendar_get_availability()
Returns the availability for the given calendar and date range.
The from and to dates are inclusive.
Parameters
int $cid: cid may be 0 for not yet existing calendars.
DateTime $from:
DateTime $to:
int|null $default_state: If $default_state is null only the stored availability is returned, otherwise the returned array is completed with this default state for missing dates.
Return value
array Array with availability within the given date range keyed by date.
2 calls to availability_calendar_get_availability()
- availability_calendar_preprocess_availability_calendar_months in ./
availability_calendar.theme.inc - Implements hook_preprocess_HOOK for theme availability_calendar @link http://api.drupal.org/api/drupal/modules--system--theme.api.php/function...
- availability_calendar_update_availability in ./
availability_calendar.inc - Sets the given date range to the given state for the given calendar.
File
- ./
availability_calendar.inc, line 512
Code
function availability_calendar_get_availability($cid, $from, $to, $default_state = NULL) {
// Get the states from the database.
$availability = array();
if (!empty($cid)) {
$availability = db_select('availability_calendar_availability')
->fields('availability_calendar_availability', array(
'date',
'sid',
))
->condition('cid', $cid)
->condition('date', array(
$from
->format(AC_ISODATE),
$to
->format(AC_ISODATE),
), 'BETWEEN')
->execute()
->fetchAllKeyed();
}
if (!empty($default_state)) {
for ($date = clone $from; $date <= $to; $date
->modify('+1 day')) {
$day = $date
->format(AC_ISODATE);
if (!array_key_exists($day, $availability)) {
$availability[$day] = $default_state;
}
}
}
return $availability;
}