/**
  * Fetch the value in a specific changeset
  * @param Tracker_Artifact_Changeset $changeset
  * @return string
  */
 public function fetchRawValueFromChangeset($changeset)
 {
     $value = '';
     if ($v = $changeset->getValue($this)) {
         if ($row = $this->getValueDao()->searchById($v->getId(), $this->id)->getRow()) {
             $value = $row['value'];
         }
     }
     return $value;
 }
 private function hasChanges(Tracker_Artifact_Changeset $new_changeset, Tracker_Artifact_Changeset $previous_changeset = null)
 {
     if (!$previous_changeset) {
         return true;
     }
     $new_value = $new_changeset->getValue($this->field);
     $previous_value = $previous_changeset->getValue($this->field);
     $diff = $new_value->getArtifactLinkInfoDiff($previous_value);
     return $diff->hasChanges();
 }
 public function extractArtifactDateFields(Tracker_Artifact $artifact, Tracker_Artifact_Changeset $last_changeset, array &$properties)
 {
     $tracker = $artifact->getTracker();
     $custom_date_fields = $this->form_element_factory->getUsedCustomDateFields($tracker);
     foreach ($custom_date_fields as $date_field) {
         $last_changeset_value = $last_changeset->getValue($date_field);
         if ($last_changeset->getValue($date_field) && $last_changeset_value) {
             $properties[$date_field->getName()] = date('c', $last_changeset_value->getTimestamp());
         }
     }
     $core_date_fields = $this->form_element_factory->getCoreDateFields($tracker);
     foreach ($core_date_fields as $date_field) {
         if ($date_field instanceof Tracker_FormElement_Field_SubmittedOn) {
             $properties[$date_field->getName()] = date('c', $artifact->getSubmittedOn());
         } elseif ($date_field instanceof Tracker_FormElement_Field_LastUpdateDate) {
             $properties[$date_field->getName()] = date('c', $artifact->getLastUpdateDate());
         }
     }
     $last_modified = $artifact->getLastUpdateDate();
     if ($last_modified === -1) {
         $last_modified = $artifact->getSubmittedOn();
     }
     $properties[self::LAST_UPDATE_PROPERTY] = date('c', $last_modified);
 }
 /**
  * Retrieve linked artifacts according to user's permissions
  * 
  * @param Tracker_Artifact_Changeset $changeset The changeset you want to retrieve artifact from
  * @param User                       $user      The user who will see the artifacts
  * 
  * @return array of Tracker_Artifact
  */
 public function getLinkedArtifacts(Tracker_Artifact_Changeset $changeset, User $user)
 {
     $artifacts = array();
     $changeset_value = $changeset->getValue($this);
     if ($changeset_value) {
         foreach ($changeset_value->getArtifactIds() as $id) {
             $artifact = $this->getArtifactFactory()->getArtifactById($id);
             if ($artifact && $artifact->userCanView($user)) {
                 $artifacts[] = $artifact;
             }
         }
     }
     return $artifacts;
 }
 /**
  * Retrieve sliced linked artifacts according to user's permissions
  *
  * This is nearly the same as a paginated list however, for performance
  * reasons, the total size may be different than the sum of total paginated
  * artifacts.
  *
  * Example to illustrate the difference between paginated and sliced:
  *
  * Given that artifact links are [12, 13, 24, 39, 65, 69]
  * And that the user cannot see artifact #39
  * When I request linked artifacts by bunchs of 2
  * Then I get [[12, 13], [24], [65, 69]]  # instead of [[12, 13], [24, 65], [69]]
  * And total size will be 6               # instead of 5
  *
  * @param Tracker_Artifact_Changeset $changeset The changeset you want to retrieve artifact from
  * @param PFUser                     $user      The user who will see the artifacts
  * @param int                        $limit     The number of artifact to fetch
  * @param int                        $offset    The offset
  *
  * @return Tracker_Artifact_PaginatedArtifacts
  */
 public function getSlicedLinkedArtifacts(Tracker_Artifact_Changeset $changeset, PFUser $user, $limit, $offset)
 {
     $changeset_value = $changeset->getValue($this);
     if (!$changeset_value) {
         return new Tracker_Artifact_PaginatedArtifacts(array(), 0);
     }
     $artifact_ids = $changeset_value->getArtifactIds();
     $size = count($artifact_ids);
     $artifacts = array();
     foreach (array_slice($artifact_ids, $offset, $limit) as $id) {
         $this->addArtifactUserCanViewFromId($artifacts, $id, $user);
     }
     return new Tracker_Artifact_PaginatedArtifacts($artifacts, $size);
 }
 /**
  * Fetch the value in a specific changeset
  * @param Tracker_Artifact_Changeset $changeset
  * @return string
  */
 public function fetchRawValueFromChangeset($changeset)
 {
     $value = '';
     $values_array = array();
     if ($v = $changeset->getValue($this->field)) {
         $values = $v->getListValues();
         foreach ($values as $val) {
             $values_array[] = $val->getLabel();
         }
     }
     return implode(",", $values_array);
 }
 /**
  *
  * @param Tracker_Artifact_Changeset $changeset
  * @return string
  */
 public function getFirstValueFor(Tracker_Artifact_Changeset $changeset)
 {
     if ($this->userCanRead()) {
         $value = $changeset->getValue($this);
         if ($value && ($last_values = $value->getListValues())) {
             // let's assume there is no more that one status
             if ($label = array_shift($last_values)->getLabel()) {
                 return $label;
             }
         }
     }
 }
 /**
  * Fetch the value in a specific changeset
  * @param Tracker_Artifact_Changeset $changeset
  * @return string
  */
 public function fetchRawValueFromChangeset($changeset)
 {
     $value = '';
     if ($v = $changeset->getValue($this->field)) {
         if (isset($v['value_id'])) {
             $v = array($v);
         }
         foreach ($v as $val) {
             $value .= $this->values[$val['value_id']]['value'];
         }
     }
     return $value;
 }
 /**
  * Return REST value of a field for a given changeset
  *
  * @param PFUser                     $user
  * @param Tracker_Artifact_Changeset $changeset
  *
  * @return mixed | null if no values
  */
 public function getRESTValue(PFUser $user, Tracker_Artifact_Changeset $changeset)
 {
     $value = $changeset->getValue($this);
     if ($value) {
         return $value->getRESTValue($user);
     }
 }
 public function getJsonValue(PFUser $user, Tracker_Artifact_Changeset $changeset)
 {
     if ($this->userCanRead($user)) {
         $value = $changeset->getValue($this);
         return $value ? $value->getJsonValue() : '';
     }
     return null;
 }
 /**
  * Fetch the value in a specific changeset
  * @param Tracker_Artifact_Changeset $changeset
  * @return string
  */
 public function fetchRawValueFromChangeset($changeset)
 {
     $value = '';
     if ($v = $changeset->getValue($this)) {
         if (isset($v['value_id'])) {
             $v = array($v);
         }
         foreach ($v as $val) {
             if ($val['value_id'] != 100) {
                 if ($row = $this->getValueDao()->searchById($val['value_id'], $this->id)->getRow()) {
                     if ($value) {
                         $value .= ', ';
                     }
                     $value .= $row['filename'];
                 }
             }
         }
     }
     return $value;
 }
Exemple #12
0
 private function getCurrentTransition($fields_data, Tracker_Artifact_Changeset $changeset = null)
 {
     $oldValues = null;
     if ($changeset) {
         $oldValues = $changeset->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;
         }
     }
     if (isset($fields_data[$this->getFieldId()])) {
         $to = (int) $fields_data[$this->getFieldId()];
         $transition = $this->getTransition($from, $to);
         return $transition;
     }
     return null;
 }