8 use Elgg\Traits\Entity\AccessCollections;
10 use Elgg\Traits\Entity\Icons;
12 use Elgg\Traits\Entity\Relationships;
13 use Elgg\Traits\Entity\Subscriptions;
54 use AccessCollections;
125 if (!empty($row) && !$this->
load($row)) {
126 throw new IOException(
'Failed to load new ' . get_class() .
" for GUID: {$row->guid}");
138 parent::initializeAttributes();
140 $this->attributes[
'guid'] =
null;
141 $this->attributes[
'type'] =
null;
142 $this->attributes[
'subtype'] =
null;
144 $this->attributes[
'owner_guid'] =
_elgg_services()->session_manager->getLoggedInUserGuid();
145 $this->attributes[
'container_guid'] =
_elgg_services()->session_manager->getLoggedInUserGuid();
148 $this->attributes[
'time_updated'] =
null;
149 $this->attributes[
'last_action'] =
null;
150 $this->attributes[
'enabled'] =
'yes';
151 $this->attributes[
'deleted'] =
'no';
152 $this->attributes[
'time_deleted'] =
null;
168 _elgg_services()->logger->error(
"Failed to clone entity with GUID $this->guid");
173 'guid' => $this->guid,
177 $this->attributes[
'guid'] =
null;
178 $this->attributes[
'time_created'] =
null;
179 $this->attributes[
'time_updated'] =
null;
180 $this->attributes[
'last_action'] =
null;
182 $this->attributes[
'subtype'] = $orig_entity->getSubtype();
186 if (is_array($metadata_array)) {
188 $metadata_names = [];
194 $metadata_names = array_unique($metadata_names);
197 foreach ($metadata_names as
$name) {
198 $this->
__set($name, $orig_entity->$name);
224 if (array_key_exists(
$name, $this->attributes)) {
226 if (is_int($this->attributes[
$name])
228 && ((
string) $this->attributes[
$name] ===
$value)) {
233 if ($this->guid && !array_key_exists(
$name, $this->orig_attributes)) {
234 $this->orig_attributes[
$name] = $this->attributes[
$name];
246 throw new ElggInvalidArgumentException(
elgg_echo(
'ElggEntity:Error:SetSubtype', [
'setSubtype()']));
248 throw new ElggInvalidArgumentException(
elgg_echo(
'ElggEntity:Error:SetEnabled', [
'enable() / disable()']));
250 throw new ElggInvalidArgumentException(
elgg_echo(
'ElggEntity:Error:SetDeleted', [
'delete() / restore()']));
253 case 'container_guid':
257 $this->attributes[
$name] =
null;
277 return $this->orig_attributes;
294 if (array_key_exists(
$name, $this->attributes)) {
295 return $this->attributes[
$name];
329 return array_key_exists(
$name, $this->
volatile) ? $this->
volatile[
$name] :
null;
362 if (!$this->hasCapability(
'commentable')) {
373 return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
427 throw new ElggInvalidArgumentException(__METHOD__ .
' requires $type and $subtype to be set');
479 return (string) $this->attributes[
'type'];
492 if ($this->guid && !array_key_exists(
'subtype', $this->orig_attributes)) {
493 $this->orig_attributes[
'subtype'] = $this->attributes[
'subtype'];
496 $this->attributes[
'subtype'] =
$subtype;
505 return (string) $this->attributes[
'subtype'];
514 return (int) $this->owner_guid;
562 return (int) $this->time_updated;
576 $url =
_elgg_services()->events->triggerResults(
'entity:url',
"{$this->getType()}:{$this->getSubtype()}", [
'entity' => $this],
$url);
577 $url =
_elgg_services()->events->triggerResults(
'entity:url', $this->getType(), [
'entity' => $this],
$url);
589 if ($this->guid > 0) {
592 $result = $this->create() !==
false;
616 $type = $this->attributes[
'type'];
617 if (!in_array(
$type, \
Elgg\Config::ENTITY_TYPES)) {
618 throw new ElggDomainException(
'Entity type must be one of the allowed types: ' . implode(
', ', \
Elgg\Config::ENTITY_TYPES));
621 $subtype = $this->attributes[
'subtype'];
623 throw new ElggInvalidArgumentException(
'All entities must have a subtype');
626 $owner_guid = (int) $this->attributes[
'owner_guid'];
627 $access_id = (int) $this->attributes[
'access_id'];
628 $now = $this->getCurrentTime()->getTimestamp();
629 $time_created = isset($this->attributes[
'time_created']) ? (int) $this->attributes[
'time_created'] : $now;
630 $deleted = $this->attributes[
'deleted'];
631 $time_deleted = (int) $this->attributes[
'time_deleted'];
642 throw new ElggInvalidArgumentException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
646 throw new ElggInvalidArgumentException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
653 $owner = $this->getOwnerEntity();
655 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
656 $error .=
" but the given owner {$owner_guid} could not be loaded.";
657 throw new ElggInvalidArgumentException(
$error);
662 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}) with owner {$owner_guid},";
663 $error .=
" but the user wasn't permitted to write to the owner's container.";
664 throw new ElggInvalidArgumentException(
$error);
672 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
673 $error .=
" but the given container {$container_guid} could not be loaded.";
674 throw new ElggInvalidArgumentException(
$error);
678 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
679 $error .=
" but was not permitted to write to container {$container_guid}.";
680 throw new ElggInvalidArgumentException(
$error);
684 if (!
_elgg_services()->events->triggerBefore(
'create', $this->type, $this)) {
696 'time_updated' => $now,
697 'last_action' => $now,
699 'time_deleted' => $time_deleted
700 ], $this->attributes);
703 throw new IOException(
"Unable to save new object's base entity information!");
706 $this->attributes[
'subtype'] =
$subtype;
707 $this->attributes[
'guid'] = (int)
$guid;
709 $this->attributes[
'time_updated'] = (int) $now;
710 $this->attributes[
'last_action'] = (int) $now;
712 $this->attributes[
'deleted'] =
$deleted;
713 $this->attributes[
'time_deleted'] = (int) $time_deleted;
721 if (count($this->temp_metadata) > 0) {
722 foreach ($this->temp_metadata as
$name =>
$value) {
727 $this->temp_metadata = [];
731 if (count($this->temp_annotations) > 0) {
732 foreach ($this->temp_annotations as
$name =>
$value) {
736 $this->temp_annotations = [];
747 _elgg_services()->events->triggerAfter(
'create', $this->type, $this);
761 if (!$this->canEdit()) {
766 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
770 $this->invalidateCache();
773 $guid = (int) $this->guid;
780 $time_deleted = (int) $this->time_deleted;
783 throw new ElggInvalidArgumentException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
787 throw new ElggInvalidArgumentException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
796 'time_updated' =>
$time,
799 'time_deleted' => $time_deleted
801 if ($ret ===
false) {
805 $this->attributes[
'time_updated'] =
$time;
807 _elgg_services()->events->triggerAfter(
'update', $this->type, $this);
809 $this->orig_attributes = [];
824 protected function load(stdClass $row): bool {
825 $attributes = array_merge($this->attributes, (array) $row);
827 if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys(
$attributes)) !== []) {
833 if (!in_array(
$name, self::PRIMARY_ATTR_NAMES)) {
834 $this->setVolatileData(
"select:{$name}",
$value);
839 if (in_array(
$name, static::INTEGER_ATTR_NAMES)) {
868 public function disable(
string $reason =
'',
bool $recursive =
true): bool {
873 if (!
_elgg_services()->events->trigger(
'disable', $this->type, $this)) {
877 if (!$this->canEdit()) {
881 if ($this instanceof
ElggUser && !$this->isBanned()) {
887 $unban_after =
false;
890 if (!empty($reason)) {
891 $this->disable_reason = $reason;
894 $guid = (int) $this->guid;
906 'batch_inc_offset' =>
false,
909 foreach ([
'owner_guid',
'container_guid'] as $db_column) {
915 foreach ($subentities as $subentity) {
916 if (!$subentity->isEnabled()) {
920 $subentity->addRelationship(
$guid,
'disabled_with');
921 $subentity->disable($reason,
true);
934 $this->invalidateCache();
936 $this->attributes[
'enabled'] =
'no';
937 _elgg_services()->events->triggerAfter(
'disable', $this->type, $this);
950 public function enable(
bool $recursive =
true): bool {
951 if (empty($this->guid)) {
955 if (!
_elgg_services()->events->trigger(
'enable', $this->type, $this)) {
959 if (!$this->canEdit()) {
970 'relationship' =>
'disabled_with',
971 'relationship_guid' => $this->guid,
972 'inverse_relationship' =>
true,
975 'batch_inc_offset' =>
false,
978 foreach ($disabled_with_it as $e) {
979 $e->enable($recursive);
980 $e->removeRelationship($this->guid,
'disabled_with');
988 $this->attributes[
'enabled'] =
'yes';
989 _elgg_services()->events->triggerAfter(
'enable', $this->type, $this);
1001 return $this->enabled ==
'yes';
1021 public function delete(
bool $recursive =
true, ?
bool $persistent =
null):
bool {
1022 if (!$this->canDelete()) {
1031 $persistent = !$this->hasCapability(
'restorable');
1036 return $this->persistentDelete($recursive);
1038 return $this->trash($recursive);
1041 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
1066 protected function trash(
bool $recursive =
true): bool {
1069 $this->attributes[
'deleted'] =
'yes';
1083 public function restore(
bool $recursive =
true): bool {
1084 if (!$this->isDeleted()) {
1088 if (empty($this->guid) || !$this->canEdit()) {
1092 return _elgg_services()->events->triggerSequence(
'restore', $this->type, $this,
function () use ($recursive) {
1098 $this->attributes[
'deleted'] =
'no';
1099 $this->attributes[
'time_deleted'] = 0;
1101 $this->removeAllRelationships(
'deleted_by');
1102 $this->removeAllRelationships(
'deleted_with');
1112 'relationship' =>
'deleted_with',
1113 'relationship_guid' => $this->guid,
1114 'inverse_relationship' =>
true,
1117 'batch_inc_offset' =>
false,
1121 foreach ($deleted_with_it as $e) {
1122 if (!$e->restore($recursive)) {
1123 $deleted_with_it->reportFailure();
1139 return $this->deleted ===
'yes';
1150 $object = $this->prepareObject(
new \
Elgg\Export\Entity());
1166 $object->type = $this->getType();
1167 $object->subtype = $this->getSubtype();
1168 $object->owner_guid = $this->getOwnerGUID();
1169 $object->container_guid = $this->getContainerGUID();
1170 $object->time_created = date(
'c', $this->getTimeCreated());
1171 $object->time_updated = date(
'c', $this->getTimeUpdated());
1172 $object->url = $this->getURL();
1186 $this->{
'geo:lat'} = $lat;
1187 $this->{
'geo:long'} = $long;
1196 return (float) $this->{
'geo:lat'};
1205 return (float) $this->{
'geo:long'};
1216 return (int) $this->getGUID();
1245 $this->attributes[
'last_action'] =
$posted;
1262 $this->attributes[
'time_deleted'] =
$deleted;
1275 $this->_is_cacheable = false;
1288 $this->_is_cacheable = true;
1306 return $this->_is_cacheable;
1316 if (!$this->isCacheable()) {
1347 return _elgg_services()->entity_capabilities->hasCapability($this->getType(), $this->getSubtype(), $capability);
getCurrentTime($modifier='')
Get the (cloned) time.
$guid
Reset an ElggUpgrade.
if(! $user||! $user->canDelete()) $name
$id
Generic annotation delete action.
if(! $new_container instanceof \ElggEntity) if(! $new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) $display_name
$params
Saves global plugin settings.
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
$attributes
Elgg AJAX loader.
if(! $annotation instanceof ElggAnnotation) $time
A generic class that contains shared code among \ElggExtender, \ElggEntity, and \ElggRelationship.
initializeAttributes()
Initialize the attributes array.
getVolatileData(string $name)
Get a piece of volatile (non-persisted) data on this entity.
getType()
Returns the entity type.
restore(bool $recursive=true)
Restore the entity.
__set($name, $value)
Set an attribute or metadata value for this entity.
disable(string $reason='', bool $recursive=true)
Disable this entity.
getObjectFromID(int $id)
For a given ID, return the object associated with it.
setContainerGUID(int $container_guid)
Set the container for this object.
trash(bool $recursive=true)
Move the entity to the trash.
toObject(array $params=[])
Export an entity.
getSystemLogID()
{Return an identification for the object for storage in the system log.This id must be an integer....
canWriteToContainer(int $user_guid=0, string $type='', string $subtype='')
Can a user add an entity to this container.
setVolatileData(string $name, $value)
Set a piece of volatile (non-persisted) data on this entity.
canEdit(int $user_guid=0)
Can a user edit this entity?
getFields()
Helper function to easily retrieve form fields for this entity.
updateTimeDeleted(?int $deleted=null)
Update the time_deleted column in the entities table.
getSubtype()
Get the entity subtype.
static getDefaultFields()
Returns a default set of fields to be used for forms related to this entity.
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted.
getContainerGUID()
Gets the container GUID for this entity.
__get($name)
Get an attribute or metadata value.
hasAccess(int $user_guid=0)
Check if the given user has access to this entity.
disableCaching()
Disable runtime caching for entity.
enableCaching()
Enable runtime caching for entity.
invalidateCache()
Invalidate cache for entity.
canComment(int $user_guid=0)
Can a user comment on an entity?
update()
Update the entity in the database.
getDisplayName()
Get the entity's display name.
getOwnerEntity()
Gets the \ElggEntity that owns this entity.
create()
Create a new entry in the entities table.
removeAllRelatedRiverItems()
Removes all river items related to this entity.
getContainerEntity()
Get the container entity for this object.
save()
Save this data to the appropriate database table.bool
getURL()
Gets the URL for this entity.
getLongitude()
Return the entity's longitude.
__construct(?\stdClass $row=null)
Create a new entity.
hasCapability(string $capability)
Checks a specific capability is enabled for the entity type/subtype.
setSubtype(string $subtype)
Set the subtype of the entity.
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
isCacheable()
Is entity cacheable in the runtime cache.
isDeleted()
Is the entity marked as deleted.
isEnabled()
Is this entity enabled?
canDelete(int $user_guid=0)
Can a user delete this entity?
persistentDelete(bool $recursive=true)
Permanently delete the entity from the database.
load(stdClass $row)
Loads attributes from the entities table into the object.
getGUID()
Returns the guid.
setDisplayName(string $display_name)
Sets the title or name of this entity.
enable(bool $recursive=true)
Enable the entity.
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
canAnnotate(int $user_guid=0, string $annotation_name='')
Can a user annotate an entity?
cache()
Cache the entity in a session cache.
__clone()
Clone an entity.
getOwnerGUID()
Get the guid of the entity's owner.
getLatitude()
Return the entity's latitude.
countComments()
Count the number of comments attached to this entity.
setLatLong(float $lat, float $long)
Set latitude and longitude metadata tags for a given entity.
updateLastAction(?int $posted=null)
Update the last_action column in the entities table.
Database abstraction query builder.
A generic parent class for database exceptions.
Exception thrown if a value does not adhere to a defined valid data domain.
An IO Exception, throw when an IO Exception occurs.
Exception thrown if an argument is not of the expected type.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
const ELGG_IGNORE_ACCESS
elgg_call() flags
const ELGG_HIDE_DISABLED_ENTITIES
const ELGG_SHOW_DISABLED_ENTITIES
const ELGG_SHOW_DELETED_ENTITIES
const ACCESS_DEFAULT
Controls access levels on \ElggEntity entities, metadata, and annotations.
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
if(! $user instanceof \ElggUser) $time_created
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
if($email instanceof \Elgg\Email) $object
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
_elgg_services()
Get the global service provider.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
get_entity(int $guid)
Loads and returns an entity object from a guid.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
setMetadata(string $name, mixed $value, string $value_type='', bool $multiple=false)
Set metadata on this entity.
getMetadata(string $name)
Return the value of a piece of metadata.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type='')
Adds an annotation to an entity.
trait Metadata
Bundle all metadata related functions for an \ElggEntity.
trait Annotations
Bundle all annotations related functions for an \ElggEntity.
deleteMetadata(?string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
elgg_normalize_url(string $url)
elgg_generate_entity_url(ElggEntity $entity, string $resource='view', ?string $subresource=null, array $parameters=[])
Generate entity URL from a named route.
elgg_delete_river(array $options=[])
Delete river items based on $options.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.