class CerPresetFinder in Corresponding Entity References 7.3
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 which need to be inverted before use). The execute() method will return a merged and sorted array of presets, but the segmented result set is exposed to the world as well for other uses (i.e., CER Entity Settings' selection handler).
Hierarchy
- class \EntityFieldQuery
- class \CerPresetFinder
Expanded class hierarchy of CerPresetFinder
File
- includes/
CerPresetFinder.inc, line 12
View source
class CerPresetFinder extends EntityFieldQuery {
public $result = array();
protected $entity;
public function __construct(EntityDrupalWrapper $entity = NULL) {
$this->entity = $entity;
$this
->entityCondition('entity_type', 'cer')
->addTag('cer_presets')
->addMetaData('entity', $entity);
}
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;
}
/**
* @return EntityFieldQuery
*/
public function find($left = NULL, $right = NULL, $bidirectional = NULL, $operator = 'STARTS_WITH') {
$query = new EntityFieldQuery();
if ($left) {
$query
->fieldCondition('cer_left', 'path', $left, $operator);
}
if ($right) {
$query
->fieldCondition('cer_right', 'path', $right, $operator);
}
if (isset($bidirectional)) {
$query
->fieldCondition('cer_bidirectional', 'value', (bool) $bidirectional);
}
return $query
->entityCondition('entity_type', 'cer')
->fieldCondition('cer_enabled', 'value', TRUE);
}
private function _load(array $result) {
return isset($result['cer']) ? entity_load('cer', array_keys($result['cer'])) : array();
}
private function _sort(CerPreset $a, CerPreset $b) {
$a_weight = $a->wrapper->cer_weight
->value();
$b_weight = $b->wrapper->cer_weight
->value();
if ($a_weight > $b_weight) {
return 1;
}
elseif ($b_weight > $a_weight) {
return -1;
}
else {
return 0;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CerPresetFinder:: |
protected | property | ||
CerPresetFinder:: |
public | property | ||
CerPresetFinder:: |
public | function |
Executes the query. Overrides EntityFieldQuery:: |
|
CerPresetFinder:: |
public | function | ||
CerPresetFinder:: |
private | function | ||
CerPresetFinder:: |
private | function | ||
CerPresetFinder:: |
public | function | ||
EntityFieldQuery:: |
public | property | Flag indicating whether this is querying current or all revisions. | |
EntityFieldQuery:: |
public | property | TRUE if the query has already been altered, FALSE if it hasn't. | |
EntityFieldQuery:: |
public | property | TRUE if this is a count query, FALSE if it isn't. | |
EntityFieldQuery:: |
public | property | Query behavior for deleted data. | |
EntityFieldQuery:: |
public | property | Associative array of entity-generic metadata conditions. | |
EntityFieldQuery:: |
public | property | The method executing the query, if it is overriding the default. | |
EntityFieldQuery:: |
public | property | List of field conditions. | |
EntityFieldQuery:: |
public | property | List of field meta conditions (language and delta). | |
EntityFieldQuery:: |
public | property | A list of field arrays used. | |
EntityFieldQuery:: |
public | property | A list of metadata added to this query. | |
EntityFieldQuery:: |
public | property | List of order clauses. | |
EntityFieldQuery:: |
public | property | The ordered results. | |
EntityFieldQuery:: |
public | property | The query pager data. | |
EntityFieldQuery:: |
public | property | List of property conditions. | |
EntityFieldQuery:: |
public | property | The query range. | |
EntityFieldQuery:: |
public | property | A list of the tags added to this query. | |
EntityFieldQuery:: |
public | function | Adds a condition to an already built SelectQuery (internal function). | |
EntityFieldQuery:: |
protected | function | Adds the given condition to the proper condition array. | |
EntityFieldQuery:: |
public | function | Adds additional metadata to the query. | |
EntityFieldQuery:: |
public | function | Adds a tag to the query. | |
EntityFieldQuery:: |
public | function | Queries the current or every revision. | |
EntityFieldQuery:: |
public | function | Sets the query to be a count query only. | |
EntityFieldQuery:: |
public | function | Filters on the data being deleted. | |
EntityFieldQuery:: |
public | function | Adds a condition on entity-generic metadata. | |
EntityFieldQuery:: |
public | function | Orders the result set by entity-generic metadata. | |
EntityFieldQuery:: |
public | function | Adds a condition on field values. | |
EntityFieldQuery:: |
public | function | Adds a condition on the field delta column. | |
EntityFieldQuery:: |
public | function | Adds a condition on the field language column. | |
EntityFieldQuery:: |
public | function | Orders the result set by a given field column. | |
EntityFieldQuery:: |
function | Finishes the query. | ||
EntityFieldQuery:: |
function | Gets the total number of results and initializes a pager for the query. | ||
EntityFieldQuery:: |
public | function | Enables a pager for the query. | |
EntityFieldQuery:: |
public | function | Adds a condition on an entity-specific property. | |
EntityFieldQuery:: |
public | function | Orders the result set by an entity-specific property. | |
EntityFieldQuery:: |
protected | function | Queries entity tables in SQL for property conditions and sorts. | |
EntityFieldQuery:: |
public | function | Determines the query callback to use for this entity query. | |
EntityFieldQuery:: |
public | function | Restricts a query to a given range in the result set. | |
EntityFieldQuery:: |
constant | Indicates that both deleted and non-deleted fields should be returned. | ||
EntityFieldQuery:: |
public | function | Enables sortable tables for this query. |