You are here

public function BatEventController::batStoreSave in Booking and Availability Management Tools for Drupal 7

Handles saving to the BatStore.

Parameters

\Roomify\Bat\Unit\Unit $unit: The unit to save.

\DateTime $start_date:

\DateTime $end_date:

string $event_type:

string $granularity:

string $event_state:

int $event_id:

bool|false $remove: Set to TRUE if the event is to be removed (event_id set to zero).

2 calls to BatEventController::batStoreSave()
BatEventController::deleteEvent in modules/bat_event/bat_event.module
BatEventController::save in modules/bat_event/bat_event.module
Implements EntityAPIControllerInterface.

File

modules/bat_event/bat_event.module, line 1420
Manage Events - Events store the EventValue of a Unit over a period of time.

Class

BatEventController
The Controller for BatEvent entities.

Code

public function batStoreSave(Unit $unit, \DateTime $start_date, \DateTime $end_date, $event_type, $granularity, $event_state, $event_id, $remove = FALSE) {
  $prefix = bat_get_db_prefix();
  $state_store = new DrupalDBStore($event_type, DrupalDBStore::BAT_STATE, $prefix);
  $event_store = new DrupalDBStore($event_type, DrupalDBStore::BAT_EVENT, $prefix);
  $units = array(
    $unit,
  );
  $state_calendar = new Calendar($units, $state_store);
  $event_calendar = new Calendar($units, $event_store);
  $state_event = new Event($start_date, $end_date, $unit, $event_state);
  if (!$remove) {
    $event_id_event = new Event($start_date, $end_date, $unit, $event_id);
  }
  else {
    $event_id_event = new Event($start_date, $end_date, $unit, 0);
  }
  $state_calendar
    ->addEvents(array(
    $state_event,
  ), $granularity);
  $event_calendar
    ->addEvents(array(
    $event_id_event,
  ), $granularity);
}