php8
[web.mtrack] / MTrackWeb / TicketEdit.php
index 1fbaa96..41e5176 100644 (file)
@@ -132,6 +132,31 @@ class MTrackWeb_TicketEdit extends MTrackWeb
             $en->find(true);
             $this->issue->status = $en->id;
         }
+        
+        
+        //  VALIDATE POST!??!
+        
+        
+        if (!empty($_REQUEST['act_now'])) { //=+ adding act now..
+            // check project / assigned person / !closed for more than 3 'act_now'
+            //DB_DataObject::DebugLevel(1);
+            $xx = DB_DataObject::factory('mtrack_ticket');
+            $xx->owner_id = $this->issue->owner_id;
+            $xx->project_id  = $this->issue->project_id;
+            $xx->act_now = 1;
+            $xx->resolution_id = 0;
+            $xx->whereAdd('id != ' . ((int) $this->issue->id)); // just in case we are double setting...
+            if ($xx->count() > 2) {
+                $this->jerr("To many act-now tasks assigned to that person, wait until the have completed some");
+            }
+            
+            
+            
+        }
+        
+        
+        
+        
         $this->issue->setFrom($_POST); 
         
         /*
@@ -195,6 +220,10 @@ class MTrackWeb_TicketEdit extends MTrackWeb
             empty($_POST['estimate']) ? 0 : $_POST['estimate']
         );
         */
+        
+        
+        
+        
         $this->issue->project_id = $this->currentProject();
         
         
@@ -203,7 +232,10 @@ class MTrackWeb_TicketEdit extends MTrackWeb
        
         
         if ($this->issue->id) {
-            $this->issue->update($old);
+            if (0 === $this->issue->update($old)) {
+                $this->jerr("nothing changed?");
+            
+            }
         } else {
             $this->issue->insert();
             $old = false;
@@ -218,6 +250,46 @@ class MTrackWeb_TicketEdit extends MTrackWeb
         
         // issue ticket... - add watches etc... 
         
+        
+        
+         
+        
+        $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.. -- 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})   "  */
+        );
+        
+        
         /*
         //$this->issue->save($CS);
         
@@ -278,7 +350,7 @@ class MTrackWeb_TicketEdit extends MTrackWeb
         
         
         
-        foreach(array( 'classification', 'priority', 'severity', 'resolution' ) as $c)  {
+        foreach(array( 'classification', 'priority', 'severity' ) as $c)  {
             $d = DB_DataObject::factory('core_enum');
             $d->etype = $c;
             $d->orderBy('seqid ASC, name ASC');
@@ -287,24 +359,34 @@ class MTrackWeb_TicketEdit extends MTrackWeb
                 
             }
             $ar = $d->fetchAll('id','name');
-            if (!$this->id) {
-                $ar =  array(0 => '-- Select --') + $ar;
-            }
+            
+            // mid point..
+            $ak = array_keys($ar);
+            $mid = floor(count($ak) / 2 );
+            $def = $ak[$mid];
+            
+            //var_dump($ar[$def]);
+            
             $this->elements[$c.'_id'] = new HTML_Template_Flexy_Element('select');
             $this->elements[$c.'_id']->setOptions($ar);
+            if (!$this->id) {
+                $this->elements[$c.'_id']->setValue($def);
+            }
+            
             
         }
+       // DB_DAtaObject::DebugLevel(1);
         
         $pd = DB_DataObject::factory('ProjectDirectory');
         $pd->project_id = $this->currentProject();
         $pd->whereAdd("ProjectDirectory.role != ''");
-        $pd->joinAdd(DB_DataObject::factory('Person'), 'LEFT');
+        $pd->joinAdd(DB_DataObject::factory('core_person'), 'LEFT');
         $pd->selectAdd();
         $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('id', 'name');
-        
+        $users = array('' => '--select--') + $users;
         
         //$users = array();
          
@@ -314,10 +396,9 @@ class MTrackWeb_TicketEdit extends MTrackWeb
         $this->elements['developer_id'] = new HTML_Template_Flexy_Element('select');
         $this->elements['developer_id']->setOptions($users);
         
-        
-        
-        
-        if (false && $this->currentProject()) {
+          
+        if ($this->currentProject()) {
+            /*
             $d = DB_DataObject::factory('mtrack_project_component');
             $d->project_id = $this->currentProject();
             $d->orderBy('name');
@@ -326,17 +407,17 @@ class MTrackWeb_TicketEdit extends MTrackWeb
             $this->elements['component[]']->setOptions($d->fetchAll('id', 'name'));
             $ar = $this->issue->components();
             $this->elements['component[]']->setValue(array_keys($ar));
-        
-        
+            */
+            //DB_DataObject::debugLevel(1);
             $d = DB_DataObject::factory('mtrack_milestone');
             $d->project_id = $this->currentProject();
             $d->orderBy('(case when duedate is null then 1 else 0 end), duedate, name');
             $d->whereAdd('completed != 1');
             $d->whereAdd('deleted != 1');
-            $this->elements['milestone'] = new HTML_Template_Flexy_Element('select');
-            $this->elements['milestone']->setOptions($d->fetchAll('id', 'name'));
-            $ar = $this->issue->milestone();
-            $this->elements['milestone']->setValue(array_keys($ar));
+            $this->elements['milestone_id'] = new HTML_Template_Flexy_Element('select');
+            $this->elements['milestone_id']->setOptions(array(''=>'--select--') + $d->fetchAll('id', 'name'));
+            //$ar = $this->issue->milestone();
+            //$this->elements['milestone_id']->setValue(array_keys($ar));
         }
         
         // FIX ME - need to determine who the owner is..
@@ -345,8 +426,9 @@ class MTrackWeb_TicketEdit extends MTrackWeb
         
        
         
-        
-        $this->elements = HTML_Template_Flexy_Factory::fromArray($this->issue->toArray(), $this->elements);
+        if ($this->id) {
+            $this->elements = HTML_Template_Flexy_Factory::fromArray($this->issue->toArray(), $this->elements);
+        }
 
         
         // keywords -- in toArray...