UserModel

Type
Class
Namespace
Craft
Inherits
Craft\UserModel » Craft\BaseElementModel » Craft\BaseModel » CModel » CComponent
Implements
ArrayAccess, IteratorAggregate
Since
1.0

User model class.

See also http://craftcms.com

View source

Protected Properties

PropertyDescription
$classSuffixstring
$elementTypestring
$strictAttributesboolean – Whether this model should be strict about only allowing values to be set on defined attributes

$elementType

Signature

protected string $elementType = \Craft\ElementType::User

Public Methods

MethodDescription
__call()Magic __call() method, used for chain-setting attribute values.
__construct()Constructor
__get()Getter
__isset()Treats custom fields as properties.
__set()PHP setter magic method.
__toString()Use the full name or username as the string representation.
__unset()Sets a component property to be null.
addError()Adds a new error to the specified attribute.
addErrors()Adds a list of errors.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
attributeLabels()Returns the attribute labels.
attributeNames()Returns the list of this model's attribute names.
behaviors()Returns a list of behaviors that this model should behave as.
can()Returns whether the user has permission to perform a given action.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
clearErrors()Removes errors for all attributes or a single attribute.
copy()Returns a copy of this model.
createValidators()Creates validator objects based on the specification in {@link rules}.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
generateAttributeLabel()Generates a user friendly attribute label.
getAllErrors()Returns all errors in a single, flattened list, devoid of attribute names.
getAncestors()Returns the element's ancestors.
getAttribute()Gets an attribute’s value.
getAttributeConfigs()Returns this model's normalized attribute configs.
getAttributeLabel()Returns the text label for the specified attribute.
getAttributes()Returns an array of attribute values.
getChildren()Returns the element's children.
getClassHandle()Get the class name, sans namespace and suffix.
getContent()Returns the content for the element.
getContentFromPost()Returns the raw content from the post data, before it was passed through {@link prepValueFromPost()}.
getContentPostLocation()Returns the location in POST that the content was pulled from.
getContentTable()Returns the name of the table this element's content is stored in.
getCooldownEndTime()Returns the time when the user will be over their cooldown period.
getCpEditUrl()Returns the element's CP edit URL.
getDescendants()Returns the element's descendants.
getEagerLoadedElements()Returns some eager-loaded elements on a given handle.
getElementType()Returns the type of element this is.
getError()Returns the first error of the specified attribute.
getErrors()Returns the errors for all attribute or a single attribute.
getEventHandlers()Returns the list of attached event handlers for an event.
getExtraAttributeNames()Returns a list of the names of the extra attributes that have been saved on this model, if it's not strict.
getFieldColumnPrefix()Returns the field column prefix this element's content uses.
getFieldContext()Returns the field context this element's content uses.
getFieldLayout()Returns the field layout used by this element.
getFieldValue()Returns the prepped content for a given field.
getFriendlyName()Gets the user's first name or username.
getFullName()Gets the user's full name.
getGroups()Returns the user's groups.
getHasFreshContent()Returns whether the element’s content is "fresh" (unsaved and without validation errors).
getIterator()Returns an iterator for traversing the attributes in the model.
getLink()Returns an anchor pre-filled with this element's URL and title.
getLocales()Returns the locale IDs this element is available in.
getName()Returns the user's full name or username.
getNext()Returns the next element relative to this one, from a given set of criteria.
getNextSibling()Returns the element's next sibling.
getParent()Get the element's parent.
getParents()Returns a new ElementCriteriaModel prepped to return this element's same-type parents.
getPhotoUrl()Returns the URL to the user's photo.
getPrev()Returns the previous element relative to this one, from a given set of criteria.
getPrevSibling()Returns the element's previous sibling.
getRawContent()Returns the raw content saved on this entity.
getRef()Returns the reference string to this element.
getRemainingCooldownTime()Returns the remaining cooldown time for this user, if they've entered their password incorrectly too many times.
getSafeAttributeNames()Returns the attribute names that are safe to be massively assigned.
getScenario()Returns the scenario that this model is used in.
getSiblings()Returns all of the element's siblings.
getStatus()Returns the element's status.
getThumbUrl()Returns the URL to the element's thumbnail, if there is one.
getTitle()Returns the element's title.
getTotalDescendants()Returns the total number of descendants that the element has.
getUrl()Returns the element's full URL.
getUrlFormat()Returns the URL format used to generate this element's URL.
getValidatorList()Returns all the validators declared in the model.
getValidators()Returns the validators applicable to the current {@link scenario}.
hasDescendants()Returns whether the element has descendants.
hasEagerLoadedElements()Returns whether elements have been eager-loaded with a given handle.
hasErrors()Returns a value indicating whether there is any validation error.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
hasShunned()Returns whether the user has shunned a given message.
isAncestorOf()Returns whether this element is an ancestor of another one.
isAttributeRequired()Returns a value indicating whether the attribute is required.
isAttributeSafe()Returns a value indicating whether the attribute is safe for massive assignments.
isChildOf()Returns whether this element is a direct child of another one.
isCurrent()Returns whether this is the current logged-in user.
isDescendantOf()Returns whether this element is a descendant of another one.
isEditable()Returns whether the current user can edit the element.
isInGroup()Returns whether the user is in a specific group.
isNextSiblingOf()Returns whether this element is the direct next sibling of another one.
isParentOf()Returns whether this element is a direct parent of another one.
isPrevSiblingOf()Returns whether this element is the direct previous sibling of another one.
isSiblingOf()Returns whether this element is a sibling of another one.
offsetExists()Treats custom fields as array offsets.
offsetGet()Returns the element at the specified offset.
offsetSet()Sets the element at the specified offset.
offsetUnset()Unsets the element at the specified offset.
onAfterConstruct()This event is raised after the model instance is created by new operator.
onAfterValidate()This event is raised after the validation is performed.
onBeforeValidate()This event is raised before the validation is performed.
onUnsafeAttribute()This method is invoked when an unsafe attribute is being massively assigned.
populateModel()Populates a new model instance with a given set of attributes.
populateModels()Mass-populates models based on an array of attribute arrays.
raiseEvent()Raises an event.
rules()Returns this model's validation rules.
setActive()Sets a user's status to active.
setAttribute()Sets an attribute's value.
setAttributes()Sets multiple attribute values at once.
setContent()Sets the content for the element.
setContentFromPost()Sets the content from post data, calling prepValueFromPost() on the field types.
setContentPostLocation()Sets the location in POST that the content was pulled from.
setEagerLoadedElements()Sets some eager-loaded elements on a given handle.
setGroups()Sets an array of {@link UserGroupModel} objects on the user.
setNext()Sets the default next element.
setParent()Sets the element's parent.
setPrev()Sets the default previous element.
setRawPostContent()Sets a field’s raw post content.
setScenario()Sets the scenario for the model.
unsetAttributes()Sets the attributes to be null.
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.

