function RulesEntityController::buildQuery

Overridden to support tags and events in $conditions.

See also

EntityAPIControllerExportable::buildQuery()

File

includes/rules.core.inc, line 236

Class

RulesEntityController
Make sure loaded rule configs are instantiated right.

Code

protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
    $query = parent::buildQuery($ids, $conditions, $revision_id);
    $query_conditions =& $query->conditions();
    foreach ($query_conditions as &$condition) {
        // One entry in $query_conditions is a string with key '#conjunction'.
        // @see QueryConditionInterface::conditions()
        if (is_array($condition)) {
            // Support using 'tags' => array('tag1', 'tag2') as condition.
            if ($condition['field'] == 'base.tags') {
                $query->join('rules_tags', 'rt', 'base.id = rt.id');
                $condition['field'] = 'rt.tag';
            }
            // Support using 'event' => $name as condition.
            if ($condition['field'] == 'base.event') {
                $query->join('rules_trigger', 'tr', "base.id = tr.id");
                $condition['field'] = 'tr.event';
                // Use like operator to support % wildcards also.
                $condition['operator'] = 'LIKE';
            }
        }
    }
    return $query;
}