DataObjects/core.sql
[Pman.Core] / DataObjects / Events.php
index 417253e..f955885 100644 (file)
@@ -69,19 +69,37 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         //    &_columns=on_id_cohead_number,event_when << this is ignored at present.
         // max(event_when) is not supported... by any query yet..
         
+        if (isset($q['on_table']) && !strlen($q['on_table'])) {
+            // empty ontable queries.. these are valid..
+            $this->whereAdd("$tn.on_table = ''");
+        }
+        
+        
         if (isset($q['query']['person_sum'])) {
             //DB_DataObject::debugLevel(1);
             $this->_extra_cols = array('qty' );
             $this->selectAdd("count($tn.id) as qty");
+            $this->selectAdd("count( distinct $tn.on_id) as uqty");
+            $this->whereAdd('LENGTH(join_person_id_id.name) > 0 ');
             $this->groupBy('person_id');
         }
          if (isset($q['query']['table_sum'])) {
             //DB_DataObject::debugLevel(1);
-            $this->_extra_cols = array('qty' );
+            $this->_extra_cols = array('qty' , 'uqty');
             $this->selectAdd("count($tn.id) as qty");
-            $this->groupBy('person_id');
+            $this->selectAdd("count( distinct $tn.on_table, $tn.on_id) as uqty");
+            
+            $this->groupBy('on_table');
+        }
+         if (isset($q['query']['day_sum'])) {
+            //DB_DataObject::debugLevel(1);
+            $this->_extra_cols = array('qty' , 'uqty');
+            $this->selectAdd("DATE_FORMAT(event_when, '%Y-%m-%d') as on_day");
+            $this->selectAdd("count($tn.id) as qty");
+            $this->selectAdd("count( distinct $tn.on_id) as uqty");
+            
+            $this->groupBy('on_day');
         }
-        
         
         if (isset($q['_join'])) {
             //DB_DataObject::DebugLevel(1);
@@ -220,15 +238,15 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         $pg = $ff->page;
         $au = $pg->getAuthUser();
         
-        if ($ff->cli && empty($au) && isset($obj->person_id)) {
-            $au = DB_DataObject::Factory('Person'); // not always a person..
-            $au->get($obj->person_id);
+        if ($ff->cli) { // && empty($au) && isset($obj->person_id)) {
+            $au = false;
+           // $au = DB_DataObject::Factory('Person'); // not always a person..
+           // $au->get($obj->person_id);
         } 
-         
-         
-         
+          
         $this->person_name = $au && !empty($au->name) ? $au->name : '';
-        $this->person_id = $au ? $au->id : '';
+        $this->person_id = $au ? $au->id : -1;
+        $this->person_table = $au ? $au->tableName() : '';
         $this->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
         $this->action = $act;
         $this->on_table = $obj ? $obj->tableName() : '';