r857: Finished implementing fetch_user_cache()
[bugdar.git] / includes / class_notification.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * Notification Center
24 *
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.
27 *
28 * @author Iris Studios, Inc.
29 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
30 * @version $Revision$
31 * @package Bugdar
32 *
33 */
34 class NotificationCenter
35 {
36 /**
37 * Bug information
38 * @var array
39 * @access private
40 */
41 var $bug = array();
42
43 /**
44 * Global bugsys registry
45 * @var object
46 * @access private
47 */
48 var $registry = null;
49
50 /**
51 * Role list: a list of user IDs with their relations to the bug
52 * @var array
53 * @access private
54 */
55 var $roles = array(
56 '-notapplicable-' => array(),
57 'reporter' => array(),
58 'assignee' => array(),
59 'favourite' => array(),
60 'voter' => array(),
61 'commenter' => array()
62 );
63
64 /**
65 * User cache list
66 * @var array
67 * @access private
68 */
69 var $users = array();
70
71 // ###################################################################
72 /**
73 * Constructor: set database objects
74 *
75 * @access public
76 */
77 function __construct()
78 {
79 global $bugsys;
80
81 $this->registry =& $bugsys;
82 }
83
84 // ###################################################################
85 /**
86 * (PHP 4) Constructor
87 *
88 * @access public
89 */
90 function NotificationCenter()
91 {
92 $this->__construct();
93 }
94
95 // ###################################################################
96 /**
97 * Fetches all the users who could be related to the bug and sticks
98 * their information into an array.
99 *
100 * @access private
101 */
102 function fetch_user_cache()
103 {
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))
106 {
107 $this->roles['favourite']["$fav[userid]"] = $fav['userid'];
108 }
109
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']);
112
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))
115 {
116 $this->roles['commenter']["$comment[userid]"] = $comment['userid'];
117 }
118
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);
121
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) . ")
128 ");
129 while ($user = $this->registry->db->fetch_array($userinfo))
130 {
131 if (!is_array($this->users["$user[userid]"]))
132 {
133 $this->users["$user[userid]"] = $user;
134 unset($this->users["$user[userid]"]['mask'], $this->users["$user[userid]"]['relation']);
135 }
136 $this->users["$user[userid]"]['options']["$user[relation]"] = $user['mask'];
137 }
138 }
139
140 // ###################################################################
141 /**
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.
146 *
147 * @access public
148 *
149 * @param array Original data (BugAPI->objdata)
150 * @param array Modified data (BugAPI->values)
151 */
152 function send_bug_changes_notice($original, $modified)
153 {
154 $this->bug = $modified;
155
156 $this->roles['-notapplicable-'] = array($original['assignedto'], $modified['assignedto']);
157 $this->roles['reporter'] = array($original['userid']);
158 $this->roles['assignee'] = array($modified['assignedto']);
159
160 $this->fetch_user_cache();
161
162 if ($original['assignedto'] != $modified['assignedto'])
163 {
164 if ($original['assignedto'] != '')
165 {
166 $this->notice_no_longer_assigned($original['assignedto']);
167 }
168 if ($modified['assignedto'] != '')
169 {
170 $this->notice_now_assigned($modified['assignedto']);
171 }
172 }
173
174 if ($original['status'] != $modified['status'])
175 {
176 $this->notice_status_change($original['status'], $modified['status']);
177 }
178 if ($original['resolution'] != $modified['resoultion'])
179 {
180 $this->notice_resolution_change($original['resolution'], $modified['resolution']);
181 }
182
183 if ($original['duplicates'] != $modified['duplicates'])
184 {
185 $this->notice_duplicates_change($original['duplicates'], $modified['duplicates']);
186 }
187 }
188
189 // ###################################################################
190 /**
191 * Sends an email to the specified user ID that they are no longer the
192 * person assigned to the bug.
193 *
194 * @access private
195 *
196 * @param integer User ID to send to
197 */
198 function notice_no_longer_assigned($userid)
199 {
200 if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'])
201 {
202
203 }
204 }
205
206 // ###################################################################
207 /**
208 * Informs the user that they have been made the assignee of the bug.
209 *
210 * @access private
211 *
212 * @param integer User ID
213 */
214 function notice_now_assigned($userid)
215 {
216 if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'])
217 {
218
219 }
220 }
221
222 // ###################################################################
223 /**
224 * Sends a message to inform users that the status has changed.
225 *
226 * @access private
227 *
228 * @param integer Old status
229 * @param integer New status
230 */
231 function notice_status_change($old, $new)
232 {
233
234 }
235
236 // ###################################################################
237 /**
238 * Sends an email to inform users that the resolution has changed.
239 *
240 * @access private
241 *
242 * @param integer Old resolution
243 * @param integer New resolution
244 */
245 function notice_resolution_change($old, $new)
246 {
247
248 }
249
250 // ###################################################################
251 /**
252 * Informs users that the duplicates list has changed.
253 *
254 * @access private
255 *
256 * @param string Old duplicates list
257 * @param string New duplicates list
258 */
259 function notice_duplicates_change($old, $new)
260 {
261
262 }
263 }
264
265 /*=====================================================================*\
266 || ###################################################################
267 || # $HeadURL$
268 || # $Id$
269 || ###################################################################
270 \*=====================================================================*/
271 ?>