Index: Notifier.class.php =================================================================== --- Notifier.class.php (revision 177) +++ Notifier.class.php (working copy) @@ -142,7 +142,35 @@ tpl_fetch(get_template_path('new_comment', 'notifier')) ); // send } // newMessageComment + + /** + * Tests to see if $new_user is not the same as $old_user + * if users are different return true so a notification can be sent + * otherwise return false so the notification can be avoided + * + * @param $new_user (optional) Newly assigned user (if applicable) + * @param $old_user (optional) Previously assigned user (if applicable) + * @return boolean + */ + static function nodifyNeeded($new_user, $old_user) { + if ($old_user instanceof User) { + // We have a new owner and it is different than old owner + if ($new_user instanceof User && $new_user->getId() <> $old_user->getId()) { + return true; + } + } else { + // We have new owner + if ($new_user instanceof User) { + return true; + } + } // if + + return false; + + } + + // --------------------------------------------------- // Milestone // --------------------------------------------------- @@ -171,7 +199,86 @@ tpl_fetch(get_template_path('milestone_assigned', 'notifier')) ); // send } // milestoneAssigned + + /** + * Task has been assigned to the user + * + * @param ProjectTask $task + * @return boolean + * @throws NotifierConnectionError + */ + function taskAssigned(ProjectTask $task) { + if ($task->isCompleted()) { + return true; // task has been already completed... + } // if + if (!($task->getAssignedTo() instanceof User)) { + return true; // not assigned to user + } // if + + tpl_assign('task_assigned', $task); + + return self::sendEmail( + self::prepareEmailAddress($task->getAssignedTo()->getEmail(), $task->getAssignedTo()->getDisplayName()), + self::prepareEmailAddress($task->getCreatedBy()->getEmail(), $task->getCreatedByDisplayName()), + $task->getProject()->getName() . ' - ' . lang('task assigned to you') . " - " . $task->getText(), + tpl_fetch(get_template_path('task_assigned', 'notifier'), 'html') + ); // send + + + + } // milestoneAssigned + + /** + * Send new comment notification to selected users, if not message (because message is already treated and can subscribre/unsubscribe) + * + * @param comment $comment + * @return boolean + * @throws NotifierConnectionError + */ + static function newOtherComment(Comment $comment, $people) { + if (!is_array($people) || !count($people)) { + return; // nothing here... + } // if + + // normally, if comment on message, shouldn't be using this function by the normal subscription + if (($comment->getObject() instanceof ProjectMessage)) { + throw new Error('Invalid comment object'); + } // if + + if (!is_array($people)) { + return true; // no subscribers + } // if + + $recipients = array(); + foreach ($people as $subscriber) { + if ($subscriber->getId() == $comment->getCreatedById()) { + continue; // skip comment author + } // if + + if ($comment->isPrivate()) { + if ($subscriber->isMemberOfOwnerCompany()) { + $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName()); + } // if + } else { + $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName()); + } // of + } // foreach + + if (!count($recipients)) { + return true; // no recipients + } // if + + tpl_assign('new_comment', $comment); + + return self::sendEmail( + $recipients, + self::prepareEmailAddress($comment->getCreatedBy()->getEmail(), $comment->getCreatedByDisplayName()), + $comment->getProject()->getName(), + tpl_fetch(get_template_path('new_comment', 'notifier')) + ); // send + } // newOtherComment + // --------------------------------------------------- // Util functions // --------------------------------------------------- @@ -217,7 +324,7 @@ * @param string content-transfer-encoding,optional * @return bool successful */ - static function sendEmail($to, $from, $subject, $body = false, $type = 'text/plain', $encoding = '8bit') { + static function sendEmail($to, $from, $subject, $body = false, $type = 'text/html', $encoding = '') { Env::useLibrary('swift'); $mailer = self::getMailer();