You are here

class OrganigramsItemController in Organigrams 7

Controller class for organigrams items.

This extends the DrupalDefaultEntityController class. Only alternation is that we match the condition on organigrams item name case-independently.

Hierarchy

Expanded class hierarchy of OrganigramsItemController

1 string reference to 'OrganigramsItemController'
organigrams_entity_info in ./organigrams.module
Implements hook_entity_info().

File

./organigrams.module, line 2112
Defines the organigrams functions and entity types.

View source
class OrganigramsItemController extends EntityAPIController {

  /**
   * Builds the query to load the entity.
   *
   * @param array $ids
   *   An array of entity IDs, or FALSE to load all entities.
   * @param array $conditions
   *   An array of conditions in the form 'field' => $value.
   * @param mixed $revision_id
   *   The ID of the revision to load, or FALSE if this query is asking for the
   *   most current revision(s).
   *
   * @return SelectQuery
   *   A SelectQuery object for loading the entity.
   */
  protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
    $query = parent::buildQuery($ids, $conditions, $revision_id);
    $query
      ->addTag('translatable');
    $query
      ->addTag('organigrams_item_access');

    // When name is passed as a condition use LIKE.
    if (isset($conditions['name'])) {
      $query_conditions =& $query
        ->conditions();
      foreach ($query_conditions as $key => $condition) {
        if ($condition['field'] == 'base.name') {
          $query_conditions[$key]['operator'] = 'LIKE';
          $query_conditions[$key]['value'] = db_like($query_conditions[$key]['value']);
        }
      }
    }

    // Add the machine name field from the {organigrams} table.
    $query
      ->innerJoin('organigrams_data', 'o', 'base.oid = o.oid');
    $query
      ->addField('o', 'machine_name', 'organigrams_machine_name');
    return $query;
  }

  /**
   * Gets entities from the static cache.
   *
   * @param array $ids
   *   An array of entity IDs, or FALSE to load all entities.
   * @param array $conditions
   *   An array of conditions in the form 'field' => $value.
   *
   * @return array
   *   Array of entities from the entity cache.
   */
  protected function cacheGet($ids, $conditions = array()) {
    $organigrams_items = parent::cacheGet($ids, $conditions);

    // Name matching is case insensitive, note that with some collations
    // LOWER() and drupal_strtolower() may return different results.
    foreach ($organigrams_items as $organigrams_item) {

      // Convert organigrams item to an array.
      $organigrams_item_values = (array) $organigrams_item;

      // Remove any mismatching names.
      if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($organigrams_item_values['name']))) {

        // Remove the organigrams item.
        unset($organigrams_items[$organigrams_item->iid]);
      }
    }
    return $organigrams_items;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::attachLoad protected function Attaches data to entities upon loading. 4
DrupalDefaultEntityController::cacheSet protected function Stores entities in the static entity cache.
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::create public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::create
EntityAPIController::delete public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::delete 1
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::export public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::export 1
EntityAPIController::import public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::import
EntityAPIController::invoke public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::invoke 1
EntityAPIController::load public function Overridden. Overrides DrupalDefaultEntityController::load 1
EntityAPIController::query public function Builds and executes the query for loading.
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController::resetCache 1
EntityAPIController::save public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::save 1
EntityAPIController::saveRevision protected function Saves an entity revision.
EntityAPIController::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::view 1
EntityAPIController::__construct public function Overridden. Overrides DrupalDefaultEntityController::__construct 1
OrganigramsItemController::buildQuery protected function Builds the query to load the entity. Overrides EntityAPIController::buildQuery
OrganigramsItemController::cacheGet protected function Gets entities from the static cache. Overrides DrupalDefaultEntityController::cacheGet