/**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 public function getNumericValues(Tracker_Artifact_ChangesetValue $changeset_value)
 {
     $bind_values = $this->getBindValues($changeset_value->getValue());
     return $this->extractNumericValues($bind_values);
 }
 /**
  * Fetch the html code to display the field value in artifact in read only mode
  *
  * @param Tracker_Artifact                $artifact The artifact
  * @param Tracker_Artifact_ChangesetValue $value    The actual value of the field
  *
  * @return string
  */
 public function fetchArtifactValueReadOnly(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null)
 {
     if (empty($value)) {
         return '';
     }
     $hp = Codendi_HTMLPurifier::instance();
     return $hp->purify("{$value->getValue()}", CODENDI_PURIFIER_CONVERT_HTML);
 }
 /**
  * Fetch the html code to display the field value in tooltip
  *
  * @param Tracker_Artifact $artifact
  * @param Tracker_Artifact_ChangesetValue_Text $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) {
         $purifier = Codendi_HTMLPurifier::instance();
         $html .= $purifier->purify($value->getValue());
     }
     return $html;
 }
 /**
  * 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(100);
     }
     if ($previous_changesetvalue) {
         $old_value = $previous_changesetvalue->getValue();
     }
     if (empty($old_value)) {
         $old_value = array(100);
     }
     sort($old_value);
     sort($new_value);
     return $old_value != $new_value;
 }
 /**
  * Fetch the html code to display the field value in tooltip
  *
  * @param Tracker_Artifact $artifact
  * @param Tracker_Artifact_ChangesetValue_Text $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->getValue();
     }
     return $html;
 }