27 parent::initializeAttributes();
28 $this->attributes[
'subtype'] =
'user';
34 $this->prev_last_action = 0;
35 $this->last_login = 0;
36 $this->prev_last_login = 0;
58 if ($fallback !== null) {
71 _elgg_services()->logger->error(
"User entities no longer contain {$name}");
74 _elgg_services()->logger->error(
"password_hash is a readonly attribute.");
90 if ($existing_user && ($existing_user->guid !== $this->guid)) {
96 if (!in_array(
$value, [
'yes',
'no'],
true)) {
125 public function ban($reason =
'') {
135 $this->ban_reason = $reason;
136 $this->banned =
'yes';
158 unset($this->ban_reason);
159 $this->banned =
'no';
172 return $this->banned ==
'yes';
182 $is_admin = ($this->admin ==
'yes');
199 if (!
_elgg_services()->events->trigger(
'make_admin',
'user', $this)) {
203 $this->admin =
'yes';
221 if (!
_elgg_services()->events->trigger(
'remove_admin',
'user', $this)) {
241 if ($this->last_login ==
$time) {
248 $this->last_login =
$time;
262 if ($this->last_action ==
$time) {
283 if (!isset($this->validated)) {
286 return (
bool) $this->validated;
298 $this->validated = $status;
299 $this->validated_method = $method;
301 if ((
bool) $status) {
308 _elgg_services()->events->triggerAfter(
'validate',
'user', $this);
310 _elgg_services()->events->triggerAfter(
'invalidate',
'user', $this);
331 if ($create_river_item) {
333 'view' =>
'river/relationship/friend/create',
334 'action_type' =>
'friend',
335 'subject_guid' => $this->guid,
388 $options[
'relationship'] =
'friend';
399 $options[
'relationship'] =
'friend';
401 $options[
'inverse_relationship'] =
true;
416 $options[
'relationship'] =
'member';
437 $options[
'relationship'] =
'friend';
439 $options[
'relationship_join_on'] =
'container_guid';
463 $object = parent::prepareObject($object);
467 unset($object->read_access);
504 $this->{
"notification:method:$method"} = (int)
$enabled;
505 return (
bool) $this->
save();
524 foreach ($methods as $method) {
525 $settings[$method] = (bool) $this->{
"notification:method:$method"};
539 public function cache($persist =
true) {
540 if ($persist && $this->username) {
544 $this->
volatile = [];
546 _elgg_services()->dataCache->usernames->save($this->username, $this);
548 $this->
volatile = $tmp;
551 parent::cache($persist);
561 if ($this->username) {
565 parent::invalidateCache();
571 public function delete($recursive =
true) {
572 $result = parent::delete($recursive);
getFriends(array $options=[])
{Gets this entity's friends.Options array. See elgg_get_entities() for a list of options. 'relationship_guid' is set to this entity, relationship name to 'friend' and type to 'user'.[]|int|mixed}
addFriend($friend_guid, $create_river_item=false)
Adds a user as a friend.
enable($recursive=true)
Enable the entity.
if(!$item instanceof ElggRiverItem) $object
getLanguage($fallback=null)
Get user language or default to site language.
if(!$user||!$user->canDelete()) $name
get_user($guid)
Get a user object from a GUID.
makeAdmin()
Make the user an admin.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
setPassword($password)
Set the necessary metadata to store a hash of the user's password.
setNotificationSetting($method, $enabled=true)
Enable or disable a notification delivery method.
getGUID()
Returns the guid.
invalidateCache()
Invalidate cache for entity.
getCurrentTime($modifier= '')
Get the (cloned) time.
setLastLogin()
Sets the last logon time of the user to right now.
$guid
Removes an admin notice.
elgg_create_river_item(array $options=[])
Adds an item to the river.
prepareObject(\Elgg\Export\Entity $object)
{}
canEdit($user_guid=0)
Can a user edit this entity?
get_user_by_username($username)
Get user by username.
removeRelationship($guid_two, $relationship)
Remove a relationship.
$user_guid
Validate a user.
getObjects(array $options=[])
{Get an array of owned by this entity.Options array. See elgg_get_entities() for a list of options...
if(!$user||!$user->canEdit()) $password
setLastAction()
Sets the last action time of the given user to right now.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
if(!$entity instanceof ElggEntity) $time
isFriend()
Determines whether or not this user is a friend of the currently logged in user.
$enabled
Sample cli installer script.
isFriendOf($user_guid)
Determines whether or not this user is another user's friend.
ban($reason= '')
Ban this user.
check_entity_relationship($guid_one, $relationship, $guid_two)
Check if a relationship exists between two entities.
getFriendsOf(array $options=[])
{Gets users who have made this entity a friend.Options array. See elgg_get_entities() for a list of o...
cache($persist=true)
Cache the entity in a session and persisted caches.
getOwnerGUID()
Get a user's owner GUID.
isEnabled()
Is this entity enabled?
getNotificationSettings()
Returns users's notification settings [ 'email' => true, // enabled 'ajax' => false, // disabled ]
setMetadata($name, $value, $value_type= '', $multiple=false)
Set metadata on this entity.
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
getGroups(array $options=[])
Gets the user's groups.
removeFriend($friend_guid)
Removes a user as a friend.
isAdmin()
Is this user admin?
isValidated()
Gets the validation status of a user.
setValidationStatus($status, $method= '')
Set the validation status for a user.
removeAdmin()
Remove the admin flag for user.
if(elgg_get_config('allow_registration')==false) $friend_guid
_elgg_services()
Get the global service provider.
isBanned()
Is this user banned or not?
canComment($user_guid=0, $default=null)
Can a user comment on this user?
getFriendsObjects(array $options=[])
{Get an array of owned by this entity's friends.Options array. See elgg_get_entities() for a list of...
getDisplayName()
Get the entity's display name.
isFriendsWith($user_guid)
Determines whether this user is friends with another user.
elgg_get_config($name, $default=null)
Get an Elgg configuration value.