array(), 'reporter' => array(), 'assignee' => array(), 'favourite' => array(), 'voter' => array(), 'commenter' => array() ); /** * User cache list * @var array * @access private */ var $users = array(); /** * A list of notices per-user that are combined together in NotificationCenter::finalize() * @var array * @access private */ var $notices = array(); // ################################################################### /** * Constructor: set database objects * * @access public */ function __construct() { global $bugsys; $this->registry =& $bugsys; } // ################################################################### /** * (PHP 4) Constructor * * @access public */ function NotificationCenter() { $this->__construct(); } // ################################################################### /** * Sets the bug data so that all methods in this class have access to * it when sending emails. * * @access public * * @param array Original bug data * @param array Modified bug data */ function set_bug_data($original, $modified = array()) { if (sizeof($modified) > 0) { $this->bug = $modified; } $this->original = $original; $this->modified = $modified; $this->roles['-notapplicable-'] = (sizeof($modified) > 0 ? array($original['assignedto'], $modified['assignedto']) : array($original['assignedto'])); $this->roles['reporter'] = array($original['userid']); $this->roles['assignee'] = (sizeof($modified) > 0 ? array($modified['assignedto']) : array($original['assignedto'])); $this->fetch_user_cache(); } // ################################################################### /** * Fetches all the users who could be related to the bug and sticks * their information into an array. * * @access private */ function fetch_user_cache() { $favourites = $this->registry->db->query("SELECT userid FROM " . TABLE_PREFIX . "favourite WHERE bugid = " . $this->registry->clean($this->bug['bugid'], TYPE_UINT)); while ($fav = $this->registry->db->fetch_array($favourites)) { $this->roles['favourite']["$fav[userid]"] = $fav['userid']; } $voters = $this->registry->db->query_first("SELECT userids FROM " . TABLE_PREFIX . "vote WHERE bugid = " . $this->registry->clean($this->bug['bugid'], TYPE_UINT)); $this->roles['voter'] = preg_split('#,#', $voters['userids'], 0, PREG_SPLIT_NO_EMPTY); $commenters = $this->registry->db->query("SELECT userid FROM " . TABLE_PREFIX . "comment WHERE bugid = " . $this->registry->clean($this->bug['bugid'], TYPE_UINT)); while ($comment = $this->registry->db->fetch_array($commenters)) { $this->roles['commenter']["$comment[userid]"] = $comment['userid']; } $masterids = array_merge($this->roles['-notapplicable-'], $this->roles['reporter'], $this->roles['assignee'], $this->roles['favourite'], $this->roles['voter'], $this->roles['commenter']); $masterids = array_unique($masterids); $userinfo = $this->registry->db->query(" SELECT user.*, useremail.* FROM " . TABLE_PREFIX . "useremail AS useremail LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = useremail.userid) WHERE useremail.userid IN (" . implode(',', $masterids) . ") "); while ($user = $this->registry->db->fetch_array($userinfo)) { if (!is_array($this->users["$user[userid]"])) { $this->users["$user[userid]"] = $user; unset($this->users["$user[userid]"]['mask'], $this->users["$user[userid]"]['relation']); } $this->users["$user[userid]"]['options']["$user[relation]"] = $user['mask']; } } // ################################################################### /** * Sends the appropriate emails for changes to bugs. This function * works a lot like the Logging class by taking BugAPI->objdata and * BugAPI->values and then comparing the two arries and sending emails * with the differences. * * @access public */ function send_bug_changes_notice() { if (!isset($this->modified['bugid'])) { return; } if ($this->original['assignedto'] != $this->modified['assignedto']) { if ($this->original['assignedto'] != '') { $this->notice_no_longer_assigned($this->original['assignedto']); } if ($this->modified['assignedto'] != '') { $this->notice_now_assigned($this->modified['assignedto']); } } if ($this->original['status'] != $this->modified['status']) { $this->notice_status_change($this->original['status'], $this->modified['status']); } if ($this->original['resolution'] != $this->modified['resoultion']) { $this->notice_resolution_change($this->original['resolution'], $this->modified['resolution']); } if ($this->original['duplicates'] != $this->modified['duplicates']) { $this->notice_duplicates_change($this->original['duplicates'], $this->modified['duplicates']); } } // ################################################################### /** * Sends an email to the specified user ID that they are no longer the * person assigned to the bug. * * @access private * * @param integer User ID to send to */ function notice_no_longer_assigned($userid) { if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'] AND in_array($userid, $this->roles['-notapplicable-'])) { $this->notices["$userid"][] = sprintf( $this->registry->lang->string('You are no longer assigned to this bug, per %1$s\'s changes.'), construct_user_display($this->registry->userinfo, false) ); } } // ################################################################### /** * Informs the user that they have been made the assignee of the bug. * * @access private * * @param integer User ID */ function notice_now_assigned($userid) { if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'] AND in_array($userid, $this->roles['-notapplicable-'])) { $this->notices["$userid"][] = sprintf( $this->registry->lang->string('You have been assigned to this bug by %1$s.'), construct_user_display($this->registry->userinfo, false) ); } } // ################################################################### /** * Sends a message to inform users that the status has changed. * * @access private * * @param integer Old status * @param integer New status */ function notice_status_change($old, $new) { $userlist = $this->fetch_users_with_on_bit('statusresolve'); foreach ($userlist AS $userid => $user) { $this->notices["$user[userid]"][] = sprintf( $this->registry->lang->string('The status field has changed from "%1$s" to "%2$s".'), $this->registry->datastore['status']["$old"]['status'], $this->registry->datastore['status']["$new"]['status'] ); } } // ################################################################### /** * Sends an email to inform users that the resolution has changed. * * @access private * * @param integer Old resolution * @param integer New resolution */ function notice_resolution_change($old, $new) { $userlist = $this->fetch_users_with_on_bit('statusresolve'); foreach ($userlist AS $userid => $user) { $this->notices["$user[userid]"][] = sprintf( $this->registry->lang->string('The resolution field has changed from "%1$s" to "%2$s".'), $this->registry->datastore['resolution']["$old"]['resolution'], $this->registry->datastore['resolution']["$new"]['resolution'] ); } } // ################################################################### /** * Informs users that the duplicates list has changed. * * @access private * * @param string Old duplicates list * @param string New duplicates list */ function notice_duplicates_change($old, $new) { } // ################################################################### /** * Sends the appropriate users information about a new comment being * posted to the bug report. * * @access public * * @param array CommentAPI->values array */ function send_new_comment_notice($comment) { $userlist = $this->fetch_users_with_on_bit('newcomment'); foreach ($userlist AS $userid => $user) { $this->notices["$user[userid]"][] = sprintf( $this->registry->lang->string('The following comment was added by %1$s on %2$s: ============================================ %3$s ============================================'), construct_user_display($this->registry->userinfo, false), $this->registry->modules['date']->format($this->registry->options['dateformat'], $comment['dateline']), $comment['comment'] ); } } // ################################################################### /** * Generates an array of users who have a given email notification flag * turned on in their bitfields. * * @access private * * @param string Notification bitfield name * * @return array Array of users and their data */ function fetch_users_with_on_bit($bitname) { $idlist = array(); foreach ($this->users AS $user) { foreach ($this->registry->emailoptions['relations'] AS $name => $bit) { if (in_array($user['userid'], $this->roles["$name"]) AND $user['options']["$bit"] & $this->registry->emailoptions['notifications']["$bitname"]) { $idlist[] = $user['userid']; } } } $masters = array_unique($idlist); $return = array(); foreach ($masters AS $userid) { $return["$userid"] =& $this->users["$userid"]; } return $return; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>