/** * @return SimpleXMLElement */ protected function createFieldChangeNodeInChangesetNode(Tracker_Artifact_ChangesetValue $changeset_value, SimpleXMLElement $changeset_xml) { $field = $changeset_value->getField(); $field_change = $changeset_xml->addChild('field_change'); $field_change->addAttribute('field_name', $field->getName()); $field_change->addAttribute('type', $this->getFieldChangeType()); return $field_change; }
private function isUsed(Tracker_Artifact_ChangesetValue $changeset_value) { $ugroup_ids = $changeset_value->getPerms(); if (count($ugroup_ids) === 1 && (int) $ugroup_ids[0] === ProjectUGroup::ANONYMOUS) { return false; } return count($ugroup_ids) > 0; }
public function fetchArtifactValueReadOnly(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { if (empty($value) || !$value->getTimestamp()) { return $this->field->getNoValueLabel(); } $value_timestamp = $value->getTimestamp(); $formatted_value = $value_timestamp ? $this->formatDateForDisplay($value_timestamp) : ''; return $formatted_value; }
private function isFieldChangeExportable($export_mode, Tracker_Artifact_ChangesetValue $changeset_value) { if ($export_mode === self::EXPORT_SNAPSHOT) { return true; } if ($changeset_value->hasChanged()) { return true; } return false; }
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(); }
/** * Fetch artifact value for email * @param Tracker_Artifact $artifact * @param PFUser $user * @param Tracker_Artifact_ChangesetValue $value * @param string $format * @return string */ public function fetchMailArtifactValue(Tracker_Artifact $artifact, PFUser $user, Tracker_Artifact_ChangesetValue $value = null, $format = 'text') { $output = ''; switch ($format) { case 'html': $proto = $GLOBALS['sys_force_ssl'] ? 'https' : 'http'; $output_value = isset($value) ? $value->getValue() : ''; $output .= '<a href= "' . $proto . '://' . $GLOBALS['sys_default_domain'] . TRACKER_BASE_URL . '/?' . http_build_query(array('aid' => (int) $artifact->id)) . '">' . $output_value . '</a>'; break; default: $output .= $artifact->getPerTrackerArtifactId(); break; } return $output; }
/** * Constructor * * @param Tracker_FormElement_Field_ArtifactLink $field The field of the value * @param boolean $has_changed If the changeset value has chnged from the previous one * @param array $artifact_links array of artifact_id => Tracker_ArtifactLinkInfo * @param array $reverse_artifact_links array of artifact_id => Tracker_ArtifactLinkInfo */ public function __construct($id, $field, $has_changed, $artifact_links, $reverse_artifact_links) { parent::__construct($id, $field, $has_changed); $this->artifact_links = $artifact_links; $this->reverse_artifact_links = $reverse_artifact_links; $this->user_manager = UserManager::instance(); }
/** * Returns a diff between current changeset value and changeset value in param * * @param Tracker_Artifact_ChangesetValue $changeset_value The changeset value to compare to this changeset value * * @return string The difference between another $changeset_value, false if no differences */ public function diff($changeset_value, $format = 'html') { $previous = $changeset_value->getValue(); $next = $this->getValue(); $changes = false; if ($previous != $next) { $removed_elements = array_diff($previous, $next); $removed_arr = array(); $method = 'getLabel'; if ($format === 'html') { $method = 'getUrl'; } foreach ($removed_elements as $art_id => $removed_element) { $removed_arr[] = $removed_element->{$method}(); } $removed = implode(', ', $removed_arr); $added_elements = array_diff($next, $previous); $added_arr = array(); foreach ($added_elements as $art_id => $added_element) { $added_arr[] = $added_element->{$method}(); } $added = implode(', ', $added_arr); if (empty($next)) { $changes = ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'cleared'); } else { if (empty($previous)) { $changes = ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'set_to') . ' ' . $added; } else { if (count($previous) == 1 && count($next) == 1) { $changes = ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'changed_from') . ' ' . $removed . ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'to') . ' ' . $added; } else { if ($removed) { $changes = $removed . ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'removed'); } if ($added) { if ($changes) { $changes .= PHP_EOL; } $changes .= $added . ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'added'); } } } } } return $changes; }
function testValidateUpdateFieldNotSubmitted() { stub($this->field1)->isValid()->returns(true); stub($this->field1)->userCanUpdate()->returns(true); stub($this->field1)->isRequired()->returns(true); stub($this->field2)->isValid()->returns(true); stub($this->field3)->isValid()->returns(true); stub($this->workflow)->validate()->returns(true); $this->changeset_value1->setReturnValue('getValue', 999); $GLOBALS['Language']->expectNever('getText', array('plugin_tracker_common_artifact', 'err_required', '*')); $fields_data = array(); $this->assertTrue($this->new_changeset_fields_validator->validate($this->artifact_update, $fields_data)); $this->assertFalse(isset($fields_data[101])); }
/** * Check if there are changes between old and new value for this field * * @param Tracker_Artifact_ChangesetValue $previous_changesetvalue The data stored in the db * @param mixed $new_value May be string or array * * @return bool true if there are differences */ public function hasChanges($previous_changesetvalue, $new_value) { if (!is_array($new_value)) { $new_value = array($new_value); } if (empty($new_value)) { $new_value = array(Tracker_FormElement_Field_List_Bind_StaticValue_None::VALUE_ID); } if ($previous_changesetvalue) { $old_value = $previous_changesetvalue->getValue(); } if (empty($old_value)) { $old_value = array(Tracker_FormElement_Field_List_Bind_StaticValue_None::VALUE_ID); } sort($old_value); sort($new_value); return $old_value != $new_value; }
private function isFileField(Tracker_Artifact_ChangesetValue $changeset_value) { $field = $changeset_value->getField(); return is_a($field, 'Tracker_FormElement_Field_File'); }
public function getNumericValues(Tracker_Artifact_ChangesetValue $changeset_value) { $bind_values = $this->getBindValues($changeset_value->getValue()); return $this->extractNumericValues($bind_values); }
/** * Constructor * * @param Tracker_FormElement_Field_String $field The field of the value * @param boolean $has_changed If the changeset value has chnged from the previous one * @param string $text The string * @param string $format The format */ public function __construct($id, $field, $has_changed, $text, $format) { parent::__construct($id, $field, $has_changed); $this->text = $text; $this->format = $format; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact * @param Tracker_Artifact_ChangesetValue_Float $value The changeset value of this field * @return string The html code to display the field value in tooltip */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if ($value) { $html .= $value->getFloat(); } return $html; }
/** * Constructor * * @param Tracker_FormElement_Field_File $field The field of the value * @param boolean $has_changed If the changeset value has chnged from the previous one * @param array $files array of Tracker_FileInfo */ public function __construct($id, $field, $has_changed, $files) { parent::__construct($id, $field, $has_changed); $this->files = $files; }
/** * Fetch the html code to display the field value in artifact * * @param Tracker_Artifact $artifact The artifact * @param Tracker_Artifact_ChangesetValue $value The actual value of the field * @param array $submitted_values The value already submitted by the user * * @return string */ public function fetchMailArtifactValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null, $format = 'text') { if (empty($value)) { return ''; } $output = ''; switch ($format) { case 'html': $artifactlink_infos = $value->getValue(); $output .= '<ul>'; foreach ($artifactlink_infos as $artifactlink_info) { $output .= '<li>' . $artifactlink_info->getUrl() . '</li>'; } $output .= '<ul>'; break; default: $output = PHP_EOL; $artifactlink_infos = $value->getValue(); foreach ($artifactlink_infos as $artifactlink_info) { $output .= $artifactlink_info->getLabel(); $output .= PHP_EOL; } break; } return $output; }
/** * Check if there are changes between old and new value for this field * * @param Tracker_Artifact_ChangesetValue $previous_changesetvalue The data stored in the db * @param mixed $new_value May be string or array * * @return bool true if there are differences */ public function hasChanges($previous_changesetvalue, $new_value) { return $previous_changesetvalue->getText() != $new_value; }
/** * Check if there are changes between old and new value for this field * * @param Tracker_Artifact_ChangesetValue $old_value The data stored in the db * @param mixed $new_value May be string or array * * @return bool true if there are differences */ public function hasChanges(Tracker_Artifact_ChangesetValue $old_value, $new_value) { return $old_value->getNumeric() != $new_value; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact The artifact * @param Tracker_ChangesetValue_File $value The changeset value of this field * * @return string The html code to display the field value in tooltip */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if ($value) { $files_info = $value->getFiles(); if (count($files_info)) { $hp = Codendi_HTMLPurifier::instance(); $added = array(); foreach ($files_info as $file_info) { $add = ''; if ($file_info->isImage()) { $query = $this->getFileHTMLPreviewUrl($file_info); $add .= '<img src="' . $query . '" alt="' . $hp->purify($file_info->getDescription(), CODENDI_PURIFIER_CONVERT_HTML) . '" style="vertical-align:middle;" />'; } else { if ($file_info->getDescription()) { $add .= $hp->purify($file_info->getDescription(), CODENDI_PURIFIER_CONVERT_HTML); } else { $add .= $hp->purify($file_info->getFilename(), CODENDI_PURIFIER_CONVERT_HTML); } } $added[] = $add; } $html .= implode('<br />', $added); } } return $html; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact * @param Tracker_Artifact_ChangesetValue_String $value The ChangesetValue_String * @return string The html code to display the field value in tooltip */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $hp = Codendi_HTMLPurifier::instance(); $html = ''; if ($value) { $html .= $hp->purify($value->getText(), CODENDI_PURIFIER_CONVERT_HTML); } return $html; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact The artifact * @param Tracker_ChangesetValue_File $value The changeset value of this field * * @return string The html code to display the field value in tooltip */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if ($value) { $files_info = $value->getFiles(); if (count($files_info)) { $hp = Codendi_HTMLPurifier::instance(); $added = array(); foreach ($files_info as $file_info) { $add = ''; if ($file_info->isImage()) { $query = http_build_query(array('aid' => $artifact->id, 'field' => $this->id, 'func' => 'preview-attachment', 'attachment' => $file_info->getId())); $add .= '<img src="' . TRACKER_BASE_URL . '/?' . $query . '" alt="' . $hp->purify($file_info->getDescription(), CODENDI_PURIFIER_CONVERT_HTML) . '" style="vertical-align:middle;" />'; } else { if ($file_info->getDescription()) { $add .= $hp->purify($file_info->getDescription(), CODENDI_PURIFIER_CONVERT_HTML); } else { $add .= $hp->purify($file_info->getFilename(), CODENDI_PURIFIER_CONVERT_HTML); } } $added[] = $add; } $html .= implode('<br />', $added); } } return $html; }
/** * Fetch the html code to display the field value in artifact * * @param Tracker_Artifact $artifact The artifact * @param PFUser $user The user who will receive the email * @param Tracker_Artifact_ChangesetValue $value The actual value of the field * @param array $submitted_values The value already submitted by the user * * @return string */ public function fetchMailArtifactValue(Tracker_Artifact $artifact, PFUser $user, Tracker_Artifact_ChangesetValue $value = null, $format = 'text') { if (empty($value) || !$value->getValue()) { return '-'; } $output = ''; switch ($format) { case 'html': $artifactlink_infos = $value->getValue(); $url = array(); foreach ($artifactlink_infos as $artifactlink_info) { if ($artifactlink_info->userCanView($user)) { $url[] = $artifactlink_info->getUrl(); } } return implode(' , ', $url); default: $output = PHP_EOL; $artifactlink_infos = $value->getValue(); foreach ($artifactlink_infos as $artifactlink_info) { if ($artifactlink_info->userCanView($user)) { $output .= $artifactlink_info->getLabel(); $output .= PHP_EOL; } } break; } return $output; }
/** * Constructor * * @param Tracker_FormElement_Field_Date $field The field of the value * @param boolean $has_changed If the changeset value has chnged from the previous one * @param int $timestamp The date */ public function __construct($id, $field, $has_changed, $timestamp) { parent::__construct($id, $field, $has_changed); $this->timestamp = $timestamp; }
/** * Check if there are changes between old and new value for this field * * @param Tracker_Artifact_ChangesetValue $old_value The data stored in the db * @param mixed $new_value May be string or array * * @return bool true if there are differences */ public function hasChanges(Tracker_Artifact_ChangesetValue $old_value, $new_value) { return strtotime($this->formatDate($old_value->getTimestamp())) != strtotime($new_value); }
/** * Constructor * * @param Tracker_FormElement_Field_Date $field The field of the value * @param boolean $has_changed If the changeset value has chnged from the previous one * @param array $perms The permissions */ public function __construct($id, $field, $has_changed, $used, $perms) { parent::__construct($id, $field, $has_changed); $this->perms = $perms; $this->used = $used; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact * @param Tracker_Artifact_ChangesetValue_PermissionsOnArtifact $value The changeset value for this field * @return string */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if ($value && $artifact->useArtifactPermissions()) { $ugroup_dao = $this->getUGroupDao(); $perms = $value->getPerms(); $perms_name = array(); foreach ($perms as $perm) { $row = $ugroup_dao->searchByUGroupId($perm)->getRow(); $perms_name[] = util_translate_name_ugroup($row['name']); } $html .= implode(",", $perms_name); } return $html; }
/** * Constructor * * @param Tracker_FormElement_Field_Numeric $field The field of the value * @param boolean $has_changed If the changeset value has chnged from the previous one * @param numeric $numeric The numeric */ public function __construct($id, $field, $has_changed, $numeric) { parent::__construct($id, $field, $has_changed); $this->numeric = $numeric; }
/** * Check if there are changes between old and new value for this field * * @param Tracker_Artifact_ChangesetValue $old_value The data stored in the db * @param array $new_value array of artifact ids * * @return bool true if there are differences */ public function hasChanges(Tracker_Artifact_ChangesetValue $old_value, $new_value) { return $old_value->hasChanges($new_value); }
/** * Check if there are changes between old and new value for this field * * @param Tracker_Artifact_ChangesetValue $previous_changesetvalue The data stored in the db * @param string $new_value string * * @return bool true if there are differences */ public function hasChanges($previous_changesetvalue, $new_value) { return $previous_changesetvalue->getValue() != $this->sanitize($new_value); }
/** * Keep the value * * @param Tracker_Artifact $artifact The artifact * @param int $changeset_value_id The id of the changeset_value * @param Tracker_Artifact_ChangesetValue $previous_changesetvalue The data previously stored in the db * * @return int or array of int */ protected function keepValue($artifact, $changeset_value_id, Tracker_Artifact_ChangesetValue $previous_changesetvalue) { return $this->getValueDao()->keep($previous_changesetvalue->getId(), $changeset_value_id); }