public function process(Tracker_Artifact $artifact, array $fields_data) { $tracker_data = array(); //only when a previous changeset exists if (!$artifact->getLastChangeset() instanceof Tracker_Artifact_Changeset_Null) { foreach ($artifact->getLastChangeset()->getValues() as $key => $field) { if ($field instanceof Tracker_Artifact_ChangesetValue_Date || $field instanceof Tracker_Artifact_ChangesetValue_List) { $tracker_data[$key] = $field->getValue(); } } } //replace where appropriate with submitted values foreach ($fields_data as $key => $value) { $tracker_data[$key] = $value; } //addlastUpdateDate and submitted on if available foreach ($this->formelement_factory->getAllFormElementsForTracker($artifact->getTracker()) as $field) { if ($field instanceof Tracker_FormElement_Field_LastUpdateDate) { $tracker_data[$field->getId()] = date("Y-m-d"); } if ($field instanceof Tracker_FormElement_Field_SubmittedOn) { $tracker_data[$field->getId()] = $artifact->getSubmittedOn(); } if ($field instanceof Tracker_FormElement_Field_Date && !array_key_exists($field->getId(), $tracker_data)) { //user doesn't have access to field $tracker_data[$field->getId()] = $field->getValue($field->getId()); } } return $tracker_data; }
private function getIndexedFields(Tracker $tracker) { $indexed_fields = array(); foreach ($this->formelement_factory->getUsedFields($tracker) as $field) { $indexed_fields[$field->getId()] = $field; } return $indexed_fields; }
private function getMappingFieldValuesIndexedByTracker(Tracker $tracker) { $mappings = array(); foreach ($this->dao->searchMappingFieldValues($tracker->getId()) as $row) { $field = $this->element_factory->getFieldById($row['field_id']); $value = $field->getListValueById($row['value_id']); $mappings[$row['tracker_id']][$row['field_id']][$row['value_id']] = new Cardwall_OnTop_Config_ValueMapping($value, $row['column_id']); } return $mappings; }
private function trackerHasOnlyTitleRequired(Tracker $tracker, Tracker_Semantic_Title $semantic_title) { $used_fields = $this->form_element_factory->getUsedFields($tracker); foreach ($used_fields as $used_field) { if ($used_field->isRequired() && $used_field->getId() != $semantic_title->getFieldId()) { return false; } } return true; }
/** * Should we move this method outside of changeset creation * so that we can remove the dependency on artifact factory * and enforce SRP ? */ protected function saveArtifactAfterNewChangeset(Tracker_Artifact $artifact, array $fields_data, PFUser $submitter, Tracker_Artifact_Changeset $new_changeset, Tracker_Artifact_Changeset $previous_changeset = null) { if ($this->artifact_factory->save($artifact)) { $used_fields = $this->formelement_factory->getUsedFields($artifact->getTracker()); foreach ($used_fields as $field) { $field->postSaveNewChangeset($artifact, $submitter, $new_changeset, $previous_changeset); } $artifact->getWorkflow()->after($fields_data, $new_changeset, $previous_changeset); return true; } return false; }
/** * Validate the fields contained in $fields_data, and update $fields_data for invalid data * $fields_data is an array of [field_id] => field_data * * @param array $fields_data The field data * * @return boolean true if all fields are valid, false otherwise. This function update $field_data (set values to null if not valid) */ public function validate(Tracker_Artifact $artifact, $fields_data) { $is_valid = true; $used_fields = $this->formelement_factory->getUsedFields($artifact->getTracker()); foreach ($used_fields as $field) { $submitted_value = $this->getSubmittedValue($field, $fields_data); if ($this->canValidateField($artifact, $field)) { $is_valid = $this->validateField($artifact, $field, $submitted_value) && $is_valid; } } return $is_valid; }
/** * Build a Report criteria based on submitted values. * * If used cannot access requested value (eg. forged URL) the Query is modified * to remove the offending query. * * @return array of \Tracker_Report_Criteria */ public function getSharedFieldsCriteria(User $user, Project $project, Tracker_Report $report, Tracker_CrossSearch_Query $cross_search_query) { $fields = $this->form_element_factory->getSharedFieldsReadableBy($user, $project); $criteria = array(); $allowed_field_ids = array(); foreach ($fields as $field) { $allowed_field_ids[$field->getId()] = true; $field->setCriteriaValue($this->getSelectedValues($field, $cross_search_query->getSharedFields())); $criteria[] = $this->buildCriteria($report, $field); } $cross_search_query->purgeSharedFieldNotInList($allowed_field_ids); return $criteria; }
public function update(Tracker $tracker, SimpleXMLElement $artifact_xml, array $submitted_values, PFUser $user, $submitted_on) { $artifact_xml->changeset->submitted_on = date('c', $submitted_on); $artifact_xml->changeset->submitted_by = $user->getId(); foreach ($artifact_xml->changeset->field_change as $field_change) { $field_name = (string) $field_change['field_name']; $field = $this->formelement_factory->getUsedFieldByNameForUser($tracker->getId(), $field_name, $user); if ($field && isset($submitted_values[$field->getId()])) { $submitted_value = $submitted_values[$field->getId()]; $this->visitor->update($field_change, $field, $submitted_value); } } }
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 exportAttachmentsInArchive(Tracker_Artifact $artifact, ZipArchive $archive) { $file_fields = $this->form_element_factory->getUsedFileFields($artifact->getTracker()); $last_changeset = $artifact->getLastChangeset(); if (!$last_changeset) { return; } foreach ($file_fields as $field) { $value = $last_changeset->getValue($field); if ($value) { $this->addFilesIntoArchive($value, $archive); } } }
public function getCriteria() { $rank = 0; foreach ($this->soap_criteria as $key => $value) { $is_advanced = false; if ($formelement = $this->formelement_factory->getFormElementByName($this->getTracker()->getId(), $value->field_name)) { if ($formelement->userCanRead($this->current_user)) { $criteria = new Tracker_Report_Criteria(0, $this, $formelement, $rank, $is_advanced); $formelement->setCriteriaValueFromSOAP($criteria, $value->value); $this->criteria[$formelement->getId()] = $criteria; $rank++; } } } return $this->criteria; }
/** * build pie chart properties * * @param Pie_Engine $engine object */ function buildProperties($engine) { parent::buildProperties($engine); $engine->data = array(); $engine->legend = null; $result = array(); $ff = Tracker_FormElementFactory::instance(); $af = $ff->getFormElementById($this->chart->getField_base()); if ($af && $af->userCanRead()) { $select = " SELECT count(a.id) AS nb, " . $af->getQuerySelect(); $from = " FROM tracker_artifact AS a INNER JOIN tracker_changeset AS c ON (c.artifact_id = a.id) " . $af->getQueryFrom(); $where = " WHERE a.id IN (" . $this->artifacts['id'] . ") \n AND c.id IN (" . $this->artifacts['last_changeset_id'] . ") "; $sql = $select . $from . $where . ' GROUP BY ' . $af->getQueryGroupBy(); $res = db_query($sql); while ($data = db_fetch_array($res)) { if ($data[$af->name] !== null) { $engine->data[] = $data['nb']; $engine->legend[] = $af->fetchRawValue($data[$af->name]); } else { $engine->data[] = $data['nb']; $engine->legend[] = $GLOBALS['Language']->getText('global', 'none'); } } } return $result; }
/** * @return array */ public function getFieldsData(SimpleXMLElement $xml_field_change) { $data = array(); if (!$xml_field_change->field_change) { return $data; } foreach ($xml_field_change->field_change as $field_change) { $field = $this->formelement_factory->getUsedFieldByName($this->tracker->getId(), (string) $field_change['field_name']); if ($field) { $this->appendValidValue($data, $field, $field_change); } else { $this->logger->debug("Skipped unknown/unused field " . (string) $field_change['field_name']); } } return $data; }
protected function getFullRESTRepresentation($value) { $classname_with_namespace = 'Tuleap\\Tracker\\REST\\Artifact\\ArtifactFieldValueFullRepresentation'; $artifact_field_value_full_representation = new $classname_with_namespace(); $artifact_field_value_full_representation->build($this->field->getId(), Tracker_FormElementFactory::instance()->getType($this->field), $this->field->getLabel(), $value); return $artifact_field_value_full_representation; }
/** * @see Cardwall_OnTop_Config_Command::execute() */ public function execute(Codendi_Request $request) { if (!is_array($request->get('mapping_field'))) { return; } $mapping_fields = $this->getMappingFields(); foreach ($request->get('mapping_field') as $mapping_tracker_id => $mapping_tracker_info) { if (!isset($mapping_tracker_info['field'])) { continue; } $field_id = (int) $mapping_tracker_info['field']; $mapping_tracker = $this->tracker_factory->getTrackerById($mapping_tracker_id); $field = $this->form_element_factory->getFieldById($field_id); $this->save($mapping_tracker_info, $mapping_fields, $mapping_tracker, $field); } }
public function getFullRESTValue(PFUser $user, Tracker_Artifact_Changeset $changeset) { $classname_with_namespace = 'Tuleap\\Tracker\\REST\\Artifact\\ArtifactFieldValueFullRepresentation'; $artifact_field_value_full_representation = new $classname_with_namespace(); $artifact_field_value_full_representation->build($this->getId(), Tracker_FormElementFactory::instance()->getType($this), $this->getLabel(), (int) $changeset->getArtifact()->getPerTrackerArtifactId()); return $artifact_field_value_full_representation; }
protected function getComputedFieldValue(PFUser $user, Tracker_Artifact $milestone_artifact, $field_name) { $field = $this->formelement_factory->getComputableFieldByNameForUser($milestone_artifact->getTracker()->getId(), $field_name, $user); if ($field) { return $field->getComputedValue($user, $milestone_artifact); } return 0; }
private function getFieldFromReportField(Tracker_Report_Field $report_field, Tracker $tracker) { if ($this->isASharedField($report_field)) { return $this->factory->getFieldFromTrackerAndSharedField($tracker, $report_field); } else { return $report_field; } }
public function __construct(AgileDashboard_Kanban $kanban, PFUser $user, $user_is_kanban_admin, $language, $project_id) { $user_preferences = new AgileDashboard_KanbanUserPreferences(); $kanban_representation_builder = new Tuleap\AgileDashboard\REST\v1\Kanban\KanbanRepresentationBuilder($user_preferences, new AgileDashboard_KanbanColumnFactory(new AgileDashboard_KanbanColumnDao(), $user_preferences), TrackerFactory::instance(), Tracker_FormElementFactory::instance()); $this->kanban_representation = json_encode($kanban_representation_builder->build($kanban, $user)); $this->user_is_kanban_admin = (int) $user_is_kanban_admin; $this->language = $language; $this->project_id = $project_id; }
private function getFieldValue(User $user, Planning_ArtifactMilestone $milestone, $field_name) { $milestone_artifact = $milestone->getArtifact(); $field = $this->formelement_factory->getComputableFieldByNameForUser($milestone_artifact->getTracker()->getId(), $field_name, $user); if ($field) { return $field->getComputedValue($user, $milestone_artifact); } return 0; }
/** * Get static selectbox field * * @param Tracker $tracker * @param int $field_id */ private function getStaticSelectBoxField(Tracker $tracker, $field_id) { $usedStaticFields = $this->formelement_factory->getUsedStaticSbFields($tracker); foreach ($usedStaticFields as $staticField) { if ($staticField->getId() == $field_id) { return $staticField; } } throw new SoapFault(check_field_fault, "Static selectbox Field not found", "getStaticSelectBoxField"); }
/** * * @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']); }
private function getOneTriggeringField(Tracker $target_tracker, $trigger_field_id, $trigger_value_id) { $field = $this->formelement_factory->getUsedFormElementFieldById($trigger_field_id); if ($field) { if ($field->getTracker()->getParent() == $target_tracker) { return new Tracker_Workflow_Trigger_FieldValue($field, $this->getMatchingValueById($field, $trigger_value_id)); } throw new Tracker_FormElement_InvalidFieldException("Trigger field doesn't belong to target tracker"); } }
/** * * @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; }
private function getCardUpdateInfo(Tracker_Artifact $artifact, PFUser $current_user) { $card_info = array(); $tracker_id = $artifact->getTracker()->getId(); $remaining_effort_field = $this->form_element_factory->getComputableFieldByNameForUser($tracker_id, Tracker::REMAINING_EFFORT_FIELD_NAME, $current_user); if ($remaining_effort_field) { $remaining_effort = $remaining_effort_field->fetchCardValue($artifact); $card_info[$artifact->getId()] = array(Tracker::REMAINING_EFFORT_FIELD_NAME => $remaining_effort); } return $card_info; }
/** * The singleton method * * @return WorkflowFactory */ public static function instance() { if (!isset(self::$_instance)) { $formelement_factory = Tracker_FormElementFactory::instance(); $logger = new WorkflowBackendLogger(new BackendLogger()); $trigger_rules_manager = new Tracker_Workflow_Trigger_RulesManager(new Tracker_Workflow_Trigger_RulesDao(), $formelement_factory, new Tracker_Workflow_Trigger_RulesProcessor(UserManager::instance()->getUserById(Tracker_Workflow_WorkflowUser::ID), $logger), $logger); $c = __CLASS__; self::$_instance = new $c(TransitionFactory::instance(), TrackerFactory::instance(), $formelement_factory, $trigger_rules_manager, $logger); } return self::$_instance; }
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(); } }
function displayDefineDependencies($engine, $request, $current_user, $source_field_id, $target_field_id) { $hp = Codendi_HTMLPurifier::instance(); $this->tracker->displayAdminItemHeader($engine, 'dependencies'); $source_field = $this->form_element_factory->getFieldById($source_field_id); $target_field = $this->form_element_factory->getFieldById($target_field_id); //Display creation form echo '<h3>' . $GLOBALS['Language']->getText('plugin_tracker_field_dependencies', 'dependencies_matrix_title') . '</h3>'; echo '<p>' . $GLOBALS['Language']->getText('plugin_tracker_field_dependencies', 'dependencies_matrix_help', array($source_field->getlabel(), $target_field->getlabel())) . '</p>'; $this->displayDependenciesMatrix($source_field, $target_field); }
private function instantiateMappingFromRow(Tracker $tracker, array &$mappings, array $row, Cardwall_OnTop_Config_ColumnCollection $columns) { $mapping_tracker = $this->tracker_factory->getTrackerById($row['tracker_id']); if ($mapping_tracker && $mapping_tracker != $tracker) { //TODO: field is used? $available_fields = $this->element_factory->getUsedSbFields($mapping_tracker); $mapping_field = $this->element_factory->getFieldById($row['field_id']); if ($mapping_field) { $mapping = $this->instantiateFreestyleMapping($tracker, $mappings, $mapping_tracker, $available_fields, $mapping_field); } else { $status_field = $mapping_tracker->getStatusField(); if ($status_field) { $mapping = $this->instantiateMappingStatus($tracker, $mappings, $mapping_tracker, $available_fields, $columns); } else { $mapping = $this->instantiateNoFieldMapping($mapping_tracker, $available_fields); } } $mappings[$mapping_tracker->getId()] = $mapping; } }
public function getConfigFactory() { if (!$this->config_factory) { require_once 'OnTop/ConfigFactory.class.php'; require_once TRACKER_BASE_DIR . '/Tracker/TrackerFactory.class.php'; $tracker_factory = TrackerFactory::instance(); $element_factory = Tracker_FormElementFactory::instance(); $this->config_factory = new Cardwall_OnTop_ConfigFactory($tracker_factory, $element_factory); } return $this->config_factory; }