Pman/Roo.php
[Pman.Base] / Pman / Roo.php
index 632d3ad..a0d3058 100644 (file)
@@ -16,7 +16,7 @@ require_once 'Pman.php';
  * - postListExtra - add extra column data on the results (like new messages etc.)
  * -postListFilter($data, $authUser, $request) return $data - add extra data to an object
  * 
- * - toRooSingleArray($authUser) // single fetch, add data..
+ * - toRooSingleArray($authUser, $request) // single fetch, add data..
  * - toRooArray($request) /// toArray if you need to return different data.. for a list fetch.
  * 
  * 
@@ -59,7 +59,7 @@ class Pman_Roo extends Pman
      * 
      * csvCols[0] csvCols[1]....    = .... column titles for CSV output
      * 
-     * csvTitle[0], csvTitle[1] ....  = columns to use for CSV output
+     * csvTitles[0], csvTitles[1] ....  = columns to use for CSV output
      *
      * sort        = sort column (',' comma delimited)
      * dir         = sort direction ?? in future comma delimited...
@@ -73,7 +73,8 @@ class Pman_Roo extends Pman
     function get($tab)
     {
          //  $this->jerr("Not authenticated", array('authFailure' => true));
-       //echo '<PRE>';print_R($_GET);  DB_DataObject::debuglevel(1);
+       //echo '<PRE>';print_R($_GET);
+     //  DB_DataObject::debuglevel(1);
         
         $this->init(); // from pnan.
         
@@ -122,7 +123,7 @@ class Pman_Roo extends Pman
                 $this->jerr("PERMISSION DENIED");
             }
             
-            $this->jok(method_exists($x, 'toRooSingleArray') ? $x->toRooSingleArray($this->authUser) : $x->toArray());
+            $this->jok(method_exists($x, 'toRooSingleArray') ? $x->toRooSingleArray($this->authUser, $_REQUEST) : $x->toArray());
             
         }
         if (isset($_REQUEST['_delete'])) {
@@ -153,6 +154,7 @@ class Pman_Roo extends Pman
             $this->jerr("PERMISSION DENIED");
         }
         
+      //  DB_DataObject::debuglevel(1);
         // sets map and countWhat
         $this->loadMap($x, $_columns, empty($_REQUEST['_distinct']) ? false:  $_REQUEST['_distinct']);
         
@@ -461,6 +463,35 @@ class Pman_Roo extends Pman
             $this->jerr("PERMISSION DENIED");
         }
        
+        // check any locks..
+        // only done if we recieve a lock_id.
+        // we are very trusing here.. that someone has not messed around with locks..
+        // the object might want to check in their checkPerm - if locking is essential..
+        
+        $lock = DB_DataObjecT::factory('Core_locking');
+        if (is_a($lock,'DB_DataObject'))  {
+                 
+            $lock->on_id = $x->id;
+            $lock->on_table= $x->tableName();
+            if (!empty($_REQUEST['_lock_id'])) {
+                $lock->whereAdd('id != ' . ((int)$_REQUEST['_lock_id']));
+            }
+            $lock->limit(1);
+            if ($lock->find(true)) {
+                // it's locked by someone else..
+                $p = $lock->person();
+                $this->jerr("Your lock is invalid, This record is locked by " . $p->name . " at " .$lock->created);
+            }
+            // check the users lock.. - no point.. ??? - if there are no other locks and it's not the users, then they can 
+            // edit it anyways...
+            
+        }
+        
+         
+        
+        
+        
+       
         $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
 
        
@@ -588,8 +619,16 @@ class Pman_Roo extends Pman
                     $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
                 }
                 $chk->{$ka[1]} =  $xx->$pk;
-                if ($chk->count()) {
-                    $this->jerr('Delete Dependant records first ('. $ka[0]. ':' . $ka[1] .'='.$xx->$pk.')');
+                $matches = $chk->count();
+                if ($matches) {
+                    $chk->limit(1);
+                    $o = $chk->fetchAll();
+                    $desc =  $ka[0]. ':' . $ka[1] .'='.$xx->$pk;
+                    if (method_exists($chk, 'toEventString')) {
+                        $desc = $ka[0] . ' : ' . $o[0]->toEventString();
+                    }
+                    
+                    $this->jerr("Delete Dependant records ($matches found),  first is ( $desc )");
                 }
             }
             // finally log it.. 
@@ -612,6 +651,9 @@ class Pman_Roo extends Pman
     function loadMap($do, $filter=false, $distinct = false) 
     {
         //DB_DataObject::debugLevel(1);
+        
+         $this->countWhat = false;
+        
         $conf = array();
         
         $this->init();
@@ -624,7 +666,7 @@ class Pman_Roo extends Pman
         //$ff->DB_DataObject['ini_'. $db->database()];
         //echo '<PRE>';print_r($do->links());exit;
         //var_dump($mods);
-        
+        /*
         if (in_array('Builder', $mods) ) {
             
             foreach(in_array('Builder', $mods) ? scandir($this->rootDir.'/Pman') : $mods as $m) {
@@ -643,8 +685,9 @@ class Pman_Roo extends Pman
                 $map = $conf[$do->tableName()];
             } 
         } else {
+            */
             $map = $do->links();
-        }
+        //}
          
         
         
@@ -660,7 +703,7 @@ class Pman_Roo extends Pman
         $do->selectAdd(); // we need thsi as normally it's only cleared by an empty selectAs call.
         
         $selectAs = array(array(  $xx , '%s', false));
-        $this->countWhat = false;
+       
         $has_distinct = false;
         if ($filter || $distinct) {
             $cols = array();