class BatEventTypeController in Booking and Availability Management Tools for Drupal 7
The Controller for Event Type entities.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
- class \EntityAPIControllerExportable
- class \BatEventTypeController
- class \EntityAPIControllerExportable
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of BatEventTypeController
1 string reference to 'BatEventTypeController'
- bat_event_entity_info in modules/
bat_event/ bat_event.module - Implements hook_entity_info().
File
- modules/
bat_event/ bat_event.module, line 1502 - Manage Events - Events store the EventValue of a Unit over a period of time.
View source
class BatEventTypeController extends EntityAPIControllerExportable {
/**
* Create a event type - we first set up the values that are specific
* to our event type schema but then also go through the EntityAPIController
* function.
*
* @param array $values
* Array containing properties to include in the event type.
*
* @return object
* A event type object with all default fields initialized.
*/
public function create(array $values = array()) {
// Add values that are specific to our Event Type.
$values += array(
'id' => '',
'is_new' => TRUE,
'data' => '',
);
$event_type = parent::create($values);
return $event_type;
}
/**
* @param object $entity
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
if (empty($entity->{$this->idKey})) {
// Create all tables necessary for this Event Type.
bat_event_create_event_type_schema($entity->type);
// Create a field of type 'Entity Reference' to reference a Bat Unit.
bat_event_type_add_target_entity_field($entity);
if (isset($entity->fixed_event_states)) {
if ($entity->fixed_event_states) {
// Create a field of type 'Bat Event State Reference' to reference an Event State.
bat_event_type_add_event_state_reference($entity);
}
}
}
return parent::save($entity);
}
/**
* @param array $ids
*/
public function delete($ids, DatabaseTransaction $transaction = NULL) {
parent::delete($ids);
foreach ($ids as $id) {
// Delete all tables necessary for this Event Type.
bat_event_delete_event_type_schema($id);
// Delete the states associated with this Event Type.
bat_event_delete_states_by_type($id);
}
}
/**
* @param object $entity
* @param string $prefix
*/
public function export($entity, $prefix = '') {
$vars = get_object_vars($entity);
unset($vars[$this->statusKey], $vars[$this->moduleKey], $vars['is_new']);
if ($this->nameKey != $this->idKey) {
unset($vars[$this->idKey]);
}
// Export event states.
if ($entity->fixed_event_states) {
$event_states = array();
foreach (bat_event_get_states($entity->type) as $state) {
$event_states[] = array(
'machine_name' => $state['machine_name'],
'label' => $state['label'],
'color' => $state['color'],
'calendar_label' => $state['calendar_label'],
'locked' => $state['locked'],
'blocking' => $state['blocking'],
'default_state' => $state['default_state'],
);
}
$vars['event_states'] = $event_states;
}
return entity_var_json_export($vars, $prefix);
}
/**
* @param string $export
*/
public function import($export) {
$vars = drupal_json_decode($export);
if (is_array($vars)) {
if (isset($vars['event_states'])) {
$event_type = $vars['type'];
foreach ($vars['event_states'] as $event_state) {
bat_event_save_state($event_state, $event_type);
}
}
return $this
->create($vars);
}
return FALSE;
}
}