X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=RooGetTrait.php;h=162ebce1d0e998dc6863e32dbb7e31b2835e16de;hp=bfc370bceae9924dff3c6762472292b12fd0b922;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=ebef0905dbf82ef51fa6c68add03e5633afdb595 diff --git a/RooGetTrait.php b/RooGetTrait.php index bfc370bc..162ebce1 100644 --- a/RooGetTrait.php +++ b/RooGetTrait.php @@ -107,7 +107,8 @@ trait Pman_Core_RooGetTrait { PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError')); - $tab = array_shift(explode('/', $tab)); + $explode_tab = explode('/', $tab); + $tab = array_shift($explode_tab); $x = $this->dataObject($tab); @@ -236,7 +237,7 @@ trait Pman_Core_RooGetTrait { // filter results, and add any data that is needed... if (method_exists($x,'postListFilter')) { - $ret = $x->postListFilter($ret, $this->getAuthUser(), $_REQUEST); + $ret = $x->postListFilter($ret, $this->authUser, $_REQUEST); } @@ -275,135 +276,6 @@ trait Pman_Core_RooGetTrait { } - function setFilters($x, $q) - { - if (method_exists($x, 'applyFilters')) { - // DB_DataObject::debugLevel(1); - if (false === $x->applyFilters($q, $this->getAuthUser(), $this)) { - return; - } - } - $q_filtered = array(); - - $keys = $x->keys(); - // var_dump($keys);exit; - foreach($q as $key=>$val) { - - if (in_array($key,$keys) && !is_array($val)) { - - $x->$key = $val; - } - - // handles name[]=fred&name[]=brian => name in ('fred', 'brian'). - // value is an array.. - if (is_array($val) ) { - - $pref = ''; - - if ($key[0] == '!') { - $pref = '!'; - $key = substr($key,1); - } - - if (!in_array( $key, array_keys($this->cols))) { - continue; - } - - // support a[0] a[1] ..... => whereAddIn( - $ar = array(); - $quote = false; - foreach($val as $k=>$v) { - if (!is_numeric($k)) { - $ar = array(); - break; - } - // FIXME: note this is not typesafe for anything other than mysql.. - - if (!is_numeric($v) || !is_long($v)) { - $quote = true; - } - $ar[] = $v; - - } - if (count($ar)) { - - - $x->whereAddIn($pref . ( - isset($this->colsJname[$key]) ? - $this->colsJname[$key] : - ($x->tableName(). '.'.$key)), - $ar, $quote ? 'string' : 'int'); - } - - continue; - } - - - // handles !name=fred => name not equal fred. - if ($key[0] == '!' && in_array(substr($key, 1), array_keys($this->cols))) { - - $key = substr($key, 1) ; - - $x->whereAdd( ( - isset($this->colsJname[$key]) ? - $this->colsJname[$key] : - $x->tableName(). '.'.$key ) . ' != ' . - (is_numeric($val) ? $val : "'". $x->escape($val) . "'") - ); - continue; - - } - - switch($key) { - - // Events and remarks -- fixme - move to events/remarsk... - case 'on_id': // where TF is this used... - if (!empty($q['query']['original'])) { - // DB_DataObject::debugLevel(1); - $o = (int) $q['query']['original']; - $oid = (int) $val; - $x->whereAdd("(on_id = $oid OR - on_id IN ( SELECT distinct(id) FROM Documents WHERE original = $o ) - )"); - continue; - - } - $x->on_id = $val; - - - default: - if (strlen($val) && $key[0] != '_') { - $q_filtered[$key] = $val; - } - - // subjoined columns = check the values. - // note this is not typesafe for anything other than mysql.. - - if (isset($this->colsJname[$key])) { - $quote = false; - if (!is_numeric($val) || !is_long($val)) { - $quote = true; - } - $x->whereAdd( "{$this->colsJname[$key]} = " . ($quote ? "'". $x->escape($val) ."'" : $val)); - - } - - - continue; - } - } - if (!empty($q_filtered)) { - $x->setFrom($q_filtered); - } - - if (!empty($q['query']['name'])) { - if (in_array( 'name', array_keys($x->table()))) { - $x->whereAdd($x->tableName().".name LIKE '". $x->escape($q['query']['name']) . "%'"); - } - } - - } - function applySort($x, $sort = '', $dir ='') { $sort = empty($_REQUEST['sort']) ? $sort : $_REQUEST['sort']; @@ -415,7 +287,7 @@ trait Pman_Core_RooGetTrait { $sorted = false; if (method_exists($x, 'applySort')) { $sorted = $x->applySort( - $this->getAuthUser(), + $this->authUser, $sort, $dir, array_keys($this->cols), @@ -430,6 +302,7 @@ trait Pman_Core_RooGetTrait { $cols = $x->table(); $excols = array_keys($this->cols); + //print_R($excols); if (isset($x->_extra_cols)) { $excols = array_merge($excols, $x->_extra_cols); @@ -556,37 +429,13 @@ trait Pman_Core_RooGetTrait { } - var $cols = array(); - - function loadMap($do, $cfg =array()) - { - $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']; - - return; - - } - function meta($x, $data) { $lost = 0; $cols = array_keys($data[0]); $options = &PEAR::getStaticProperty('DB_DataObject','options'); - $reader = $options["ini_{$x->_database}"] .'.reader'; + $reader = $options["ini_{$x->databaseNickname()}"] .'.reader'; if (!file_exists( $reader )) { return; } @@ -617,4 +466,39 @@ trait Pman_Core_RooGetTrait { } + + function multiSort($x) + { + $ms = json_decode($_REQUEST['_multisort']); + if (!isset($ms->order) || !is_array($ms->order)) { + return; + } + $sort_str = array(); + + $cols = $x->table(); + + foreach($ms->order as $col) { + if (!isset($ms->sort->{$col})) { + continue; // no direction.. + } + $ms->sort->{$col} = $ms->sort->{$col} == 'ASC' ? 'ASC' : 'DESC'; + + if (strlen($col) && isset($cols[$col]) ) { + $sort_str[] = $x->tableName() .'.'.$col . ' ' . $ms->sort->{$col}; + continue; + } + + if (in_array($col, array_keys($this->cols))) { + $sort_str[] = $col. ' ' . $ms->sort->{$col}; + continue; + } + if (isset($x->_extra_cols) && in_array($col, $x->_extra_cols)) { + $sort_str[] = $col. ' ' . $ms->sort->{$col}; + } + } + + if ($sort_str) { + $x->orderBy(implode(', ', $sort_str )); + } + } }