DataObjects/Mtrack_ticket.php
authorAlan Knowles <alan@akkbhome.com>
Wed, 6 Apr 2011 23:29:28 +0000 (07:29 +0800)
committerAlan Knowles <alan@akkbhome.com>
Wed, 6 Apr 2011 23:29:28 +0000 (07:29 +0800)
DataObjects/Mtrack_ticket.php

index 1299215..30a0d0e 100644 (file)
@@ -54,7 +54,121 @@ class Pman_MTrack_DataObjects_Mtrack_ticket extends DB_DataObject
     
     function toEmail($person, $lasttime)
     {
+        $ff = HTML_FlexyFramework::get();
+        $headers = $this->calcAddress($changes, $person);
         
+        $headers += array(
+            'MIME-Version' => '1.0',
+            'Content-Type' => 'text/plain; charset="UTF-8"',
+            'Content-Transfer-Encoding' => 'quoted-printable',
+        );
+    
+        
+        $mid = $this->id . '@' . php_uname('n');
+        
+        $p = $this->project();
+         
+        $subj = "[" . $p->code . ' - ' . $p->name . "] ";
+    
+        $headers['X-mtrack-project-list'] = $p->code;
+        //foreach ($projects as $pname) {
+        //  $headers["X-mtrack-project-$pname"] = $pname;
+         // $headers['X-mtrack-project'][] = $pname;
+        //}
+        //} else {
+        //$subj = '';
+        // }
+    
+        $headers['Subject'] = sprintf("%s#%s %s (%s %s)",
+          $subj, $ticket->id, $ticket->summary, $ticket->status_name, $ticket->classification_id_name);
+    
+        $owner =  $ticket->owner_id ? $ticket->owner_id_name : 'nobody';
+    
+        $body = 
+            sprintf("%s/Ticket.php/%s\n\n", $ff->MTrackWeb['url'], $ticket->id) .
+            sprintf("#%s: %s (%s %s)\n", $ticket->id, $ticket->summary, $ticket->status_name, $ticket->classification_id_name) .
+            sprintf("Responsible: %s (%s / %s)\n", $owner, $ticket->priority_id_name, $ticket->severity_id_name) .
+    
+            //sprintf("Milestone: %s\n", join(', ', $T->getMilestones()));
+            //sprintf("Component: %s\n", join(', ', $T->getComponents()));
+            "\n";
+    
+      // Display changed fields grouped by the person that last changed them
+        //$who_changed = array();
+        //foreach ($field_changers as $field => $who) {
+        //  $who_changed[$who][] = $field;
+        //}
+        $body.="\n\n";
+        foreach ($changes as $change) {
+            
+            $body .= "{$change->changedate}:  Change by {$change->person_id_name}\n";
+            $body .= str_repeat('-', 80) . "\n";
+            if (!empty($change->reason)) {
+                $body.= $change->reason;
+            }
+            $ar = $change->cachedAudit();
+            foreach($ar as $audit) {
+                
+                switch($audit->field()) {
+                    case 'id':
+                        continue; //??? ignore?
+                    case '@components':
+                        continue;
+                    //  $old = array();
+                    //  foreach (preg_split("/\s*,\s*/", $old_values[$field]) as $id) {
+                     /*   if (!strlen($id)) continue;
+                        $c = get_component($id);
+                        $old[$id] = $c->name;
+                      }
+                      $value = $T->getComponents();
+                      $field = 'Component';
+                      break;
+                     */
+                    case '@milestones':
+                        continue;
+                    //  $old = array();
+                    //  foreach (preg_split("/\s*,\s*/", $old_values[$field]) as $id) {
+                      /*  if (!strlen($id)) continue;
+                        $m = get_milestone($id);
+                        $old[$id] = $m->name;
+                      }
+                      $value = array();
+                      $value = $T->getMilestones();
+                      $field = 'Milestone';
+                      break;
+                      */
+                    case '@keywords':
+                        continue;
+                    /*
+                      $old = array();
+                      $field = 'Keywords';
+                      $value = $T->getKeywords();
+                      break;
+                      */
+                      
+                    //case 'commit?'  
+                      
+                    default:
+                        $oldvalue = $audit->oldvalue($change);
+                        $value = $audit->oldvalue($change);
+                        if (!strlen($oldvalue)) {
+                            $body .= "Set {$audit->field()} to: {$value}\n";
+                            continue;
+                        }
+                        
+                        if (!strlen($value)) {
+                            $body .= "Removed {$audit->field()} - was: {$oldvalue}\n";
+                            continue;
+                        }
+                        $body .= "Changed {$audit->field()} from :{$oldvalue} -> {$value}\n";
+                        continue;  
+                }
+            }
+        }
+        
+        $body .= sprintf("%s/Ticket.php/%s\n\n", $ff->MTrackWeb['url'], $ticket->id);
+        
+        echo $body;