/** * @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); }
/** * Returns the stripped down form on a workflow * * @param object com_meego_package_details object */ public function get_stripped_forms_for_package($package = null) { $retval = array(); $object = new com_meego_package($package->packageguid); $workflows = midgardmvc_helper_workflow_utils::get_workflows_for_object($object); if (is_array($workflows)) { $this->mvc->component->load_library('Workflow'); foreach ($workflows as $name => $workflow_data) { $args = array('package' => $package->packagename, 'version' => $package->packageversion, 'project' => $package->repoprojectname, 'repository' => $package->reponame, 'arch' => $package->repoarch, 'workflow' => $name); $workflow_definition = new $workflow_data['provider'](); $values = $workflow_definition->start($object); $workflow = $workflow_definition->get(); if (isset($values['review_form'])) { $form = new midgardmvc_ui_forms_form($values['review_form']); $fields = midgardmvc_ui_forms_generator::list_fields($form); foreach ($fields as $field) { $retval[$name][$field->title]['widget'] = $field->widget; $retval[$name][$field->title]['options'] = $field->options; } } else { if (isset($values['execution'])) { $args['execution'] = $values['execution']; $execution = new midgardmvc_helper_workflow_execution_interactive($workflow, $args['execution']); $variables = $execution->getVariables(); if (isset($variables['review_form'])) { $form = new midgardmvc_ui_forms_form($variables['review_form']); $fields = midgardmvc_ui_forms_generator::list_fields($form); foreach ($fields as $field) { $retval[$name][$field->title]['widget'] = $field->widget; $retval[$name][$field->title]['options'] = $field->options; } } } } } } return $retval; }
/** * */ private function load_workflow(array $args) { if ($this->package->metadata->hidden) { return null; } $list_of_workflows = midgardmvc_helper_workflow_utils::get_workflows_for_object($this->package); if (!isset($list_of_workflows[$args['workflow']])) { throw new midgardmvc_exception_notfound("Unable to run workflow {$args['workflow']} for this package instance"); } return $list_of_workflows[$args['workflow']]['provider']; }
/** * Returns all possible workflows assigned to the given package * * @param object com_meego_package_details object * @return null or an array with workflow URLs and CSS data */ public function get_workflows($package) { $retval = null; // this method is called from other classes too $this->isuser = $this->mvc->authentication->is_user(); if (is_object($package) && !$package->packagehidden) { $object = new com_meego_package($package->packageguid); $list_of_workflows = midgardmvc_helper_workflow_utils::get_workflows_for_object($object); foreach ($list_of_workflows as $workflow => $workflow_data) { if (!$this->isuser) { $workflow_data['css'] .= ' login'; } $retval[] = array('name' => $workflow, 'label' => $workflow_data['label'], 'url' => $this->mvc->dispatcher->generate_url('package_instance_workflow_start', array('package' => $package->packagename, 'version' => $package->packageversion, 'project' => $package->repoprojectname, 'repository' => $package->reponame, 'arch' => $package->repoarch, 'workflow' => $workflow), 'com_meego_packages'), 'css' => $workflow_data['css']); } } return $retval; }