php8
[web.mtrack] / MTrackWeb / Timeline.php
index 525ae98..80b5ebc 100644 (file)
@@ -41,12 +41,10 @@ class MTrackWeb_Timeline extends MTrackWeb
         
         $start = empty($_REQUEST['from_date']) ? date('Y-m-01') : 
             date('Y-m-01', strtotime($_REQUEST['from_date']));
+
+        $start_day = empty($_REQUEST['from_date']) ? date('Y-m-d') : 
+            date('Y-m-d', strtotime($_REQUEST['from_date']));
             
-        if (!empty($_REQUEST['viewtype']) && $_REQUEST['viewtype'] = 'summary') {
-                $isSummary = true;
-        }
-        $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 1 MONTH");
-        
         $e->whereAdd("
             ( ontable='mtrack_ticket' AND
                 onid IN (SELECT id FROM mtrack_ticket where project_id = $pid)
@@ -56,6 +54,41 @@ class MTrackWeb_Timeline extends MTrackWeb
                 onid IN (SELECT id FROM mtrack_repos where project_id = $pid)
             )
         ");
+            
+        if (!empty($_REQUEST['viewtype']) && $_REQUEST['viewtype'] == 'summary') {
+            //DB_DataObject::debugLevel(1);
+            $isSummary = true;
+            $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 1 MONTH");
+            $e->selectAdd();
+            $e->joinAdd(DB_DataObject::factory('core_person'), 'LEFT');
+            $e->selectAdd("
+                     DATE_FORMAT(changedate, '%Y-%m-%d')  as changeday,
+                     CONCAT(DATE_FORMAT(changedate, '%Y-%m-%d-') ,Person.id)  as id,
+                     Person.name as name,
+                     COUNT(mtrack_change.id) as nchanges
+                    ");
+            $e->groupBy("changeday,id,name");
+            $e->orderBy('changeday desc, name asc');
+            $ret = array();
+            $e->find();
+            while($e->fetch()) {
+                $ret[] = $e->toArray();
+            }
+            $this->jdata($ret);
+            
+            
+        }  
+        $e->whereAdd("changedate >= '$start_day 00:00:00' AND
+                      changedate < '$start_day 00:00:00' + INTERVAL 1 DAY");
+         
+        //DB_DataObject::debugLevel(1);
+        
+       
+        
+        
+        
+        
+        
         $ar = $e->fetchAll();
         $this->events = array();
         //$this->hist= array();
@@ -74,23 +107,87 @@ class MTrackWeb_Timeline extends MTrackWeb
                 $add['first_of_day'] = 1;
             }
             $last_day = $day;
-            
+            $p = $h->person();
+            $add['person_id_name'] = $p->name;
+            $add['person_id_email'] = $p->email;
             $add['audit'] = $h->cachedAuditToString();
-            //$add['object'] = $h->objectCached();
-    
-            $this->events[] = $add;
+            $add['audit_ar'] = $h->cachedAuditToJSONArray();
+            // add the underlying object..
+            $add = array_merge($add, $h->objectCached()->toArray('object_%s'));
             
-          
             
+            
+            
+            
+            
+    
+            $this->events[] = $add;
+             
         }
-       
-        $this->jdata($this->events);
+        $total = count($this->events);
+        $extra = !$total ? array() :  array(
+                 'metaData'  => $this->meta($e, $this->events)
+        );
+             
+         
+
+        $this->jdata($this->events, $total, $extra);
     
          
          
     
     }
+     /**
+      * this is a very simple version of the main one in roo.php
+      */
+    function meta($x, $data)
+    {
+        // this is not going to work on queries where the data does not match the database def..
+        // for unknown columns we send them as stirngs..
+        $lost = 0;
+        $cols  = array_keys($data[0]);
      
-
+        
+        
+        
+        
+        $options = HTML_FlexyFramework::get()->DB_DataObject;
+        //echo '<PRE>';print_r($options); exit;
+        $reader = $options["ini_{$x->_database}"] .'.reader';
+        if (!file_exists( $reader )) {
+            return;
+        }
+        
+        $rdata = unserialize(file_get_contents($reader));
+        
+        //echo '<PRE>';print_r($rdata);exit;
+        
+        $meta = array();
+        foreach($cols as $c ) {
+            $cc = $x->tableName().'.'.$c;
+            if (      !isset($rdata[$cc]) 
+                ||    !is_array($rdata[$cc])
+            ) {
+                
+                $meta[] = $c;
+                continue;    
+            }
+            $add = $rdata[$cc];
+            $add['name'] = $c;
+            $meta[] = $add;
+        }
+        
+        
+        
+        return array(
+            'totalProperty' =>  'total',
+            'successProperty' => 'success',
+            'root' => 'data',
+            'id' => 'id',
+            'fields' => $meta
+        );
+         
+        
+    }
 }