You are here

class BatEventTypeController in Booking and Availability Management Tools for Drupal 7

The Controller for Event Type entities.

Hierarchy

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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatEventTypeController::create public function 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. Overrides EntityAPIController::create
BatEventTypeController::delete public function Overrides EntityAPIControllerExportable::delete
BatEventTypeController::export public function Overrides EntityAPIControllerExportable::export
BatEventTypeController::import public function Overrides EntityAPIController::import
BatEventTypeController::save public function Overrides EntityAPIControllerExportable::save
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
EntityAPIController::$bundleKey protected property
EntityAPIController::$cacheComplete protected property
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::query public function Builds and executes the query for loading.
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::saveRevision protected function Saves an entity revision.
EntityAPIControllerExportable::$entityCacheByName protected property
EntityAPIControllerExportable::$nameKey protected property
EntityAPIControllerExportable::applyConditions protected function
EntityAPIControllerExportable::attachLoad protected function Overridden. Overrides DrupalDefaultEntityController::attachLoad
EntityAPIControllerExportable::buildQuery protected function Support loading by name key. Overrides EntityAPIController::buildQuery
EntityAPIControllerExportable::cacheGet protected function Overridden. Overrides DrupalDefaultEntityController::cacheGet
EntityAPIControllerExportable::cacheGetByName protected function Like cacheGet() but keyed by name.
EntityAPIControllerExportable::cacheSet protected function Overridden. Overrides DrupalDefaultEntityController::cacheSet
EntityAPIControllerExportable::invoke public function Overridden to care about reverted bundle entities and to skip Rules. Overrides EntityAPIController::invoke
EntityAPIControllerExportable::load public function Overridden to support passing numeric ids as well as names as $ids. Overrides EntityAPIController::load
EntityAPIControllerExportable::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides EntityAPIController::resetCache
EntityAPIControllerExportable::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIController::view
EntityAPIControllerExportable::__construct public function Overridden. Overrides EntityAPIController::__construct