예제 #1
0
 /**
  * returns an array of ids
  * @param   array   $clause             clause array
  * @param   Boolean $do_count           if true, returns a count of the list
  * @return  array
  * @throws  \Exception                  if this is not a subclasss
  */
 public static function getList($clause = array(), $do_count = false)
 {
     $model_name = self::getCalledClass();
     if (!$model_name || $model_name == 'Model') {
         throw new Exception('Cannot use getList on a non subclass of Model.');
     }
     $fn = \getList::getFn(\aql::get_aql($model_name));
     return $fn($clause, $do_count);
 }
 /**
  * Returns a getList object with filters defined based on the given AQL
  * @param   string      $aql
  * @param   Boolean     $search_operators
  * @return  \getList
  * @throws  \Exception  if invalid AQL
  */
 public static function autoGenerate($aql, $search_operators = false)
 {
     if (!aql::is_aql($aql)) {
         throw new \Exception('autoGenerate requires AQL.');
     }
     $aql_array = aql2array($aql);
     $min_aql = aql::minAQLFromArr($aql_array);
     $fields = array();
     foreach ($aql_array as $k => $f) {
         $fields = array_merge($fields, $f['fields']);
     }
     $lst = new self();
     $lst->setAQL($min_aql)->defineFilters(array_map(function ($field) use($lst, $search_operators, $fields) {
         $op = array_search($field, $fields);
         return array('operator' => $search_operators ? $op : null, 'callback' => function ($val) use($lst, $fields, $field) {
             $where = \getList::prepVal(\getList::csvToArray($val));
             $lst->where[] = "{$field} in {$where}";
         });
     }, $fields));
     return $lst;
 }