Craft 2 Class Reference

Class UserModel

Package
craft.app.models
Namespace
Craft
Inheritance
class UserModel » BaseElementModel » BaseModel » \CModel » \CComponent
Implements
\ArrayAccess, \Traversable, \IteratorAggregate
Since
1.0
Source Code
craft/app/models/UserModel.php

User model class.

Public Properties
Property Type Description Defined By
allErrors array Returns all errors in a single, flattened list, devoid of attribute names. BaseModel
ancestors ElementCriteriaModel Returns the element's ancestors. BaseElementModel
attributeConfigs array Returns this model's normalized attribute configs. BaseModel
attributes array Returns an array of attribute values. BaseModel
children ElementCriteriaModel Returns the element's children. BaseElementModel
classHandle string Get the class name, sans namespace and suffix. BaseModel
content ContentModel Returns the content for the element. BaseElementModel
contentFromPost array Returns the raw content from the post data, before it was passed through prepValueFromPost(). BaseElementModel
contentPostLocation string / null Returns the location in POST that the content was pulled from. BaseElementModel
contentTable string Returns the name of the table this element's content is stored in. BaseElementModel
cooldownEndTime DateTime / null Returns the time when the user will be over their cooldown period. UserModel
cpEditUrl string / false Returns the element's CP edit URL. UserModel
descendants ElementCriteriaModel Returns the element's descendants. BaseElementModel
elementType string Returns the type of element this is. BaseElementModel
errors array Returns the errors for all attribute or a single attribute. \CModel
extraAttributeNames array Returns a list of the names of the extra attributes that have been saved on this model, if it's not strict. BaseModel
fieldColumnPrefix string Returns the field column prefix this element's content uses. BaseElementModel
fieldContext string Returns the field context this element's content uses. BaseElementModel
fieldLayout FieldLayoutModel / null Returns the field layout used by this element. BaseElementModel
friendlyName string / null Gets the user's first name or username. UserModel
fullName string / null Gets the user's full name. UserModel
groups array Returns the user's groups. UserModel
hasFreshContent bool Returns whether the element’s content is "fresh" (unsaved and without validation errors). BaseElementModel
iterator \CMapIterator Returns an iterator for traversing the attributes in the model. \CModel
locales array Returns the locale IDs this element is available in. BaseElementModel
name string Returns the user's full name or username. UserModel
next ElementCriteriaModel / null Returns the next element relative to this one, from a given set of criteria. BaseElementModel
nextSibling BaseElementModel / null Returns the element's next sibling. BaseElementModel
parent BaseElementModel / null Get the element's parent. BaseElementModel
parents ElementCriteriaModel Returns a new ElementCriteriaModel prepped to return this element's same-type parents. BaseElementModel
photoUrl string / null Returns the URL to the user's photo. UserModel
prev ElementCriteriaModel / null Returns the previous element relative to this one, from a given set of criteria. BaseElementModel
prevSibling BaseElementModel / null Returns the element's previous sibling. BaseElementModel
rawContent mixed Returns the raw content saved on this entity. BaseElementModel
ref string / null Returns the reference string to this element. UserModel
remainingCooldownTime DateInterval / null Returns the remaining cooldown time for this user, if they've entered their password incorrectly too many times. UserModel
safeAttributeNames array Returns the attribute names that are safe to be massively assigned. \CModel
scenario string Returns the scenario that this model is used in. \CModel
siblings ElementCriteriaModel Returns all of the element's siblings. BaseElementModel
status string / null Returns the element's status. UserModel
thumbUrl false / null / string Returns the URL to the element's thumbnail, if there is one. UserModel
title string Returns the element's title. BaseElementModel
totalDescendants bool Returns the total number of descendants that the element has. BaseElementModel
url string Returns the element's full URL. BaseElementModel
urlFormat string / null Returns the URL format used to generate this element's URL. BaseElementModel
validatorList \CList Returns all the validators declared in the model. \CModel
validators array Returns the validators applicable to the current scenario. \CModel
Protected Properties
Property Type Description Defined By
classSuffix string BaseModel
strictAttributes bool Whether this model should be strict about only allowing values to be set on defined attributes BaseModel
Public Methods
Method Description Defined By
__call() Magic __call() method, used for chain-setting attribute values. BaseModel
__construct() Constructor BaseModel
__get() Getter BaseElementModel
__isset() Treats custom fields as properties. BaseElementModel
__set() PHP setter magic method. BaseModel
__toString() Use the full name or username as the string representation. UserModel
__unset() Sets a component property to be null. \CComponent
addError() Adds a new error to the specified attribute. \CModel
addErrors() Adds a list of errors. \CModel
asa() Returns the named behavior object. \CComponent
attachBehavior() Attaches a behavior to this component. \CComponent
attachBehaviors() Attaches a list of behaviors to the component. \CComponent
attachEventHandler() Attaches an event handler to an event. \CComponent
attributeLabels() Returns the attribute labels. BaseModel
attributeNames() Returns the list of this model's attribute names. BaseModel
behaviors() Returns a list of behaviors that this model should behave as. \CModel
can() Returns whether the user has permission to perform a given action. UserModel
canGetProperty() Determines whether a property can be read. \CComponent
canSetProperty() Determines whether a property can be set. \CComponent
clearErrors() Removes errors for all attributes or a single attribute. \CModel
copy() Returns a copy of this model. BaseModel
createValidators() Creates validator objects based on the specification in rules. \CModel
detachBehavior() Detaches a behavior from the component. \CComponent
detachBehaviors() Detaches all behaviors from the component. \CComponent
detachEventHandler() Detaches an existing event handler. \CComponent
disableBehavior() Disables an attached behavior. \CComponent
disableBehaviors() Disables all behaviors attached to this component. \CComponent
enableBehavior() Enables an attached behavior. \CComponent
enableBehaviors() Enables all behaviors attached to this component. \CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. \CComponent
generateAttributeLabel() Generates a user friendly attribute label. This is done by replacing underscores or dashes with blanks and changing the first letter of each word to upper case. For example, 'department_name' or 'DepartmentName' becomes 'Department Name'. BaseModel
getAllErrors() Returns all errors in a single, flattened list, devoid of attribute names. BaseModel
getAncestors() Returns the element's ancestors. BaseElementModel
getAttribute() Gets an attribute’s value. BaseElementModel
getAttributeConfigs() Returns this model's normalized attribute configs. BaseModel
getAttributeLabel() Returns the text label for the specified attribute. \CModel
getAttributes() Returns an array of attribute values. BaseModel
getChildren() Returns the element's children. BaseElementModel
getClassHandle() Get the class name, sans namespace and suffix. BaseModel
getContent() Returns the content for the element. BaseElementModel
getContentFromPost() Returns the raw content from the post data, before it was passed through prepValueFromPost(). BaseElementModel
getContentPostLocation() Returns the location in POST that the content was pulled from. BaseElementModel
getContentTable() Returns the name of the table this element's content is stored in. BaseElementModel
getCooldownEndTime() Returns the time when the user will be over their cooldown period. UserModel
getCpEditUrl() Returns the element's CP edit URL. UserModel
getDescendants() Returns the element's descendants. BaseElementModel
getEagerLoadedElements() Returns some eager-loaded elements on a given handle. BaseElementModel
getElementType() Returns the type of element this is. BaseElementModel
getError() Returns the first error of the specified attribute. \CModel
getErrors() Returns the errors for all attribute or a single attribute. \CModel
getEventHandlers() Returns the list of attached event handlers for an event. \CComponent
getExtraAttributeNames() Returns a list of the names of the extra attributes that have been saved on this model, if it's not strict. BaseModel
getFieldColumnPrefix() Returns the field column prefix this element's content uses. BaseElementModel
getFieldContext() Returns the field context this element's content uses. BaseElementModel
getFieldLayout() Returns the field layout used by this element. BaseElementModel
getFieldValue() Returns the prepped content for a given field. BaseElementModel
getFriendlyName() Gets the user's first name or username. UserModel
getFullName() Gets the user's full name. UserModel
getGroups() Returns the user's groups. UserModel
getHasFreshContent() Returns whether the element’s content is "fresh" (unsaved and without validation errors). BaseElementModel
getIterator() Returns an iterator for traversing the attributes in the model. \CModel
getLocales() Returns the locale IDs this element is available in. BaseElementModel
getName() Returns the user's full name or username. UserModel
getNext() Returns the next element relative to this one, from a given set of criteria. BaseElementModel
getNextSibling() Returns the element's next sibling. BaseElementModel
getParent() Get the element's parent. BaseElementModel
getParents() Returns a new ElementCriteriaModel prepped to return this element's same-type parents. BaseElementModel
getPhotoUrl() Returns the URL to the user's photo. UserModel
getPrev() Returns the previous element relative to this one, from a given set of criteria. BaseElementModel
getPrevSibling() Returns the element's previous sibling. BaseElementModel
getRawContent() Returns the raw content saved on this entity. BaseElementModel
getRef() Returns the reference string to this element. UserModel
getRemainingCooldownTime() Returns the remaining cooldown time for this user, if they've entered their password incorrectly too many times. UserModel
getSafeAttributeNames() Returns the attribute names that are safe to be massively assigned. \CModel
getScenario() Returns the scenario that this model is used in. \CModel
getSiblings() Returns all of the element's siblings. BaseElementModel
getStatus() Returns the element's status. UserModel
getThumbUrl() Returns the URL to the element's thumbnail, if there is one. UserModel
getTitle() Returns the element's title. BaseElementModel
getTotalDescendants() Returns the total number of descendants that the element has. BaseElementModel
getUrl() Returns the element's full URL. BaseElementModel
getUrlFormat() Returns the URL format used to generate this element's URL. BaseElementModel
getValidatorList() Returns all the validators declared in the model. \CModel
getValidators() Returns the validators applicable to the current scenario. \CModel
hasDescendants() Returns whether the element has descendants. BaseElementModel
hasEagerLoadedElements() Returns whether elements have been eager-loaded with a given handle. BaseElementModel
hasErrors() Returns a value indicating whether there is any validation error. \CModel
hasEvent() Determines whether an event is defined. \CComponent
hasEventHandler() Checks whether the named event has attached handlers. \CComponent
hasProperty() Determines whether a property is defined. \CComponent
hasShunned() Returns whether the user has shunned a given message. UserModel
isAncestorOf() Returns whether this element is an ancestor of another one. BaseElementModel
isAttributeRequired() Returns a value indicating whether the attribute is required. \CModel
isAttributeSafe() Returns a value indicating whether the attribute is safe for massive assignments. \CModel
isChildOf() Returns whether this element is a direct child of another one. BaseElementModel
isCurrent() Returns whether this is the current logged-in user. UserModel
isDescendantOf() Returns whether this element is a descendant of another one. BaseElementModel
isEditable() Returns whether the current user can edit the element. UserModel
isInGroup() Returns whether the user is in a specific group. UserModel
isNextSiblingOf() Returns whether this element is the direct next sibling of another one. BaseElementModel
isParentOf() Returns whether this element is a direct parent of another one. BaseElementModel
isPrevSiblingOf() Returns whether this element is the direct previous sibling of another one. BaseElementModel
isSiblingOf() Returns whether this element is a sibling of another one. BaseElementModel
offsetExists() Treats custom fields as array offsets. BaseElementModel
offsetGet() Returns the element at the specified offset. \CModel
offsetSet() Sets the element at the specified offset. \CModel
offsetUnset() Unsets the element at the specified offset. \CModel
onAfterConstruct() This event is raised after the model instance is created by new operator. \CModel
onAfterValidate() This event is raised after the validation is performed. \CModel
onBeforeValidate() This event is raised before the validation is performed. \CModel
onUnsafeAttribute() This method is invoked when an unsafe attribute is being massively assigned. \CModel
populateModel() Populates a new model instance with a given set of attributes. UserModel
populateModels() Mass-populates models based on an array of attribute arrays. BaseModel
raiseEvent() Raises an event. \CComponent
rules() Returns this model's validation rules. BaseModel
setActive() Sets a user's status to active. UserModel
setAttribute() Sets an attribute's value. BaseModel
setAttributes() Sets multiple attribute values at once. BaseModel
setContent() Sets the content for the element. BaseElementModel
setContentFromPost() Sets the content from post data, calling prepValueFromPost() on the field types. BaseElementModel
setContentPostLocation() Sets the location in POST that the content was pulled from. BaseElementModel
setEagerLoadedElements() Sets some eager-loaded elements on a given handle. BaseElementModel
setGroups() Sets an array of UserGroupModel objects on the user. UserModel
setNext() Sets the default next element. BaseElementModel
setParent() Sets the element's parent. BaseElementModel
setPrev() Sets the default previous element. BaseElementModel
setRawPostContent() Sets a field’s raw post content. BaseElementModel
setScenario() Sets the scenario for the model. \CModel
unsetAttributes() Sets the attributes to be null. \CModel
validate() Validates all of the attributes for the current Model. Any attributes that fail validation will additionally get logged to the craft/storage/runtime/logs folder with a level of LogLevel::Warning. UserModel
Protected Methods
Method Description Defined By
afterConstruct() This method is invoked after a model instance is created by new operator. \CModel
afterValidate() This method is invoked after validation ends. \CModel
beforeValidate() This method is invoked before validation starts. \CModel
createContent() Creates the content model associated with this element. BaseElementModel
defineAttributes() Defines this model's attributes. UserModel
getFieldByHandle() Returns the field with a given handle. BaseElementModel
Events
Event Description Defined By
onAfterConstruct This event is raised after the model instance is created by new operator. \CModel
onBeforeValidate This event is raised before the validation is performed. \CModel
onAfterValidate This event is raised after the validation is performed. \CModel
onUnsafeAttribute This method is invoked when an unsafe attribute is being massively assigned. \CModel

