You are here

public function CerPresetFinder::execute in Corresponding Entity References 7.3

Executes the query.

After executing the query, $this->orderedResults will contain a list of the same stub entities in the order returned by the query. This is only relevant if there are multiple entity types in the returned value and a field ordering was requested. In every other case, the returned value contains everything necessary for processing.

Return value

Either a number if count() was called or an array of associative arrays of stub entities. The outer array keys are entity types, and the inner array keys are the relevant ID. (In most cases this will be the entity ID. The only exception is when age=FIELD_LOAD_REVISION is used and field conditions or sorts are present -- in this case, the key will be the revision ID.) The entity type will only exist in the outer array if results were found. The inner array values are always stub entities, as returned by entity_create_stub_entity(). To traverse the returned array:


    foreach ($query->execute() as $entity_type => $entities) {
      foreach ($entities as $entity_id => $entity) {
  

Note if the entity type is known, then the following snippet will load the entities found:

$result = $query
  ->execute();
if (!empty($result[$my_type])) {
  $entities = entity_load($my_type, array_keys($result[$my_type]));
}

Overrides EntityFieldQuery::execute

File

includes/CerPresetFinder.inc, line 27

Class

CerPresetFinder
This class is a unified way for CER to find the presets that apply to a given entity. The result set is segmented into two parts: presets where the entity is on the left side, and bidirectional presets with the entity on the right side (i.e., the ones…

Code

public function execute() {
  $lineage = $this->entity->cer->lineage
    ->value();
  $this->result['cer'] = $this
    ->fieldCondition('cer_enabled', 'value', TRUE)
    ->fieldCondition('cer_left', 'path', $lineage, 'STARTS_WITH')
    ->_load(parent::execute());
  $this->fieldConditions = array();
  $this->result['cer__invert'] = $this
    ->fieldCondition('cer_enabled', 'value', TRUE)
    ->fieldCondition('cer_bidirectional', 'value', TRUE)
    ->fieldCondition('cer_right', 'path', $lineage, 'STARTS_WITH')
    ->_load(parent::execute());
  $result = $this->result['cer'];
  foreach ($this->result['cer__invert'] as $preset) {
    $result[] = $preset
      ->invert();
  }
  usort($result, array(
    $this,
    '_sort',
  ));
  return $result;
}