From 829d03a1836824eb556e8b8d551de70c7cc7fb36 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 29 May 2006 06:28:40 +0000 Subject: [PATCH] r859: - Adding some notification implementation to the notice_*() functions - Setting up for the notification center in editreport.php --- editreport.php | 9 ++++ includes/class_notification.php | 96 ++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/editreport.php b/editreport.php index 381bee4..8642691 100644 --- a/editreport.php +++ b/editreport.php @@ -25,6 +25,7 @@ $focus['showreport'] = 'focus'; require_once('./global.php'); require_once('./includes/functions_product.php'); +require_once('./includes/class_notification.php'); require_once('./includes/api_bug.php'); require_once('./includes/api_comment.php'); @@ -73,6 +74,8 @@ $bugfields = array( 'componentid' => 'component' ); +$notif = new NotificationCenter; + // ################################################################### if ($_POST['do'] == 'update') @@ -126,6 +129,8 @@ if ($_POST['do'] == 'update') $comment->set('comment', $commenttext); $comment->insert(); + $notif->send_new_comment_notice($comment->values); + $bugapi->set('lastposttime', $comment->values['dateline']); $bugapi->set('lastpostby', $bugsys->userinfo['userid']); $bugapi->set('lastpostbyname', $bugsys->userinfo['displayname']); @@ -189,6 +194,10 @@ if ($_POST['do'] == 'update') $log->update_history(); + $notif->send_bug_changes_notice($bugapi->objdata, $bugapi->values); + + print_r($notif); + $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]"); } diff --git a/includes/class_notification.php b/includes/class_notification.php index 44fe869..1e4f2e3 100644 --- a/includes/class_notification.php +++ b/includes/class_notification.php @@ -68,6 +68,13 @@ class NotificationCenter */ 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 @@ -197,9 +204,13 @@ class NotificationCenter */ function notice_no_longer_assigned($userid) { - if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto']) + 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) + ); } } @@ -213,9 +224,13 @@ class NotificationCenter */ function notice_now_assigned($userid) { - if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto']) + 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) + ); } } @@ -230,7 +245,16 @@ class NotificationCenter */ 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'] + ); + } } // ################################################################### @@ -244,7 +268,16 @@ class NotificationCenter */ 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'] + ); + } } // ################################################################### @@ -258,7 +291,58 @@ class NotificationCenter */ 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) + { + + } + + // ################################################################### + /** + * 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; } } -- 2.22.5