Example #1
0
 /**
  * generates index of posted forms for the given package
  */
 public function get_posted_forms_index(array $args)
 {
     // @todo: check user
     // @todo: localize title
     $current_page = 1;
     if (array_key_exists('page', $_GET) && is_numeric($_GET['page']) && $_GET['page'] > 0) {
         $current_page = $_GET['page'];
     }
     $forms = com_meego_packages_forms::get_posted_forms($args['package'], $current_page);
     $this->data['title'] = "Posted Forms";
     $this->data['forms'] = $forms['forms'];
     $this->data['previous_page'] = $forms['previous_page'];
     $this->data['next_page'] = $forms['next_page'];
     if (isset($forms['items_shown'])) {
         $this->data['items_shown'] = $forms['items_shown'];
     }
     if (isset($forms['total'])) {
         $this->data['total_apps'] = $forms['total'];
     }
 }
 /**
  * Sets $this->data['packages'] for the template
  *
  * This function groups packages into applications, so e.g. 5 variants of
  * the same package will mean 1 item in the final array.
  *
  * @param array of com_meeg_package_details objects
  * @param string filter type: 'top' or 'staging': settings URL will depend on it
  * @param boolean if true then return info about older packages too
  *
  * @return array
  *
  */
 public function set_data(array $packages, $filter_type = 'top', $history = false)
 {
     $all = array();
     // a flag for tricky situations caused by additional hand imports
     $remember = false;
     // store guid for promoted apps (ie. apps that passed qa)
     $promotedtoguid = '';
     $promotedfromguid = '';
     $default_latest = array('packagescore' => '', 'packagename' => '', 'packageguid' => '', 'promotedfromguid' => '', 'promotedtoguid' => '', 'os' => '', 'version' => '', 'size' => 'n/a', 'promoted' => 'n/a', 'released' => 'n/a', 'lastupdate' => 'n/a', 'variants' => array(), 'iconurl' => '');
     $latest = $default_latest;
     $matched = $this->request->get_route()->get_matched();
     // this index will be used to grab the download URL of the appropriate arch variant of the package
     $index = 0;
     // this method is called from other classes too
     $this->isuser = $this->mvc->authentication->is_user();
     if (isset($matched['ux']) && array_key_exists($matched['ux'], $this->mvc->configuration->ux_arch_map)) {
         $index = $this->mvc->configuration->ux_arch_map[$matched['ux']];
     }
     foreach ($packages as $package) {
         if ($package->packagename != $latest['packagename']) {
             // processing a different package, so reset some internal arrays
             $all = array();
             $latest = $default_latest;
         }
         if (!isset($this->data['packages'][$package->packagename]['name'])) {
             // set the guid
             $this->data['packages'][$package->packagename]['packageguid'] = $package->packageguid;
             // set the name
             $this->data['packages'][$package->packagename]['name'] = $package->packagename;
             // set the title
             $this->data['packages'][$package->packagename]['title'] = $package->packagetitle;
             // get roles
             $this->data['packages'][$package->packagename]['roles'] = self::get_roles($package->packageguid);
             // gather some basic stats
             $stats = com_meego_packages_controllers_package::get_statistics($package->packagename);
             // set the total number of comments
             $this->data['packages'][$package->packagename]['number_of_comments'] = $stats['number_of_comments'];
             // figure out if there are posted forms for this app
             $this->data['packages'][$package->packagename]['posted_forms'] = count(com_meego_packages_forms::get_all_forms($package->packageguid));
             if (array_key_exists('number_of_rates', $stats)) {
                 // total number of rates
                 $this->data['packages'][$package->packagename]['number_of_rates'] = $stats['number_of_rates'];
             }
             // the stars as html snippet for the average rating; should be used as-is in the template
             $this->data['packages'][$package->packagename]['average_rating'] = $stats['average_rating'];
             $this->data['packages'][$package->packagename]['stars'] = com_meego_ratings_controllers_rating::draw_stars($stats['average_rating']);
             // collect ratings and comments (used in application detailed view)
             if (!array_key_exists('ratings', $this->data['packages'][$package->packagename])) {
                 $this->data['packages'][$package->packagename]['ratings'] = array();
             }
             $ratings = self::prepare_ratings($package->packagename, $history);
             $this->data['packages'][$package->packagename]['ratings'] = $ratings['ratings'];
             $this->data['packages'][$package->packagename]['is_there_comment'] = $history ? $history : $ratings['comment'];
             // set a summary
             $this->data['packages'][$package->packagename]['summary'] = $package->packagesummary;
             // set a longer description
             $this->data['packages'][$package->packagename]['description'] = $package->packagedescription;
             $this->data['packages'][$package->packagename]['basecategoryname'] = $package->basecategoryname;
             // base category name
             $this->data['packages'][$package->packagename]['iconurl'] = false;
             $this->data['packages'][$package->packagename]['screenshoturl'] = false;
             // a package may have multiple arches
             // but we should nominate one to be the default in order to support the new design
             $this->data['packages'][$package->packagename]['defaultdownloadurl'] = false;
             $_package = new com_meego_package($package->packageid);
             $attachments = $_package->list_attachments();
             $_icon_marker = 'icon.png';
             $_screenshot_marker = 'screenshot.png';
             $this->data['packages'][$package->packagename]['screenshots'] = false;
             foreach ($attachments as $attachment) {
                 if ($attachment->mimetype == 'image/png') {
                     if (strrpos($attachment->name, $_screenshot_marker) !== false) {
                         $this->data['packages'][$package->packagename]['screenshots'][] = $this->mvc->dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'prop480x300', 'filename' => $attachment->name), '/');
                     }
                     if (strrpos($attachment->name, $_icon_marker) !== false && !$this->data['packages'][$package->packagename]['iconurl']) {
                         $this->data['packages'][$package->packagename]['iconurl'] = $this->mvc->dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'icon', 'filename' => $attachment->name), '/');
                     }
                 }
             }
         }
         if (count($this->data['packages'][$package->packagename]['screenshots'])) {
             $this->data['packages'][$package->packagename]['screenshoturl'] = $this->data['packages'][$package->packagename]['screenshots'][0];
         }
         // if the UX is empty then we consider the package to be good for all UXes
         // this value is used in the template to show a proper icon
         $package->ux = $package->repoosux;
         if (!strlen($package->ux)) {
             $package->ux = 'universal';
         }
         $this->data['ux'] = $package->ux;
         // provide a link to visit the app page
         $package->localurl = self::get_localurl($package);
         // provide a link to visit the app's full history
         $this->data['packages'][$package->packagename]['historyurl'] = self::get_historyurl($package);
         $variant_info = array('ux' => $package->repoosux, 'repoos' => $package->repoos, 'repoarch' => $package->repoarch, 'packageid' => $package->packageid, 'packageguid' => $package->packageguid, 'packageinstallfileurl' => $package->packageinstallfileurl);
         //echo "current latest: " . $latest['packagename'] . ':' . $latest['version'] . ' vs package: ' . $package->packagename . ':' . $package->packageversion . "\n";
         if ($latest['version'] <= $package->packageversion) {
             $qarelease = $this->mvc->i18n->get('label_app_type_qarelease');
             $promoted = $this->mvc->i18n->get('label_app_type_promoted');
             $staging = $this->mvc->i18n->get('label_app_type_staging');
             //echo $package->packagename . ':' . $package->packageversion . ' from ' . $package->repoprojectname . " will be set as latest\n";
             //echo "latest score: " . $latest['packagescore'] . ', curtent package score: ' . $package->packagescore . "\n";
             if ($latest['packageguid']) {
                 if ($latest['version'] == $package->packageversion) {
                     if ($latest['repoid'] == $package->repoid && (int) $latest['packagescore'] > $package->packagescore) {
                         $remember = $latest;
                         //echo $package->packageversion . ' (score: ' . $remember['packagescore'] . ') from ' . $package->reponame .' repo id: ' . $package->repoid . " is already the latest, maybe it was reimported by hand for some reason\n";
                     } else {
                         //echo $package->packageversion . " is already the latest, this is probably from an other project; check if it was ever promoted\n";
                         $predecessors = self::get_predecessors($package->packageguid, 3);
                         if (count($predecessors)) {
                             foreach ($predecessors as $key => $guid) {
                                 //echo "compare: " . $guid . ' vs ' . $latest['packageguid'] . "\n";
                                 if ($guid == $latest['packageguid'] || isset($remember) && $guid == $remember['packageguid'] && $remember['packagescore'] > 0 && $remember['packagescore'] > $package->packagescore) {
                                     //echo "this version: " . $package->packageversion . ' was promoted on ' . $package->packagecreated->format('Y-m-d h:i e') . "\n";
                                     $promotedfromguid = $guid;
                                     if ($remember) {
                                         //echo "update history backwards";
                                         $all[$remember['released']]['promotedtoguid'] = $remember['packageguid'];
                                         $all[$remember['released']]['type'] = $promoted;
                                         $remember = false;
                                     } else {
                                         $promotedtoguid = $package->packageguid;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $all[$latest['released']] = array('size' => $latest['size'], 'repoid' => $latest['repoid'], 'version' => $latest['version'], 'variants' => $latest['variants'], 'released' => $latest['released'], 'packageid' => $latest['packageid'], 'packageguid' => $latest['packageguid'], 'packagescore' => $latest['packagescore'], 'hidden' => $latest['hidden'], 'publishers' => $latest['publishers'], 'localurl' => isset($latest['localurl']) ? $latest['localurl'] : false);
                 if ($latest['promotedfromguid']) {
                     $latest['type'] = $qarelease;
                     $all[$latest['released']]['promotedfromguid'] = $latest['promotedfromguid'];
                 } else {
                     if ($promotedtoguid) {
                         $latest['type'] = $promoted;
                         $all[$latest['released']]['promotedtoguid'] = $promotedtoguid;
                         $promotedtoguid = '';
                     } else {
                         $latest['type'] = $staging;
                     }
                 }
                 $all[$latest['released']]['type'] = $latest['type'];
                 $latest = $default_latest;
             }
             $latest['ux'] = $package->ux;
             $latest['size'] = $package->packagesize ? (int) ($package->packagesize / 1024) . ' kb' : 'n/a';
             $latest['publishers'] = self::get_roles($package->packageguid, 'downloader');
             $latest['repoid'] = $package->repoid;
             $latest['hidden'] = $package->packagehidden;
             $latest['version'] = $package->packageversion;
             $latest['released'] = $package->packagecreated->format('Y-m-d H:i');
             // @todo: this might not be needed
             $latest['variants'][$package->repoarch] = $variant_info;
             $latest['packageid'] = $package->packageid;
             $latest['lastupdate'] = $package->packagerevised->format('Y-m-d H:i');
             $latest['packageguid'] = $package->packageguid;
             $latest['packagename'] = $package->packagename;
             $latest['packagescore'] = $package->packagescore;
             if ($promotedfromguid) {
                 $latest['promotedfromguid'] = $promotedfromguid;
                 if (!$latest['hidden']) {
                     $latest['localurl'] = $package->localurl;
                 }
                 $promotedfromguid = '';
             } else {
                 if ($promotedtoguid) {
                     $latest['promotedtoguid'] = $promotedtoguid;
                     $promotedtoguid = '';
                 } else {
                     if (!$latest['hidden']) {
                         $latest['localurl'] = '/staging' . $package->localurl;
                     }
                 }
             }
         } elseif ($latest['version'] > $package->packageversion) {
             // this should not happen if the packages are ordered by version
             // anyway this package should go to all
             //echo $package->packageversion . ' from ' . $package->repoprojectname . ' goes to all' . "\n";
             $all[$package->packagecreated->format('Y-m-d H:i')] = $package->packageguid;
         }
         // add the latest to the all array
         $all[$latest['released']] = array('size' => $latest['size'], 'repoid' => $latest['repoid'], 'version' => $latest['version'], 'variants' => $latest['variants'], 'released' => $latest['released'], 'packageid' => $latest['packageid'], 'packageguid' => $latest['packageguid'], 'packagescore' => $latest['packagescore'], 'hidden' => $latest['hidden'], 'publishers' => $latest['publishers'], 'localurl' => isset($latest['localurl']) ? $latest['localurl'] : false);
         if ($latest['promotedfromguid']) {
             $all[$latest['released']]['type'] = $qarelease;
             $all[$latest['released']]['promotedfromguid'] = $latest['promotedfromguid'];
         } else {
             $all[$latest['released']]['type'] = $staging;
         }
         //echo "\n\n";
         //ob_flush();
         // set the default download url for the package
         if (array_key_exists($index, $latest['variants']) && !$this->data['packages'][$package->packagename]['defaultdownloadurl']) {
             // index was set at the beginning of this method
             $this->data['packages'][$package->packagename]['defaultdownloadurl'] = $latest['variants'][$index]['packageinstallfileurl'];
             // set a different downloadurl in case the configured download schema for this OS is 'apps'
             if (array_key_exists('download', $this->mvc->configuration->os_ux[$latest['variants'][$index]['repoos']]) && $this->mvc->configuration->os_ux[$latest['variants'][$index]['repoos']]['download'] == 'apps') {
                 $this->data['packages'][$package->packagename]['defaultdownloadurl'] = 'apps://' . $latest['variants'][$index]['packageid'];
             }
         }
         // set the latest of this package
         if (!array_key_exists('latest', $this->data['packages'][$package->packagename])) {
             $this->data['packages'][$package->packagename]['latest'] = array('version' => '', 'variants' => array());
         }
         if ($this->data['packages'][$package->packagename]['latest']['version'] <= $latest['version']) {
             $this->data['packages'][$package->packagename]['latest'] = $latest;
         }
         // always keep it up-to-date
         $this->data['packages'][$package->packagename]['all'] = $all;
         switch ($filter_type) {
             case 'staging':
                 $route_id = 'staging_apps_by_name';
                 break;
             case 'top':
             default:
                 $route_id = 'apps_by_name';
         }
         $this->data['packages'][$package->packagename]['localurl'] = $this->mvc->dispatcher->generate_url($route_id, array('os' => $package->repoos, 'version' => $package->repoosversion, 'ux' => is_array($matched) && array_key_exists('ux', $matched) ? $matched['ux'] : $package->ux, 'basecategory' => com_meego_packages_controllers_package::determine_base_category($package), 'packagename' => $package->packagename), $this->request);
         // do not bother any further for hidden instances
         if ($package->packagehidden) {
             continue;
         }
         // get the workflows for this package
         // todo: this will get workflows for all versions
         if (!array_key_exists('workflows', $this->data['packages'][$package->packagename])) {
             $this->data['packages'][$package->packagename]['workflows'] = array();
         }
         // get workflows, if any
         $workflows = self::get_workflows($package);
         if (is_array($workflows)) {
             $this->data['packages'][$package->packagename]['workflows'] = $workflows;
         }
     }
     //foreach
     if (isset($package)) {
         // let's unset the default variant, so we don't list it among the "other downloads"
         unset($this->data['packages'][$package->packagename]['latest']['variants'][$index]);
     }
     /*
             if (   isset($package)
                 && array_key_exists($package->packagename, $this->data['packages']))
             {
                 $latestversion = $this->data['packages'][$package->packagename]['latest']['version'];
                 if (array_key_exists($latestversion, $this->data['packages'][$package->packagename]['all']))
                 {
                     // always remove the latest from the all array
                     unset($this->data['packages'][$package->packagename]['all'][$latestversion]);
                 }
             }
     */
     // and we don't need this either
     unset($latest);
     if (isset($this->data['packages'])) {
         return $this->data['packages'];
     }
 }