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($bug['bugid'], TYPE_UINT
));
105 while ($fav = $this->registry
->db
->fetch_array($favourites))
107 $this->roles
['favourite']["$fav[userid]"] = $fav['userid'];
110 $voters = $this->regisry
->db
->query_first("SELECT userids FROM " . TABLE_PREFIX
. "vote WHERE bugid = " . $this->registry
->clean($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($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);
125 // ###################################################################
127 * Sends the appropriate emails for changes to bugs. This function
128 * works a lot like the Logging class by taking BugAPI->objdata and
129 * BugAPI->values and then comparing the two arries and sending emails
130 * with the differences.
134 * @param array Original data (BugAPI->objdata)
135 * @param array Modified data (BugAPI->values)
137 function send_bug_changes_notice($original, $modified)
139 $this->bug
= $modified;
141 $this->roles
['-notapplicable-'] = array($original['assignedto'], $modified['assignedto']);
142 $this->roles
['reporter'] = array($original['userid']);
143 $this->roles
['assignee'] = array($modified['assignedto']);
145 $this->fetch_user_cache();
147 if ($original['assignedto'] != $modified['assignedto'])
149 if ($original['assignedto'] != '')
151 $this->notice_no_longer_assigned($original['assignedto']);
153 if ($modified['assignedto'] != '')
155 $this->notice_now_assigned($modified['assignedto']);
159 if ($original['status'] != $modified['status'])
161 $this->notice_status_change($original['status'], $modified['status']);
163 if ($original['resolution'] != $modified['resoultion'])
165 $this->notice_resolution_change($original['resolution'], $modified['resolution']);
168 if ($original['duplicates'] != $modified['duplicates'])
170 $this->notice_duplicates_change($original['duplicates'], $modified['duplicates']);
174 // ###################################################################
176 * Sends an email to the specified user ID that they are no longer the
177 * person assigned to the bug.
181 * @param integer User ID to send to
183 function notice_no_longer_assigned($userid)
185 if ($this->users
["$userid"]['options'][0] & $this->registry
->emailoptions
['notifications']['assignedto'])
191 // ###################################################################
193 * Informs the user that they have been made the assignee of the bug.
197 * @param integer User ID
199 function notice_now_assigned($userid)
201 if ($this->users
["$userid"]['options'][0] & $this->registry
->emailoptions
['notifications']['assignedto'])
207 // ###################################################################
209 * Sends a message to inform users that the status has changed.
213 * @param integer Old status
214 * @param integer New status
216 function notice_status_change($old, $new)
221 // ###################################################################
223 * Sends an email to inform users that the resolution has changed.
227 * @param integer Old resolution
228 * @param integer New resolution
230 function notice_resolution_change($old, $new)
235 // ###################################################################
237 * Informs users that the duplicates list has changed.
241 * @param string Old duplicates list
242 * @param string New duplicates list
244 function notice_duplicates_change($old, $new)
250 /*=====================================================================*\
251 || ###################################################################
254 || ###################################################################
255 \*=====================================================================*/