本文整理汇总了PHP中XoopsUser::setVar方法的典型用法代码示例。如果您正苦于以下问题:PHP XoopsUser::setVar方法的具体用法?PHP XoopsUser::setVar怎么用?PHP XoopsUser::setVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XoopsUser
的用法示例。
在下文中一共展示了XoopsUser::setVar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: change
/**
* Modify user information
*
* @param \XoopsUser $xoopsUser user object
* @param string $data data
* @param string $uname username
* @param string $pwd password
*
* @return bool|XoopsUser
*/
public function change(\XoopsUser $xoopsUser, $data, $uname, $pwd = null)
{
$xoops = \Xoops::getInstance();
$ret = false;
$member_handler = $xoops->getHandlerMember();
$xoopsUser->setVar('pass', password_hash(stripslashes($pwd), PASSWORD_DEFAULT));
$this->setVarsMapping($xoopsUser, $data);
if ($member_handler->insertUser($xoopsUser)) {
return $xoopsUser;
} else {
$xoops->redirect(\XoopsBaseConfig::get('url') . '/user.php', 5, $xoopsUser->getHtmlErrors());
}
return $ret;
}
示例2: profile_getUserForm
/**
* Get {@link Xoops\Form\ThemeForm} for editing a user
*
* @param XoopsUser $user
* @param ProfileProfile|null $profile
* @param bool $action
* @return Xoops\Form\ThemeForm
*/
function profile_getUserForm(XoopsUser &$user, ProfileProfile $profile = null, $action = false)
{
$xoops = Xoops::getInstance();
if ($action === false) {
$action = $_SERVER['REQUEST_URI'];
}
$title = $user->isNew() ? _PROFILE_AM_ADDUSER : XoopsLocale::EDIT_PROFILE;
$form = new Xoops\Form\ThemeForm($title, 'userinfo', $action, 'post', true);
/* @var $profile_handler ProfileProfileHandler */
$profile_handler = $xoops->getModuleHandler('profile');
// Dynamic fields
if (!$profile) {
$profile = $profile_handler->getProfile($user->getVar('uid'));
}
// Get fields
$fields = $profile_handler->loadFields();
// Get ids of fields that can be edited
$gperm_handler = $xoops->getHandlerGroupperm();
$editable_fields = $gperm_handler->getItemIds('profile_edit', $xoops->user->getGroups(), $xoops->module->getVar('mid'));
if ($user->isNew() || $xoops->user->isAdmin()) {
$elements[0][] = array('element' => new Xoops\Form\Text(XoopsLocale::USERNAME, 'uname', 3, $xoops->user->isAdmin() ? 60 : $xoops->getConfig('maxuname'), $user->getVar('uname', 'e')), 'required' => 1);
$email_text = new Xoops\Form\Text('', 'email', 4, 60, $user->getVar('email'));
} else {
$elements[0][] = array('element' => new Xoops\Form\Label(XoopsLocale::USERNAME, $user->getVar('uname')), 'required' => 0);
$email_text = new Xoops\Form\Label('', $user->getVar('email'));
}
$email_tray = new Xoops\Form\ElementTray(XoopsLocale::EMAIL, '<br />');
$email_tray->addElement($email_text, $user->isNew() || $xoops->user->isAdmin() ? 1 : 0);
$weights[0][] = 0;
$elements[0][] = array('element' => $email_tray, 'required' => 0);
$weights[0][] = 0;
if ($xoops->user->isAdmin() && $user->getVar('uid') != $xoops->user->getVar('uid')) {
//If the user is an admin and is editing someone else
$pwd_text = new Xoops\Form\Password('', 'password', 3, 32);
$pwd_text2 = new Xoops\Form\Password('', 'vpass', 3, 32);
$pwd_tray = new Xoops\Form\ElementTray(XoopsLocale::PASSWORD . '<br />' . XoopsLocale::TYPE_NEW_PASSWORD_TWICE_TO_CHANGE_IT);
$pwd_tray->addElement($pwd_text);
$pwd_tray->addElement($pwd_text2);
$elements[0][] = array('element' => $pwd_tray, 'required' => 0);
//cannot set an element tray required
$weights[0][] = 0;
$level_radio = new Xoops\Form\Radio(_PROFILE_MA_USERLEVEL, 'level', $user->getVar('level'));
$level_radio->addOption(1, _PROFILE_MA_ACTIVE);
$level_radio->addOption(0, _PROFILE_MA_INACTIVE);
//$level_radio->addOption(-1, _PROFILE_MA_DISABLED);
$elements[0][] = array('element' => $level_radio, 'required' => 0);
$weights[0][] = 0;
}
$elements[0][] = array('element' => new Xoops\Form\Hidden('uid', $user->getVar('uid')), 'required' => 0);
$weights[0][] = 0;
$elements[0][] = array('element' => new Xoops\Form\Hidden('op', 'save'), 'required' => 0);
$weights[0][] = 0;
$cat_handler = $xoops->getModuleHandler('category');
$categories = array();
$all_categories = $cat_handler->getObjects(null, true, false);
$count_fields = count($fields);
/* @var ProfileField $field */
foreach ($fields as $field) {
if (in_array($field->getVar('field_id'), $editable_fields)) {
// Set default value for user fields if available
if ($user->isNew()) {
$default = $field->getVar('field_default');
if ($default !== '' && $default !== null) {
$user->setVar($field->getVar('field_name'), $default);
}
}
if ($profile->getVar($field->getVar('field_name'), 'n') === null) {
$default = $field->getVar('field_default', 'n');
$profile->setVar($field->getVar('field_name'), $default);
}
$fieldinfo['element'] = $field->getEditElement($user, $profile);
$fieldinfo['required'] = $field->getVar('field_required');
$key = @$all_categories[$field->getVar('cat_id')]['cat_weight'] * $count_fields + $field->getVar('cat_id');
$elements[$key][] = $fieldinfo;
$weights[$key][] = $field->getVar('field_weight');
$categories[$key] = @$all_categories[$field->getVar('cat_id')];
}
}
if ($xoops->isUser() && $xoops->user->isAdmin()) {
$xoops->loadLanguage('admin', 'profile');
$gperm_handler = $xoops->getHandlerGroupperm();
//If user has admin rights on groups
include_once $xoops->path('modules/system/constants.php');
if ($gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $xoops->user->getGroups(), 1)) {
//add group selection
$group_select = new Xoops\Form\SelectGroup(XoopsLocale::USER_GROUPS, 'groups', false, $user->getGroups(), 5, true);
$elements[0][] = array('element' => $group_select, 'required' => 0);
//set as latest;
$weights[0][] = $count_fields + 1;
}
}
ksort($elements);
//.........这里部分代码省略.........
示例3: profile_getUserForm
/**
* Get {@link XoopsThemeForm} for editing a user
*
* @param XoopsUser $user {@link XoopsUser} to edit
* @param ProfileProfile|XoopsObject|null $profile
* @param bool $action
*
* @return object
*/
function profile_getUserForm(XoopsUser $user, ProfileProfile $profile = null, $action = false)
{
if ($action === false) {
$action = $_SERVER['REQUEST_URI'];
}
if (empty($GLOBALS['xoopsConfigUser'])) {
$config_handler = xoops_getHandler('config');
$GLOBALS['xoopsConfigUser'] = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
}
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
$title = $user->isNew() ? _PROFILE_AM_ADDUSER : _US_EDITPROFILE;
$form = new XoopsThemeForm($title, 'userinfo', $action, 'post', true);
$profile_handler = xoops_getModuleHandler('profile');
// Dynamic fields
if (!$profile) {
$profile_handler = xoops_getModuleHandler('profile', 'profile');
$profile = $profile_handler->get($user->getVar('uid'));
}
// Get fields
$fields = $profile_handler->loadFields();
// Get ids of fields that can be edited
$gperm_handler = xoops_getHandler('groupperm');
$editable_fields = $gperm_handler->getItemIds('profile_edit', $GLOBALS['xoopsUser']->getGroups(), $GLOBALS['xoopsModule']->getVar('mid'));
if ($user->isNew() || $GLOBALS['xoopsUser']->isAdmin()) {
$elements[0][] = array('element' => new XoopsFormText(_US_NICKNAME, 'uname', 25, $GLOBALS['xoopsUser']->isAdmin() ? 60 : $GLOBALS['xoopsConfigUser']['maxuname'], $user->getVar('uname', 'e')), 'required' => 1);
$email_text = new XoopsFormText('', 'email', 30, 60, $user->getVar('email'));
} else {
$elements[0][] = array('element' => new XoopsFormLabel(_US_NICKNAME, $user->getVar('uname')), 'required' => 0);
$email_text = new XoopsFormLabel('', $user->getVar('email'));
}
$email_tray = new XoopsFormElementTray(_US_EMAIL, '<br>');
$email_tray->addElement($email_text, $user->isNew() || $GLOBALS['xoopsUser']->isAdmin() ? 1 : 0);
$weights[0][] = 0;
$elements[0][] = array('element' => $email_tray, 'required' => 0);
$weights[0][] = 0;
if ($GLOBALS['xoopsUser']->isAdmin() && $user->getVar('uid') != $GLOBALS['xoopsUser']->getVar('uid')) {
//If the user is an admin and is editing someone else
$pwd_text = new XoopsFormPassword('', 'password', 10, 32);
$pwd_text2 = new XoopsFormPassword('', 'vpass', 10, 32);
$pwd_tray = new XoopsFormElementTray(_US_PASSWORD . '<br>' . _US_TYPEPASSTWICE);
$pwd_tray->addElement($pwd_text);
$pwd_tray->addElement($pwd_text2);
$elements[0][] = array('element' => $pwd_tray, 'required' => 0);
//cannot set an element tray required
$weights[0][] = 0;
$level_radio = new XoopsFormRadio(_PROFILE_MA_USERLEVEL, 'level', $user->getVar('level'));
$level_radio->addOption(1, _PROFILE_MA_ACTIVE);
$level_radio->addOption(0, _PROFILE_MA_INACTIVE);
//$level_radio->addOption(-1, _PROFILE_MA_DISABLED);
$elements[0][] = array('element' => $level_radio, 'required' => 0);
$weights[0][] = 0;
}
$elements[0][] = array('element' => new XoopsFormHidden('uid', $user->getVar('uid')), 'required' => 0);
$weights[0][] = 0;
$elements[0][] = array('element' => new XoopsFormHidden('op', 'save'), 'required' => 0);
$weights[0][] = 0;
$cat_handler = xoops_getModuleHandler('category');
$categories = array();
$all_categories = $cat_handler->getObjects(null, true, false);
$count_fields = count($fields);
foreach (array_keys($fields) as $i) {
if (in_array($fields[$i]->getVar('field_id'), $editable_fields)) {
// Set default value for user fields if available
if ($user->isNew()) {
$default = $fields[$i]->getVar('field_default');
if ($default !== '' && $default !== null) {
$user->setVar($fields[$i]->getVar('field_name'), $default);
}
}
if ($profile->getVar($fields[$i]->getVar('field_name'), 'n') === null) {
$default = $fields[$i]->getVar('field_default', 'n');
$profile->setVar($fields[$i]->getVar('field_name'), $default);
}
$fieldinfo['element'] = $fields[$i]->getEditElement($user, $profile);
$fieldinfo['required'] = $fields[$i]->getVar('field_required');
$key = @$all_categories[$fields[$i]->getVar('cat_id')]['cat_weight'] * $count_fields + $fields[$i]->getVar('cat_id');
$elements[$key][] = $fieldinfo;
$weights[$key][] = $fields[$i]->getVar('field_weight');
$categories[$key] = @$all_categories[$fields[$i]->getVar('cat_id')];
}
}
if ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->isAdmin()) {
xoops_loadLanguage('admin', 'profile');
$gperm_handler = xoops_getHandler('groupperm');
//If user has admin rights on groups
include_once $GLOBALS['xoops']->path('modules/system/constants.php');
if ($gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $GLOBALS['xoopsUser']->getGroups(), 1)) {
//add group selection
$group_select = new XoopsFormSelectGroup(_US_GROUPS, 'groups', false, $user->getGroups(), 5, true);
$elements[0][] = array('element' => $group_select, 'required' => 0);
//set as latest;
//.........这里部分代码省略.........
示例4: activateUser
/**
* activate a user
*
* @param XoopsUser $user reference to the {@link XoopsUser} object
* @return mixed successful? false on failure
*/
public function activateUser(XoopsUser $user)
{
if ($user->getVar('level') != 0) {
return true;
}
$user->setVar('level', 1);
return $this->userHandler->insert($user, true);
}