You are here

protected function OrganigramsItemController::buildQuery in Organigrams 7

Builds the query to load the entity.

Parameters

array $ids: An array of entity IDs, or FALSE to load all entities.

array $conditions: An array of conditions in the form 'field' => $value.

mixed $revision_id: The ID of the revision to load, or FALSE if this query is asking for the most current revision(s).

Return value

SelectQuery A SelectQuery object for loading the entity.

Overrides EntityAPIController::buildQuery

File

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

Class

OrganigramsItemController
Controller class for organigrams items.

Code

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