1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

EONE-62 (New Feature): almost working version when it comes to getting data;

e_front_model in development;
check_class() modified to accept values of type array;
work in progress
This commit is contained in:
secretr 2010-05-02 18:41:20 +00:00
parent 59053103a4
commit 067b0a07c2
4 changed files with 805 additions and 143 deletions

View File

@ -1260,9 +1260,9 @@ function check_class($var, $userclass = USERCLASS_LIST, $uid = 0)
return FALSE;
}
$class_array = explode(',', $userclass);
$class_array = !is_array($userclass) ? explode(',', $userclass) : $userclass;
$varList = explode(',', $var);
$varList = !is_array($var) ? explode(',', $var) : $var;
$latchedAccess = FALSE;
foreach($varList as $v)
@ -1323,6 +1323,7 @@ function getperms($arg, $ap = ADMINPERMS)
{
$sql = e107::getDb('psql');
// FIXME - cache it, avoid sql query here
if ($sql->db_Select('plugin', 'plugin_id', "plugin_path = '".$matches[2]."' LIMIT 1 "))
{
$row = $sql->db_Fetch();

View File

@ -18,7 +18,7 @@ if (!defined('e107_INIT')) { exit; }
/**
*
* @package e107
* @subpackage e107_handlers
* @category e107_handlers
* @version $Id$
* @author e107inc
*
@ -162,7 +162,8 @@ class e107
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php',
'e_user_model' => '{e_HANDLER}user_model.php',
'e_user' => '{e_HANDLER}user_model.php',
'e_current_user' => '{e_HANDLER}user_model.php',
'e_system_user' => '{e_HANDLER}user_model.php',
'e_user_extended_structure_tree' => '{e_HANDLER}user_model.php',
'e_userperms' => '{e_HANDLER}user_handler.php',
'e_validator' => '{e_HANDLER}validator_class.php',
'e_vars' => '{e_HANDLER}e_parse_class.php',
@ -908,46 +909,6 @@ class e107
return self::getSingleton('ecache', true);
}
/**
* Retrieve userclass singleton object
*
* @return user_class
*/
public static function getUserClass()
{
return self::getSingleton('user_class', true);
}
/**
* Retrieve [e_current_user] current or [e_user] target (cached) user model object.
*
* @param boolean $current true - current user; false - target user (previously cached)
* @return e_current_user|e_user
*/
public static function getUser($current = true)
{
if($current)
{
return self::getSingleton('e_current_user', true);
}
return e107::getRegistry('targets/core/user');
}
/**
* Load user data
*
* @param integer|array $user
* @return e_user
*/
public static function loadUser($user = array())
{
if(is_numeric($user_id))
{
return $this->getObject('e_user', array(), true)->load($user);
}
return $this->getObject('e_user', $user, true);
}
/**
* Retrieve user-session singleton object
*
@ -1114,6 +1075,54 @@ class e107
return self::getObject('xmlClass', null, true);
}
/**
* Retrieve userclass singleton object
*
* @return user_class
*/
public static function getUserClass()
{
return self::getSingleton('user_class', true);
}
/**
* Retrieve user model object.
*
* @param integer $user_id target user
* @return e_system_user
*/
public static function getSystemUser($user_id)
{
$user = self::getRegistry('targets/core/user/'.$user_id);
if(null === $user)
{
$user = self::getObject('e_system_user');
if($user_id) $user->load($user_id); // self registered on load
}
return $user;
}
/**
* Retrieve current user model object.
*
* @return e_user
*/
public static function getUser()
{
return self::getSingleton('e_user', true, 'targets/core/current_user');
}
/**
* Retrieve user model object.
*
* @param integer $user_id target user
* @return e_current_user
*/
public static function getUserStructure()
{
return self::getSingleton('e_user_extended_structure_tree', true);
}
/**
* Retrieve User Extended handler singleton object
* @return e107_user_extended
@ -1122,6 +1131,15 @@ class e107
{
return self::getSingleton('e107_user_extended', true);
}
/**
* Retrieve User Perms (admin perms) handler singleton object
* @return comment
*/
public static function getUserPerms()
{
return self::getSingleton('e_userperms', true);
}
/**
* Retrieve online users handler singleton object
@ -1141,16 +1159,6 @@ class e107
return self::getSingleton('e_online', true);
}
/**
* Retrieve User Perms (admin perms) handler singleton object
* @return comment
*/
public static function getUserPerms()
{
return self::getSingleton('e_userperms', true);
}
/**
* Retrieve comments handler singleton object
* @return comment

View File

@ -76,6 +76,16 @@ class e_model
* @var string
*/
protected $_field_id;
/**
* DB format array - see db::_getTypes() and db::_getFieldValue() (mysql_class.php)
* for example
*
* This can/should be overwritten by extending the class
*
* @var array
*/
protected $_FIELD_TYPES = array();
/**
* Namespace to be used for model related system messages in {@link eMessage} handler
@ -882,7 +892,7 @@ class e_model
{
return $this;
}
if($force)
{
$this->setData(array())
@ -927,6 +937,7 @@ class e_model
if($sql->getLastErrorNumber())
{
$this->addMessageDebug('SQL error #'.$sql->getLastErrorNumber().': '.$sql->getLastErrorText());
$this->addMessageDebug($sql->getLastQuery());
}
else
{
@ -985,6 +996,55 @@ class e_model
{
$this->_cache_string = $str;
}
/**
* Predefined data fields types, passed to DB handler
* @return array
*/
public function getFieldTypes()
{
return $this->_FIELD_TYPES;
}
/**
* Predefined data fields types, passed to DB handler
*
* @param array $field_types
* @return e_model
*/
public function setFieldTypes($field_types)
{
$this->_FIELD_TYPES = $field_types;
return $this;
}
/**
* Auto field type definitions
*
* @param boolean $force
* @return boolean
*/
public function setFieldTypeDefs($force = false)
{
if($force || !$this->getFieldTypes())
{
$ret = e107::getDb()->getFieldDefs($this->getModelTable());
if($ret)
{
foreach ($ret as $k => $v)
{
if('todb' == $v)
{
$ret[$k] = 'string';
}
}
$this->setFieldTypes($ret);
return true;
}
}
return false;
}
/**
* Save data to DB
@ -1240,16 +1300,6 @@ class e_admin_model extends e_model
*/
protected $_posted_data = array();
/**
* DB format array - see db::_getTypes() and db::_getFieldValue() (mysql_class.php)
* for example
*
* This can/should be overwritten by extending the class
*
* @var array
*/
protected $_FIELD_TYPES = array();
/**
* Validation structure - see {@link e_validator::$_required_rules} for
* more information about the array format.
@ -1301,27 +1351,6 @@ class e_admin_model extends e_model
return $this;
}
/**
* Predefined data fields types, passed to DB handler
* @return array
*/
public function getFieldTypes()
{
return $this->_FIELD_TYPES;
}
/**
* Predefined data fields types, passed to DB handler
*
* @param array $field_types
* @return e_admin_model
*/
public function setFieldTypes($field_types)
{
$this->_FIELD_TYPES = $field_types;
return $this;
}
/**
* Retrieves data from the object ($_posted_data) without
* key parsing (performance wise, prefered when possible)
@ -2227,6 +2256,7 @@ class e_tree_model extends e_model
{
return $this;
}
e107::getCache()->set_sys(
$this->getCacheString(true),
$this->toString(false, null, $this->getParam('nocount') ? false : true),
@ -2286,25 +2316,25 @@ class e_tree_model extends e_model
$this->_total = false;
}
$cached = $this->_getCacheData();
$cached = $this->_getCacheData();
if($cached !== false)
{
$this->_loadFromArray($cached);
return $this;
}
$class_name = $this->getParam('model_class', 'e_model');
// auto-load all
if(!$this->getParam('db_query') && $this->getModelTable())
{
$this->setParam('db_query', 'SELECT'.(!$this->getParam('nocount') ? ' SQL_CALC_FOUND_ROWS' : '').' * FROM '.$this->getModelTable());
$this->setParam('db_query', 'SELECT'.(!$this->getParam('nocount') ? ' SQL_CALC_FOUND_ROWS' : '').' * FROM #'.$this->getModelTable());
}
if($this->getParam('db_query') && $class_name && class_exists($class_name))
{
$sql = e107::getDb();
$this->_total = $sql->total_results = false;
if($sql->db_Select_gen($this->getParam('db_query')))
{
$this->_total = is_integer($sql->total_results) ? $sql->total_results : false; //requires SQL_CALC_FOUND_ROWS in query - see db handler
@ -2459,13 +2489,13 @@ class e_tree_model extends e_model
*/
public function toArray($total = false)
{
return $this->getData();
$ret = array();
foreach ($this->getTree() as $id => $model)
{
$ret[$id] = $model->toArray();
}
if($total) $ret['total'] = $this->getTotal();
return $ret;
}

View File

@ -14,15 +14,148 @@
/**
* @package e107
* @subpackage user
* @category user
* @version $Id$
* @author SecretR
*
* User Model
* Front-end User Models
*/
if (!defined('e107_INIT')) { exit; }
class e_user_model extends e_model
/**
* e_model abstract extension candidate (model_class.php)
* TODO - e_model & e_admin_model need refactoring, make e_admin_model extension of e_front_model
* We need DB interface, data validation, data security, etc. on front-end in most cases,
* the only way is additional class between e_model and e_admin_model (to avoid code duplication)
*/
class e_front_model extends e_model
{
/**
* Field type definitions
* @var array
*/
protected $_posted_data = array();
/**
* Get stored non-trusted data
* @param string $field
* @param mixed $default
* @return mixed
*/
public function getPosted($field = null, $default = null)
{
if(null === $field) return e107::getParser()->post_toForm($this->_posted_data);
if(isset($this->_posted_data[$field]))
{
return e107::getParser()->post_toForm($this->_posted_data[$field]);
}
return $default;
}
/**
* Get non-trusted data if present, else model data
* @param string $field
* @param mixed $default
* @return mixed
*/
public function getIfPosted($field, $default = null)
{
$posted = $this->getPosted($field);
if(null === $posted)
{
return $this->get($field, $default);
}
return e107::getParser()->post_toForm($posted);
}
/**
* Set non-trusted data
* @param string $field
* @param mixed $value
* @return e_user_model
*/
public function setPosted($field, $value = null)
{
if(is_array($field))
{
$this->_posted_data = $field;
}
else $this->_posted_data[$field] = $value;
return $this;
}
public function unsetPosted($field)
{
if(null === $field) $this->_posted_data = array();
else unset($this->_posted_data[$field]);
return $this;
}
/**
* Try to merge posted data with current user data
* TODO - validate first
*/
final protected function mergePosted()
{
$this->setFieldTypeDefs(false);
$error = false;
foreach ($this->_posted_data as $field => $value)
{
if(!$this->isWritable($field) || !isset($this->_FIELD_TYPES[$field])) continue;
if($this->sanitize($this->_FIELD_TYPES[$field], $value))
{
$this->set($field, $value);
}
else
{
$error = true;
$this->addMessageError($field.': TODO message errors');
}
}
return $error;
}
public function sanitize($type, &$value)
{
$tp = e107::getParser();
switch ($type)
{
case 'int':
case 'integer':
$value = intval($this->toNumber($value));
return true;
break;
case 'str':
case 'string':
$value = $tp->toDB($value);
return true;
break;
case 'float':
$value = $this->toNumber($value);
return true;
break;
case 'bool':
case 'boolean':
$value = ($value ? true : false);
return true;
break;
case 'null':
$value = ($value ? $tp->toDB($value) : null);
return true;
break;
}
return false;
}
}
class e_user_model extends e_front_model
{
/**
* @see e_model
@ -35,6 +168,12 @@ class e_user_model extends e_model
* @var string
*/
protected $_field_id = 'user_id';
/**
* Field type definitions
* @var array
*/
protected $_FIELD_TYPES = array();
/**
* @see e_model
@ -52,9 +191,136 @@ class e_user_model extends e_model
/**
* Extended structure
*
* @var e_user_extended_strcuture
* @var e_user_extended_structure
*/
protected $_extended_strcuture = null;
protected $_extended_structure = null;
/**
* User model of current editor
* @var e_user_model
*/
protected $_editor = null;
/**
* Always return integer
*
* @see e107_handlers/e_model#getId()
*/
public function getId()
{
return (integer) parent::getId();
}
final public function getAdminId()
{
return ($this->isAdmin() ? $this->getId() : false);
}
final public function getAdminName()
{
return ($this->isAdmin() ? $this->getValue('name') : '');
}
final public function getAdminEmail()
{
return ($this->isAdmin() ? $this->getValue('email') : '');
}
final public function getAdminPwchange()
{
return ($this->isAdmin() ? $this->getValue('pwchange') : '');
}
final public function getAdminPerms()
{
return $this->getValue('perms');
}
public function isCurrent()
{
return false;
}
final public function isAdmin()
{
return ($this->getValue('admin') ? true : false);
}
final public function isMainAdmin()
{
return $this->checkAdminPerms('0');
}
final public function isUser()
{
return ($this->getId() ? true : false);
}
public function hasEditor()
{
return null !== $this->_editor;
}
final protected function _setClassList($uid = '')
{
$this->_class_list = array();
if($this->isUser())
{
if($this->getValue('class'))
{
$this->_class_list = explode(',', $this->getValue('class'));
}
$this->_class_list[] = e_UC_MEMBER;
if($this->isAdmin())
{
$this->_class_list[] = e_UC_ADMIN;
}
if($this->isMainAdmin())
{
$this->_class_list[] = e_UC_MAINADMIN;
}
}
else
{
$this->_class_list[] = e_UC_GUEST;
}
$this->_class_list[] = e_UC_READONLY;
$this->_class_list[] = e_UC_PUBLIC;
return $this;
}
final public function getClassList($toString = false)
{
if(null === $this->_class_list)
{
$this->_setClassList();
}
return ($toString ? implode(',', $this->_class_list) : $this->_class_list);
}
final public function checkClass($class, $allowMain = true)
{
// FIXME - replace check_class() here
return (($allowMain && $this->isMainAdmin()) || check_class($class, $this->getClassList(), 0));
}
final public function checkAdminPerms($perm_str)
{
// FIXME - method to replace getperms()
return ($this->isAdmin() && getperms($perm_str, $this->getAdminPerms()));
}
final public function checkEditorPerms($class = '')
{
if(!$this->hasEditor()) return false;
$editor = $this->getEditor();
if('' !== $class) return ($editor->isAdmin() && $editor->checkClass($class));
return $editor->isAdmin();
}
/**
* Get User value
@ -78,7 +344,7 @@ class e_user_model extends e_model
public function setValue($field, $value)
{
$field = 'user_'.$field;
$this->set($field, $value, false);
$this->set($field, $value, true);
return $this;
}
@ -89,9 +355,9 @@ class e_user_model extends e_model
* @param string $default
* @return mixed
*/
public function getExtendedValue($field, $default = '')
public function getExtended($field)
{
return $this->getExtendedModel()->getValue($field, $default);
return $this->getExtendedModel()->getValue($field);
}
/**
@ -101,7 +367,7 @@ class e_user_model extends e_model
* @param mixed $value
* @return e_user_model
*/
public function setExtendedValue($field, $value)
public function setExtended($field, $value)
{
$this->getExtendedModel()->setValue($field, $value);
return $this;
@ -112,12 +378,11 @@ class e_user_model extends e_model
*
* @return e_user_extended_model
*/
public function getExtended()
public function getExtendedModel()
{
if(null === $this->_extended_model)
{
$this->_extended_model = new e_user_extended_model();
$this->_extended_model->load($this->getId());
$this->_extended_model = new e_user_extended_model($this);
}
return $this->_extended_model;
}
@ -128,20 +393,40 @@ class e_user_model extends e_model
* @param e_user_extended_model $extended_model
* @return e_user_model
*/
public function setExtended($extended_model)
public function setExtendedModel($extended_model)
{
$this->_extended_model = $extended_model;
return $this;
}
/**
* Get extended structure tree
*
* @return e_user_extended_strcuture_tree
* Get current user editor model
* @return e_user_model
*/
public function getExtendedStructure()
public function getEditor()
{
return e107::getExtendedStructure();
return $this->_editor;
}
/**
* Get current user editor model
* @return e_user_model
*/
public function setEditor($user_model)
{
$this->_editor = $user_model;
return $this;
}
/**
* Check if passed field is writable
* @param string $field
* @return boolean
*/
public function isWritable($field)
{
if(!is_string($field)) return true;
return !in_array($field, array($this->getFieldIdName(), 'user_admin', 'user_perms'));
}
/**
@ -149,7 +434,7 @@ class e_user_model extends e_model
*
* @return e_user_model
*/
public function setAsTarget()
protected function setAsTarget()
{
e107::setRegistry('targets/core/user/'.$this->getId() , $this);
return $this;
@ -160,7 +445,7 @@ class e_user_model extends e_model
*
* @return e_user_model
*/
public function clearTarget()
protected function clearTarget()
{
e107::setRegistry('targets/core/user'.$this->getId(), null);
return $this;
@ -175,10 +460,36 @@ class e_user_model extends e_model
if($this->getId())
{
// no errors - register
$this->setAsTarget();
$this->setAsTarget()
->setEditor(e107::getUser()); //set current user as default editor
}
}
/**
* Send model data to DB
*/
public function save()
{
if(!$this->getId())
{
return false; // TODO - message
}
if(!$this->checkEditorPerms())
{
return false; // TODO - message, admin log
}
if($this->mergePosted() && $this->data_has_changed)
{
$update['data'] = $this->getData();
$upate['WHERE'] = $this->getFieldIdName().'='.$this->getId();
$upate['_FIELD_TYPES'] = $this->getFieldTypes();
return e107::getDb()->db_Update($this->getModelTable(), $upate);
}
return 0;
}
public function destroy()
{
$this->clearTarget()
@ -190,23 +501,124 @@ class e_user_model extends e_model
}
}
// TODO Current user model is under construction
class e_current_user extends e_user_model
// TODO - add some more useful methods, sc_* methods support
class e_system_user extends e_user_model
{
/**
* Constructor
*
* @param array $user_data trusted data, loaded from DB
* @return void
*/
public function __construct($user_data = array())
{
if($user_data)
{
$this->_data = $user_data;
$this->setEditor(e107::getUser());
}
}
final public function isCurrent()
{
// check against current system user
return ($this->getId() && $this->getId() == e107::getUser()->getId());
}
}
/**
* Current system user - additional data protection is required
* @author SecretR
*/
class e_user extends e_user_model
{
public function __construct()
{
// reference to self
$this->setEditor($this);
}
/**
* Yes, it's current user - return always true
* NOTE: it's not user check, use isUser() instead!
* @return boolean
*/
final public function isCurrent()
{
return true;
}
}
// TODO - add some more useful methods, sc_* methods support
class e_user extends e_user_model
{
final public function isCurrent()
// TODO login by name/password, load, set cookie/session data
final public function login($uname, $upass_plain, $uauto = false, $uchallange = false)
{
// FIXME - check against current system user
return ($this->getId() && $this->getId() === USERID);
// FIXME - rewrite userlogin - clean up redirects and
//$userlogin = new userlogin($uname, $upass_plain, $uauto, $uchallange);
// if($userlogin->getId()) $this->load() --> use the previously set user COOKIE/SESSION data
return $this->isUser();
}
/**
*
* @return unknown_type
*/
protected function initConstants()
{
//FIXME - BC - constants from init_session() should be defined here
//init_session(); // the old way
}
/**
* TODO destroy cookie/session data, self destroy
* @return void
*/
final public function logout()
{
// FIXME - destoy cookie/session data first
$this->_data = array();
if(null !== $this->_extended_model)
{
$this->_extended_model->destroy();
}
e107::setRegistry('targets/core/current_user', null);
}
/**
* TODO load user data by cookie/session data
* @return e_user
*/
final public function load($force = false)
{
// init_session() should come here
// $this->initConstants(); - called after data is loaded
// FIXME - temporary here, for testing only!!!
if(USER) $this->setData(get_user_data(USERID));
return $this;
}
/**
* Not allowed
*
* @return e_user_model
*/
final protected function setAsTarget()
{
return $this;
}
/**
* Not allowed
*
* @return e_user_model
*/
final protected function clearTarget()
{
return $this;
}
public function destroy()
{
// not allowed - see logout()
}
}
@ -230,41 +642,209 @@ class e_user_extended_model extends e_model
*/
protected $_message_stack = 'user';
/**
* @var e_user_extended_structure_tree
*/
protected $_structure = null;
/**
* User model, the owner of extended fields model
* @var e_user_model
*/
protected $_user = null;
/**
* User model
* @var e_user_model
*/
protected $_editor = null;
/**
* Stores access classes and default value per custom field
* @var array
*/
protected $_struct_index = array();
/**
* Constructor
* @param e_user_model $user_model
* @return void
*/
public function __construct(e_user_model $user_model)
{
$this->setUser($user_model)
->setEditor(e107::getUser()) // current by default
->load();
}
/**
* Get user model
* @return e_user_model
*/
public function getUser()
{
return $this->_user;
}
/**
* Set User model
* @param $user_model
* @return e_user_extended_model
*/
public function setUser($user_model)
{
$this->_user = $user_model;
return $this;
}
/**
* Get current user editor model
* @return e_user_model
*/
public function getEditor()
{
return $this->_editor;
}
/**
* Get current user editor model
* @return e_user_model
*/
public function setEditor($user_model)
{
$this->_editor = $user_model;
return $this;
}
/**
* Get User extended field value
*
* Returns NULL when field/default value not found or not enough permissions
* @param string$field
* @param string $default
* @return mixed
*/
public function getValue($field, $default = '')
public function getValue($field)
{
$field = 'user_'.$field;
return $this->get($field, $default);
$field = 'user_'.$field;
if(!$this->checkRead($field)) return null;
return $this->get($field, $this->getDefault($field));
}
/**
* Set User extended field value
*
* Set User extended field value, only if current editor has write permissions
* Note: Data is not sanitized!
* @param string $field
* @param mixed $value
* @return e_user_model
* @return e_user_extended_model
*/
public function setValue($field, $value)
{
$field = 'user_'.$field;
$this->set($field, $value, false);
if(!$this->checkWrite($field)) return $this;
$this->set($field, $value, true);
return $this;
}
/**
* Get default field value, defined by extended field structure
* Returns NULL if field/default value not found
* @param string $field
* @return mixed
*/
public function getDefault($field)
{
return varset($this->_struct_index[$field]['default'], null);
}
/**
* Check field read permissions against current editor
* @param string $field
* @return boolean
*/
public function checkRead($field)
{
return $this->getEditor()->checkClass(varset($this->_struct_index[$field]['read']));
}
/**
* Check field write permissions
* @param string $field
* @return boolean
*/
public function checkWrite($field)
{
return $this->getEditor()->checkClass(varset($this->_struct_index[$field]['write']));
}
/**
* Check field signup permissions
* @param string $field
* @return boolean
*/
public function checkSignup($field)
{
return $this->getEditor()->checkClass(varset($this->_struct_index[$field]['signup']));
}
/**
* Check field applicable permissions
* @param string $field
* @return boolean
*/
public function checkApplicable($field)
{
return $this->getEditor()->checkClass(varset($this->_struct_index[$field]['applicable']));
}
/**
* @see e_model#load($id, $force)
* @return e_user_extended_model
*/
public function load($force = false)
{
if($this->getId() && !$force) return $this;
parent::load($this->getUser()->getId(), $force);
$this->_loadAccess();
return $this;
}
/**
* Load extended fields permissions once (performance)
* @return e_user_extended_model
*/
protected function _loadAccess()
{
$struct_tree = $this->getExtendedStructure();
if($this->getId() && $struct_tree->hasTree())
{
// load structure dependencies
$ignore = array($this->getFieldIdName(), 'user_hidden_fields'); // TODO - user_hidden_fields? Old?
$fields = $struct_tree->getTree();
foreach ($fields as $id => $field)
{
if(!in_array($field->getValue('name'), $ignore))
{
$this->_struct_index['user_'.$field->getValue('name')] = array(
'read' => $field->getValue('read'),
'write' => $field->getValue('write'),
'signup' => $field->getValue('signup'),
'apply' => $field->getValue('applicable'),
'default' => $field->getValue('default'),
);
}
}
}
return $this;
}
/**
* Get extended structure tree
*
* @return e_user_extended_strcuture_tree
* @return e_user_extended_structure_tree
*/
public function getExtendedStructure()
{
return e107::getExtendedStructure();
if(null === $this->_structure) $this->_structure = e107::getUserStructure();
return $this->_structure;
}
}
@ -286,7 +866,7 @@ class e_user_extended_structure_model extends e_model
* @see e_model
* @var string
*/
protected $_message_stack = 'user';
protected $_message_stack = 'user_struct';
/**
* Get User extended structure field value
@ -297,7 +877,7 @@ class e_user_extended_structure_model extends e_model
*/
public function getValue($field, $default = '')
{
$field = 'user_extended_struct'.$field;
$field = 'user_extended_struct_'.$field;
return $this->get($field, $default);
}
@ -310,7 +890,7 @@ class e_user_extended_structure_model extends e_model
*/
public function setValue($field, $value)
{
$field = 'user_extended_struct'.$field;
$field = 'user_extended_struct_'.$field;
$this->set($field, $value, false);
return $this;
}
@ -324,7 +904,7 @@ class e_user_extended_structure_model extends e_model
}
}
class e_user_extended_strcuture_tree extends e_tree_model
class e_user_extended_structure_tree extends e_tree_model
{
/**
* @see e_model
@ -347,26 +927,69 @@ class e_user_extended_strcuture_tree extends e_tree_model
/**
* @var string
*/
protected $_cache_string = 'user';
protected $_cache_string = 'nomd5_user_extended_struct';
/**
* Force system cache
* Force system cache (cache used even if disabled by site admin)
* @var boolen
*/
protected $_cache_force = true;
/**
* Force system cache (cache used even if disabled by site admin)
* @var boolen
*/
protected $_name_index = true;
/**
* Constructor - auto-load
* @return void
*/
public function __construct()
{
$this->load();
}
public function getNodeByName($name)
{
if($this->isNodeName($name))
{
return $this->getNode($this->getNodeId($name));
}
return null;
}
public function isNodeName($name)
{
return (isset($this->_name_index[$name]) && $this->isNode($this->_name_index[$name]));
}
public function getNodeId($name)
{
return $this->_name_index[$name];
}
/**
* Load tree data
*
* @see e107_handlers/e_tree_model#load($force)
* @param boolean $force
*/
public function load($force = false)
{
$this->setParam('nocount', true)
->setParam('model_class', 'e_user_extended_structure_model');
parent::load($force);
return $this;
}
/**
* Build name index on load
* @param e_user_extended_structure_model $model
*/
protected function _onLoad($model)
{
$this->_name_index['user_'.$model->getValue('name')] = $model->getId();
return $this;
}
}