本文整理匯總了PHP中UserModel::populateModel方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserModel::populateModel方法的具體用法?PHP UserModel::populateModel怎麽用?PHP UserModel::populateModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserModel
的用法示例。
在下文中一共展示了UserModel::populateModel方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getUserByUid
/**
* Returns a user by their UID.
*
* ```php
* $user = craft()->users->getUserByUid($userUid);
* ```
*
* @param int $uid The user’s UID.
*
* @return UserModel|null The user with the given UID, or `null` if a user could not be found.
*/
public function getUserByUid($uid)
{
$userRecord = UserRecord::model()->findByAttributes(array('uid' => $uid));
if ($userRecord) {
return UserModel::populateModel($userRecord);
}
return null;
}
示例2: onBeforeSaveUser
/**
* Handle the onBeforeSaveUser event.
*
* @param Event $event
*/
public function onBeforeSaveUser(Event $event)
{
// Get user id to save
$id = $event->params['user']->id;
if (!$event->params['isNewUser']) {
// Get old user from db
$user = UserModel::populateModel(UserRecord::model()->findById($id));
// Get fields
$this->before = $this->fields($user);
} else {
// Get fields
$this->before = $this->fields($event->params['user'], true);
}
}
示例3: getUser
/**
* Gets the currently logged-in user.
*
* @return UserModel|null
*/
public function getUser()
{
// Does a user appear to be logged in?
if (Craft::isInstalled() && $this->getState('__id') !== null) {
if (!isset($this->_user)) {
$userRow = $this->_getUserRow($this->getId());
if ($userRow) {
$this->_userModel = UserModel::populateModel($userRow);
} else {
$this->_userModel = false;
}
}
return $this->_userModel ? $this->_userModel : null;
}
}
示例4: getUser
/**
* Returns the currently logged-in user.
*
* @return UserModel|null The currently logged-in user, or `null`.
*/
public function getUser()
{
// Does a user appear to be logged in?
if (craft()->isInstalled() && !$this->getIsGuest()) {
if (!isset($this->_userModel)) {
$userRow = $this->_getValidUserRow($this->getId());
// Only return active and pending users.
if ($userRow) {
$this->_userModel = UserModel::populateModel($userRow);
} else {
$this->_userModel = false;
}
}
return $this->_userModel ? $this->_userModel : null;
}
}
示例5: populateElementModel
/**
* @inheritDoc IElementType::populateElementModel()
*
* @param array $row
*
* @return array
*/
public function populateElementModel($row)
{
return UserModel::populateModel($row);
}
示例6: getUser
/**
* Returns the currently logged-in user.
*
* @return UserModel|null The currently logged-in user, or `null`.
*/
public function getUser()
{
// Does a user appear to be logged in?
if (craft()->isInstalled() && !$this->getIsGuest()) {
if (!isset($this->_userModel)) {
$userRow = $this->_getUserRow($this->getId());
if ($userRow && $userRow['status'] == UserStatus::Active || $userRow['status'] == UserStatus::Pending) {
$this->_userModel = UserModel::populateModel($userRow);
} else {
$this->_userModel = false;
}
}
return $this->_userModel ? $this->_userModel : null;
}
}
示例7: getUser
/**
* Returns the currently logged-in user.
*
* @return UserModel|null The currently logged-in user, or `null`.
*/
public function getUser()
{
// Does a user appear to be logged in?
if (craft()->isInstalled() && !$this->getIsGuest()) {
if (!isset($this->_userModel)) {
$userRow = $this->_getUserRow($this->getId());
// Only return active and pending users.
if ($userRow) {
$validUser = false;
// Keeping extra logic here so the upgrade to 2.3 won't freak.
// First the pre 2.3 check.
if (isset($userRow['status']) && $userRow['status'] == UserStatus::Active || isset($userRow['status']) && $userRow['status'] == UserStatus::Pending) {
$validUser = true;
}
// Now the 2.3 check. If all 3 of these are false, then the user is active or pending.
if (isset($userRow['suspended']) && isset($userRow['archived']) && isset($userRow['locked']) && (!$userRow['suspended'] && !$userRow['archived'] && !$userRow['locked'])) {
$validUser = true;
}
if ($validUser) {
$this->_userModel = UserModel::populateModel($userRow);
}
} else {
$this->_userModel = false;
}
}
return $this->_userModel ? $this->_userModel : null;
}
}
示例8: getUser
/**
* Returns the currently logged-in user.
*
* @return UserModel|null The currently logged-in user, or `null`.
*/
public function getUser()
{
// Does a user appear to be logged in?
if (craft()->isInstalled() && !$this->getIsGuest()) {
if (!isset($this->_userModel)) {
$userRow = $this->_getUserRow($this->getId());
// Only return active and pending users.
if ($userRow) {
$validUser = false;
// TODO: Remove after next breakpoint.
// Keeping extra logic here so the upgrade to 2.3 won't freak.
// First the pre 2.3 check.
if (isset($userRow['status']) && $userRow['status'] == UserStatus::Active || isset($userRow['status']) && $userRow['status'] == UserStatus::Pending) {
$validUser = true;
}
// Now the 2.3 check. If all 3 of these are false, then the user is active or pending.
if (isset($userRow['suspended']) && isset($userRow['archived']) && isset($userRow['locked']) && (!$userRow['suspended'] && !$userRow['archived'] && !$userRow['locked'])) {
$validUser = true;
}
// One last attempt.
if (!$validUser) {
// If the previous user was an admin and we're impersonating the current user.
if ($previousUserId = craft()->httpSession->get(static::USER_IMPERSONATE_KEY)) {
$previousUser = craft()->users->getUserById($previousUserId);
if ($previousUser && $previousUser->admin) {
$validUser = true;
}
}
}
if ($validUser) {
$this->_userModel = UserModel::populateModel($userRow);
}
} else {
$this->_userModel = false;
}
}
return $this->_userModel ? $this->_userModel : null;
}
}
示例9: findUser
/**
* Finds a user.
*
* @param UserCriteria|null $criteria
* @return array
*/
public function findUser(UserCriteria $criteria = null)
{
if (!$criteria) {
$criteria = new UserCriteria();
}
$query = craft()->db->createCommand()->select('u.*')->from('users u');
$this->_applyUserConditions($query, $criteria);
$result = $query->queryRow();
if ($result) {
return UserModel::populateModel($result);
}
}
示例10: log
/**
* Initialize the category saving/deleting events.
*/
public function log()
{
// Get values before saving
craft()->on('users.onBeforeSaveUser', function (Event $event) {
// Get user id to save
$id = $event->params['user']->id;
if (!$event->params['isNewUser']) {
// Get old user from db
$user = UserModel::populateModel(UserRecord::model()->findById($id));
// Get fields
craft()->auditLog_user->before = craft()->auditLog_user->fields($user);
} else {
// Get fields
craft()->auditLog_user->before = craft()->auditLog_user->fields($event->params['user'], true);
}
});
// Get values after saving
craft()->on('users.onSaveUser', function (Event $event) {
// Get saved user
$user = $event->params['user'];
// Get fields
craft()->auditLog_user->after = craft()->auditLog_user->fields($user);
// New row
$log = new AuditLogRecord();
// Set user id
$log->userId = craft()->userSession->getUser() ? craft()->userSession->getUser()->id : $user->id;
// Set element type
$log->type = ElementType::User;
// Set origin
$log->origin = craft()->request->isCpRequest() ? craft()->config->get('cpTrigger') . '/' . craft()->request->path : craft()->request->path;
// Set before
$log->before = craft()->auditLog_user->before;
// Set after
$log->after = craft()->auditLog_user->after;
// Set status
$log->status = $event->params['isNewUser'] ? AuditLogModel::CREATED : AuditLogModel::MODIFIED;
// Save row
$log->save(false);
// Callback
craft()->auditLog->elementHasChanged(ElementType::User, $user->id, craft()->auditLog_user->before, craft()->auditLog_user->after);
});
// Get values before deleting
craft()->on('users.onBeforeDeleteUser', function (Event $event) {
// Get deleted user
$user = $event->params['user'];
// Get fields
craft()->auditLog_user->before = craft()->auditLog_user->fields($user);
craft()->auditLog_user->after = craft()->auditLog_user->fields($user, true);
// New row
$log = new AuditLogRecord();
// Set user id
$log->userId = craft()->userSession->getUser()->id;
// Set element type
$log->type = ElementType::User;
// Set origin
$log->origin = craft()->request->isCpRequest() ? craft()->config->get('cpTrigger') . '/' . craft()->request->path : craft()->request->path;
// Set before
$log->before = craft()->auditLog_user->before;
// Set after
$log->after = craft()->auditLog_user->after;
// Set status
$log->status = AuditLogModel::DELETED;
// Save row
$log->save(false);
// Callback
craft()->auditLog->elementHasChanged(ElementType::User, $user->id, craft()->auditLog_user->before, craft()->auditLog_user->after);
});
}