Property Details

cooldownEndTime public property #

Returns the time when the user will be over their cooldown period.

public DateTime|null getCooldownEndTime()

cpEditUrl public property #

Returns the element's CP edit URL.

public string|false getCpEditUrl()

friendlyName public property #

Gets the user's first name or username.

public string|null getFriendlyName()

fullName public property #

Gets the user's full name.

public string|null getFullName()

groups public property #

Returns the user's groups.

public array getGroups(string|null $indexBy = null)
public null setGroups($groups $groups)

name public property #

Returns the user's full name or username.

public string getName()

photoUrl public property #

Returns the URL to the user's photo.

public string|null getPhotoUrl(int $size = 100)

ref public property #

Returns the reference string to this element.

public string|null getRef()

remainingCooldownTime public property #

Returns the remaining cooldown time for this user, if they've entered their password incorrectly too many times.

public DateInterval|null getRemainingCooldownTime()

status public property #

Returns the element's status.

public string|null getStatus()

thumbUrl public property #

Returns the URL to the element's thumbnail, if there is one.

public false|null|string getThumbUrl(int $size = 100)

Method Details

__toString() public method #

Use the full name or username as the string representation.

public string __toString()
Returns string

can() public method #

Returns whether the user has permission to perform a given action.

public bool can(string $permission)
$permission string
Returns bool

