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 getLastChangesetValue(Tracker_Artifact $artifact, Tracker_FormElement_Field $field)
 {
     $last_changeset = $artifact->getLastChangeset();
     if (!$last_changeset) {
         return null;
     }
     return $last_changeset->getValue($field);
 }
 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 getBaseArtifact(Tracker_Artifact $artifact, array &$properties)
 {
     $last_changeset = $artifact->getLastChangeset();
     $last_changeset_id = $last_changeset ? $last_changeset->getId() : -1;
     $properties = array('id' => $artifact->getId(), 'group_id' => $artifact->getTracker()->getGroupId(), 'tracker_id' => $artifact->getTrackerId(), 'last_changeset_id' => $last_changeset_id);
     $this->artifact_properties_extractor->extractTrackerUserGroups($artifact, $properties);
     $this->artifact_properties_extractor->extractArtifactUserGroups($artifact, $properties);
     if ($last_changeset) {
         $this->artifact_properties_extractor->extractArtifactTextFields($artifact, $last_changeset, $properties);
         $this->artifact_properties_extractor->extractArtifactDateFields($artifact, $last_changeset, $properties);
     }
 }
 public function __construct($follow_ups, $artifact_links, $form_elements, Tracker_Artifact $artifact, PFUser $user)
 {
     $this->follow_ups = $follow_ups;
     $this->artifact_links = $artifact_links;
     $this->artifact = $artifact;
     $this->artifact_id = $artifact->getId();
     $this->artifact_title = $artifact->getTitle();
     $this->artifact_uri = $artifact->getUri();
     $this->last_changeset_id = $artifact->getLastChangeset()->getId();
     $this->form_elements = $form_elements;
     $this->user = $user;
 }
Пример #6
0
 private function updateParent(Tracker_Artifact $parent, Tracker_Artifact $child, Tracker_Workflow_Trigger_TriggerRule $rule)
 {
     $target = $rule->getTarget();
     try {
         $comment = '<p>' . $GLOBALS['Language']->getText('workflow_trigger_rules_processor', 'parent_update', array('art #' . $child->getId(), $child->getLastChangeset()->getUri())) . '</p>';
         $comment .= '<p>' . $rule->getAsChangesetComment() . '</p>';
         $parent->createNewChangeset($target->getFieldData(), $comment, $this->workflow_user, true, Tracker_Artifact_Changeset_Comment::HTML_COMMENT);
         $this->logger->debug('Parent successfully updated.');
     } catch (Tracker_Exception $e) {
         $this->logger->debug('Error while updating the parent artifact: ' . $e->getMessage());
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_common_artifact', 'error_processor_update', array($parent->fetchDirectLinkToArtifact(), $e->getMessage())), CODENDI_PURIFIER_DISABLED);
     }
 }
 private function isCurrentChangesetTheLastChangeset(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $current_changeset_value)
 {
     $file_field = $current_changeset_value->getField();
     $last_changeset = $artifact->getLastChangeset();
     if (!$last_changeset) {
         return false;
     }
     $last_changeset_value = $last_changeset->getValue($file_field);
     if (!$last_changeset_value) {
         return false;
     }
     return $last_changeset_value->getId() === $current_changeset_value->getId();
 }
 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);
         }
     }
 }
Пример #9
0
 /**
  * Execute actions before transition happens (if there is one)
  * 
  * @param Array $fields_data  Request field data (array[field_id] => data)
  * @param User  $current_user The user who are performing the update
  * 
  * @return void
  */
 public function before(array &$fields_data, User $current_user)
 {
     if (isset($fields_data[$this->getFieldId()])) {
         $oldValues = $this->artifact->getLastChangeset()->getValue($this->getField());
         $from = null;
         if ($oldValues) {
             if ($v = $oldValues->getValue()) {
                 // Todo: what about multiple values in the changeset?
                 list(, $from) = each($v);
                 $from = (int) $from;
             }
         }
         $to = (int) $fields_data[$this->getFieldId()];
         $transition = $this->getTransition($from, $to);
         if ($transition) {
             $transition->before($fields_data, $current_user);
         }
     }
 }
