Skip to content
Snippets Groups Projects
Commit 231a2fa2 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add iteratable UserList class

Add routine to get ticket's recipients (owner + active collaborators)
parent d8e06626
Branches
Tags
No related merge requests found
......@@ -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);
}
......
......@@ -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) : '';
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment