Beispiel #1
0
 public static function action_getList($args, &$returncode, &$profile, &$auth = false, $format = false)
 {
     if ($auth) {
         $returncode = ResponseCode::BAD_REQUEST;
         return false;
     }
     if (!$profile->perm_app_getlist) {
         $returncode = ResponseCode::ACTION_NOT_ALLOWED;
         return false;
     }
     $maxResults = isset($args->max_results) && $args->max_results > 0 && $args->max_results <= 60 ? (int) $args->max_results : 15;
     $startWith = isset($args->start_result) ? (int) $args->start_result : 1;
     $showTotal = isset($args->show_total_results) ? $args->show_total_results == 1 : false;
     $sort = isset($args->sort_by) ? $args->sort_by : 'relevance';
     $fields = isset($args->fields) && is_array($args->fields) ? $args->fields : array();
     $cat = isset($args->filter->category) ? (int) $args->filter->category : 0;
     $filter = isset($args->filter->text) ? $args->filter->text : false;
     $app_ids = isset($args->filter->app_id) ? $args->filter->app_id : false;
     $itunes_ids = isset($args->filter->itunes_id) ? $args->filter->itunes_id : false;
     $am = ApplicationModel::getInstance();
     $results = $am->getAppListCached($maxResults, false, $sort, $cat, $filter, $app_ids, $itunes_ids, $startWith);
     $legal = $profile->allowed_app_fields;
     $realfields = ShortAppBean::getFields();
     $apps = array();
     foreach ($results as $result) {
         $i = count($apps);
         $apps[$i]['id'] = $result->id;
         foreach ($fields as $field) {
             if ($field != 'id' && in_array($field, $realfields) && (in_array($field, $legal) || $legal[0] == 'ALL')) {
                 $apps[$i][$field] = $result->{$field};
             }
         }
     }
     $data = array('apps' => $apps);
     if ($showTotal) {
         $total = $am->getResultCountCached($cat, $filter, $app_ids, $itunes_ids);
         $data['total_results'] = $total;
     }
     $returncode = ResponseCode::OK;
     return $data;
 }
Beispiel #2
0
 public function getAppList($perpage, $page, $sort = 'relevance', $cat = 0, $filter = false, $app_ids = false, $itunes_ids = false, $overrideStartWith = false, $fullinfo = false)
 {
     $query = new Query('SELECT');
     if (($filter = trim($filter)) == '') {
         $filter = false;
     }
     switch ($sort) {
         case 'appname':
             $query->orderby('app.name', 'ASC');
             break;
         case 'newapps':
             $query->orderby('app.date_added', 'DESC');
             break;
         case 'relevance':
             if ($filter) {
                 $query->orderby('namematch', 'DESC');
                 $query->orderby('score', 'DESC');
                 break;
             }
         case 'newvers':
         default:
             $sort = 'newvers';
             $query->orderby('latest_version_added', 'DESC');
     }
     $query->limit($perpage, $overrideStartWith ?: $perpage * ($page - 1));
     $inclids = array();
     if ($filter) {
         $inclids = $this->getMatchedIDs($filter);
         $newfilter = $this->processFilter($filter);
         if ($sort == 'relevance') {
             $query->field('CASE when name like ? then 1 else 0 END', 'namematch', '%' . $filter . '%');
             $query->field('MATCH(app.name, app.description) AGAINST(? IN BOOLEAN MODE)', 'score', $newfilter);
         }
         $query->whereOpenGroup('AND');
         $query->where('MATCH(app.name, app.description) AGAINST(? IN BOOLEAN MODE)', $newfilter);
         foreach ($inclids as $inclid) {
             $query->where('app.id = ?', $inclid, 'OR');
         }
         $query->whereCloseGroup();
     }
     if ($cat > 0) {
         $query->where('app.category_id = ?', $cat);
     }
     if ($app_ids) {
         if (is_array($app_ids)) {
             $query->whereOpenGroup('AND');
             foreach ($app_ids as $app_id) {
                 $query->where('app.id = ?', $app_id, 'OR');
             }
             $query->whereCloseGroup();
         } else {
             $query->where('app.id = ?', $app_id);
         }
     }
     if ($itunes_ids) {
         if (is_array($itunes_ids)) {
             $query->whereOpenGroup('AND');
             foreach ($itunes_ids as $itunes_id) {
                 $query->where('app.itunes_id = ?', $itunes_id, 'OR');
             }
             $query->whereCloseGroup();
         } else {
             $query->where('app.itunes_id = ?', $itunes_id);
         }
     }
     if ($fullinfo) {
         $result = ApplicationBean::select($query, true);
     } else {
         $result = ShortAppBean::select($query, true);
     }
     if (!$result) {
         return false;
     }
     return $result;
 }