function finder::choice_find in Finder 7.2
Finder choice find.
A subfunction of find() which deals specifically with the finder_choice table.
1 call to finder::choice_find()
- finder::find in includes/
finder.inc - Finder find.
File
- includes/
finder.inc, line 583 - finder.inc
Class
- finder
- An object to contain all of the data to generate a finder, plus the member functions to build the finder, and render the output.
Code
function choice_find() {
$keywords =& $this->find['keywords'];
$match =& $this->find['match'];
$matches =& $this->find['matches'];
$pager =& $this->find['pager'];
$element =& $this->find['element'];
// Populate the $matches variable.
foreach (array_keys($keywords) as $eid) {
if ($eid == $element->id && !empty($match)) {
$matches[$eid]['match'] = $match;
}
elseif (empty($matches[$eid])) {
$matches[$eid]['match'] = $this
->esetting($this->elements[$eid], 'match', 'e');
}
if (empty($matches[$eid]['match_x'])) {
$matches[$eid]['match_x'] = array(
'operator' => $this
->esetting($this->elements[$eid], 'match_custom_operator', '='),
'value_prefix' => $this
->esetting($this->elements[$eid], 'match_custom_prefix'),
'value_suffix' => $this
->esetting($this->elements[$eid], 'match_custom_suffix'),
);
}
}
$query = db_select('finder_choice', 'fc')
->fields('fc', array(
'choice_key',
'choice_value',
))
->condition('fc.finder', $this->id)
->condition('fc.element', $element->id)
->distinct();
if (!empty($keywords[$element->id])) {
$placeholder_count = 0;
foreach (array_values($keywords[$element->id]) as $keyword_position => $keyword) {
if (!empty($keyword)) {
$key_placeholder = ':finder_keyword_' . $placeholder_count++;
list($key_field, $key_value, $key_op) = array_values((array) $this
->match_args('fc.choice_key', $keyword, $matches[$element->id]['match'], $matches[$element->id]['match_x']));
$val_placeholder = ':finder_keyword_' . $placeholder_count++;
list($val_field, $val_value, $val_op) = array_values((array) $this
->match_args('fc.choice_value', $keyword, $matches[$element->id]['match'], $matches[$element->id]['match_x']));
$expression = '(' . $key_field . ' ' . $key_op . ' ' . $key_placeholder . ' OR ' . $val_field . ' ' . $val_op . ' ' . $val_placeholder . ')';
$query
->where($expression, array(
$key_placeholder => $key_value,
$val_placeholder => $val_value,
));
}
}
}
if ($pager) {
$query
->range(0, $pager);
}
$this->find['results'] = $query
->execute()
->fetchAllKeyed(0, 1);
}