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 = [];
190 $metadata_names[] = $metadata->name;
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];
253 case 'container_guid':
257 $this->attributes[
$name] = null;
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;
373 return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
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'];
523 return $this->owner_guid ?
get_entity($this->owner_guid) : null;
576 $url =
_elgg_services()->events->triggerResults(
'entity:url',
"{$this->getType()}:{$this->getSubtype()}", [
'entity' => $this],
$url);
589 if ($this->guid > 0) {
616 $type = $this->attributes[
'type'];
617 if (!in_array(
$type, \
Elgg\Config::ENTITY_TYPES)) {
621 $subtype = $this->attributes[
'subtype'];
626 $owner_guid = (int) $this->attributes[
'owner_guid'];
627 $access_id = (int) $this->attributes[
'access_id'];
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'];
655 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
656 $error .=
" but the given owner {$owner_guid} could not be loaded.";
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.";
672 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
673 $error .=
" but the given container {$container_guid} could not be loaded.";
678 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
679 $error .=
" but was not permitted to write to container {$container_guid}.";
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);
766 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
773 $guid = (int) $this->guid;
780 $time_deleted = (int) $this->time_deleted;
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)) {
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)) {
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);
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)) {
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 {
1030 if (!isset($persistent)) {
1035 if (empty($this->guid) || $persistent) {
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 {
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';
1166 $object->type = $this->
getType();
1172 $object->url = $this->
getURL();
1173 $object->read_access = (int) $this->
access_id;
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;
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
getSubtype()
Get the entity subtype.
getOwnerGUID()
Get the guid of the entity's owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
__clone()
Clone an entity.
$params
Saves global plugin settings.
setVolatileData(string $name, $value)
Set a piece of volatile (non-persisted) data on this entity.
__get($name)
Get an attribute or metadata value.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
getOwnerEntity()
Gets the that owns this entity.
persistentDelete(bool $recursive=true)
Permanently delete the entity from the database.
const ACCESS_DEFAULT
Controls access levels on entities, metadata, and annotations.
An IO Exception, throw when an IO Exception occurs.
canWriteToContainer(int $user_guid=0, string $type= '', string $subtype= '')
Can a user add an entity to this container.
if(!$user||!$user->canDelete()) $name
canDelete(int $user_guid=0)
Can a user delete this entity?
invalidateCache()
Invalidate cache for entity.
canComment(int $user_guid=0)
Can a user comment on an entity?
initializeAttributes()
Initialize the attributes array.
if(!$user instanceof\ElggUser) $time_created
countComments()
Count the number of comments attached to this entity.
elgg_delete_river(array $options=[])
Delete river items based on $options.
getVolatileData(string $name)
Get a piece of volatile (non-persisted) data on this entity.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
enable(bool $recursive=true)
Enable the entity.
if(!$annotation instanceof ElggAnnotation) $time
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
Database abstraction query builder.
getGUID()
Returns the guid.
getContainerGUID()
Gets the container GUID for this entity.
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
enableCaching()
Enable runtime caching for entity.
canAnnotate(int $user_guid=0, string $annotation_name= '')
Can a user annotate an entity?
cache()
Cache the entity in a session cache.
canEdit(int $user_guid=0)
Can a user edit this entity?
const ELGG_HIDE_DISABLED_ENTITIES
getObjectFromID(int $id)
For a given ID, return the object associated with it.
getCurrentTime($modifier= '')
Get the (cloned) time.
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
const ELGG_IGNORE_ACCESS
elgg_call() flags
disableCaching()
Disable runtime caching for entity.
setSubtype(string $subtype)
Set the subtype of the entity.
const ELGG_SHOW_DISABLED_ENTITIES
removeAllRelatedRiverItems()
Removes all river items related to this entity.
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.
hasAccess(int $user_guid=0)
Check if the given user has access to this entity.
load(stdClass $row)
Loads attributes from the entities table into the object.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
elgg_generate_entity_url(ElggEntity $entity, string $resource= 'view', string $subresource=null, array $parameters=[])
Generate entity URL from a named route.
A generic parent class for database exceptions.
__set($name, $value)
Set an attribute or metadata value for this entity.
toObject(array $params=[])
Export an entity.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type= '')
Adds an annotation to an entity.
trait Annotations
Bundle all annotations related functions for an .
setMetadata(string $name, mixed $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
isDeleted()
Is the entity marked as deleted.
setLatLong(float $lat, float $long)
Set latitude and longitude metadata tags for a given entity.
hasCapability(string $capability)
Checks a specific capability is enabled for the entity type/subtype.
A generic class that contains shared code among , , and .
isEnabled()
Is this entity enabled?
const ELGG_SHOW_DELETED_ENTITIES
update()
Update the entity in the database.
if($email instanceof\Elgg\Email) $object
trash(bool $recursive=true)
Move the entity to the trash.
getType()
Returns the entity type.
updateTimeDeleted(int $deleted=null)
Update the time_deleted column in the entities table.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
create()
Create a new entry in the entities table.
setContainerGUID(int $container_guid)
Set the container for this object.
_elgg_services()
Get the global service provider.
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
restore(bool $recursive=true)
Restore the entity.
getMetadata(string $name)
Return the value of a piece of metadata.
isCacheable()
Is entity cacheable in the runtime cache.
getLatitude()
Return the entity's latitude.
if(!$new_container instanceof\ElggEntity) if(!$new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) $display_name
__construct(stdClass $row=null)
Create a new entity.
getContainerEntity()
Get the container entity for this object.
elgg_normalize_url(string $url)
disable(string $reason= '', bool $recursive=true)
Disable this entity.
updateLastAction(int $posted=null)
Update the last_action column in the entities table.
$id
Generic annotation delete action.
getURL()
Gets the URL for this entity.
setDisplayName(string $display_name)
Sets the title or name of this entity.
getDisplayName()
Get the entity's display name.
$guid
Reset an ElggUpgrade.
getLongitude()
Return the entity's longitude.
trait Metadata
Bundle all metadata related functions for an .