Ejemplo n.º 1
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;
 }