Пример #10
0
 public function getFieldJsonValue(PFUser $user, Tracker_FormElement_Field $field)
 {
     return $field->getJsonValue($user, $this->artifact->getLastChangeset());
 }
 /**
  * Retreive The last date Field value
  *
  * @param Tracker_Artifact $artifact The artifact
  *
  * @return date
  */
 public function getLastValue(Tracker_Artifact $artifact)
 {
     return date("Y-m-d", $artifact->getLastChangeset()->getSubmittedOn());
 }
 private function getFieldsValues(PFUser $user, Tracker_Artifact $artifact)
 {
     $changeset = $artifact->getLastChangeset();
     return $this->mapAndFilter($this->formelement_factory->getUsedFieldsForREST($artifact->getTracker()), $this->getFieldsValuesFilter($user, $changeset));
 }
Пример #13
0
 public function isInColumn(Tracker_Artifact $artifact, Cardwall_FieldProviders_IProvideFieldGivenAnArtifact $field_provider, Cardwall_Column $column)
 {
     $artifact_status = null;
     $field = $field_provider->getField($artifact->getTracker());
     if ($field) {
         $last_changeset = $artifact->getLastChangeset();
         if ($last_changeset) {
             $artifact_status = $field->getFirstValueFor($last_changeset);
         }
     }
     return $column->canContainStatus($artifact_status, $this->getMappingFor($artifact->getTracker()));
 }
Пример #14
0
 /**
  * @throws Tracker_Workflow_PermissionTransitionViolationException
  *
  * @return void
  */
 public function validate($fields_data, Tracker_Artifact $artifact)
 {
     if (!$this->is_used) {
         return;
     }
     $transition = $this->getCurrentTransition($fields_data, $artifact->getLastChangeset());
     if (isset($transition)) {
         if (!$transition->validate($fields_data, $artifact)) {
             throw new Tracker_Workflow_PermissionTransitionViolationException();
         }
     }
 }
 /**
  * @return Array the ids
  */
 private function getLastChangesetArtifactIds(Tracker_Artifact $artifact)
 {
     $lastChangeset = $artifact->getLastChangeset();
     $ids = array();
     if ($lastChangeset) {
         $ids = $artifact->getLastChangeset()->getValue($this)->getArtifactIds();
     }
     return $ids;
 }
 /**
  * Instanciate a new object based on a artifact
  *
  * @param Tracker_Artifact $artifact
  *
  * @return Tracker_ArtifactLinkInfo
  */
 public static function buildFromArtifact(Tracker_Artifact $artifact)
 {
     $tracker = $artifact->getTracker();
     $klass = __CLASS__;
     return new $klass($artifact->getId(), $tracker->getItemName(), $tracker->getGroupId(), $tracker->getId(), $artifact->getLastChangeset()->getId());
 }
