/** * @todo: docs */ public function get_instance(array $args) { if (isset($args['project'])) { $qbproject = com_meego_project::new_query_builder(); $qbproject->add_constraint('name', '=', $args['project']); $projects = $qbproject->execute(); if (count($projects)) { $project = $projects[0]; } } $qb = com_meego_package::new_query_builder(); $qb->add_constraint('name', '=', $args['package']); $qb->add_constraint('version', '=', $args['version']); $qb->add_constraint('repository.project', '=', $project->id); $qb->add_constraint('repository.name', '=', $args['repository']); $qb->add_constraint('repository.arch', '=', $args['arch']); $packages = $qb->execute(); if (count($packages) == 0) { throw new midgardmvc_exception_notfound("Package not found"); } $this->data['package'] = $packages[0]; if (empty($this->data['package']->title)) { $this->data['package']->title = $this->data['package']->name; } $this->data['package']->description = str_replace("\n\n", "<br /><br />", $this->data['package']->description); if ($this->data['package']->category) { $qb = com_meego_package_category::new_query_builder(); $qb->add_constraint('id', '=', $this->data['package']->category); $categories = $qb->execute(); if (count($categories) == 0) { throw new midgardmvc_exception_notfound("Package category not found"); } $this->data['package']->category_name = $categories[0]->name; while ($categories[0]->up != 0) { $qb = com_meego_package_category::new_query_builder(); $qb->add_constraint('id', '=', $categories[0]->up); $categories = $qb->execute(); if (count($categories) == 0) { throw new midgardmvc_exception_notfound("Package parent category not found"); } $this->data['package']->category_name = $categories[0]->name . "/" . $this->data['package']->category_name; } } else { $this->data['package']->category_name = ""; } // get license info $license = new com_meego_license($this->data['package']->license); $this->data['package']->licensename = $license->name; $this->data['package']->licenseurl = $license->url; $this->data['package']->localurl = $this->mvc->dispatcher->generate_url('package', array('package' => $this->data['package']->name), $this->request); $this->data['package']->repositoryobject = new com_meego_repository($this->data['package']->repository); $this->data['package']->repositoryobject->localurl = $this->mvc->dispatcher->generate_url('repository', array('project' => $args['project'], 'repository' => $this->data['package']->repositoryobject->name, 'arch' => $this->data['package']->repositoryobject->arch), $this->request); $this->data['package']->iconurl = false; $this->data['package']->screenshoturl = false; $attachments = $this->data['package']->list_attachments(); $_icon_marker = 'icon.png'; $_screenshot_marker = 'screenshot.png'; foreach ($attachments as $attachment) { if ($attachment->mimetype == 'image/png') { if (strrpos($attachment->name, $_screenshot_marker) !== false && !$this->data['package']->screenshoturl) { $this->data['package']->screenshoturl = $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['package']->iconurl) { $this->data['package']->iconurl = $this->mvc->dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => '', 'filename' => $attachment->name), '/'); } } } $storage = new midgard_query_storage('com_meego_package_relation'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('from', $storage), '=', new midgard_query_value($this->data['package']->id))); $res = $q->execute(); if ($res != 'MGD_ERR_OK') { $_mc = midgard_connection::get_instance(); echo "Error received from midgard_connection: " . $_mc->get_error_string() . "\n"; return; } $relations = $q->list_objects(); /* maps relation types to human parsable names */ $typemap = array('requires' => 'Requires', 'buildrequires' => 'Build requires', 'obsoletes' => 'Obsoletes', 'conflicts' => 'Conflicts', 'provides' => 'Provides'); $this->data['relations'] = array(); foreach ($relations as $relation) { $_url = false; $_title = $relation->relation; if (!isset($this->data['relations'][$relation->relation])) { $this->data['relations'][$relation->relation] = array('title' => $_title, 'packages' => array()); } $_relpackage = null; $storage = new midgard_query_storage('com_meego_package_details'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('packageid', $storage), '=', new midgard_query_value($relation->to))); $q->execute(); $_packages = $q->list_objects(); if (count($_packages)) { $_relpackage = $_packages[0]; } if ($_relpackage) { $_url = $this->mvc->dispatcher->generate_url('package_instance', array('package' => $relation->toname, 'version' => $relation->version, 'project' => $args['project'], 'repository' => $_relpackage->reponame, 'arch' => $_relpackage->repoarch), $this->request); } $_relation = $relation; if (array_key_exists($relation->relation, $typemap)) { $this->data['relations'][$relation->relation]['title'] = $typemap[$relation->relation] . ':'; } $_relation->localurl = $_url; array_push($this->data['relations'][$relation->relation]['packages'], $_relation); } unset($relations, $relation, $_relation, $_url, $typemap); if (!$this->data['package']->packagehidden) { $list_of_workflows = midgardmvc_helper_workflow_utils::get_workflows_for_object($this->data['package']); } // @todo: get completed workflows and offer an index page for admins // to list of forms and get an accumulated result $this->data['workflows'] = array(); foreach ($list_of_workflows as $workflow => $workflow_data) { $this->data['workflows'][] = array('label' => $workflow_data['label'], 'url' => $this->mvc->dispatcher->generate_url('package_instance_workflow_start', array('package' => $this->data['package']->name, 'version' => $this->data['package']->version, 'project' => $args['project'], 'repository' => $args['repository'], 'arch' => $args['arch'], 'workflow' => $workflow), $this->request), 'css' => $workflow_data['css']); } // get the ratings for this package // enable if the template does not use dynamic loading // $this->data['package']->ratings = self::prepare_ratings($this->data['package']->guid); }
/** * */ public function get_repository(array $args) { $qb = com_meego_repository::new_query_builder(); $qb->add_constraint('disabledownload', '=', false); if (isset($args['project'])) { $qbproject = com_meego_project::new_query_builder(); $qbproject->add_constraint('name', '=', $args['project']); $projects = $qbproject->execute(); if (count($projects)) { $qb->add_constraint('project', '=', $projects[0]->id); } $this->data['projectname'] = $args['project']; } if (isset($args['repository'])) { $qb->add_constraint('name', '=', $args['repository']); } if (isset($args['arch'])) { $qb->add_constraint('arch', '=', $args['arch']); } $repositories = $qb->execute(); if (count($repositories) == 0) { throw new midgardmvc_exception_notfound("Repository not found"); } $this->data['repository'] = $repositories[0]; $this->data['packages'] = array(); $storage = new midgard_query_storage('com_meego_package'); $q = new midgard_query_select($storage); $qc = new midgard_query_constraint(new midgard_query_property('repository', $storage), '=', new midgard_query_value($this->data['repository']->id)); $q->set_constraint($qc); $q->add_order(new midgard_query_property('name', $storage), SORT_ASC); $q->execute(); $packages = $q->list_objects(); // by default noone can manage workflows $this->request->set_data_item('manage_workflows', false); $cnt = 0; foreach ($packages as $package) { // by default there are no posted forms $package->posts = false; ++$cnt % 2 == 0 ? $package->rawclass = 'even' : ($package->rawclass = 'odd'); if (empty($package->title)) { $package->title = $package->name; } $package->localurl = $this->mvc->dispatcher->generate_url('package_instance', array('package' => $package->name, 'version' => $package->version, 'project' => $args['project'], 'repository' => $this->data['repository']->name, 'arch' => $this->data['repository']->arch), $this->request); // see if packages in this repo have forms submitted $storage = new midgard_query_storage('com_meego_package_forms_posted'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('packageguid'), '=', new midgard_query_value($package->guid))); $q->execute(); // todo: what happens if a package has posts from many different // or workflows if ($q->get_results_count()) { $_url = $this->mvc->dispatcher->generate_url('package_posted_forms', array('package' => $package->guid), 'com_meego_packages'); $package->posts = $_url; } $this->data['packages'][] = $package; } $user = $this->mvc->authentication->get_user(); if ($user) { if ($user->is_admin()) { // admins can manage and create new workflows $this->request->set_data_item('manage_workflows', true); $this->request->set_data_item('create_form_url', $this->mvc->dispatcher->generate_url('form_create', array('parent' => $this->data['repository']->guid), 'midgardmvc_ui_forms')); } // get a list of forms $forms = null; $storage = new midgard_query_storage('midgardmvc_ui_forms_form'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('parent'), '=', new midgard_query_value($this->data['repository']->guid))); $q->execute(); $items = $q->list_objects(); foreach ($items as $item) { $form = $item; $form->edit_url = $this->mvc->dispatcher->generate_url('form_update', array('form' => $item->guid), 'midgardmvc_ui_forms'); $forms[] = $form; } $this->request->set_data_item('forms', $forms); } }