+ private function mkTests($field, $text)
+ {
+ $tests = array();
+ $tests[] = $field . self::makeSqlConcat($text, self::MODE_PREFIX);
+ if (!$this->ac_beginwith) {
+ $tests[] = $field . self::makeSqlConcat(' ' . $text, self::MODE_CONTAINS);
+ $tests[] = $field . self::makeSqlConcat('-' . $text, self::MODE_CONTAINS);
+ }
+ return $tests;
+ }
+
+ // {{{ function getAutoComplete
+ public function getAutoComplete($text)
+ {
+ $text = str_replace(array('%', '_'), '', $text);
+
+ if (is_null($this->ac_where) || $this->ac_where == '') {
+ $where = '';
+ } else {
+ $where = $this->ac_where . ' AND ';
+ }
+
+ $tests = $this->mkTests($this->valfield, $text);
+ if (!is_null($this->valfield2)) {
+ $tests = array_merge($tests, $this->mkTests($this->valfield2, $text));
+ }
+
+ $where .= '(' . implode(' OR ', $tests) . ')';
+
+ return XDB::iterator('SELECT ' . $this->valfield . ' AS field'
+ . ($this->ac_distinct ? (', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb') : '')
+ . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . '
+ FROM ' . $this->from . '
+ ' . $this->ac_join . '
+ WHERE ' . $where . '
+ GROUP BY ' . $this->valfield . '
+ ORDER BY ' . ($this->ac_distinct ? 'nb DESC' : $this->valfield) . '
+ LIMIT 11');
+ }
+ // }}}
+
+ // {{{ function makeSqlConcat