defineAttributes() protected method #

Defines this model's attributes.

protected array defineAttributes()
Returns array

getAttribute() public method #

Gets an attribute’s value.

public mixed getAttribute(string $name, bool $flattenValue = false)
$name string The attribute’s name.
$flattenValue bool
Returns mixed

getCooldownEndTime() public method #

Returns the time when the user will be over their cooldown period.

public DateTime|null getCooldownEndTime()
Returns DateTime / null

getCpEditUrl() public method #

Returns the element's CP edit URL.

public string|false getCpEditUrl()
Returns string / false

getFriendlyName() public method #

Gets the user's first name or username.

public string|null getFriendlyName()
Returns string / null

getFullName() public method #

Gets the user's full name.

public string|null getFullName()
Returns string / null

getGroups() public method #

Returns the user's groups.

public array getGroups(string|null $indexBy = null)
$indexBy string / null
Returns array

getName() public method #

Returns the user's full name or username.

public string getName()
Returns string

getPhotoUrl() public method #

Returns the URL to the user's photo.

public string|null getPhotoUrl(int $size = 100)
$size int
Returns string / null

getRef() public method #

Returns the reference string to this element.

public string|null getRef()
Returns string / null

getRemainingCooldownTime() public method #

Returns the remaining cooldown time for this user, if they've entered their password incorrectly too many times.

