You are here

function availability_calendar_update_multiple_availability in Availability Calendars 7.5

Same name and namespace in other branches
  1. 7.3 availability_calendar.inc \availability_calendar_update_multiple_availability()
  2. 7.4 availability_calendar.inc \availability_calendar_update_multiple_availability()

Updates/inserts the states for the given ranges.

Parameters

NULL|int $cid: The calendar id. If empty, a new calendar will be created.

array[] $changes: An array of changes each entry is an array with keys state, from and to.

Return value

int The cid (of the existing or newly created calendar).

Throws

\Exception

2 calls to availability_calendar_update_multiple_availability()
AvailabilityCalendarFieldHandler::prepareCalendar in ./availability_calendar_migrate_field_handlers.inc
Prepares an Availability Calendar.
availability_calendar_field_attach_submit_inc in ./availability_calendar.widget.inc
Called by implementation of hook_field_attach_submit. @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...

File

./availability_calendar.inc, line 663

Code

function availability_calendar_update_multiple_availability($cid, $changes) {
  if (empty($cid)) {

    // Always create a new calendar, even if no changes has been entered.
    $cid = availability_calendar_create_calendar();
  }
  else {
    if (!empty($changes)) {

      // But only change the "last updated" date if there are actual changes.
      availability_calendar_update_calendar($cid);
    }
  }
  foreach ($changes as $change) {
    availability_calendar_update_availability($cid, $change['state'], $change['from'], $change['to'], FALSE);
  }
  return $cid;
}