RooGetTrait.php
[Pman.Core] / RooGetTrait.php
index 3c69565..1ddc7d2 100644 (file)
@@ -275,65 +275,6 @@ trait Pman_Core_RooGetTrait {
         
     }
     
-    function selectSingle($x, $id, $req=false)
-    {
-        $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
-
-        if (!is_array($id) && empty($id)) {
-            
-            if (method_exists($x, 'toRooSingleArray')) {
-                $this->jok($x->toRooSingleArray($this->getAuthUser(), $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);
-        }
-        
-        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->getAuthUser(), $req));
-        }
-        if (method_exists($x, 'toRooArray')) {
-            $this->jok($x->toRooArray($req));
-        }
-        
-        $this->jok($x->toArray());
-        
-        
-    }
-    
     function setFilters($x, $q)
     {
         if (method_exists($x, 'applyFilters')) {
@@ -615,32 +556,41 @@ trait Pman_Core_RooGetTrait {
         
     }
     
-    var $cols = array();
-    
-    function loadMap($do, $cfg =array())
+    function meta($x, $data)
     {
-        $onlycolumns    = !empty($cfg['columns']) ? $cfg['columns'] : false;
-        $distinct       = !empty($cfg['distinct']) ? $cfg['distinct'] : false;
-        $excludecolumns = !empty($cfg['exclude']) ? $cfg['exclude'] : array();
-          
-        $excludecolumns[] = 'passwd'; // we never expose passwords
-       
-        $ret = $do->autoJoin(array(
-            'include' => $onlycolumns,
-            'exclude' => $excludecolumns,
-            'distinct' => $distinct
-        ));
-        
-      
-        
-        $this->countWhat = $ret['count'];
-        $this->cols = $ret['cols'];
-        $this->colsJname = $ret['join_names'];
+        $lost = 0;
+        $cols  = array_keys($data[0]);
+     
+        $options = &PEAR::getStaticProperty('DB_DataObject','options');
+        $reader = $options["ini_{$x->_database}"] .'.reader';
+        if (!file_exists( $reader )) {
+            return;
+        }
         
+        $rdata = unserialize(file_get_contents($reader));
         
-        return;
+        $keys = $x->keys();
+        $key = empty($keys) ? 'id' : $keys[0];
         
         
+        $meta = array();
+        foreach($cols as $c ) {
+            if (!isset($this->cols[$c]) || !isset($rdata[$this->cols[$c]]) || !is_array($rdata[$this->cols[$c]])) {
+                $meta[] = $c;
+                continue;    
+            }
+            $add = $rdata[$this->cols[$c]];
+            $add['name'] = $c;
+            $meta[] = $add;
+        }
+        return array(
+            'totalProperty' =>  'total',
+            'successProperty' => 'success',
+            'root' => 'data',
+            'id' => $key, // was 'id'...
+            'fields' => $meta
+        );
+         
         
     }
 }