r856: Now we get information correctly in 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 print_r($masterids);
123 }
124
125 // ###################################################################
126 /**
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.
131 *
132 * @access public
133 *
134 * @param array Original data (BugAPI->objdata)
135 * @param array Modified data (BugAPI->values)
136 */
137 function send_bug_changes_notice($original, $modified)
138 {
139 $this->bug = $modified;
140
141 $this->roles['-notapplicable-'] = array($original['assignedto'], $modified['assignedto']);
142 $this->roles['reporter'] = array($original['userid']);
143 $this->roles['assignee'] = array($modified['assignedto']);
144
145 $this->fetch_user_cache();
146
147 if ($original['assignedto'] != $modified['assignedto'])
148 {
149 if ($original['assignedto'] != '')
150 {
151 $this->notice_no_longer_assigned($original['assignedto']);
152 }
153 if ($modified['assignedto'] != '')
154 {
155 $this->notice_now_assigned($modified['assignedto']);
156 }
157 }
158
159 if ($original['status'] != $modified['status'])
160 {
161 $this->notice_status_change($original['status'], $modified['status']);
162 }
163 if ($original['resolution'] != $modified['resoultion'])
164 {
165 $this->notice_resolution_change($original['resolution'], $modified['resolution']);
166 }
167
168 if ($original['duplicates'] != $modified['duplicates'])
169 {
170 $this->notice_duplicates_change($original['duplicates'], $modified['duplicates']);
171 }
172 }
173
174 // ###################################################################
175 /**
176 * Sends an email to the specified user ID that they are no longer the
177 * person assigned to the bug.
178 *
179 * @access private
180 *
181 * @param integer User ID to send to
182 */
183 function notice_no_longer_assigned($userid)
184 {
185 if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'])
186 {
187
188 }
189 }
190
191 // ###################################################################
192 /**
193 * Informs the user that they have been made the assignee of the bug.
194 *
195 * @access private
196 *
197 * @param integer User ID
198 */
199 function notice_now_assigned($userid)
200 {
201 if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'])
202 {
203
204 }
205 }
206
207 // ###################################################################
208 /**
209 * Sends a message to inform users that the status has changed.
210 *
211 * @access private
212 *
213 * @param integer Old status
214 * @param integer New status
215 */
216 function notice_status_change($old, $new)
217 {
218
219 }
220
221 // ###################################################################
222 /**
223 * Sends an email to inform users that the resolution has changed.
224 *
225 * @access private
226 *
227 * @param integer Old resolution
228 * @param integer New resolution
229 */
230 function notice_resolution_change($old, $new)
231 {
232
233 }
234
235 // ###################################################################
236 /**
237 * Informs users that the duplicates list has changed.
238 *
239 * @access private
240 *
241 * @param string Old duplicates list
242 * @param string New duplicates list
243 */
244 function notice_duplicates_change($old, $new)
245 {
246
247 }
248 }
249
250 /*=====================================================================*\
251 || ###################################################################
252 || # $HeadURL$
253 || # $Id$
254 || ###################################################################
255 \*=====================================================================*/
256 ?>