예제 #1
0
 /**
  * Cache method to populate autocomplete options
  *
  * @param   plgFabrik_Element  $elementModel  element model
  * @param   string             $search        serch string
  *
  * @since   3.0.7
  *
  * @return string  json encoded search results
  */
 public static function cacheAutoCompleteOptions($elementModel, $search)
 {
     $params = $elementModel->getParams();
     $db = FabrikWorker::getDbo();
     $c = $elementModel->getValColumn();
     if (!strstr($c, 'CONCAT')) {
         $c = FabrikString::safeColName($c);
     }
     $filterMethod = $elementModel->getFilterBuildMethod();
     if ($filterMethod == 1) {
         $join = $elementModel->getJoin()->table_join;
         $opts = array();
         $opts['label'] = !strstr($c, 'CONCAT') ? $join . '.' . $c : $c;
         return parent::cacheAutoCompleteOptions($elementModel, $search, $opts);
     }
     // $$$ hugh - added 'autocomplete_how', currently just "starts_with" or "contains"
     // default to "contains" for backward compat.
     if ($params->get('dbjoin_autocomplete_how', 'contains') == 'contains') {
         $elementModel->_autocomplete_where = $c . ' LIKE ' . $db->quote('%' . $search . '%');
     } else {
         $elementModel->_autocomplete_where = $c . ' LIKE ' . $db->quote($search . '%');
     }
     $opts = array('mode' => 'filter');
     $tmp = $elementModel->_getOptions(array(), 0, true, $opts);
     return json_encode($tmp);
 }