DataObjects/Events.php
[Pman.Core] / DataObjects / Events.php
index 8bc71bf..e285634 100644 (file)
@@ -25,6 +25,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
     public $person_id;                       // int(11)  
     public $remarks;                         // blob(65535)  blob
     public $person_table;                    // string(64)
+    public $dupe_id;                    // int(11)
 
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
@@ -37,18 +38,20 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
     {
         $tn = $this->tableName();
         // if not empty on_table
+        
         if(!empty($q['person_table'])){
             $jt = DB_DataObject::factory($q['person_table']);
 
-            $et = DB_DataObject::factory($tn);
+            
             
             if(!array_key_exists("{$jt->tableName()}_id", $this->tableColumns())){ // coz we have triiger on mysql...
                 
                 $keys = $jt->keys();
             
                 $this->_join = "LEFT JOIN {$jt->tableName()} AS join_person_id_id ON (join_person_id_id.{$keys[0]}=Events.person_id)";
+                
                 $this->selectAdd();
-                $this->selectAs($et,'%s','evet');
+                $this->selectAs();
 
                 $this->selectAs($jt, 'person_id_%s', 'join_person_id_id');
 
@@ -71,12 +74,12 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             }
             
             $jt = DB_DataObject::factory($person);
-            $this->whereAdd("
-                    person_table  = '{$jt->tableName()}'
-                    OR
-                    person_table = ''
-                    OR person_table IS NULL"
-            ); // default to  our standard.. - unless otherwise requested..
+            //$this->whereAdd("
+            //        person_table  = '{$jt->tableName()}'
+            //        OR
+            //        person_table = ''
+            //        OR person_table IS NULL"
+            //); // default to  our standard.. - unless otherwise requested..
         }
         
         
@@ -88,6 +91,11 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             $dt = date('Y-m-d' , strtotime($q['query']['to']));
             $this->whereAdd(" {$tn}.event_when <=  '$dt' ");
         }
+        
+        if(!empty($q['_with_dupe_count'])){
+            $this->dupe_id = 0;                                   
+            $this->selectAdd("(select count(*)+1 from Events ev_cnt where ev_cnt.dupe_id = {$tn}.id) as dupe_count");
+        }
         /*
         if (!empty($q['query']['grouped']) && $q['query']['grouped'] == 'gr') {
             // grouped..
@@ -99,13 +107,6 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         }
         */
         
-        if (!$au->hasPerm("Admin.Admin_Tab", 'S')) {
-            //DB_DataObject::DebugLevel(1);
-            // they can only view their changes..
-            $this->whereAdd("($tn.person_id = {$au->id} OR $tn.person_id = 0)");
-//            $this->person_id = $au->id;
-            
-        }
         // _join = tablename,tablename...
         
         /// on_table=cohead
@@ -209,8 +210,9 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             if (!$obj) {
                 $roo->jerr("ontable is invalid");
             }
+            
             if (!method_exists($obj,'relatedWhere')) {
-                $roo->jerr( $q['_related_on_table'] . " Does not have method relatedWhere :" .
+                $roo->jerr( $q['_related_on_table'] . " Does not have method relatedWhere  or relatedEventsWhere:" .
                            implode(',', get_class_methods($obj)));
             }
             if ($obj && method_exists($obj,'relatedWhere')) {
@@ -234,11 +236,10 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
                 $this->whereAdd(implode(' OR ' , $w));
             }
             
-            
-            
-            
+         
             
         }
+        
         // since roo does not support autojoin yet..
         if (!isset($q['_distinct'])) {
             //$this->autoJoinExtra();
@@ -253,10 +254,18 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             $tnb = $this->escape($q['query']['on_table']);
             $this->whereAdd("Events.on_table LIKE '%{$tnb}%'");
         } 
-        
+        echo "fuk"; die;
     }
-      
     
+    function applyPermissionFilters($q, $au ,$roo)
+    {
+        if (!$au->hasPerm("Admin.Admin_Tab", 'S')) {
+            //DB_DataObject::DebugLevel(1);
+            // they can only view their changes..
+            $this->whereAdd("($tn.person_id = {$au->id} OR $tn.person_id = 0)");
+//            $this->person_id = $au->id;
+        }
+    }
     
     /**
      * check who is trying to access this. false == access denied..
@@ -307,6 +316,9 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         } 
           
         $this->person_name = $au && !empty($au->name) ? $au->name : '';
+        //print_r($au);
+        //exit;
+        //$this->who = $au && !empty($au->name) ? $au->name : '';
         if (empty($au) || (isset($au->id) && empty($au->id))) {
             // not authenticated - and a standard id based object
             $this->person_id = 0;
@@ -316,7 +328,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             $cols = $this->tableColumns();
             $col = isset($cols[$col]) ? $col : 'person_id'; // for BC.... - revert to using person_id
             $this->{$col} = $au->pid();
-            //$this->person_id = $au ? (!empty($au->id) ? $au->id : $au->pid()) : -1;
+            //$this->person_id = $au ? (!empty($au->id) ? $au->id : $au->pid()) : -1;            
         }
         $this->person_table = $au ? $au->tableName() : '';
         $this->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
@@ -413,7 +425,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 $this->ipaddr = $_SERVER['HTTP_X_FORWARDED_FOR'];
             }
-        }
+        }        
     }
     
     function beforeUpdate($old, $request,$roo)
@@ -471,14 +483,16 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             $user = getenv('USERNAME'); // windows.
         }
         
-        // DEPRICATED...
+        
+   
+        if (!empty($ff->Pman['storedir'])) {
+            return $ff->Pman['storedir'] .'/Events/'.$user;
+        }
+        // DEPRICATED... 
         if (!empty($ff->Pman['event_log_dir'])) {
             return $ff->Pman['event_log_dir'] . '/'.$user;
         }
-        if (!empty($ff->Pman['storedir'])) {
-            return $ff->Pman['storedir'] .'/Events/'.$user;
         
-        }
         return false;
     }
     
@@ -487,6 +501,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
     function writeEventLog($extra_data  = false)
     {
         $logdir = $this->logDir();
+        
         if (!$logdir) {
             return false;
         }
@@ -498,6 +513,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             
             @mkdir(dirname($file),0700,true); // this might fail if it does not have correct permissions..
             if (!file_exists(dirname($file))) {
+                print_r($this);
                 die("could not create $file - permissons are not correct"); // fatal, otherwise we loop!?
             }
             
@@ -696,4 +712,6 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         $this->selectAdd('join_person_id_id.email as email');
         
     }
+    
+    
 }