diff --git a/include/class.ticket.php b/include/class.ticket.php index cd3a649ec71323b2419caa6301d80021a390ca7d..2e98d8654e0fe62675ef350bc3824316bd2b84a5 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -598,6 +598,23 @@ class Ticket { return $this->collaborators; } + //UserList of recipients (owner + collaborators) + function getRecipients() { + + if (!isset($this->recipients)) { + $list = new UserList(); + $list->add($this->getOwner()); + if ($collabs = $this->getActiveCollaborators()) { + foreach ($collabs as $c) + $list->add($c); + } + $this->recipients = $list; + } + + return $this->recipients; + } + + function addCollaborator($user, $vars, &$errors) { if (!$user || $user->getId()==$this->getOwnerId()) @@ -610,6 +627,7 @@ class Ticket { return null; $this->collaborators = null; + $this->recipients = null; return $c; } @@ -958,14 +976,13 @@ class Ticket { if (!$vars || !$vars['variables'] - || !($collaborators=$this->getActiveCollaborators()) + || !($recipients=$this->getRecipients()) || !($dept=$this->getDept()) || !($tpl=$dept->getTemplate()) || !($msg=$tpl->getActivityNoticeMsgTemplate()) || !($email=$dept->getEmail())) return; - $msg = $this->replaceVars($msg->asArray(), $vars['variables']); if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator())) @@ -978,9 +995,9 @@ class Ticket { if($vars['references']) $options['references'] = $vars['references']; - foreach($collaborators as $collaborator) { - $notice = $this->replaceVars($msg, array('recipient' => $collaborator)); - $email->send($collaborator->getEmail(), $notice['subj'], $notice['body'], $attachments, + foreach($recipients as $recipient) { + $notice = $this->replaceVars($msg, array('recipient' => $recipient)); + $email->send($recipient->getEmail(), $notice['subj'], $notice['body'], $attachments, $options); } diff --git a/include/class.user.php b/include/class.user.php index 1212627e5d81c38590773cfd91d7b61dff0fa3ea..e74e922a56e65ebf82bccbcdc2d7393688fc3e7f 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -468,4 +468,55 @@ class UserEmail extends UserEmailModel { } } + +/* + * Generic user list. + */ +class UserList implements IteratorAggregate, ArrayAccess { + private $users; + + function __construct($list = array()) { + $this->users = $list; + } + + function add($user) { + $this->offsetSet(null, $user); + } + + function offsetSet($offset, $value) { + + if (is_null($offset)) + $this->users[] = $value; + else + $this->users[$offset] = $value; + } + + function offsetExists($offset) { + return isset($this->users[$offset]); + } + + function offsetUnset($offset) { + unset($this->users[$offset]); + } + + function offsetGet($offset) { + return isset($this->users[$offset]) ? $this->users[$offset] : null; + } + + function getIterator() { + return new ArrayIterator($this->users); + } + + function __toString() { + + $list = array(); + foreach($this->users as $user) { + if (is_object($user)) + $list [] = $user->getName(); + } + + return $list ? implode(', ', $list) : ''; + } +} + ?>