/**
  * @todo: docs
  */
 public function execute(ezcWorkflowExecution $execution)
 {
     $form = midgardmvc_ui_forms_generator::get_by_guid($execution->getVariable('review_form'));
     $instance = new midgardmvc_ui_forms_form_instance($execution->getVariable('review'));
     $review = midgardmvc_ui_forms_store::load_form($form, $instance);
     $items = $form->items;
     $boolean_count = 0;
     $positive = 0;
     $package = new com_meego_package($instance->relatedobject);
     foreach ($items as $key => $item) {
         if ($key == "redirect_link" || $key == "execution") {
             continue;
         }
         try {
             $field = new midgardmvc_ui_forms_form_field($key);
         } catch (Exception $e) {
             midgardmvc_core::get_instance()->log('Invalid field detected in distill review: ' . $key . ', value: ' . $item, 'warning');
         }
         // todo: ugly hardcoded check, but what can we do..
         if ($field->title == "Should the application be in this application catalog?") {
             // if the answer belongs to a certain field then we process
             // this field must be a boolean too
             if ($item instanceof midgardmvc_helper_forms_field_boolean) {
                 if ($item->get_value()) {
                     // add +1 to the package score
                     $package->metadata->score++;
                 } else {
                     //  oh yes, we do give -1 points too ;)
                     $package->metadata->score--;
                 }
                 $res = $package->update();
                 if (!$res) {
                     //update failed; do what?
                 }
             }
         } else {
             // otherwise
             continue;
         }
     }
     // pass on the score
     $execution->setVariable('distilled_review', $package->metadata->score);
 }
Example #2
0
 /**
  *
  */
 public function post_resume_package_instance(array $args)
 {
     $request = $this->mvc->context->get_request();
     $route = $request->get_route();
     $route->template_aliases['root'] = 'cmp-html-snippet';
     $this->mvc->log(__CLASS__, 'QA resume start', 'info');
     self::get_resume_package_instance($args);
     if (empty($this->data['forms'])) {
         throw new midgardmvc_exception_httperror('POST not allowed when there are no forms for the workflow', 405);
     }
     $list_of_variables = array();
     foreach ($this->data['forms'] as $variable => $formdata) {
         $formdata['form']->process_post();
         $instance = new midgardmvc_ui_forms_form_instance();
         $instance->form = $formdata['db_form']->id;
         $instance->relatedobject = $this->package->guid;
         $instance->create();
         if (!midgardmvc_ui_forms_store::store_form($formdata['form'], $instance)) {
             $instance->delete();
             continue;
         }
         $list_of_variables[$variable] = $instance->guid;
     }
     $values = $this->workflow_definition->resume($this->execution->guid, $list_of_variables);
     // populate the package
     $this->data['package'] = $this->package;
     if (!isset($values['execution'])) {
         // Workflow resumed
         unset($this->data['forms']);
         unset($this->data['package']);
         $this->data['workflow'] = 'resumed';
         $this->data['posted_forms'] = $this->mvc->templating->dynamic_load('com_meego_packages', 'package_posted_forms', array('package' => $this->package->guid), true);
         // return json; see init_qa.js for processing the response
         $route->template_aliases['root'] = 'midgardmvc-show-json';
     }
     $this->mvc->log(__CLASS__, 'QA resume finished', 'info');
 }