RooTrait.php
[Pman.Core] / RooTrait.php
index 7b4e40a..1bb4ed6 100644 (file)
@@ -134,4 +134,51 @@ trait Pman_Core_RooTrait {
         $this->jerr($out);
         
     }
+    
+    
+    
+    function addEvent($act, $obj = false, $remarks = '') 
+    {
+        
+        if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
+            return;
+        }
+        
+        $au = $this->getAuthUser();
+       
+        $e = DB_DataObject::factory('Events');
+        $e->init($act,$obj,$remarks); 
+         
+        $e->event_when = date('Y-m-d H:i:s');
+        
+        $eid = $e->insert();
+        
+        // fixme - this should be in onInsert..
+        $wa = DB_DataObject::factory('core_watch');
+        if (method_exists($wa,'notifyEvent')) {
+            $wa->notifyEvent($e); // trigger any actions..
+        }
+        
+        
+        $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
+        
+        return $e;
+        
+    }
+    
+    function getAuthUser()
+    {
+        if (!empty($this->authUser)) {
+            return $this->authUser;
+        }
+        $ff = HTML_FlexyFramework::get();
+        $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
+        
+        $u = DB_DataObject::factory( $tbl );
+        if (!$u->isAuth()) {
+            return false;
+        }
+        $this->authUser =$u->getAuthUser();
+        return $this->authUser ;
+    }
 }