Пример #17
0
 /**
  * Return artifact info from artifact object
  *
  * If there is already an artifact info available in DB result, use this one
  * instead of re-creating it (artifact_info from DB contains extra informations
  * like the "artifact link column value")
  *
  * @param Tracker_Artifact $artifact
  * @param array $artifacts_info
  *
  * @return array
  */
 private function getArtifactInfo(Tracker_Artifact $artifact, array $artifacts_info)
 {
     if (isset($artifacts_info[$artifact->getId()])) {
         return $artifacts_info[$artifact->getId()];
     } else {
         return array('id' => $artifact->getId(), 'last_changeset_id' => $artifact->getLastChangeset()->getId(), 'tracker_id' => $artifact->getTrackerId());
     }
 }
 /**
  * Retreive The last date Field value
  *
  * @param Tracker_Artifact $artifact The artifact
  *
  * @return date
  */
 public function getLastValue(Tracker_Artifact $artifact)
 {
     return date(Tracker_FormElement_DateFormatter::DATE_FORMAT, $artifact->getLastChangeset()->getSubmittedOn());
 }
 private function getFieldValuesIndexedByName(PFUser $user, Tracker_Artifact $artifact)
 {
     $changeset = $artifact->getLastChangeset();
     $values = array();
     foreach ($this->formelement_factory->getUsedFieldsForREST($artifact->getTracker()) as $field) {
         if (!$field->userCanRead($user) || !$field instanceof Tracker_FormElement_Field_Alphanum) {
             continue;
         }
         $field_value = $field->getRESTValue($user, $changeset);
         $values[$field->getName()] = $field_value;
     }
     return $values;
 }
 /**
  * Get the html code to display the field in a tooltip
  * @param Tracker_Artifact $artifact
  * @return string html
  */
 public function fetchTooltip($artifact)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $html = '';
     if ($this->userCanRead()) {
         $html .= '<tr valign="top"><td>';
         $html .= '<label style="font-weight:bold">' . $hp->purify($this->getLabel(), CODENDI_PURIFIER_CONVERT_HTML) . ':</label>';
         $html .= '</td><td>';
         $value = $artifact->getLastChangeset()->getValue($this);
         $html .= $this->fetchTooltipValue($artifact, $value);
         $html .= '</td></tr>';
     }
     return $html;
 }
 /**
  * @see Tracker_FormElement_Field::fetchCardValue()
  */
 public function fetchCardValue(Tracker_Artifact $artifact, Tracker_CardDisplayPreferences $display_preferences)
 {
     $html = '';
     //We have to fetch all values of the changeset as we are a list of value
     //This is the case only if we are multiple but an old changeset may
     //contain multiple values
     $values = array();
     foreach ($this->getBind()->getChangesetValues($artifact->getLastChangeset()->id) as $v) {
         $val = $this->getBind()->formatCardValue($v, $display_preferences);
         if ($val != '') {
             $values[] = $val;
         }
     }
     $html .= implode(' ', $values);
     return $html;
 }
 public function isPreviousChangesetEmpty(Tracker_Artifact $artifact, $value)
 {
     $last_changeset = $artifact->getLastChangeset();
     if ($last_changeset && count($last_changeset->getValue($this)->getFiles()) > 0) {
         return $this->areAllFilesDeletedFromPreviousChangeset($last_changeset, $value);
     }
     return true;
 }
 /**
  * @see Tracker_FormElement_Field::fetchCardValue()
  */
 public function fetchCardValue(Tracker_Artifact $artifact, Tracker_CardDisplayPreferences $display_preferences)
 {
     $value = $artifact->getLastChangeset()->getValue($this);
     return $this->fetchTooltipValue($artifact, $value);
 }
 /**
  * Fetch the html code to display the field value in card
  *
  * @param Tracker_Artifact $artifact
  *
  * @return string
  */
 public function fetchCardValue(Tracker_Artifact $artifact, Tracker_CardDisplayPreferences $display_preferences = null)
 {
     //return $this->fetchTooltipValue($artifact, $artifact->getLastChangeset()->getValue($this));
     $artifact_id = $artifact->getId();
     $changeset_id = $artifact->getLastChangeset()->getId();
     $value = $artifact->getLastChangeset()->getValue($this);
     $report = Tracker_ReportFactory::instance()->getDefaultReportsByTrackerId($artifact->getTracker()->getId());
     $request = HTTPRequest::instance();
     if ($request->exist('report')) {
         $report = Tracker_ReportFactory::instance()->getReportById($request->get('report'), UserManager::instance()->getCurrentUser()->getId());
     }
     return $this->fetchChangesetValue($artifact_id, $changeset_id, $value, $report);
 }
Пример #25
0
 private function getFieldValueFromLastChangeset(Tracker_Artifact $artifact, Tracker_FormElement_Field $field)
 {
     $value = null;
     $last_changeset = $artifact->getLastChangeset();
     if ($last_changeset) {
         $last_changeset_value = $last_changeset->getValue($field);
         if ($last_changeset_value) {
             $value = $last_changeset_value->getValue();
         }
     }
     return $value;
 }
 /**
  * Get the color for the current value of the field for an artifact.
  *
  * If no value, null is returned.
  *
  * @param Tracker_Artifact $artifact
  *
  * @return string | null
  */
 public function getCurrentDecoratorColor(Tracker_Artifact $artifact)
 {
     $changeset = $artifact->getLastChangeset();
     if (!$changeset) {
         return null;
     }
     $values = $this->getBind()->getChangesetValues($changeset->getId());
     if (!$values) {
         return null;
     }
     // We might have many values selected in a list field (eg:
     // multi-selectbox, checkbox). As we want only one color,
     // arbitrary take the color of the first selected value.
     $value_id = $values[0]['id'];
     $decorators = $this->getDecorators();
     if (!isset($decorators[$value_id])) {
         return null;
     }
     return $decorators[$value_id]->css(null);
 }