You are here

function availability_calendar_delete_availability in Availability Calendars 7.4

Same name and namespace in other branches
  1. 7.5 availability_calendar.inc \availability_calendar_delete_availability()

Deletes availability data.

Not all 3 parameters can be null.

Parameters

int|null $cid: The calendar id to delete the availability for. If null, availability data for all calendars is deleted.

DateTime|null $from: The lowest date (inclusive) to delete availability data. If null, all availability before the $to date is deleted.

DateTime|null $to: The highest date (inclusive) to delete availability data. If null, all availability data after the $from date is deleted.

File

./availability_calendar.inc, line 628

Code

function availability_calendar_delete_availability($cid, $from, $to) {
  if ($from !== NULL && !$from instanceof DateTime) {
    return;
  }
  if ($to !== NULL && !$to instanceof DateTime) {
    return;
  }
  if ($cid === NULL && $from === NULL && $to === NULL) {
    return;
  }
  $query = db_delete('availability_calendar_availability');
  if ($cid !== NULL) {
    $query
      ->condition('cid', (int) $cid, '=');
  }
  if ($from !== NULL) {
    $query
      ->condition('date', $from
      ->format(AC_ISODATE), '>=');
  }
  if ($to !== NULL) {
    $query
      ->condition('date', $to
      ->format(AC_ISODATE), '<=');
  }
  $query
    ->execute();
}