public function setUp() { parent::setUp(); $changeset_factory = mock('Tracker_Artifact_ChangesetFactory'); $this->tracker = aMockTracker()->withId(1)->build(); $this->new_artifact = partial_mock('Tracker_Artifact', array('createNewChangeset')); $this->new_artifact->setId($this->new_artifact_id); $this->layout = mock('Tracker_IDisplayTrackerLayout'); $this->user = mock('PFUser'); $this->xml_exporter = mock('Tracker_XML_Exporter_ArtifactXMLExporter'); $this->xml_importer = mock('Tracker_Artifact_XMLImport'); $this->xml_updater = mock('Tracker_XML_Updater_ChangesetXMLUpdater'); $this->file_updater = mock('Tracker_XML_Updater_TemporaryFileXMLUpdater'); $this->from_changeset = stub('Tracker_Artifact_Changeset')->getId()->returns($this->changeset_id); $this->from_artifact = partial_mock('Tracker_Artifact', array('getChangesetFactory')); $this->from_artifact->setId($this->artifact_id); $this->from_artifact->setTracker($this->tracker); $this->from_artifact->setChangesets(array($this->changeset_id => $this->from_changeset)); stub($this->from_artifact)->getChangesetFactory()->returns($changeset_factory); stub($this->from_changeset)->getArtifact()->returns($this->from_artifact); $this->children_xml_exporter = mock('Tracker_XML_Exporter_ChildrenXMLExporter'); $this->children_xml_importer = mock('Tracker_XML_Importer_ChildrenXMLImporter'); $this->artifacts_imported_mapping = mock('Tracker_XML_Importer_ArtifactImportedMapping'); $backend_logger = mock("BackendLogger"); $this->logger = new Tracker_XML_Importer_CopyArtifactInformationsAggregator($backend_logger); $this->submitted_values = array(); $this->artifact_factory = mock('Tracker_ArtifactFactory'); stub($this->artifact_factory)->getArtifactByIdUserCanView($this->user, $this->artifact_id)->returns($this->from_artifact); $this->request = aRequest()->with('from_artifact_id', $this->artifact_id)->with('from_changeset_id', $this->changeset_id)->with('artifact', $this->submitted_values)->build(); $this->action = new Tracker_Action_CopyArtifact($this->tracker, $this->artifact_factory, $this->xml_exporter, $this->xml_importer, $this->xml_updater, $this->file_updater, $this->children_xml_exporter, $this->children_xml_importer, $this->artifacts_imported_mapping, $this->logger); $this->a_mocked_artifact = mock("Tracker_Artifact"); }
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; }
public function getErrorMessage() { $backlog_item_name = $this->artifact->getTitle(); $tracker_name = $this->artifact->getTracker()->getName(); $uri = $this->artifact->getUri(); return $GLOBALS['Language']->getText('plugin_cardwall', 'cells_not_displayed', array($backlog_item_name, $tracker_name, $uri)); }
public function setUp() { parent::setUp(); $tracker_user_story_id = 103; $user_story_id = 107; $submitted_by = 102; $submitted_on = 1234567890; $use_artifact_permissions = false; $tracker = aMockTracker()->withId($this->tracker_id)->build(); $this->layout = mock('Tracker_IDisplayTrackerLayout'); $this->request = aRequest()->with('func', 'artifact-update')->build(); $this->user = mock('PFUser'); $this->formelement_factory = mock('Tracker_FormElementFactory'); $this->hierarchy_factory = mock('Tracker_HierarchyFactory'); $this->computed_field = mock('Tracker_FormElement_Field_Computed'); $this->us_computed_field = mock('Tracker_FormElement_Field_Computed'); $this->user_story = mock('Tracker_Artifact'); $tracker_user_story = aMockTracker()->withId($tracker_user_story_id)->build(); stub($this->user_story)->getTrackerId()->returns($tracker_user_story_id); stub($this->user_story)->getTracker()->returns($tracker_user_story); stub($this->user_story)->getId()->returns($user_story_id); $this->task = partial_mock('Tracker_Artifact', array('createNewChangeset'), array($this->artifact_id, $this->tracker_id, $submitted_by, $submitted_on, $use_artifact_permissions)); $this->task->setHierarchyFactory($this->hierarchy_factory); $this->task->setTracker($tracker); $this->task->setFormElementFactory($this->formelement_factory); stub($this->task)->createNewChangeset()->returns(true); stub($this->formelement_factory)->getComputableFieldByNameForUser($tracker_user_story_id, Tracker::REMAINING_EFFORT_FIELD_NAME, $this->user)->returns($this->us_computed_field); stub($this->computed_field)->fetchCardValue($this->task)->returns(42); stub($this->us_computed_field)->fetchCardValue($this->user_story)->returns(23); $this->event_manager = mock('EventManager'); $this->action = new Tracker_Action_UpdateArtifact($this->task, $this->formelement_factory, $this->event_manager); }
private function artifactMatchTriggerValue(Tracker_Artifact $sibling, Tracker_Workflow_Trigger_FieldValue $trigger) { if ($trigger->getField()->getTracker() == $sibling->getTracker()) { return $trigger->isSetForArtifact($sibling); } return true; }
public function getColumnIdOfKanbanItem(Tracker_Artifact $artifact) { $row = $this->item_dao->getColumnIdOfKanbanItem($artifact->getTrackerId(), $artifact->getId())->getRow(); if (!$row) { return null; } return (int) $row['bindvalue_id']; }
/** * Add to $artifacts_xml the xml structure of an artifact */ public function exportFullHistory(SimpleXMLElement $artifacts_xml, Tracker_Artifact $artifact) { $artifact_xml = $artifacts_xml->addChild('artifact'); $artifact_xml->addAttribute('id', $artifact->getId()); foreach ($artifact->getChangesets() as $changeset) { $this->changeset_exporter->exportFullHistory($artifact_xml, $changeset); } }
public function getField(Tracker_Artifact $artifact) { $mapping = $this->config->getMappingFor($artifact->getTracker()); if ($mapping) { return $mapping->getField(); } return $this->semantic_status_provider->getField($artifact); }
/** * Get all changesets in a format ready for json conversion * * @param Tracker_Artifact $artifact * @param Integer $changeset_id * @return array */ public function getNewChangesetsFormattedForJson(Tracker_Artifact $artifact, $changeset_id) { $changesets = array(); foreach ($this->dao->searchChangesetNewerThan($artifact->getId(), $changeset_id) as $row) { $changesets[] = $this->json_formatter->format($this->getChangesetFromRow($artifact, $row)); } return $changesets; }
/** * @param PFUser $user * @param Tracker_Artifact $artifact * * @return mixed */ private function getCurrentComputedValue(Tracker_Artifact $artifact) { $row = $this->getValueDao()->getLastValue($artifact->getId(), $this->getId()); if ($row) { return $row['value']; } return 0; }
private function getLastChangesetValue(Tracker_Artifact $artifact, Tracker_FormElement_Field $field) { $last_changeset = $artifact->getLastChangeset(); if (!$last_changeset) { return null; } return $last_changeset->getValue($field); }
/** * @param User $user * @param Tracker_Artifact $artifact * * @return mixed */ private function getCurrentComputedValue(Tracker_Artifact $artifact) { $value = $artifact->getValue($this); if ($value) { return $value->getValue(); } return null; }
/** * Return true if given artifact has the same value than current object * * @param Tracker_Artifact $artifact * @return boolean */ public function isSetForArtifact(Tracker_Artifact $artifact) { $artifact_value = $artifact->getValue($this->getField()); if ($artifact_value && $artifact_value->getValue() == array($this->getValue()->getId())) { return true; } return false; }
/** * * @param Tracker_Artifact $artifact * * @return Tracker_FormElement_Field[] */ public function getFields(Tracker_Artifact $artifact) { $diplayed_fields = array(); $tracker = $artifact->getTracker(); foreach ($this->getDisplayedFields($tracker) as $field) { $diplayed_fields[] = $field; } return $diplayed_fields; }
private function isArtifactInParentTracker(Tracker_Artifact $linked_artifact) { $linked_artifact_tracker_id = $linked_artifact->getTrackerId(); $parent_tracker = $this->tracker->getParent(); if ($parent_tracker) { return $parent_tracker->getId() == $linked_artifact_tracker_id; } return false; }
private function sendResponse(Codendi_Request $request, $feedback_level, $message, $unsubscribe) { if ($request->isAjax()) { $this->sendAjaxResponse($unsubscribe, $message); return; } $GLOBALS['Response']->addFeedback($feedback_level, $message); $GLOBALS['Response']->redirect($this->artifact->getUri()); }
private function linkArtifact(PFUser $current_user, Tracker_Artifact $new_artifact) { $artifact_link_id = $this->request->get('artifact-link-id'); $source_artifact = $this->tracker_artifact_factory->getArtifactById($artifact_link_id); if (!$source_artifact) { return; } $source_artifact->linkArtifact($new_artifact->getId(), $current_user); }
private function setItemTitle(Tracker_Artifact $artifact) { $title = $artifact->getTitle(); $xref = $artifact->getXRef(); $class = $artifact->getTracker()->getColor(); $this->item_title = $title; $this->item_class = $class; $this->item_xref = $xref; }
private function fetchArtifactInformations(Tracker_Artifact $artifact) { $html = ""; $html_purifier = Codendi_HTMLPurifier::instance(); $artifact_id = $html_purifier->purify($artifact->getId()); $changeset_id = $html_purifier->purify($artifact->getLastChangeset()->getId()); $html .= '<input type="hidden" id="artifact_informations" data-artifact-id="' . $artifact_id . '" data-changeset-id="' . $changeset_id . '">'; return $html; }
private function getParentNode(Tracker_Artifact $parent, array &$cache_alreaydy_built_parents) { if (!isset($cache_alreaydy_built_parents[$parent->getId()])) { $parent_node = new TreeNode(); $parent_node->setId($parent->getId()); $parent_node->setObject($parent); $cache_alreaydy_built_parents[$parent->getId()] = $parent_node; } return $cache_alreaydy_built_parents[$parent->getId()]; }
/** * Retrieve submitter recipients for a given artifact * * @param Tracker_Artifact $artifact * * @return Array of PFUser */ function getRecipientsFromArtifact(Tracker_Artifact $artifact) { $recipients = array(); $userManager = $artifact->getUserManager(); $userId = $artifact->getSubmittedBy(); $user = $userManager->getUserById($userId); if ($user) { $recipients[$userId] = $user; } return $recipients; }
private function getAssigneeIds(Tracker_Artifact $artifact) { $contributor_field = $artifact->getTracker()->getContributorField(); if ($contributor_field) { $assignee = $artifact->getValue($contributor_field); if ($assignee) { return $assignee->getValue(); } } return array(); }
/** * @param ArtifactValuesRepresentation[] $values * @param Tracker_Artifact $artifact */ public function getFieldsDataOnUpdate(array $values, Tracker_Artifact $artifact) { $new_values = array(); $indexed_fields = $this->getIndexedFields($artifact->getTracker()); foreach ($values as $value) { $array_representation = $value->toArray(); $field = $this->getField($indexed_fields, $array_representation); $new_values[$field->getId()] = $field->getFieldDataFromRESTValue($array_representation, $artifact); } return $new_values; }
private function fetchNewArtifactForm(Codendi_Request $request, PFUser $current_user) { $html = ''; $html .= '<input type="hidden" name="link-artifact-id" value="' . $this->source_artifact->getId() . '" />'; if ($request->get('immediate')) { $html .= '<input type="hidden" name="immediate" value="1" />'; } $html .= $this->fetchFormElements($request, $current_user); $html .= '<input class="btn btn-primary" type="submit" id="tracker_artifact_submit" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" />'; return $html; }
/** * @param Tracker_Artifact $artifact The child * @param Tracker_Artifact $parent The parent * @param Tracker_Semantic_Status $semantic The status semantic used by the corresponding tracker */ public function __construct(Tracker_Artifact $artifact, Tracker_Artifact $parent, Tracker_Semantic_Status $semantic) { $base_url = get_server_url(); $this->xref = $artifact->getXRef(); $this->title = $artifact->getTitle(); $this->id = $artifact->getId(); $this->url = $base_url . $artifact->getUri(); $this->status = $semantic->getStatus($artifact); $this->parent_id = $parent->getId(); $this->has_children = $artifact->hasChildren(); }
/** * Retrieves the artifacts planned for the given milestone artifact. * * @param PFUser $user * @param Tracker_Artifact $milestone_artifact * @param Cardwall_OnTop_Config_ColumnCollection $columns * * @return Cardwall_Swimline[] */ private function getSwimlines(PFUser $user, Tracker_Artifact $milestone_artifact, Cardwall_OnTop_Config_ColumnCollection $columns) { $swimlines = array(); foreach ($this->dao->getBacklogArtifacts($milestone_artifact->getId()) as $row) { $swimline_artifact = $this->artifact_factory->getInstanceFromRow($row); if ($swimline_artifact->userCanView($user)) { $swimlines[] = $this->buildSwimlineForArtifact($user, $swimline_artifact, $columns); } } return $swimlines; }
private function getParentInSameHierarchy(Tracker $expected_parent_tracker, Tracker_Artifact $source_artifact, User $user) { if ($source_artifact->getTracker() == $expected_parent_tracker) { return $source_artifact; } else { $parent = $source_artifact->getParent($user); if ($parent) { return $this->getParentInSameHierarchy($expected_parent_tracker, $parent, $user); } } }
private function findNearestMilestoneWithBacklogTracker(Tracker $expected_backlog_tracker, Tracker_Artifact $source_artifact, User $user) { $planning = $this->planning_factory->getPlanningByPlanningTracker($source_artifact->getTracker()); if ($planning && $planning->getBacklogTracker() == $expected_backlog_tracker) { return $this->milestone_factory->getMilestoneFromArtifactWithPlannedArtifacts($source_artifact, $user); } else { $parent = $source_artifact->getParent($user); if ($parent) { return $this->findNearestMilestoneWithBacklogTracker($expected_backlog_tracker, $parent, $user); } } }
public function getFields(Tracker_Artifact $artifact) { $diplayed_fields = array(); $tracker_id = $artifact->getTrackerId(); foreach ($this->displayed_fields as $diplayed_field_name) { $field = $this->form_element_factory->getUsedFieldByNameForUser($tracker_id, $diplayed_field_name, $this->user_manager->getCurrentUser()); if ($field) { $diplayed_fields[] = $field; } } return $diplayed_fields; }
/** * 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; }