Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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']);
     }
 }
Exemplo n.º 3
0
 /**
  * Some template hack
  */
 public function inject_template(midgardmvc_core_request $request)
 {
     $this->mvc = midgardmvc_core::get_instance();
     if (!$this->connected) {
         self::get_connected();
     }
     if (!$this->mvc->configuration->exists('default')) {
         // workaround to avoid an exception while templating
         return true;
     }
     $this->request = $request;
     $route = $this->request->get_route();
     if ($route->id == "apps_index") {
         $route->template_aliases['topbar'] = 'cmp-welcome-text';
     } else {
         $route->template_aliases['topbar'] = 'cmp-menubar';
     }
     // login link with redirect specified
     $request->set_data_item('redirect_link', $this->mvc->context->get_request(0)->get_path());
     // placeholder for a link to list staging apps
     $request->set_data_item('staging_link', false);
     // set if user is admin
     $request->set_data_item('admin', false);
     // admins get a link to category management UI
     $request->set_data_item('category_admin_url', false);
     // flag to show newest and hottest blocks
     $request->set_data_item('bottomblocks', false);
     if ($this->mvc->authentication->is_user()) {
         if ($this->mvc->authentication->get_user()->is_admin()) {
             $request->set_data_item('admin', true);
             $category_admin_url = $this->mvc->dispatcher->generate_url('basecategories_admin_index', array(), $request);
             $request->set_data_item('category_admin_url', $category_admin_url);
         }
     }
     $matched = $route->get_matched();
     if (!$matched && $route->id == 'search') {
         // if we have a search we may be lucky and get a nicely set matched array
         $matched = $this->request->get_query();
     }
     if (is_array($matched) && array_key_exists('os', $matched) && array_key_exists('version', $matched) && array_key_exists('ux', $matched)) {
         $os = $matched['os'];
         $ux = $matched['ux'];
         $redirect = false;
         $decoded = '';
         if (array_key_exists('basecategory', $matched)) {
             $decoded = rawurldecode($matched['basecategory']);
             $matched['basecategory'] = $decoded;
             if (array_key_exists($decoded, $this->mvc->configuration->basecategory_css_map)) {
                 $matched['basecategory_css'] = $this->mvc->configuration->basecategory_css_map[$decoded];
             } else {
                 $matched['basecategory_css'] = strtolower($decoded);
             }
         } else {
             $matched['basecategory'] = false;
             $matched['basecategory_css'] = '';
         }
         if (!array_key_exists($matched['os'], $this->mvc->configuration->os_map)) {
             $redirect = true;
             $os = $this->mvc->configuration->default['os'];
         }
         // if the matched UX is not configured then we shout out loud
         if (!array_key_exists($matched['ux'], $this->mvc->configuration->os_ux[$os])) {
             $redirect = true;
             $ux = $this->mvc->configuration->latest[$os]['ux'];
         }
         $matched['prettyversion'] = $matched['version'];
         if (array_key_exists('versions', $this->mvc->configuration->os_map[$matched['os']])) {
             if (array_key_exists($matched['version'], $this->mvc->configuration->os_map[$matched['os']]['versions'])) {
                 $matched['prettyversion'] = $this->mvc->configuration->os_map[$matched['os']]['versions'][$matched['version']];
             }
         }
         if ($redirect) {
             //throw new midgardmvc_exception_notfound("Please pick a valid UX, " . $matched['ux'] . " does not exist.", 404);
             com_meego_packages_controllers_basecategory::redirect($os, $matched['version'], $ux);
         }
         // gather available UXes for the popups
         // @todo: this piece of code is only needed for some of the routes
         // so we should not run it when not needed
         $uxes = array();
         $versions = array();
         $repositories = com_meego_packages_controllers_application::get_top_project_repos();
         $latest = $this->mvc->configuration->latest;
         foreach ($repositories as $repository) {
             if (array_key_exists($repository->repoos, $latest) && $repository->repoosversion == $latest[$repository->repoos]['version']) {
                 if (!strlen($repository->repoosux)) {
                     // No UX means a core or universal repo, so we populate all UXes
                     foreach ($this->mvc->configuration->os_ux[$repository->repoos] as $configured_ux => $configured_ux_title) {
                         $uxes[$repository->repoos . $configured_ux] = com_meego_packages_controllers_application::populate_repo_ux($repository, $configured_ux);
                     }
                 } else {
                     $uxes[$repository->repoos . $repository->repoosux] = com_meego_packages_controllers_application::populate_repo_ux($repository);
                 }
             }
             if ($matched['os'] == $repository->repoos) {
                 // all versions of the matched, current UX
                 if ($repository->repoosux == '' || $repository->repoosux == 'universal' || $repository->repoosux == $matched['ux'] && !array_key_exists($repository->repoosversion, $versions)) {
                     $prettyversion = $repository->repoosversion;
                     if (array_key_exists('versions', $this->mvc->configuration->os_map[$repository->repoos])) {
                         if (array_key_exists($repository->repoosversion, $this->mvc->configuration->os_map[$repository->repoos]['versions'])) {
                             $prettyversion = $this->mvc->configuration->os_map[$repository->repoos]['versions'][$repository->repoosversion];
                         }
                     }
                     $_repo = com_meego_packages_controllers_application::populate_repo_ux($repository, $matched['ux']);
                     $versions[$repository->repoosversion] = array('version' => $repository->repoosversion, 'url' => $_repo['url'], 'prettyversion' => $prettyversion);
                 }
             }
             // if we are not serving a staging_ route then
             // check if the repo's project has a staging project configured
             if ($route->id == "basecategories_os_version_ux" && substr($route->id, 0, 8) != 'staging_' && $repository->repoos == $os && $this->mvc->configuration->top_projects[$repository->projectname]['staging']) {
                 //echo "call count of apps\n"; ob_flush();
                 $cnt = com_meego_packages_controllers_application::count_number_of_apps($repository->repoos, $repository->repoosversion, 0, $matched['ux'], 'staging');
                 if ($cnt) {
                     $workflows = com_meego_packages_controllers_workflow::get_open_workflows_for_osux($repository->repoos, $repository->repoosversion, $matched['ux']);
                     if (count($workflows)) {
                         // if there is at least 1 workflow then we set and show the link in the templates
                         $link = $this->mvc->dispatcher->generate_url('staging_basecategories_os_version_ux', array('os' => $os, 'version' => (string) $repository->repoosversion, 'ux' => $matched['ux']), 'com_meego_packages');
                         $request->set_data_item('staging_link', $link);
                     }
                 }
             }
         }
         krsort($uxes);
         ksort($versions);
         $request->set_data_item('uxes', $uxes);
         $request->set_data_item('versions', $versions);
     }
     // in case there is no matched stuff from the request we will use the defaults configured
     if (!is_array($matched)) {
         $matched = array();
     }
     if (is_array($matched) && (!array_key_exists('os', $matched) || !array_key_exists('version', $matched) || !array_key_exists('prettyversion', $matched) || !array_key_exists('ux', $matched))) {
         $default_os = $this->mvc->configuration->default['os'];
         $matched = array_merge($matched, $this->mvc->configuration->latest[$default_os]);
         $matched['os'] = $this->mvc->configuration->default['os'];
         $matched['prettyversion'] = $matched['version'];
         if (array_key_exists('versions', $this->mvc->configuration->os_map[$matched['os']])) {
             if (array_key_exists($matched['version'], $this->mvc->configuration->os_map[$matched['os']]['versions'])) {
                 $matched['prettyversion'] = $this->mvc->configuration->os_map[$matched['os']]['versions'][$matched['version']];
             }
         }
         $this->part = 'packages';
     }
     // Add the CSS and JS files needed by Packages
     $this->add_head_elements();
     $matched['configured_ux'] = ucwords($this->mvc->configuration->os_ux[$matched['os']][$matched['ux']]);
     if (array_key_exists('client', $this->mvc->configuration->os_ux[$matched['os']])) {
         $matched['appsclient'] = $this->mvc->configuration->os_ux[$matched['os']]['client'];
     } else {
         $matched['appsclient'] = false;
     }
     $request->set_data_item('matched', $matched);
     if (count($matched)) {
         // if we have matched then show the newest and hottest blocks
         $request->set_data_item('bottomblocks', true);
     }
     $request->set_data_item('submit_app_url', $this->mvc->configuration->submit_app_url);
     // don't show newest and hottest blocks if any of these were requested explicitly
     if ($route->id == "newest_apps" || $route->id == "hottest_apps") {
         $request->set_data_item('bottomblocks', false);
     }
     $request->set_data_item('staging_area', false);
     if (substr($route->id, 0, 8) == 'staging_') {
         $request->set_data_item('staging_area', true);
         $request->set_data_item('staging_back_link', false);
         $request->set_data_item('community_qa_url', $this->mvc->configuration->community_qa_url);
         $link = false;
         if (substr($route->id, 0, 28) == 'staging_apps_by_basecategory') {
             $link = $this->mvc->dispatcher->generate_url('staging_basecategories_os_version_ux', array('os' => $matched['os'], 'version' => (string) $matched['version'], 'ux' => $matched['ux']), 'com_meego_packages');
         }
         if (substr($route->id, 0, 21) == 'staging_apps_by_name') {
             $link = '..';
         }
         if ($link) {
             $request->set_data_item('staging_back_link', $link);
         }
     }
 }