__toString()

Use the full name or username as the string representation.

View source

Returns

string

Signature

public string __toString ( )

can()

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

View source

Arguments

Returns

boolean

Signature

public boolean can ( $permission )

getCooldownEndTime()

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

View source

Returns

Craft\DateTime, null

Signature

public Craft\DateTime, null getCooldownEndTime ( )

getCpEditUrl()

Returns the element's CP edit URL.

BaseElementModel::getCpEditUrl()

View source

Returns

string, false

Signature

public string, false getCpEditUrl ( )

getFriendlyName()

Gets the user's first name or username.

View source

Returns

string, null

Signature

public string, null getFriendlyName ( )

getFullName()

Gets the user's full name.

View source

Returns

string, null

Signature

public string, null getFullName ( )

getGroups()

Returns the user's groups.

View source

Arguments

Returns

array

Signature

public array getGroups ( $indexBy = null )

getName()

Returns the user's full name or username.

View source

Returns

string

Signature

public string getName ( )

getPhotoUrl()

Returns the URL to the user's photo.

View source

Arguments

Returns

string, null

Signature

public string, null getPhotoUrl ( $size = 100 )

getRef()

Returns the reference string to this element.

View source

Returns

string, null

Signature

public string, null getRef ( )

getRemainingCooldownTime()

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

View source

Returns

Craft\DateInterval, null

Signature

public Craft\DateInterval, null getRemainingCooldownTime ( )

getStatus()

Returns the element's status.

BaseElementModel::getStatus()

View source

Returns

string, null

Signature

public string, null getStatus ( )

getThumbUrl()

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

BaseElementModel::getThumbUrl()

View source

Arguments

Returns

false, null, string

Signature

public false, null, string getThumbUrl ( $size = 100 )

hasShunned()

Returns whether the user has shunned a given message.

View source

Arguments

Returns

boolean

Signature

public boolean hasShunned ( $message )

isCurrent()

Returns whether this is the current logged-in user.

View source

Returns

boolean

Signature

public boolean isCurrent ( )

isEditable()

Returns whether the current user can edit the element.

BaseElementModel::isEditable()

View source

Returns

boolean

Signature

public boolean isEditable ( )

isInGroup()

Returns whether the user is in a specific group.

View source

Arguments

  • $group (mixed) – The user group model, its handle, or ID.

Returns

boolean

Signature

public boolean isInGroup ( $group )

populateModel()

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

BaseModel::populateModel()

BaseModel::populateModel()

View source

Arguments

  • $attributes (mixed)

Returns

Craft\UserModel

Signature

public static Craft\UserModel populateModel ( $attributes )

setActive()

Sets a user's status to active.

View source

Signature

public void setActive ( )

setGroups()

Sets an array of {@link UserGroupModel} objects on the user.

View source

Arguments

  • $groups – An array of {@link UserGroupModel} objects.

Returns

null

Signature

public null setGroups ( $groups )

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. In addition, we check that the username does not have any whitespace in it.

View source

Arguments

Returns

boolean, null

Signature

public boolean, null validate ( $attributes = null, $clearErrors = true )

Protected Methods

MethodDescription
afterConstruct()This method is invoked after a model instance is created by new operator.
afterValidate()This method is invoked after validation ends.
beforeValidate()This method is invoked before validation starts.
createContent()Creates the content model associated with this element.
defineAttributes()Defines this model's attributes.
getFieldByHandle()Returns the field with a given handle.

defineAttributes()

Defines this model's attributes.

BaseModel::defineAttributes()

BaseModel::defineAttributes()

View source

Returns

array

Signature

protected array defineAttributes ( )

Constants

ConstantDescription
ARCHIVED
DISABLED
ENABLED