RooTrait.php
[Pman.Core] / RooTrait.php
index 1bb4ed6..1079dc5 100644 (file)
@@ -94,6 +94,67 @@ trait Pman_Core_RooTrait {
         return $x;
     }
     
+    function selectSingle($x, $id, $req=false)
+    {
+        $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
+
+        //var_dump(array(!is_array($id) , empty($id)));
+        if (!is_array($id) && empty($id)) {
+            
+            if (method_exists($x, 'toRooSingleArray')) {
+                $this->jok($x->toRooSingleArray($this->authUser, $req));
+            }
+            
+            if (method_exists($x, 'toRooArray')) {
+                $this->jok($x->toRooArray($req));
+            }
+            
+            $this->jok($x->toArray());
+        }
+       
+        
+        $this->loadMap($x, array(
+                    'columns' => $_columns,
+                     
+            ));
+        if ($req !== false) { 
+            $this->setFilters($x, $req);
+        }
+        
+        // DB_DataObject::DebugLevel(1);
+        if (is_array($id)) {
+            // lookup...
+            $x->setFrom($req['lookup'] );
+            $x->limit(1);
+            if (!$x->find(true)) {
+                if (!empty($id['_id'])) {
+                    // standardize this?
+                    $this->jok($x->toArray());
+                }
+                $this->jok(false);
+            }
+            
+        } else if (!$x->get($id)) {
+            $this->jerr("selectSingle: no such record ($id)");
+        }
+        
+        // ignore perms if comming from update/insert - as it's already done...
+        if ($req !== false && !$this->checkPerm($x,'S'))  {
+            $this->jerr("PERMISSION DENIED - si");
+        }
+        // different symantics on all these calls??
+        if (method_exists($x, 'toRooSingleArray')) {
+            $this->jok($x->toRooSingleArray($this->authUser, $req));
+        }
+        if (method_exists($x, 'toRooArray')) {
+            $this->jok($x->toRooArray($req));
+        }
+        
+        $this->jok($x->toArray());
+        
+        
+    }
+    
     /*
      * From Pman.php
      */
@@ -135,11 +196,8 @@ trait Pman_Core_RooTrait {
         
     }
     
-    
-    
     function addEvent($act, $obj = false, $remarks = '') 
     {
-        
         if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
             return;
         }
@@ -159,7 +217,6 @@ trait Pman_Core_RooTrait {
             $wa->notifyEvent($e); // trigger any actions..
         }
         
-        
         $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
         
         return $e;
@@ -168,17 +225,6 @@ trait Pman_Core_RooTrait {
     
     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 ;
+        die('Get auth user is not implement.');
     }
 }