/** * */ public function get_search_sql($search) { if (!$search) { return null; } // The search value must be found in the field options. if (!($search[3] = $this->get_search_value($search[3]))) { return null; } return parent::get_search_sql($search); }
/** * Overriding parent to adjust search value. The search value is expected to be * a list of strings separated by pipe |. The reserved string for all required is -000-. * Searching a value is searching for the index: '#n#'. * Equal is simple, e.g. '#1#3#' where the searched options are 1 and 3. * Like requires a disjunction of each option. e.g. '%#1#%' OR '%#3#%' * or */ public function get_search_sql($search) { list($element, $not, $operator, $value) = $search; // If no options, no search. if (!($options = $this->options_menu())) { return null; } $optionkeys = array_keys($options); // Search with all required. if ($value == '-000-') { $value = '#' . implode('#', $optionkeys) . '#'; $search = array($element, $not, $operator, $value); return parent::get_search_sql($search); } $searchedvalues = array_map('trim', explode('|', $value)); // Search equal to given list. if ($operator == '=') { $searchedoptions = array_intersect($options, $searchedvalues); // If we are searching for a value that is not in options, search for the impossible. if (count($searchedoptions) != count($searchedvalues)) { $search = array($element, $not, $operator, '##'); return parent::get_search_sql($search); } // All searched values are there. $value = '#' . implode('#', array_keys($searchedoptions)) . '#'; $search = array($element, $not, $operator, $value); return parent::get_search_sql($search); } // Search Like to given list. $sql = ''; $params = array(); if ($operator == 'LIKE') { $searchsqls = array(); foreach ($searchedvalues as $searched) { if ((string) $searched == '') { continue; } foreach ($options as $key => $option) { if (strpos($option, $searched) !== false) { $value = '#' . $key . '#'; $search = array($element, $not, $operator, $value); $searchsqls[$key] = parent::get_search_sql($search); } } } if ($searchsqls) { $sqlon = array(); foreach ($searchsqls as $searchsql) { list($sqlon[], $paramon, ) = $searchsql; $params = array_merge($params, $paramon); } $sql = '(' . implode(' OR ', $sqlon) . ')'; return array($sql, $params, $this->is_dataform_content()); } else { // Searched strings not found so search for the impossible to return no entries. $search = array($element, '', '=', '##'); return parent::get_search_sql($search); } } return null; }
/** * */ public function get_search_sql($search) { list($element, $not, $operator, $value) = $search; // Time list separated by .. if (strpos($value, '..') !== false) { $value = array_map('strtotime', explode('..', $value)); // Must have valid timestamps. if (in_array(false, $value, true)) { $value = '#'; } } else { $value = strtotime($value); // Must have valid timestamps. if ($value === false) { $value = '#'; } } return parent::get_search_sql(array($element, $not, $operator, $value)); }
/** * */ public function get_search_sql($search) { if (!$search) { return null; } // Convert the search value to option index. $search[3] = $this->get_search_value($search[3]); return parent::get_search_sql($search); }