Ejemplo n.º 1
0
 /**
  * $cols can be a single string or an array of strings where the first array item is the column to match on
  */
 public static function suggestionList($table, $cols, $match = false, $limit = 100, $removeUnknown = true, $where = false)
 {
     $topicTable = new OptionList(array('name' => $table));
     if (is_string($cols)) {
         $cols = array($cols, 'id');
     } else {
         $cols[] = 'id';
     }
     $info = $topicTable->info();
     if (array_search('is_default', $info['cols']) !== false) {
         $cols[] = 'is_default';
     }
     $select = $topicTable->select()->from($table, $cols);
     //look for char start
     if ($match) {
         $select->where($cols[0] . ' LIKE ? ', $match . '%');
     }
     if ($topicTable->has_is_deleted_col()) {
         $select->where('is_deleted = 0');
     }
     if ($where) {
         $select->where($where);
     }
     $select->order($cols[0] . ' ASC');
     if ($limit) {
         $select->limit($limit, 0);
     }
     $rows = $topicTable->fetchAll($select);
     $rowArray = $rows->toArray();
     //	unset 'unknown'
     if ($removeUnknown) {
         foreach ($rowArray as $key => $row) {
             if ($row[$cols[0]] == 'unknown') {
                 unset($rowArray[$key]);
             }
         }
     }
     return $rowArray;
 }