public function process(Tracker_IDisplayTrackerLayout $layout, Codendi_Request $request, PFUser $current_user) { $workflow = $this->workflow_factory->getWorkflowByTrackerId($this->tracker->id); $this->processEnabled($workflow, $request->get('is_used')); $k = 0; $field = $this->form_element_factory->getFormElementById($workflow->field_id); $field_values = $field->getBind()->getAllValues(); $currMatrix = array(); $field_value_from = null; //Add an initial state transition foreach ($field_values as $field_value_id_to => $field_value_to) { //$field_value_from=; $transition = '_' . $field_value_id_to; if ($request->existAndNonEmpty($transition)) { $currMatrix[] = array('', $field_value_id_to); $k += $this->addTransition($workflow, $transition, $field_value_from, $field_value_to); } } //Add a transition foreach ($field_values as $field_value_id_from => $field_value_from) { foreach ($field_values as $field_value_id_to => $field_value_to) { $transition = $field_value_id_from . '_' . $field_value_id_to; if ($request->existAndNonEmpty($transition)) { $currMatrix[] = array($field_value_id_from, $field_value_id_to); $k += $this->addTransition($workflow, $transition, $field_value_from, $field_value_to); } } } //Delete a transition $transitions_in_db = $workflow->getTransitions(); $nb_transitions_in_db = count($transitions_in_db); for ($i = 0; $i < $nb_transitions_in_db; $i++) { $field_value_from = $transitions_in_db[$i]->getFieldValueFrom(); $field_value_to = $transitions_in_db[$i]->getFieldValueTo(); //Treatment of the initial state if ($field_value_from == null) { $value_to_search = array('', $field_value_to->getId()); //$field_value_from->getId()=''; } else { $value_to_search = array($field_value_from->getId(), $field_value_to->getId()); } if (!in_array($value_to_search, $currMatrix)) { $this->workflow_factory->deleteTransition($workflow->workflow_id, $field_value_from, $field_value_to); $k++; } } if ($k > 0) { $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('workflow_admin', 'updated')); } $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => Workflow::FUNC_ADMIN_TRANSITIONS))); }
public function createFormElement(Tracker $tracker, array $formElement_data, User $user) { $formElement = $this->factory->getFormElementById($formElement_data['field_id']); if (!$formElement) { $exception_message = $GLOBALS['Language']->getText('plugin_tracker_formelement_exception', 'wrong_field_id', $formElement_data['field_id']); throw new Exception($exception_message); } $field = $this->getRootOriginalField($formElement); $this->assertFieldCanBeCopied($field, $user); $data = $this->populateFormElementDataForASharedField($field); $type = $data['type']; $id = $this->factory->createFormElement($tracker, $type, $data); $this->boundValuesFactory->duplicateByReference($field->getId(), $id); return $id; }
/** * * @param Tracker_Rule_Date $date_rule * @param int $tracker_id * @param int $source_field_id * @param int $target_field_id * @param string $comparator * @return \Tracker_Rule_Date */ private function populate(Tracker_Rule_Date $date_rule, $tracker_id, $source_field_id, $target_field_id, $comparator, $id = null) { $source_field = $this->element_factory->getFormElementById($source_field_id); $target_field = $this->element_factory->getFormElementById($target_field_id); $date_rule->setTrackerId($tracker_id)->setSourceFieldId($source_field_id)->setSourceField($source_field)->setTargetFieldId($target_field_id)->setTargetField($target_field)->setTrackerId($tracker_id)->setComparator($comparator); if ($date_rule !== null) { $date_rule->setId($id); } return $date_rule; }
/** * * @param type $id * * @return Tracker_FileInfo */ public function getById($id) { $row = $this->dao->searchById($id)->getRow(); if (!$row) { return; } $field_id = $this->dao->searchFieldIdByFileInfoId($id); if (!$field_id) { return; } $field = $this->formelement_factory->getFormElementById($field_id); if (!$field) { return; } if (!$field->isUsed()) { return; } return new Tracker_FileInfo($row['id'], $field, $row['submitted_by'], $row['description'], $row['filename'], $row['filesize'], $row['filetype']); }
protected function displayTransitionsMatrix($workflow, $layout, $request, $current_user) { $workflow = $this->workflow_factory->getWorkflowByTrackerId($this->tracker->id); $field = $this->form_element_factory->getFormElementById($workflow->field_id); if ($workflow->hasTransitions()) { $transitions = $workflow->getTransitions($workflow->workflow_id); $field->displayTransitionsMatrix($transitions); } else { $field->displayTransitionsMatrix(); } }
public function getCriteria() { $rank = 0; $tracker_id = $this->getTracker()->getId(); foreach ($this->rest_criteria as $field_identifier => $criterion) { $formelement = $this->formelement_factory->getFormElementById($field_identifier); if (!$formelement) { $formelement = $this->formelement_factory->getFormElementByName($tracker_id, $field_identifier); } if ($formelement && $formelement->userCanRead($this->current_user)) { $this->addCriterionToFormElement($formelement, $criterion, $rank); $rank++; } } return $this->criteria; }
/** * Retrieves the field from the given PostAction database row. * * @param array $row * * @return Tracker_FormElement_Field */ private function getFieldFromRow($row) { return $this->element_factory->getFormElementById((int) $row['field_id']); }
/** * * @param SimpleXMLElement $root * @param array $xmlMapping * @param Tracker_FormElementFactory $form_element_factory * @param int $tracker_id */ public function exportToXml(SimpleXMLElement $root, $xmlMapping, $form_element_factory, $tracker_id) { $rules = $this->searchByTrackerId($tracker_id); $list_rules = $root->addChild('list_rules'); foreach ($rules as $rule) { $source_field = $form_element_factory->getFormElementById($rule->getSourceFieldId()); $target_field = $form_element_factory->getFormElementById($rule->getTargetFieldId()); $bf = new Tracker_FormElement_Field_List_BindFactory(); //TODO: handle sb/msb bind to users and remove condition if ($bf->getType($source_field->getBind()) == 'static' && $bf->getType($target_field->getBind()) == 'static') { $child = $list_rules->addChild('rule'); $child->addChild('source_field')->addAttribute('REF', array_search($rule->source_field, $xmlMapping)); $child->addChild('target_field')->addAttribute('REF', array_search($rule->target_field, $xmlMapping)); if ($rule->source_value == Tracker_FormElement_Field_List_Bind_StaticValue_None::VALUE_ID) { $child->addChild('source_value')->addAttribute('is_none', '1'); } else { $child->addChild('source_value')->addAttribute('REF', array_search($rule->source_value, $xmlMapping['values'])); } if ($rule->target_value == Tracker_FormElement_Field_List_Bind_StaticValue_None::VALUE_ID) { $child->addChild('target_value')->addAttribute('is_none', '1'); } else { $child->addChild('target_value')->addAttribute('REF', array_search($rule->target_value, $xmlMapping['values'])); } } } }
function displayChooseSourceAndTarget($engine, $request, $current_user, $source_field_id) { $hp = Codendi_HTMLPurifier::instance(); $this->tracker->displayAdminItemHeader($engine, 'dependencies'); echo '<p>' . $GLOBALS['Language']->getText('plugin_tracker_field_dependencies', 'inline_help') . '</p>'; echo '<form action="' . TRACKER_BASE_URL . '/?" method="GET">'; echo '<input type="hidden" name="tracker" value="' . (int) $this->tracker->id . '" />'; echo '<input type="hidden" name="func" value="admin-dependencies" />'; //source $source_field = $this->form_element_factory->getFormElementById($source_field_id); if (!$source_field) { echo '<select name="source_field" onchange="this.form.submit()">'; echo '<option value="0">' . $GLOBALS['Language']->getText('plugin_tracker_field_dependencies', 'choose_source_field') . '</option>'; $sources = $this->getAllSourceFields(null); foreach ($sources as $id => $field) { echo '<option value="' . $id . '">'; echo $hp->purify($field->getLabel(), CODENDI_PURIFIER_CONVERT_HTML); echo '</option>'; } echo '</select>'; } else { echo '<input type="hidden" name="source_field" value="' . $source_field_id . '" />'; echo $source_field->getLabel(); } echo ' → '; //target $disabled = ''; if (!$source_field) { $disabled = 'disabled="disabled" readonly="readonly"'; } echo '<select name="target_field" ' . $disabled . '>'; echo '<option value="0">' . $GLOBALS['Language']->getText('plugin_tracker_field_dependencies', 'choose_target_field') . '</option>'; if ($source_field) { $sources = $this->getAllTargetFields($source_field_id); foreach ($sources as $id => $field) { echo '<option value="' . $id . '">'; echo $hp->purify($field->getLabel(), CODENDI_PURIFIER_CONVERT_HTML); echo '</option>'; } } echo '</select>'; echo ' <input type="submit" name="choose_source" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" />'; echo '</form>'; //Shortcut $sources_targets = $this->getRuleFactory()->getInvolvedFieldsByTrackerId($this->tracker->id); if (count($sources_targets)) { $dependencies = array(); foreach ($sources_targets as $row) { if ($source = $this->form_element_factory->getFormElementById($row['source_field_id'])) { if ($target = $this->form_element_factory->getFormElementById($row['target_field_id'])) { $d = '<a href="' . TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => 'admin-dependencies', 'source_field' => $row['source_field_id'], 'target_field' => $row['target_field_id'])) . '">'; $d .= $source->getLabel() . ' → ' . $target->getLabel(); $d .= '</a>'; $dependencies[] = $d; } } } if ($dependencies) { echo '<p>' . $GLOBALS['Language']->getText('plugin_tracker_field_dependencies', 'choose_existing_dependency') . '</p>'; echo '<ul><li>' . implode('</li><li>', $dependencies) . '</li></ul>'; } echo '</ul>'; } $this->tracker->displayFooter($engine); }