class NotificationCenter
{
/**
- * Bug information
- * @var array
- * @access private
- */
- var $bug = array();
+ * Bug information
+ * @var array
+ */
+ private $bug = array();
/**
- * Original bug data
- * @var array
- * @access private
- */
- var $original = array();
+ * Original bug data
+ * @var array
+ */
+ private $original = array();
/**
- * Modified bug data
- * @var array
- * @access private
- */
- var $modified = array();
+ * Modified bug data
+ * @var array
+ */
+ private $modified = array();
/**
- * Role list: a list of user IDs with their relations to the bug
- * @var array
- * @access private
- */
- var $roles = array(
+ * Role list: a list of user IDs with their relations to the bug
+ * @var array
+ */
+ private $roles = array(
'-notapplicable-' => array(),
'reporter' => array(),
'assignee' => array(),
);
/**
- * User cache list
- * @var array
- * @access private
- */
- var $users = array();
+ * User cache list
+ * @var array
+ */
+ private $users = array();
/**
- * A list of notices per-user that are combined together in NotificationCenter::finalize()
- * @var array
- * @access private
- */
- var $notices = array();
+ * A list of notices per-user that are combined together in NotificationCenter::finalize()
+ * @var array
+ */
+ private $notices = array();
- // ###################################################################
/**
- * 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())
+ * Sets the bug data so that all methods in this class have access to
+ * it when sending emails.
+ *
+ * @param array Original bug data
+ * @param array Modified bug data
+ */
+ public function setBugData($original, $modified = array())
{
if (sizeof($modified) > 0)
{
$this->roles['reporter'] = array($original['userid']);
$this->roles['assignee'][] = (sizeof($modified) > 0 ? $modified['assignedto'] : $original['assignedto']);
- $this->fetch_user_cache();
+ $this->_fetchUserCache();
}
- // ###################################################################
/**
- * Fetches all the users who could be related to the bug and sticks
- * their information into an array.
- *
- * @access private
- */
- function fetch_user_cache()
+ * Fetches all the users who could be related to the bug and sticks
+ * their information into an array.
+ */
+ private function _fetchUserCache()
{
$newbuggers = BSApp::$db->query("SELECT userid FROM " . TABLE_PREFIX . "useremail WHERE relation = " . bugdar::$emailOptions['relations']['-notapplicable-'] . " AND mask & " . bugdar::$emailOptions['notifications']['newbug']);
foreach ($newbuggers as $newbug)
$masterids = array_merge($this->roles['-notapplicable-'], $this->roles['reporter'], $this->roles['assignee'], $this->roles['favorite'], $this->roles['voter'], $this->roles['commenter']);
$masterids = BSFunctions::array_strip_empty(array_unique($masterids));
- if (is_array($masterids) AND sizeof($masterids) > 0)
+ if (is_array($masterids) && sizeof($masterids) > 0)
{
$userinfo = BSApp::$db->query("
SELECT user.*, useremail.*
}
}
- // ###################################################################
/**
- * Sends the appropriate emails for changes to bugs. This function
- * works a lot like the Logging class by taking BugAPI->record and
- * BugAPI->values and then comparing the two arries and sending emails
- * with the differences.
- *
- * @access public
- */
- function send_bug_changes_notice()
+ * Sends the appropriate emails for changes to bugs. This function
+ * works a lot like the Logging class by taking BugAPI->record and
+ * BugAPI->values and then comparing the two arries and sending emails
+ * with the differences.
+ */
+ public function sendBugChangeNotice()
{
if (!isset($this->modified['bugid']))
{
{
if ($this->original['assignedto'] != '')
{
- $this->notice_no_longer_assigned($this->original['assignedto']);
+ $this->_noticeNoLongerAssigned($this->original['assignedto']);
}
if ($this->modified['assignedto'] != '')
{
- $this->notice_now_assigned($this->modified['assignedto']);
+ $this->_noticeNowAssigned($this->modified['assignedto']);
}
}
if ($this->original['status'] != $this->modified['status'])
{
- $this->notice_status_change($this->original['status'], $this->modified['status']);
+ $this->_noticeStatusChange($this->original['status'], $this->modified['status']);
}
if ($this->original['resolution'] != $this->modified['resolution'])
{
- $this->notice_resolution_change($this->original['resolution'], $this->modified['resolution']);
+ $this->_noticeResolutionChange($this->original['resolution'], $this->modified['resolution']);
}
if ($this->original['duplicates'] != $this->modified['duplicates'])
{
- $this->notice_duplicates_change($this->original['duplicates'], $this->modified['duplicates']);
+ $this->_noticeDuplicatesChange($this->original['duplicates'], $this->modified['duplicates']);
}
// other standard fields that don't have custom masks
if ($this->original['severity'] != $this->modified['severity'])
{
- $this->notice_severity_change($this->original['severity'], $this->modified['severity']);
+ $this->_noticeSeverityChange($this->original['severity'], $this->modified['severity']);
}
if ($this->original['priority'] != $this->modified['priority'])
{
- $this->notice_priority_change($this->original['priority'], $this->modified['priority']);
+ $this->_noticePriorityChange($this->original['priority'], $this->modified['priority']);
}
- if (($this->original['product'] != $this->modified['product']) OR ($this->original['component'] != $this->modified['component']) OR ($this->original['version'] != $this->modified['version']))
+ if (($this->original['product'] != $this->modified['product']) || ($this->original['component'] != $this->modified['component']) || ($this->original['version'] != $this->modified['version']))
{
- $this->notice_pcv_change(array($this->original['product'], $this->original['component'], $this->original['version']), array($this->modified['product'], $this->modified['component'], $this->modified['version']));
+ $this->_noticePCVChange(array($this->original['product'], $this->original['component'], $this->original['version']), array($this->modified['product'], $this->modified['component'], $this->modified['version']));
}
$dofields = array(
'dependency' => -1,
'hidden' => -1
);
- foreach ($dofields AS $field => $lookup)
+ foreach ($dofields as $field => $lookup)
{
if ($this->original["$field"] != $this->modified["$field"])
{
- $this->notice_other_change($field, $this->original["$field"], $this->modified["$field"]);
+ $this->_noticeOtherChange($field, $this->original["$field"], $this->modified["$field"]);
}
}
}
- // ###################################################################
/**
- * 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)
+ * Sends an email to the specified user ID that they are no longer the
+ * person assigned to the bug.
+ *
+ * @param integer User ID to send to
+ */
+ private function _noticeNoLongerAssigned($userid)
{
- if ($this->users["$userid"]['options'][0] & bugdar::$emailOptions['notifications']['assignedto'] AND in_array($userid, $this->roles['-notapplicable-']))
+ if ($this->users["$userid"]['options'][0] & bugdar::$emailOptions['notifications']['assignedto'] && in_array($userid, $this->roles['-notapplicable-']))
{
$user = construct_user_display(bugdar::$userinfo, false);
eval('$part = "' . $this->registry->template->fetch(FetchEmailPath('notice_unassigned.part', $this->_localeFromUserId($userid))) . '";');
}
}
- // ###################################################################
/**
- * Informs the user that they have been made the assignee of the bug.
- *
- * @access private
- *
- * @param integer User ID
- */
- function notice_now_assigned($userid)
+ * Informs the user that they have been made the assignee of the bug.
+ *
+ * @param integer User ID
+ */
+ private function _noticeNowAssigned($userid)
{
- if ($this->users["$userid"]['options'][0] & bugdar::$emailOptions['notifications']['assignedto'] AND in_array($userid, $this->roles['-notapplicable-']))
+ if ($this->users["$userid"]['options'][0] & bugdar::$emailOptions['notifications']['assignedto'] && in_array($userid, $this->roles['-notapplicable-']))
{
$user = construct_user_display(bugdar::$userinfo, false);
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_assigned.part', $this->_localeFromUserId($userid))) . '";');
}
}
- // ###################################################################
/**
- * 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)
+ * Sends a message to inform users that the status has changed.
+ *
+ * @param integer Old status
+ * @param integer New status
+ */
+ private function _noticeStatusChange($old, $new)
{
- $userlist = $this->fetch_users_with_on_bit('statusresolve');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('statusresolve');
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_status.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
- * 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)
+ * Sends an email to inform users that the resolution has changed.
+ *
+ * @param integer Old resolution
+ * @param integer New resolution
+ */
+ private function _noticeResolutionChange($old, $new)
{
- $userlist = $this->fetch_users_with_on_bit('statusresolve');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('statusresolve');
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_resolution.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
- * 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)
+ * Informs users that the duplicates list has changed.
+ *
+ * @param string Old duplicates list
+ * @param string New duplicates list
+ */
+ private function _noticeDuplicatesChange($old, $new)
{
- $userlist = $this->fetch_useres_with_on_bit('duplicates');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('duplicates');
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_duplicates.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
- * Sends an email to inform users that the severity has changed.
- *
- * @access private
- *
- * @param integer Old severity
- * @param integer New severity
- */
- function notice_severity_change($old, $new)
+ * Sends an email to inform users that the severity has changed.
+ *
+ * @param integer Old severity
+ * @param integer New severity
+ */
+ private function _noticeSeverityChange($old, $new)
{
- $userlist = $this->fetch_users_with_on_bit('otherfield');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('otherfield');
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_severity.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
- * Informs users that the priority changed.
- *
- * @access private
- *
- * @param integer Old priority
- * @param integer New priority
- */
- function notice_priority_change($old, $new)
+ * Informs users that the priority changed.
+ *
+ * @param integer Old priority
+ * @param integer New priority
+ */
+ private function _noticePriorityChange($old, $new)
{
- $userlist = $this->fetch_users_with_on_bit('otherfield');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('otherfield');
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_priority.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
- * Sends an email telling users that the product, component, or version
- * has changed. This is done all at once because you really need to see
- * the whole thing in the notice.
- *
- * @access private
- *
- * @param array Original PCV
- * @param array Modified PCV
- */
- function notice_pcv_change($old, $new)
+ * Sends an email telling users that the product, component, or version
+ * has changed. This is done all at once because you really need to see
+ * the whole thing in the notice.
+ *
+ * @param array Original PCV
+ * @param array Modified PCV
+ */
+ private function _noticePCVChange($old, $new)
{
- $userlist = $this->fetch_users_with_on_bit('otherfield');
+ $userlist = $this->_fetchUsersWithOnBit('otherfield');
$old = bugdar::$datastore['product']["$old[0]"]['title'] . '/' . ($old[1] ? bugdar::$datastore['product']["$old[1]"]['title'] . '/' : '') . bugdar::$datastore['version']["$old[2]"]['version'];
$new = bugdar::$datastore['product']["$new[0]"]['title'] . '/' . ($new[1] ? bugdar::$datastore['product']["$new[1]"]['title'] . '/' : '') . bugdar::$datastore['version']["$new[2]"]['version'];
- foreach ($userlist AS $userid => $user)
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_product.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
* 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)
+ public function sendNewCommentNotice($comment)
{
- $userlist = $this->fetch_users_with_on_bit('newcomment');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('newcomment');
+ foreach ($userlist as $userid => $user)
{
$user = construct_user_display(bugdar::$userinfo, false);
$date = $this->registry->modules['date']->format(bugdar::$options['dateformat'], $comment['dateline']);
}
}
- // ###################################################################
/**
- * A notice for an individual field changing.
- *
- * @access private
- *
- * @param string Field name
- * @param mixed Original value
- * @param mixed Modified value
- */
- function notice_other_change($name, $old, $new)
+ * A notice for an individual field changing.
+ *
+ * @param string Field name
+ * @param mixed Original value
+ * @param mixed Modified value
+ */
+ private function _noticeOtherChange($name, $old, $new)
{
- $userlist = $this->fetch_users_with_on_bit('otherfield');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('otherfield');
+ foreach ($userlist as $userid => $user)
{
eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_other.part', $this->_localeFromUserId($userid))) . '";');
$this->notices["$user[userid]"][] = $email;
}
}
- // ###################################################################
/**
- * Sends appropriate users a notice when a new attachment has been
- * added.
- *
- * @access public
- *
- * @param array AttachmentAPI->values array
- * @param array List of all attachments made obsolete
- * @param array Newly-inserted attachment ID
- */
- function send_new_attachment_notice($attachment, $obsolete, $id)
+ * Sends appropriate users a notice when a new attachment has been
+ * added.
+ *
+ * @param array AttachmentAPI->values array
+ * @param array List of all attachments made obsolete
+ * @param array Newly-inserted attachment ID
+ */
+ public function sendNewAttachmentNotice($attachment, $obsolete, $id)
{
- $userlist = $this->fetch_users_with_on_bit('newattachment');
- foreach ($userlist AS $userid => $user)
+ $userlist = $this->_fetchUsersWithOnBit('newattachment');
+ foreach ($userlist as $userid => $user)
{
$user = construct_user_display(bugdar::$userinfo, false);
$obsoletes = implode(', ', (array)$obsolete);
}
}
- // ###################################################################
/**
- * Sends a new bug notification notice to all those who have the option
- * turned no. This does not use fetch_users_with_on_bit() because a
- * query is more effective.
- *
- * @access public
- *
- * @param array Bug values array
- * @param array Comment values array
- */
- function send_new_bug_notice($bug, $comment)
+ * Sends a new bug notification notice to all those who have the option
+ * turned no. This does not use fetchUsersWithOnBit() because a
+ * query is more effective.
+ *
+ * @param array Bug values array
+ * @param array Comment values array
+ */
+ public function sendNewBugNotice($bug, $comment)
{
$userinfo = BSApp::$db->query("
SELECT user.*, useremail.*
}
}
- // ###################################################################
/**
- * 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)
+ * Generates an array of users who have a given email notification flag
+ * turned on in their bitfields.
+ *
+ * @param string Notification bitfield name
+ *
+ * @return array Array of users and their data
+ */
+ private function _fetchUsersWithOnBit($bitname)
{
$idlist = array();
- foreach ($this->users AS $user)
+ foreach ($this->users as $user)
{
- foreach (bugdar::$emailOptions['relations'] AS $name => $bit)
+ foreach (bugdar::$emailOptions['relations'] as $name => $bit)
{
- if (in_array($user['userid'], $this->roles["$name"]) AND $user['options']["$bit"] & bugdar::$emailOptions['notifications']["$bitname"])
+ if (in_array($user['userid'], $this->roles["$name"]) && $user['options']["$bit"] & bugdar::$emailOptions['notifications']["$bitname"])
{
$idlist[] = $user['userid'];
}
$masters = array_unique($idlist);
$return = array();
- foreach ($masters AS $userid)
+ foreach ($masters as $userid)
{
$return["$userid"] =& $this->users["$userid"];
}
return $return;
}
- // ###################################################################
/**
- * Compiles and sends the actual emails to users.
- *
- * @access public
- */
- function finalize()
+ * Compiles and sends the actual emails to users.
+ */
+ public function finalize()
{
// get the current bug for permissions checks
$bug = BSApp::$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $this->bug['bugid']);
- foreach ($this->notices AS $userid => $noticelist)
+ foreach ($this->_notices as $userid => $noticelist)
{
if ($userid == bugdar::$userinfo['userid'])
{
- $this->registry->debug("skipping user $userid because they're the one doing the thing");
+ BSApp::debug("skipping user $userid because they're the one doing the thing");
continue;
}
// we wouldn't want people who favorite bugs getting hidden notices
if (!check_bug_permissions($bug, $this->users["$userid"]))
{
- $this->registry->debug("skipping user $userid ({$this->users[$userid]['email']}) because of permissions");
+ BSApp::debug("skipping user $userid ({$this->users[$userid]['email']}) because of permissions");
continue;
}
}
else
{
- $this->registry->debug("not sending an email to " . $userid . " because they don't have one?");
+ BSApp::debug("not sending an email to " . $userid . " because they don't have one?");
}
}
}
- // ###################################################################
/**
- * Returns the locale name from a given user ID
- *
- * @param integer User ID
- *
- * @return string Locale
- */
- function _localeFromUserId($userid)
+ * Returns the locale name from a given user ID
+ *
+ * @param integer User ID
+ *
+ * @return string Locale
+ */
+ private function _localeFromUserId($userid)
{
$langcode = bugdar::$datastore['language'][$this->users[$userid]['languageid']]['langcode'];
if (!$langcode)