2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
25 * This class determines which emails need to be sent out based on user
26 * options and bug changes, and then it sends said emails.
28 * @author Iris Studios, Inc.
29 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
34 class NotificationCenter
44 * Global bugsys registry
51 * Role list: a list of user IDs with their relations to the bug
56 '-notapplicable-' => array(),
57 'reporter' => array(),
58 'assignee' => array(),
59 'favourite' => array(),
61 'commenter' => array()
71 // ###################################################################
73 * Constructor: set database objects
77 function __construct()
81 $this->registry
=& $bugsys;
84 // ###################################################################
90 function NotificationCenter()
95 // ###################################################################
97 * Fetches all the users who could be related to the bug and sticks
98 * their information into an array.
102 function fetch_user_cache()
104 $favourites = $this->registry
->db
->query("SELECT userid FROM " . TABLE_PREFIX
. "favourite WHERE bugid = " . $this->registry
->clean($this->bug
['bugid'], TYPE_UINT
));
105 while ($fav = $this->registry
->db
->fetch_array($favourites))
107 $this->roles
['favourite']["$fav[userid]"] = $fav['userid'];
110 $voters = $this->registry
->db
->query_first("SELECT userids FROM " . TABLE_PREFIX
. "vote WHERE bugid = " . $this->registry
->clean($this->bug
['bugid'], TYPE_UINT
));
111 $this->roles
['voter'] = explode(',', $voters['userids']);
113 $commenters = $this->registry
->db
->query("SELECT userid FROM " . TABLE_PREFIX
. "comment WHERE bugid = " . $this->registry
->clean($this->bug
['bugid'], TYPE_UINT
));
114 while ($comment = $this->registry
->db
->fetch_array($commenters))
116 $this->roles
['commenter']["$comment[userid]"] = $comment['userid'];
119 $masterids = array_merge($this->roles
['-notapplicable-'], $this->roles
['reporter'], $this->roles
['assignee'], $this->roles
['favourite'], $this->roles
['voter'], $this->roles
['commenter']);
120 $masterids = array_unique($masterids);
122 $userinfo = $this->registry
->db
->query("
123 SELECT user.*, useremail.*
124 FROM " . TABLE_PREFIX
. "useremail AS useremail
125 LEFT JOIN " . TABLE_PREFIX
. "user AS user
126 ON (user.userid = useremail.userid)
127 WHERE useremail.userid IN (" . implode(',', $masterids) . ")
129 while ($user = $this->registry
->db
->fetch_array($userinfo))
131 if (!is_array($this->users
["$user[userid]"]))
133 $this->users
["$user[userid]"] = $user;
134 unset($this->users
["$user[userid]"]['mask'], $this->users
["$user[userid]"]['relation']);
136 $this->users
["$user[userid]"]['options']["$user[relation]"] = $user['mask'];
140 // ###################################################################
142 * Sends the appropriate emails for changes to bugs. This function
143 * works a lot like the Logging class by taking BugAPI->objdata and
144 * BugAPI->values and then comparing the two arries and sending emails
145 * with the differences.
149 * @param array Original data (BugAPI->objdata)
150 * @param array Modified data (BugAPI->values)
152 function send_bug_changes_notice($original, $modified)
154 $this->bug
= $modified;
156 $this->roles
['-notapplicable-'] = array($original['assignedto'], $modified['assignedto']);
157 $this->roles
['reporter'] = array($original['userid']);
158 $this->roles
['assignee'] = array($modified['assignedto']);
160 $this->fetch_user_cache();
162 if ($original['assignedto'] != $modified['assignedto'])
164 if ($original['assignedto'] != '')
166 $this->notice_no_longer_assigned($original['assignedto']);
168 if ($modified['assignedto'] != '')
170 $this->notice_now_assigned($modified['assignedto']);
174 if ($original['status'] != $modified['status'])
176 $this->notice_status_change($original['status'], $modified['status']);
178 if ($original['resolution'] != $modified['resoultion'])
180 $this->notice_resolution_change($original['resolution'], $modified['resolution']);
183 if ($original['duplicates'] != $modified['duplicates'])
185 $this->notice_duplicates_change($original['duplicates'], $modified['duplicates']);
189 // ###################################################################
191 * Sends an email to the specified user ID that they are no longer the
192 * person assigned to the bug.
196 * @param integer User ID to send to
198 function notice_no_longer_assigned($userid)
200 if ($this->users
["$userid"]['options'][0] & $this->registry
->emailoptions
['notifications']['assignedto'])
206 // ###################################################################
208 * Informs the user that they have been made the assignee of the bug.
212 * @param integer User ID
214 function notice_now_assigned($userid)
216 if ($this->users
["$userid"]['options'][0] & $this->registry
->emailoptions
['notifications']['assignedto'])
222 // ###################################################################
224 * Sends a message to inform users that the status has changed.
228 * @param integer Old status
229 * @param integer New status
231 function notice_status_change($old, $new)
236 // ###################################################################
238 * Sends an email to inform users that the resolution has changed.
242 * @param integer Old resolution
243 * @param integer New resolution
245 function notice_resolution_change($old, $new)
250 // ###################################################################
252 * Informs users that the duplicates list has changed.
256 * @param string Old duplicates list
257 * @param string New duplicates list
259 function notice_duplicates_change($old, $new)
265 /*=====================================================================*\
266 || ###################################################################
269 || ###################################################################
270 \*=====================================================================*/