public DateInterval|null getRemainingCooldownTime()
Returns DateInterval / null

getStatus() public method #

Returns the element's status.

public string|null getStatus()
Returns string / null

getThumbUrl() public method #

Returns the URL to the element's thumbnail, if there is one.

public false|null|string getThumbUrl(int $size = 100)
$size int / null
Returns string / null

hasShunned() public method #

Returns whether the user has shunned a given message.

public bool hasShunned(string $message)
$message string
Returns bool

isCurrent() public method #

Returns whether this is the current logged-in user.

public bool isCurrent()
Returns bool

isEditable() public method #

Returns whether the current user can edit the element.

public bool isEditable()
Returns bool

isInGroup() public method #

Returns whether the user is in a specific group.

public bool isInGroup(mixed $group)
$group mixed The user group model, its handle, or ID.
Returns bool

populateModel() public static method #

Populates a new model instance with a given set of attributes.

public static UserModel populateModel(mixed $attributes)
$values mixed
Returns BaseModel

setActive() public method #

Sets a user's status to active.

public void setActive()

setGroups() public method #

Sets an array of UserGroupModel objects on the user.

public null setGroups($groups $groups)
$groups $groups An array of UserGroupModel objects.

validate() public method #

Validates all of the attributes for the current Model. Any attributes that fail validation will additionally get logged to the craft/storage/runtime/logs folder with a level of LogLevel::Warning.

In addition, we check that the username does not have any whitespace in it.

public bool|null validate(null $attributes = null, bool $clearErrors = true)
$attributes null
$clearErrors bool
Returns bool / null