php8
[web.mtrack] / MTrackWeb / Ticket.php
index 3366a1a..7170d20 100644 (file)
@@ -43,7 +43,7 @@ class MTrackWeb_Ticket extends MTrackWeb
    {
      
         // -- load issue.. we should share this code with ticketedit really..
-
+        //DB_DataObject::debugLevel(1);
         $this->issue = DB_DataObject::factory('mtrack_ticket');
         $this->issue->autoJoin();
         if (!$this->id ||  !$this->issue->get($this->id)) {
@@ -83,7 +83,7 @@ class MTrackWeb_Ticket extends MTrackWeb
             $this->showEditBar = true;
         }
          
+        $this->issue->images = $this->issue->images();
         
       
     }
@@ -120,7 +120,7 @@ class MTrackWeb_Ticket extends MTrackWeb
               
             case 'accept':
                 // will be applied to the issue further down
-                $this->issue->owner = $this->authUser->id;
+                $this->issue->owner_id = $this->authUser->id;
                 if ($this->issue->status_name == 'new') {
                     $d = DB_DataObject::factory('core_enum');
                     $d->etype = 'ticketstate';
@@ -152,7 +152,7 @@ class MTrackWeb_Ticket extends MTrackWeb
         
         // things that we should not allow..
         foreach(array(
-            'estimated', 'effort', 'owner',
+            'estimated', 'effort', 'owner_id',
         ) as $k) {
             if (isset($_POST[$k])) {
                 $this->issue->setFrom(array($k => $_POST[$k]));
@@ -180,28 +180,78 @@ class MTrackWeb_Ticket extends MTrackWeb
         $this->issue->updated = $CS->id;
         $this->issue->update($old);
         
-        // if the owner has changed.. then we should add them to the watch list...
-        // MTrackWatch::watch_object('ticket', $this->issue->tid,  $this->issue->owner);
-        /*         
-        if (!count($this->error)) {
-            if (!empty($_FILES['attachments'])) {
-                require_once 'MTrack/Attachment.php';
-                foreach ($_FILES['attachments']['name'] as $fileid => $name) {
-                      
-                    MTrackAttachment::add("ticket:{$this->issue->tid}",
-                        $_FILES['attachments']['tmp_name'][$fileid],
-                        $_FILES['attachments']['name'][$fileid],
-                        $CS
-                    );
-                }
+        
+        
+        
+        if (!empty($_FILES['attachments'])) {
+            foreach ($_FILES['attachments']['name'] as $fileid => $name) {
+                $i = DB_DataObject::factory('Images');
+                $i->object($this->issue);
+                $i->ontable = $this->issue->tableName();
+                $i->onid = $this->issue->id;
+                $i->created_by = $this->authUser->id;
+                $i->mimetype = $_FILES['attachments']["type"][$fileid];
+                $i->createFrom($_FILES['attachments']['tmp_name'][$fileid],$_FILES['attachments']['name'][$fileid]);
+                
+                //    MTrackAttachment::add("ticket:{$this->issue->tid}",
+                //        $_FILES['attachments']['tmp_name'][$fileid],
+                //        $_FILES['attachments']['name'][$fileid],
+                //        $CS
+                //    );
+                //}
             }
         }
+        /*
         if (!count($this->error) && $this->id != 'new') {
             require_once 'MTrack/Attachment.php';
             MTrackAttachment::process_delete("ticket:{$this->issue->tid}", $CS);
         } 
         */
+        
+        
+        
+        
+        
+        $notify_query = "
+                (ontable='mtrack_ticket' and onid = {$this->issue->id})
+                 OR
+                 (ontable='Projects' and onid = {$this->issue->project_id})
+                 ";
+         $w = DB_DataObject::factory('core_watch');
+        $w->ensureNotify(  'mtrack_ticket' ,
+                            $this->issue->id,
+                            $this->authUser->id,
+                        $notify_query
+            );
+        
+        $w->ensureNotify(  'mtrack_ticket' ,
+                            $this->issue->id,
+                            $this->issue->owner_id,
+                        $notify_query
+            );
+        
+         $w->ensureNotify(  'mtrack_ticket' ,
+                            $this->issue->id,
+                            $this->issue->developer_id,
+                        $notify_query
+            );
+        //DB_DataObject::debugLevel(1);
+        // who to notify..
+        // who to notify.. -- originall did not send to issuer..
+        // we should probably make this configurable..
+        $w->notify( 'mtrack_ticket' , $this->issue->id,
+                    $notify_query 
+                /* " ( $notify_query )
+                    AND
+                    (person_id != {$this->authUser->id})   "   */
+        );
+        
+        
+        
+        // if the owner has changed.. then we should add them to the watch list...
+        // MTrackWatch::watch_object('ticket', $this->issue->tid,  $this->issue->owner);
+        
         $this->jok("OK");
         
     }
@@ -218,21 +268,22 @@ class MTrackWeb_Ticket extends MTrackWeb
         // FIX ME - need to determine who the owner is..
         // for a new issue it's the person who created it.
         // later on it's an assignement???
-        
+      //  DB_DataObject::debugLevel(1);
         $pd = DB_DataObject::factory('ProjectDirectory');
         $pd->project_id = $this->currentProject();
-        $pd->joinAdd('Person', 'LEFT');
+        $pd->whereAdd("ProjectDirectory.role != ''");
+        $pd->joinAdd(DB_DataObject::factory('core_person'), 'LEFT');
         $pd->selectAdd();
-        $pd->selectAdd('distinct(Person.id), distinct(Person.name)');
+        $pd->selectAdd("distinct(Person.id) as id ,  CONCAT(Person.name , '<', Person.email , '>') as name");
         $pd->groupBy('Person.id, Person.name');
         $pd->orderBy('Person.name');
-        $users = $pd->fetchAll()
+        $users = $pd->fetchAll('id', 'name');
         
         
         //$users = array();
          
-        $this->elements['owner'] = new HTML_Template_Flexy_Element('select');
-        $this->elements['owner']->setOptions($users);
+        $this->elements['owner_id'] = new HTML_Template_Flexy_Element('select');
+        $this->elements['owner_id']->setOptions($users);