TrackerItem = $TrackerItem; $this->Tracker = $TrackerItem->getTracker(); $this->Project = $this->Tracker->getProject(); $this->modifiedValues = $modifiedValues; } private function getGenericMessage() { $url = GFUrl::getUrl(); //set the main variables for the items according whether they have been changed or not $status_id_marker = $this->TrackerItem->isColumnModified(TrackerItemPeer::STATUS_ID)?'>':''; $priority_marker = $this->TrackerItem->isColumnModified(TrackerItemPeer::PRIORITY)?">":""; $summary_marker = $this->TrackerItem->isColumnModified(TrackerItemPeer::SUMMARY)?">":""; // make the body $body = $this->TrackerItem->getTracker()->getTrackerName() ." item #". $this->TrackerItem->getPrimaryKey() .", was opened at ". $this->TrackerItem->getOpenDate() . "\n\n". $priority_marker . "Priority: ". $this->TrackerItem->getPriority() ."\n". "Submitted By: ". $this->TrackerItem->getUser()->getFirstName() . " " . $this->TrackerItem->getUser()->getLastName() . " (". $this->TrackerItem->getUser()->getUnixName() . ")"."\n"; // get the user_id of the assignees $assignees = $this->TrackerItem->getAssignedUsers(); // $c = new Criteria(); foreach ($assignees as $assignee) { if (array_key_exists('assignees', $this->modifiedValues) && is_array($this->modifiedValues['assignees'])) { $marker = (in_array($assignee->getUserId(), $this->modifiedValues['assignees'])?">":""); } else { $marker = ''; } $body .= $marker."Assigned to: ". $assignee->getFirstName() . " " . $assignee->getLastName() . " (". $assignee->getUnixName() . ")"."\n"; } $body .= $summary_marker. "Summary: ". $this->getGenericSummary() ." \n"; // add the extra fields $extra_fields = $this->TrackerItem->getTracker()->getTrackerExtraFields(); $datas=$this->TrackerItem->getTrackerExtraFieldDatas(); $selected=array(); foreach ($datas as $data) { $selected[$data->getTrackerExtraFieldId()][]=$data->getFieldData(); } foreach ($extra_fields as $field) { if (array_key_exists('extra_fields', $this->modifiedValues) && is_array($this->modifiedValues['extra_fields'])) { $marker = (in_array($field->getTrackerExtraFieldId(), $this->modifiedValues['extra_fields'])?">":""); } else { $marker = ''; } $body .= $marker.$field->getFieldName() .": "; // $extra_field->getFieldData()."\n"; $str = 'N/A'; switch ($field->getFieldType()) { case TrackerExtraField::TYPE_SELECT: case TrackerExtraField::TYPE_RADIO: case TrackerExtraField::TYPE_STATUS: { if (isset($selected[$field->getTrackerExtraFieldId()])) { $element=TrackerExtraFieldElementPeer::retrieveByPk($selected[$field->getTrackerExtraFieldId()][0]); if (is_object($element)) { $str=$element->getElementName(); } else { $str='N/A'; } } else { $str='N/A'; } break; } case TrackerExtraField::TYPE_RELEASE: { if (isset($selected[$field->getTrackerExtraFieldId()])) { $element=FrsReleasePeer::retrieveByPk($selected[$field->getTrackerExtraFieldId()][0]); if (is_object($element)) { $str=$element->getReleaseName(); } else { $str='N/A'; } } else { $str='N/A'; } break; } case TrackerExtraField::TYPE_CHECKBOX: case TrackerExtraField::TYPE_MULTISELECT: { $crit = new Criteria(); $crit->add(TrackerExtraFieldElementPeer::ELEMENT_ID,$selected[$field->getTrackerExtraFieldId()],Criteria::IN); $elements=TrackerExtraFieldElementPeer::doSelect($crit); $str=''; foreach ($elements as $element) { $str .= $element->getElementName().', '; } break; } // case TrackerExtraField::TYPE_DATE: // case TrackerExtraField::TYPE_NUMERIC: // case TrackerExtraField::TYPE_TEXT: // case TrackerExtraField::TYPE_TEXTAREA: { default: { if (isset($selected[$field->getTrackerExtraFieldId()])) { $str=$selected[$field->getTrackerExtraFieldId()][0]; } else { $str='N/A'; } } } //end switch $body .= $str."\n"; unset($str); } //construct the body $body .= "\n\nInitial Comment:". "\n". StringUtils::unHtmlSpecialChars($this->TrackerItem->getDetails()) . "\n\n----------------------------------------------------------------------"; $TrackItemUrl=$url->getFullUrl($url->projectUrl($this->TrackerItem->getTracker()->getProject(), 'TrackerItemEdit', 'tracker', '', array('tracker_id' => $this->TrackerItem->getTrackerId(), 'tracker_item_id' => $this->TrackerItem->getPrimaryKey())), true)."\n"; //$TrackItemUrl=substr($TrackItemUrl,0,31).":81".substr($TrackItemUrl,31,-1); $body .= "\n\nYou can respond by visiting: ". "\n".$TrackItemUrl. "\nOr by replying to this e-mail entering your response between the following markers: ". "\n\n".TrackerItemNotification::TRACKER_MAIL_MARKER. "\n(enter your response here)". "\n".TrackerItemNotification::TRACKER_MAIL_MARKER. "\n\n----------------------------------------------------------------------"; // include the followups $c = new Criteria(); $c->addAscendingOrderByColumn(TrackerItemMessagePeer::TRACKER_ITEM_MESSAGE_ID); $followups = $this->TrackerItem->getTrackerItemMessages($c); // get the followups for this item if (count($followups)>0) { $body .= "\n\nFollow-Ups:"; foreach ($followups as $followup) { $body .= "\n\n-------------------------------------------------------"; $body .= "\nDate: ". $followup->getAdddate(); $body .= "\nBy: ". $followup->getUser()->getFirstName() . " " . $followup->getUser()->getLastName(); $body .= "\n\nComment:\n". StringUtils::unHtmlSpecialChars($followup->getBody()); // add the user who posted the followups' email to the email list } } return $body; } /** * getNotificationMessage - construct a string of this message content. * * @param User * @return string */ function getNotificationMessage(User $User) { $url = GFUrl::getUrl(); $body = $this->getGenericMessage(); // Some users that aren't monitoring may be notified, so include the following message // only if the user is monitoring $monitors_tracker = $this->Tracker->userIsMonitoring($User); $monitors_trackeritem = $this->TrackerItem->userIsMonitoring($User); if ($monitors_tracker || $monitors_trackeritem) { $TrackItemUrl=$url->getFullUrl($url->baseUrl('Login', '', 'account'), true)."\n";; //$TrackItemUrl=substr($TrackItemUrl,0,31).":81".substr($TrackItemUrl,31,-1); $body .= "\n\n______________________________________________________________________". "\n\nYou received this email because you ". "\nrequested to be notified when changes were made to this tracker.". "\nIf you don't wish to be notified in the future, please". "\nlogin to " . $TrackItemUrl . " and click this link: "; if ($monitors_trackeritem) { $TrackItemUrl=$url->getFullUrl($url->getMonitorURL(TrackerItem::SECTION, $this->TrackerItem->getPrimaryKey(), $url->projectUrl($this->Project, '', 'tracker'), false), true)."\n";; //$TrackItemUrl=substr($TrackItemUrl,0,31).":81".substr($TrackItemUrl,31,-1); $body .= "\n" . $TrackItemUrl . "\n" ; } elseif ($monitors_tracker) { $TrackItemUrl=$url->getFullUrl($url->getMonitorURL(Tracker::SECTION, $this->TrackerItem->getTracker()->getPrimaryKey(), $url->projectUrl($this->Project, '', 'tracker'), false),true); //$TrackItemUrl=substr($TrackItemUrl,0,31).":81".substr($TrackItemUrl,31,-1); $body .= "\n" . $TrackItemUrl ; } } return $body; } private function getGenericSummary() { $summary = $this->TrackerItem->getSummary(); return StringUtils::unHtmlSpecialChars($summary); } /** * getSummary - construct a string of this message summary (html chars unconverted). * * @param User * @return string */ function getSummary(User $User) { return $this->getGenericSummary(); } /** * getDetails - construct a string of this message summary (html chars unconverted). * * @param User * @return string */ function getDetails(User $User) { $details = $this->TrackerItem->getDetails(); return utf8_decode(StringUtils::unHtmlSpecialChars($details)); } /** * getNotificationSubject - construct a string of this message subject. * * @param User * @return string */ function getNotificationSubject(User $User) { return $this->getGenericSubject(); } function getGenericSubject() { $subject="[ " . $this->TrackerItem->getTracker()->getProject()->getUnixName() . " " . $this->TrackerItem->getTracker()->getTrackerName() ." Item #". $this->TrackerItem->getPrimaryKey() .'] '. $this->getGenericSummary(); return $subject; } /** * getUsers - get an array of user objects * @return array */ public function getUsers() { return $this->TrackerItem->getMonitoringUsers(); // tracker item or tracker or project monitors } /** * getSection - retrieves the section name of the trackeritem * @return string */ function getSection() { return TrackerItem::SECTION; } /** * getRefId - retrieves the id of the trackeritem that the notification belongs to * @return int */ function getRefId() { return $this->TrackerItem->getPrimaryKey(); } public function notifyUpdate() { $addresses = StringUtils::getAddressesFromList($this->TrackerItem->getTracker()->getEmailAddress()); foreach ($addresses as $address) { $message = $this->getGenericMessage(); $subject = $this->getGenericSubject().' (trackeritem-'.$this->TrackerItem->getPrimaryKey().')'; SystemUtils::sendMail($subject, $message, $address,false,SystemUtils::getFromAddress('gforge-gateway')); } } } ?>