cvs: pear /LiveUser_Admin Admin.php Storage.php /LiveUser_Admin/Auth Common.php /LiveUser_Admin/Perm Complex.php Simple.php
| From: | Lukas Smith | Date: | Tue, 11 Apr 2006 17:27:40 +0000 |
| Subject: | cvs: pear /LiveUser_Admin Admin.php Storage.php /LiveUser_Admin/Auth Common.php /LiveUser_Admin/Perm Complex.php Simple.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-39553@lists.php.net to get a copy of this message | ||
lsmith Tue Apr 11 17:27:40 2006 UTC
Modified files:
/pear/LiveUser_Admin Admin.php Storage.php
/pear/LiveUser_Admin/Auth Common.php
/pear/LiveUser_Admin/Perm Complex.php Simple.php
Log:
- added LiveUser_Admin_Storage::setSelectDefaultParams() to centralize default setting
http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Admin.php?r1=1.64&r2=1.65&diff_format=u Index: pear/LiveUser_Admin/Admin.php diff -u pear/LiveUser_Admin/Admin.php:1.64 pear/LiveUser_Admin/Admin.php:1.65 --- pear/LiveUser_Admin/Admin.php:1.64 Tue Apr 11 14:50:52 2006 +++ pear/LiveUser_Admin/Admin.php Tue Apr 11 17:27:39 2006 @@ -57,11 +57,12 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Admin.php,v 1.64 2006/04/11 14:50:52 lsmith Exp $ + * @version CVS: $Id: Admin.php,v 1.65 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ require_once 'LiveUser.php'; +require_once 'LiveUser/Admin/Storage.php'; /**#@+ * Error related constants definition @@ -536,24 +537,22 @@ * * @access public */ - function getUsers($param = array()) + function getUsers($params = array()) { - if (array_key_exists('select', $param)) { - if ($param['select'] != 'row' && $param['select'] != 'all') { - $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', - array('msg' => 'Select must be "row" or "all"')); - return false; - } - } else { - $param['select'] = 'all'; + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + + if ($params['select'] != 'row' && $params['select'] != 'all') { + $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', + array('msg' => 'Select must be "row" or "all"')); + return false; } - if (array_key_exists('container', $param) - && $param['container'] == 'auth' + if (array_key_exists('container', $params) + && $params['container'] == 'auth' ) { - return $this->_getUsersByAuth($param); + return $this->_getUsersByAuth($params); } - return $this->_getUsersByPerm($param); + return $this->_getUsersByPerm($params); } /** @@ -564,7 +563,7 @@ * * @access private */ - function _getUsersByPerm($permParam = array()) + function _getUsersByPerm($permParams = array()) { if (!is_object($this->perm)) { $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', @@ -572,8 +571,8 @@ return false; } - $first = ($permParam['select'] == 'row'); - $permUsers = $this->perm->getUsers($permParam); + $first = ($permParams['select'] == 'row'); + $permUsers = $this->perm->getUsers($permParams); if (!$permUsers) { return $permUsers; } @@ -590,12 +589,14 @@ return false; } - $authFilter = array('filters' => array('auth_user_id' => $permData['auth_user_id'])); - $authData = $this->auth->getUsers($authFilter); + $authParams = array( + 'filters' => array('auth_user_id' => $permData['auth_user_id']), + 'select' => 'row', + ); + $authData = $this->auth->getUsers($authParams); if (!$authData) { continue; } - $authData = array_shift($authData); if ($first) { return LiveUser::arrayMergeClobber($permData, $authData); @@ -614,7 +615,7 @@ * * @access private */ - function _getUsersByAuth($authParam = array(), $first = false) + function _getUsersByAuth($authParams = array()) { if (!is_object($this->auth) || !is_object($this->perm)) { $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', @@ -622,8 +623,8 @@ return false; } - $first = ($authParam['select'] == 'row'); - $authUsers = $this->auth->getUsers($authParam); + $first = ($authParams['select'] == 'row'); + $authUsers = $this->auth->getUsers($authParams); if (!$authUsers) { return $authUsers; } @@ -634,13 +635,14 @@ $users = array(); foreach ($authUsers as $authData) { - $permData = $this->perm->getUsers(array( + $permParams = array( 'filters' => array( 'auth_user_id' => $authData['auth_user_id'], 'auth_container_name' => $this->authContainerName, ), 'select' => 'row', - )); + ); + $permData = $this->perm->getUsers($permParams); if (!$permData) { continue; } http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Storage.php?r1=1.15&r2=1.16&diff_format=u Index: pear/LiveUser_Admin/Storage.php diff -u pear/LiveUser_Admin/Storage.php:1.15 pear/LiveUser_Admin/Storage.php:1.16 --- pear/LiveUser_Admin/Storage.php:1.15 Tue Mar 14 13:11:56 2006 +++ pear/LiveUser_Admin/Storage.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Storage.php,v 1.15 2006/03/14 13:11:56 lsmith Exp $ + * @version CVS: $Id: Storage.php,v 1.16 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -153,6 +153,29 @@ } /** + * Static method to set defaults into a select params array + * + * @param array params array + * @return array params array + * + * @access public + */ + function setSelectDefaultParams($params) + { + $params['fields'] = array_key_exists('fields', $params) ? $params['fields'] : array('*'); + $params['with'] = array_key_exists('with', $params) ? $params['with'] : array(); + $params['filters'] = array_key_exists('filters', $params) ? $params['filters'] : array(); + $params['orders'] = array_key_exists('orders', $params) ? $params['orders'] : array(); + $params['rekey'] = array_key_exists('rekey', $params) ? $params['rekey'] : false; + $params['group'] = array_key_exists('group', $params) ? $params['group'] : false; + $params['limit'] = array_key_exists('limit', $params) ? $params['limit'] : null; + $params['offset'] = array_key_exists('offset', $params) ? $params['offset'] : null; + $params['select'] = array_key_exists('select', $params) ? $params['select'] : 'all'; + + return $params; + } + + /** * properly disconnect from resources * * @access public http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Auth/Common.php?r1=1.29&r2=1.30&diff_format=u Index: pear/LiveUser_Admin/Auth/Common.php diff -u pear/LiveUser_Admin/Auth/Common.php:1.29 pear/LiveUser_Admin/Auth/Common.php:1.30 --- pear/LiveUser_Admin/Auth/Common.php:1.29 Tue Apr 11 16:54:02 2006 +++ pear/LiveUser_Admin/Auth/Common.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Common.php,v 1.29 2006/04/11 16:54:02 lsmith Exp $ + * @version CVS: $Id: Common.php,v 1.30 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -331,23 +331,30 @@ * 'select' - determines what query method to use: * 'one' -> queryOne, 'row' -> queryRow, * 'col' -> queryCol, 'all' ->queryAll (default) + * 'selectable_tables' - array list of tables that may be + * joined to in this query, the first element is + * the root table from which the joins are done * @return bool|array false on failure or array with selected data * * @access public */ function getUsers($params = array()) { - $fields = array_key_exists('fields', $params) ? $params['fields'] : array(); - $filters = array_key_exists('filters', $params) ? $params['filters'] : array(); - $orders = array_key_exists('orders', $params) ? $params['orders'] : array(); - $rekey = array_key_exists('rekey', $params) ? $params['rekey'] : false; - $group = array_key_exists('group', $params) ? $params['group'] : false; - $limit = array_key_exists('limit', $params) ? $params['limit'] : null; - $offset = array_key_exists('offset', $params) ? $params['offset'] : null; - $select = array_key_exists('select', $params) ? $params['select'] : 'all'; + if (array_key_exists('selectable_tables', $params) + && !empty($params['selectable_tables']) + && is_array($params['selectable_tables']) + ) { + $selectable_tables = $params['selectable_tables']; + } else { + $selectable_tables = array('users'); + } + $root_table = reset($selectable_tables); + + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); - return $this->_storage->select($select, $fields, $filters, $orders, - $rekey, $group, $limit, $offset, 'users', array('users')); + return $this->_storage->select($params['select'], $params['fields'], + $params['filters'], $params['orders'], $params['rekey'], $params['group'], + $params['limit'], $params['offset'], $root_table, $selectable_tables); } /** http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Perm/Complex.php?r1=1.97&r2=1.98&diff_format=u Index: pear/LiveUser_Admin/Perm/Complex.php diff -u pear/LiveUser_Admin/Perm/Complex.php:1.97 pear/LiveUser_Admin/Perm/Complex.php:1.98 --- pear/LiveUser_Admin/Perm/Complex.php:1.97 Tue Apr 11 09:35:50 2006 +++ pear/LiveUser_Admin/Perm/Complex.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Complex.php,v 1.97 2006/04/11 09:35:50 lsmith Exp $ + * @version CVS: $Id: Complex.php,v 1.98 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -189,7 +189,8 @@ function implyRight($data) { // Check if the implied_right_id is the same as the right_id (you can't imply itself) - if (array_key_exists('right_id', $data) && array_key_exists('implied_right_id', $data) + if (array_key_exists('right_id', $data) + && array_key_exists('implied_right_id', $data) && $data['implied_right_id'] == $data['right_id'] ) { $this->stack->push( @@ -643,6 +644,8 @@ return parent::getGroups($params); } + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + if (array_key_exists('hierarchy', $params)) { return $this->_getGroupsWithHierarchy($params); } @@ -679,9 +682,7 @@ */ function _getGroupsWithSubgroups($params) { - if (array_key_exists('select', $params) - && ($params['select'] == 'one' || $params['select'] == 'row') - ) { + if ($params['select'] == 'one' || $params['select'] == 'row') { // Don't allow 'subgroups' with 'select' if 'one' or 'row' $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', @@ -725,9 +726,14 @@ // Merge 'group_id' filter if needed if (array_key_exists('group_id', $tmp_params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { - $tmp_params['filters']['group_id'] = array_intersect($subgroup_ids, (array)$params['subgroups']['group_id']); + $tmp_params['filters']['group_id'] = array_intersect( + $subgroup_ids, + (array)$params['subgroups']['group_id'] + ); } else { $tmp_params['filters']['group_id'] = $subgroup_ids; } @@ -744,7 +750,9 @@ // Merge 'group_id' filter if needed if (array_key_exists('filters', $params) && array_key_exists('group_id', $params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { $params['filters']['group_id'] = array_intersect($result, (array)$params['filters']['group_id']); } else { @@ -783,10 +791,8 @@ function _getGroupsWithHierarchy($params) { // Sanity checks on the provided params. - if ((!array_key_exists('rekey', $params) || !$params['rekey']) - || (array_key_exists('group', $params) && $params['group']) - || (array_key_exists('select', $params) && $params['select'] != 'all') - || (array_key_exists('fields', $params) && reset($params['fields']) !== 'group_id') + if (!$params['rekey'] || $params['group'] || $params['select'] != 'all' + || (reset($params['fields']) !== 'group_id' && reset($params['fields']) !== '*') ) { $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', @@ -826,9 +832,14 @@ $params['filters'] = $hierarchy; // Merge 'group_id' filter with 'hierachy' if needed if (array_key_exists('group_id', $params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { - $params['filters']['group_id'] = array_intersect($subgroup_ids, (array)$params['filters']['group_id']); + $params['filters']['group_id'] = array_intersect( + $subgroup_ids, + (array)$params['filters']['group_id'] + ); } else { $params['filters']['group_id'] = $subgroup_ids; } @@ -890,10 +901,10 @@ // Sanity check on the provided params if the inherited of implied param is set. if ($inherited || $implied) { - if ((!array_key_exists('rekey', $params) || !$params['rekey']) - || (array_key_exists('group', $params) && $params['group']) - || (array_key_exists('select', $params) && $params['select'] != 'all') - || (array_key_exists('fields', $params) && reset($params['fields']) !== 'right_id') + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + + if (!$params['rekey'] || $params['group'] || $params['select'] !== 'all' + || (reset($params['fields']) !== 'right_id' && reset($params['fields']) !== '*') ) { $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', @@ -906,10 +917,7 @@ // Extra sanity check on the provided params if the implied param is set // (has_implied should be included in the fields. - if ($implied - && array_key_exists('fields', $params) - && !in_array('has_implied', $params['fields']) - ) { + if ($implied && !in_array('has_implied', $params['fields'])) { $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', array('msg' => "Setting 'implied' requires that 'has_implied' field needs to be in the select list") @@ -992,13 +1000,16 @@ } } } + + return $rights; + } + + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + // If the select is set to all (or not set at all) and more than one field is set, // set the type to granted if it isn't set. - } elseif ((!array_key_exists('select', $params) || $params['select'] == 'all') - && (!array_key_exists('fields', $params) - || count($params['fields']) > 1 - || reset($params['fields']) === '*' - ) + if ($params['select'] == 'all' + && (count($params['fields']) > 1 || reset($params['fields']) === '*') ) { foreach ($rights as $right_id => $right) { if (!isset($rights[$right_id]['_type']) || !$rights[$right_id]['_type']) { @@ -1061,7 +1072,9 @@ // Merge 'right_id' filter with 'implied' if needed $params['filters'] = is_array($params['implied']) ? $params['implied'] : array(); if (array_key_exists('right_id', $params['filters']) - && (!is_array($params['filters']['right_id']) || !array_key_exists('value', $params['filters']['right_id'])) + && (!is_array($params['filters']['right_id']) + || !array_key_exists('value', $params['filters']['right_id']) + ) ) { $params['filters']['right_id'] = array_intersect($result, (array)$params['filters']['right_id']); } else { @@ -1120,7 +1133,9 @@ // Merge 'group_id' filter if needed if (array_key_exists('filters', $params) && array_key_exists('group_id', $params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { $params['filters']['group_id'] = array_intersect($result, (array)$params['filters']['group_id']); } else { http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Perm/Simple.php?r1=1.82&r2=1.83&diff_format=u Index: pear/LiveUser_Admin/Perm/Simple.php diff -u pear/LiveUser_Admin/Perm/Simple.php:1.82 pear/LiveUser_Admin/Perm/Simple.php:1.83 --- pear/LiveUser_Admin/Perm/Simple.php:1.82 Tue Apr 11 09:36:20 2006 +++ pear/LiveUser_Admin/Perm/Simple.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Simple.php,v 1.82 2006/04/11 09:36:20 lsmith Exp $ + * @version CVS: $Id: Simple.php,v 1.83 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -674,23 +674,16 @@ */ function _makeGet($params, $root_table, $selectable_tables) { - $fields = array_key_exists('fields', $params) ? $params['fields'] : array(); - $with = array_key_exists('with', $params) ? $params['with'] : array(); - $filters = array_key_exists('filters', $params) ? $params['filters'] : array(); - $orders = array_key_exists('orders', $params) ? $params['orders'] : array(); - $rekey = array_key_exists('rekey', $params) ? $params['rekey'] : false; - $group = array_key_exists('group', $params) ? $params['group'] : false; - $limit = array_key_exists('limit', $params) ? $params['limit'] : null; - $offset = array_key_exists('offset', $params) ? $params['offset'] : null; - $select = array_key_exists('select', $params) ? $params['select'] : 'all'; + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); // ensure that all $with fields are fetched - $fields = array_merge($fields, array_keys($with)); + $params['filters'] = array_merge($params['filters'], array_keys($params['with'])); - $data = $this->_storage->select($select, $fields, $filters, $orders, - $rekey, $group, $limit, $offset, $root_table, $selectable_tables); + $data = $this->_storage->select($params['select'], $params['fields'], + $params['filters'], $params['orders'], $params['rekey'], $params['group'], + $params['limit'], $params['offset'], $root_table, $selectable_tables); - if (!empty($with) && is_array($data)) { + if (!empty($params['with']) && is_array($data)) { foreach ($data as $key => $row) { foreach ($params['with'] as $field => $with_params) { $with_params['filters'][$field] = $row[$field]; @@ -731,7 +724,7 @@ */ function getUsers($params = array()) { - $selectable_tables = $this->_findSelectableTables('getUsers' , $params); + $selectable_tables = $this->_findSelectableTables('getUsers', $params); $root_table = reset($selectable_tables); return $this->_makeGet($params, $root_table, $selectable_tables);
http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Admin.php?r1=1.64&r2=1.65&diff_format=u Index: pear/LiveUser_Admin/Admin.php diff -u pear/LiveUser_Admin/Admin.php:1.64 pear/LiveUser_Admin/Admin.php:1.65 --- pear/LiveUser_Admin/Admin.php:1.64 Tue Apr 11 14:50:52 2006 +++ pear/LiveUser_Admin/Admin.php Tue Apr 11 17:27:39 2006 @@ -57,11 +57,12 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Admin.php,v 1.64 2006/04/11 14:50:52 lsmith Exp $ + * @version CVS: $Id: Admin.php,v 1.65 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ require_once 'LiveUser.php'; +require_once 'LiveUser/Admin/Storage.php'; /**#@+ * Error related constants definition @@ -536,24 +537,22 @@ * * @access public */ - function getUsers($param = array()) + function getUsers($params = array()) { - if (array_key_exists('select', $param)) { - if ($param['select'] != 'row' && $param['select'] != 'all') { - $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', - array('msg' => 'Select must be "row" or "all"')); - return false; - } - } else { - $param['select'] = 'all'; + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + + if ($params['select'] != 'row' && $params['select'] != 'all') { + $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', + array('msg' => 'Select must be "row" or "all"')); + return false; } - if (array_key_exists('container', $param) - && $param['container'] == 'auth' + if (array_key_exists('container', $params) + && $params['container'] == 'auth' ) { - return $this->_getUsersByAuth($param); + return $this->_getUsersByAuth($params); } - return $this->_getUsersByPerm($param); + return $this->_getUsersByPerm($params); } /** @@ -564,7 +563,7 @@ * * @access private */ - function _getUsersByPerm($permParam = array()) + function _getUsersByPerm($permParams = array()) { if (!is_object($this->perm)) { $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', @@ -572,8 +571,8 @@ return false; } - $first = ($permParam['select'] == 'row'); - $permUsers = $this->perm->getUsers($permParam); + $first = ($permParams['select'] == 'row'); + $permUsers = $this->perm->getUsers($permParams); if (!$permUsers) { return $permUsers; } @@ -590,12 +589,14 @@ return false; } - $authFilter = array('filters' => array('auth_user_id' => $permData['auth_user_id'])); - $authData = $this->auth->getUsers($authFilter); + $authParams = array( + 'filters' => array('auth_user_id' => $permData['auth_user_id']), + 'select' => 'row', + ); + $authData = $this->auth->getUsers($authParams); if (!$authData) { continue; } - $authData = array_shift($authData); if ($first) { return LiveUser::arrayMergeClobber($permData, $authData); @@ -614,7 +615,7 @@ * * @access private */ - function _getUsersByAuth($authParam = array(), $first = false) + function _getUsersByAuth($authParams = array()) { if (!is_object($this->auth) || !is_object($this->perm)) { $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', @@ -622,8 +623,8 @@ return false; } - $first = ($authParam['select'] == 'row'); - $authUsers = $this->auth->getUsers($authParam); + $first = ($authParams['select'] == 'row'); + $authUsers = $this->auth->getUsers($authParams); if (!$authUsers) { return $authUsers; } @@ -634,13 +635,14 @@ $users = array(); foreach ($authUsers as $authData) { - $permData = $this->perm->getUsers(array( + $permParams = array( 'filters' => array( 'auth_user_id' => $authData['auth_user_id'], 'auth_container_name' => $this->authContainerName, ), 'select' => 'row', - )); + ); + $permData = $this->perm->getUsers($permParams); if (!$permData) { continue; } http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Storage.php?r1=1.15&r2=1.16&diff_format=u Index: pear/LiveUser_Admin/Storage.php diff -u pear/LiveUser_Admin/Storage.php:1.15 pear/LiveUser_Admin/Storage.php:1.16 --- pear/LiveUser_Admin/Storage.php:1.15 Tue Mar 14 13:11:56 2006 +++ pear/LiveUser_Admin/Storage.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Storage.php,v 1.15 2006/03/14 13:11:56 lsmith Exp $ + * @version CVS: $Id: Storage.php,v 1.16 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -153,6 +153,29 @@ } /** + * Static method to set defaults into a select params array + * + * @param array params array + * @return array params array + * + * @access public + */ + function setSelectDefaultParams($params) + { + $params['fields'] = array_key_exists('fields', $params) ? $params['fields'] : array('*'); + $params['with'] = array_key_exists('with', $params) ? $params['with'] : array(); + $params['filters'] = array_key_exists('filters', $params) ? $params['filters'] : array(); + $params['orders'] = array_key_exists('orders', $params) ? $params['orders'] : array(); + $params['rekey'] = array_key_exists('rekey', $params) ? $params['rekey'] : false; + $params['group'] = array_key_exists('group', $params) ? $params['group'] : false; + $params['limit'] = array_key_exists('limit', $params) ? $params['limit'] : null; + $params['offset'] = array_key_exists('offset', $params) ? $params['offset'] : null; + $params['select'] = array_key_exists('select', $params) ? $params['select'] : 'all'; + + return $params; + } + + /** * properly disconnect from resources * * @access public http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Auth/Common.php?r1=1.29&r2=1.30&diff_format=u Index: pear/LiveUser_Admin/Auth/Common.php diff -u pear/LiveUser_Admin/Auth/Common.php:1.29 pear/LiveUser_Admin/Auth/Common.php:1.30 --- pear/LiveUser_Admin/Auth/Common.php:1.29 Tue Apr 11 16:54:02 2006 +++ pear/LiveUser_Admin/Auth/Common.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Common.php,v 1.29 2006/04/11 16:54:02 lsmith Exp $ + * @version CVS: $Id: Common.php,v 1.30 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -331,23 +331,30 @@ * 'select' - determines what query method to use: * 'one' -> queryOne, 'row' -> queryRow, * 'col' -> queryCol, 'all' ->queryAll (default) + * 'selectable_tables' - array list of tables that may be + * joined to in this query, the first element is + * the root table from which the joins are done * @return bool|array false on failure or array with selected data * * @access public */ function getUsers($params = array()) { - $fields = array_key_exists('fields', $params) ? $params['fields'] : array(); - $filters = array_key_exists('filters', $params) ? $params['filters'] : array(); - $orders = array_key_exists('orders', $params) ? $params['orders'] : array(); - $rekey = array_key_exists('rekey', $params) ? $params['rekey'] : false; - $group = array_key_exists('group', $params) ? $params['group'] : false; - $limit = array_key_exists('limit', $params) ? $params['limit'] : null; - $offset = array_key_exists('offset', $params) ? $params['offset'] : null; - $select = array_key_exists('select', $params) ? $params['select'] : 'all'; + if (array_key_exists('selectable_tables', $params) + && !empty($params['selectable_tables']) + && is_array($params['selectable_tables']) + ) { + $selectable_tables = $params['selectable_tables']; + } else { + $selectable_tables = array('users'); + } + $root_table = reset($selectable_tables); + + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); - return $this->_storage->select($select, $fields, $filters, $orders, - $rekey, $group, $limit, $offset, 'users', array('users')); + return $this->_storage->select($params['select'], $params['fields'], + $params['filters'], $params['orders'], $params['rekey'], $params['group'], + $params['limit'], $params['offset'], $root_table, $selectable_tables); } /** http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Perm/Complex.php?r1=1.97&r2=1.98&diff_format=u Index: pear/LiveUser_Admin/Perm/Complex.php diff -u pear/LiveUser_Admin/Perm/Complex.php:1.97 pear/LiveUser_Admin/Perm/Complex.php:1.98 --- pear/LiveUser_Admin/Perm/Complex.php:1.97 Tue Apr 11 09:35:50 2006 +++ pear/LiveUser_Admin/Perm/Complex.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Complex.php,v 1.97 2006/04/11 09:35:50 lsmith Exp $ + * @version CVS: $Id: Complex.php,v 1.98 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -189,7 +189,8 @@ function implyRight($data) { // Check if the implied_right_id is the same as the right_id (you can't imply itself) - if (array_key_exists('right_id', $data) && array_key_exists('implied_right_id', $data) + if (array_key_exists('right_id', $data) + && array_key_exists('implied_right_id', $data) && $data['implied_right_id'] == $data['right_id'] ) { $this->stack->push( @@ -643,6 +644,8 @@ return parent::getGroups($params); } + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + if (array_key_exists('hierarchy', $params)) { return $this->_getGroupsWithHierarchy($params); } @@ -679,9 +682,7 @@ */ function _getGroupsWithSubgroups($params) { - if (array_key_exists('select', $params) - && ($params['select'] == 'one' || $params['select'] == 'row') - ) { + if ($params['select'] == 'one' || $params['select'] == 'row') { // Don't allow 'subgroups' with 'select' if 'one' or 'row' $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', @@ -725,9 +726,14 @@ // Merge 'group_id' filter if needed if (array_key_exists('group_id', $tmp_params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { - $tmp_params['filters']['group_id'] = array_intersect($subgroup_ids, (array)$params['subgroups']['group_id']); + $tmp_params['filters']['group_id'] = array_intersect( + $subgroup_ids, + (array)$params['subgroups']['group_id'] + ); } else { $tmp_params['filters']['group_id'] = $subgroup_ids; } @@ -744,7 +750,9 @@ // Merge 'group_id' filter if needed if (array_key_exists('filters', $params) && array_key_exists('group_id', $params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { $params['filters']['group_id'] = array_intersect($result, (array)$params['filters']['group_id']); } else { @@ -783,10 +791,8 @@ function _getGroupsWithHierarchy($params) { // Sanity checks on the provided params. - if ((!array_key_exists('rekey', $params) || !$params['rekey']) - || (array_key_exists('group', $params) && $params['group']) - || (array_key_exists('select', $params) && $params['select'] != 'all') - || (array_key_exists('fields', $params) && reset($params['fields']) !== 'group_id') + if (!$params['rekey'] || $params['group'] || $params['select'] != 'all' + || (reset($params['fields']) !== 'group_id' && reset($params['fields']) !== '*') ) { $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', @@ -826,9 +832,14 @@ $params['filters'] = $hierarchy; // Merge 'group_id' filter with 'hierachy' if needed if (array_key_exists('group_id', $params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { - $params['filters']['group_id'] = array_intersect($subgroup_ids, (array)$params['filters']['group_id']); + $params['filters']['group_id'] = array_intersect( + $subgroup_ids, + (array)$params['filters']['group_id'] + ); } else { $params['filters']['group_id'] = $subgroup_ids; } @@ -890,10 +901,10 @@ // Sanity check on the provided params if the inherited of implied param is set. if ($inherited || $implied) { - if ((!array_key_exists('rekey', $params) || !$params['rekey']) - || (array_key_exists('group', $params) && $params['group']) - || (array_key_exists('select', $params) && $params['select'] != 'all') - || (array_key_exists('fields', $params) && reset($params['fields']) !== 'right_id') + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + + if (!$params['rekey'] || $params['group'] || $params['select'] !== 'all' + || (reset($params['fields']) !== 'right_id' && reset($params['fields']) !== '*') ) { $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', @@ -906,10 +917,7 @@ // Extra sanity check on the provided params if the implied param is set // (has_implied should be included in the fields. - if ($implied - && array_key_exists('fields', $params) - && !in_array('has_implied', $params['fields']) - ) { + if ($implied && !in_array('has_implied', $params['fields'])) { $this->stack->push( LIVEUSER_ADMIN_ERROR, 'exception', array('msg' => "Setting 'implied' requires that 'has_implied' field needs to be in the select list") @@ -992,13 +1000,16 @@ } } } + + return $rights; + } + + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); + // If the select is set to all (or not set at all) and more than one field is set, // set the type to granted if it isn't set. - } elseif ((!array_key_exists('select', $params) || $params['select'] == 'all') - && (!array_key_exists('fields', $params) - || count($params['fields']) > 1 - || reset($params['fields']) === '*' - ) + if ($params['select'] == 'all' + && (count($params['fields']) > 1 || reset($params['fields']) === '*') ) { foreach ($rights as $right_id => $right) { if (!isset($rights[$right_id]['_type']) || !$rights[$right_id]['_type']) { @@ -1061,7 +1072,9 @@ // Merge 'right_id' filter with 'implied' if needed $params['filters'] = is_array($params['implied']) ? $params['implied'] : array(); if (array_key_exists('right_id', $params['filters']) - && (!is_array($params['filters']['right_id']) || !array_key_exists('value', $params['filters']['right_id'])) + && (!is_array($params['filters']['right_id']) + || !array_key_exists('value', $params['filters']['right_id']) + ) ) { $params['filters']['right_id'] = array_intersect($result, (array)$params['filters']['right_id']); } else { @@ -1120,7 +1133,9 @@ // Merge 'group_id' filter if needed if (array_key_exists('filters', $params) && array_key_exists('group_id', $params['filters']) - && (!is_array($params['filters']['group_id']) || !array_key_exists('value', $params['filters']['group_id'])) + && (!is_array($params['filters']['group_id']) + || !array_key_exists('value', $params['filters']['group_id']) + ) ) { $params['filters']['group_id'] = array_intersect($result, (array)$params['filters']['group_id']); } else { http://cvs.php.net/viewcvs.cgi/pear/LiveUser_Admin/Perm/Simple.php?r1=1.82&r2=1.83&diff_format=u Index: pear/LiveUser_Admin/Perm/Simple.php diff -u pear/LiveUser_Admin/Perm/Simple.php:1.82 pear/LiveUser_Admin/Perm/Simple.php:1.83 --- pear/LiveUser_Admin/Perm/Simple.php:1.82 Tue Apr 11 09:36:20 2006 +++ pear/LiveUser_Admin/Perm/Simple.php Tue Apr 11 17:27:39 2006 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2006 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Simple.php,v 1.82 2006/04/11 09:36:20 lsmith Exp $ + * @version CVS: $Id: Simple.php,v 1.83 2006/04/11 17:27:39 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -674,23 +674,16 @@ */ function _makeGet($params, $root_table, $selectable_tables) { - $fields = array_key_exists('fields', $params) ? $params['fields'] : array(); - $with = array_key_exists('with', $params) ? $params['with'] : array(); - $filters = array_key_exists('filters', $params) ? $params['filters'] : array(); - $orders = array_key_exists('orders', $params) ? $params['orders'] : array(); - $rekey = array_key_exists('rekey', $params) ? $params['rekey'] : false; - $group = array_key_exists('group', $params) ? $params['group'] : false; - $limit = array_key_exists('limit', $params) ? $params['limit'] : null; - $offset = array_key_exists('offset', $params) ? $params['offset'] : null; - $select = array_key_exists('select', $params) ? $params['select'] : 'all'; + $params = LiveUser_Admin_Storage::setSelectDefaultParams($params); // ensure that all $with fields are fetched - $fields = array_merge($fields, array_keys($with)); + $params['filters'] = array_merge($params['filters'], array_keys($params['with'])); - $data = $this->_storage->select($select, $fields, $filters, $orders, - $rekey, $group, $limit, $offset, $root_table, $selectable_tables); + $data = $this->_storage->select($params['select'], $params['fields'], + $params['filters'], $params['orders'], $params['rekey'], $params['group'], + $params['limit'], $params['offset'], $root_table, $selectable_tables); - if (!empty($with) && is_array($data)) { + if (!empty($params['with']) && is_array($data)) { foreach ($data as $key => $row) { foreach ($params['with'] as $field => $with_params) { $with_params['filters'][$field] = $row[$field]; @@ -731,7 +724,7 @@ */ function getUsers($params = array()) { - $selectable_tables = $this->_findSelectableTables('getUsers' , $params); + $selectable_tables = $this->_findSelectableTables('getUsers', $params); $root_table = reset($selectable_tables); return $this->_makeGet($params, $root_table, $selectable_tables);