r859: - Adding some notification implementation to the notice_*() functions
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 29 May 2006 06:28:40 +0000 (06:28 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 29 May 2006 06:28:40 +0000 (06:28 +0000)
- Setting up for the notification center in editreport.php

editreport.php
includes/class_notification.php

index 381bee447702e1a177807184e53c1893a75bf07c..8642691ae03d94e303b7a7c7dabbc71070d782b6 100644 (file)
@@ -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]");
 }
 
index 44fe869fc5f3c1374572dc1ab2dc572c120f2f8e..1e4f2e3fba01b7fc61d0f5032083288a6754eb86 100644 (file)
@@ -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;
        }
 }