/**
  * Returns all packages that belong to a certain base category
  * @param array args; 'basecategory' argument can be like: Games
  */
 public function get_packages_by_basecategory(array $args)
 {
     // get the base category object
     $basecategory = com_meego_packages_controllers_basecategory::load_object($args);
     if (is_object($basecategory)) {
         $this->data['base'] = true;
         $this->data['categorytree'] = false;
         $this->data['basecategory'] = strtolower($basecategory->name);
         // get relations
         $relations = com_meego_packages_controllers_basecategory::load_relations_for_basecategory($basecategory->id);
         $packages = array();
         // gather all packages from each relation
         foreach ($relations as $relation) {
             $storage = new midgard_query_storage('com_meego_package_details');
             $q = new midgard_query_select($storage);
             $qc = new midgard_query_constraint(new midgard_query_property('packagecategory'), '=', new midgard_query_value($relation->packagecategory));
             $q->set_constraint($qc);
             $q->execute();
             $packages = array_merge($q->list_objects(), $packages);
         }
         // sort the packages by title
         uasort($packages, function ($a, $b) {
             if ($a->packagename == $b->packagename) {
                 return 0;
             }
             return $a->packagename < $b->packagename ? -1 : 1;
         });
         // prepare the data for the template
         self::set_data($packages);
     } else {
         // oops, there are no packages for this base category..
         throw new midgardmvc_exception_notfound("There is no category called: " . $args['basecategory']);
     }
 }
 /**
  * Returns all apps that match the criteria specified by the args
  *
  * @param array GET args
  * @param string filter type: 'top' for top projects only, 'staging' for staging projects only
  * @param string for free text search: title, name, summary, filename will be searched.
  *
  * @return array of com_meego_package_details objects
  */
 public function get_applications_by_criteria(array $args, $filter_type = 'top', $freetext_search = null)
 {
     $ux = null;
     if (array_key_exists('ux', $args)) {
         $ux = $args['ux'];
     }
     // get the base category object
     $basecategory = com_meego_packages_controllers_basecategory::load_object($args);
     if (is_object($basecategory)) {
         $packages = array();
         // get relations
         $relations = com_meego_packages_controllers_basecategory::load_relations_for_basecategory($basecategory->id);
         // gather all packages from each relation
         foreach ($relations as $relation) {
             if ($args['packagename']) {
                 $filtered = self::get_filtered_applications($args['os'], null, $relation->packagecategory, $basecategory->id, $ux, $args['packagename'], $filter_type, $freetext_search);
             } else {
                 $filtered = self::get_filtered_applications($args['os'], $args['version'], $relation->packagecategory, $basecategory->id, $ux, $args['packagename'], $filter_type, $freetext_search);
             }
             if (is_array($filtered)) {
                 $packages = array_merge($filtered, $packages);
             }
         }
         // sort the packages by name
         if (count($packages)) {
             uasort($packages, function ($a, $b) {
                 if ($a->packagename == $b->packagename) {
                     return 0;
                 }
                 return $a->packagename < $b->packagename ? -1 : 1;
             });
         }
     } else {
         // oops, there are no packages for this base category..
         throw new midgardmvc_exception_notfound("There is no category called: " . $args['basecategory']);
     }
     return $packages;
 }