fix unititialize value
[Pman.Base] / Pman / Roo.php
index 3cccb1a..d22fdae 100644 (file)
@@ -13,7 +13,7 @@ require_once 'Pman.php';
  * 
  * - applySort($au, $sortcol, $direction, $array_of_columns, $multisort) -- does not support multisort at present..
  * - applyFilters($_REQUEST, $authUser, $roo) -- apply any query filters on data. and hide stuff not to be seen. (RETURN false to prevent default filters.)
- * - postListExtra($_REQUEST) : array(extra_name => data) - add extra column data on the results (like new messages etc.)
+ * - postListExtra($_REQUEST, $roo, $array_data) : array(extra_name => data) - 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, $request) // single fetch, add data..
@@ -25,7 +25,7 @@ require_once 'Pman.php';
  *      ... call $roo->jerr() on failure...
  *
  *  BEFORE
- * - beforeDelete($dependants_array, $roo) Argument is an array of un-find/fetched dependant items.
+ * - beforeDelete($dependants_array, $roo, $request) Argument is an array of un-find/fetched dependant items.
  *                      - jerr() will stop insert.. (Prefered)
  *                      - return false for fail and set DO->err;
  * - beforeUpdate($old, $request,$roo) - after update - jerr() will stop insert..
@@ -36,9 +36,7 @@ require_once 'Pman.php';
  * - onInsert($request,$roo, $event) - after insert
  * - onDelete($req, $roo) - after delete
  * - onUpload($roo)
- * 
- * 
+ *  
  * - toEventString (for logging - this is generically prefixed to all database operations.)
  */
 
@@ -142,10 +140,10 @@ class Pman_Roo extends Pman
      *   applyFilters($_REQUEST, $authUser, $roo)
      *                     -- apply any query filters on data. and hide stuff not to be seen.
      *                     -- can exit by calling $roo->jerr()
-     *   postListExtra($_REQUEST) : array(extra_name => data)
-     *                     - add extra column data on the results (like new messages etc.)
+     *   postListExtra($_REQUEST, $roo, $array_data) : array(extra_name => data)
+     *                     - add extra column to the jdata return key/value info.
      *   postListFilter($data, $authUser, $request) return $data
-     *                      - add extra data to an object
+     *                      - modify the returned array of data (either add stuff to the data, or remove lines etc)
      * 
      *   
      *   toRooSingleArray($authUser, $request) : array
@@ -243,10 +241,10 @@ class Pman_Roo extends Pman
        
         // sets map and countWhat
         $this->loadMap($x, array(
-                    'columns' => $_columns,
-                    'distinct' => empty($_REQUEST['_distinct']) ? false:  $_REQUEST['_distinct'],
-                    'exclude' => empty($_REQUEST['_exclude_columns']) ? false:  explode(',', $_REQUEST['_exclude_columns'])
-            ));
+                'columns' => $_columns,
+                'distinct' => empty($_REQUEST['_distinct']) ? false:  $_REQUEST['_distinct'],
+                'exclude' => empty($_REQUEST['_exclude_columns']) ? false:  explode(',', $_REQUEST['_exclude_columns'])
+        ));
         
         
         $this->setFilters($x,$_REQUEST);
@@ -258,8 +256,18 @@ class Pman_Roo extends Pman
          //print_r($x);
         // build join if req.
           //DB_DataObject::debugLevel(1);
-       //   var_dump($this->countWhat);
-        $total = $x->count($this->countWhat);
+        // count with multiple joins and no conditions can be quite slow - so if there are no conditions - just remove the joins from the count.
+        $xx = clone($x);
+        $old_where = $x->whereAdd();
+        if (empty($old_where )) {
+            $xx->_join = '';
+        } else {
+            $x->whereAdd($old_where);
+            $xx=clone($x);
+            
+        }
+       
+        $total = $xx->count($this->countWhat);
         // sorting..
       //   
         //var_dump($total);exit;
@@ -324,7 +332,7 @@ class Pman_Roo extends Pman
         
         $extra = false;
         if (method_exists($queryObj ,'postListExtra')) {
-            $extra = $queryObj->postListExtra($_REQUEST, $this);
+            $extra = $queryObj->postListExtra($_REQUEST, $this, $ret);
         }
         
         
@@ -344,17 +352,12 @@ class Pman_Roo extends Pman
             
         
         }
-        //die("DONE?");
-      
-        //if ($x->tableName() == 'Documents_Tracking') {
-        //    $ret = $this->replaceSubject(&$ret, 'doc_id_subject');
-       // }
-        
         
         
         if (!empty($_REQUEST['_requestMeta']) &&  count($ret)) {
             $meta = $this->meta($x, $ret);
             if ($meta) {
+                $extra = $extra ? $extra: array();
                 $extra['metaData'] = $meta;
             }
         }
@@ -759,12 +762,12 @@ class Pman_Roo extends Pman
                     $ms ? json_decode($ms) : false
             );
         }
+        
         if ($ms !== false) {
             return $this->multiSort($x);
         }
-        
         if ($sorted === false) {
-            
             $cols = $x->tableColumns();
             $excols = array_keys($this->cols);
             
@@ -906,7 +909,6 @@ class Pman_Roo extends Pman
         if (method_exists($x, 'toRooArray')) {
             $this->jok($x->toRooArray($req));
         }
-        
         $this->jok($x->toArray());
         
         
@@ -914,7 +916,7 @@ class Pman_Roo extends Pman
     
     function insert($x, $req, $with_perm_check = true)
     {
-        if (method_exists($x, 'setFromRoo')) {
+         if (method_exists($x, 'setFromRoo')) {
             $res = $x->setFromRoo($req, $this);
             if (is_string($res)) {
                 $this->jerr($res);
@@ -922,7 +924,7 @@ class Pman_Roo extends Pman
         } else {
             $x->setFrom($req);
         }
-        
+
         if ( $with_perm_check &&  !$this->checkPerm($x,'A', $req))  {
             $this->jerr("PERMISSION DENIED (i)");
         }
@@ -976,7 +978,7 @@ class Pman_Roo extends Pman
         if ($ev) { 
             $ev->audit($x);
         }
-        
+      
         // note setFrom might handle this before hand...!??!
         if (!empty($_FILES) && method_exists($x, 'onUpload')) {
             $x->onUpload($this, $_REQUEST);
@@ -1236,7 +1238,7 @@ class Pman_Roo extends Pman
             $match_total = 0;
             
             if ( $has_beforeDelete ) {
-                if ($xx->beforeDelete($match_ar, $this) === false) {
+                if ($xx->beforeDelete($match_ar, $this, $_REQUEST) === false) {
                     $errs[] = "Delete failed ({$xx->id})\n".
                         (isset($xx->err) ? $xx->err : '');
                     continue;