137 if (!empty($row) && !$this->
load($row)) {
138 throw new IOException(
'Failed to load new ' . get_class() .
" for GUID: {$row->guid}");
150 parent::initializeAttributes();
152 $this->attributes[
'guid'] = null;
153 $this->attributes[
'type'] = $this->
getType();
154 $this->attributes[
'subtype'] = null;
156 $this->attributes[
'owner_guid'] =
_elgg_services()->session_manager->getLoggedInUserGuid();
157 $this->attributes[
'container_guid'] =
_elgg_services()->session_manager->getLoggedInUserGuid();
160 $this->attributes[
'time_updated'] = null;
161 $this->attributes[
'last_action'] = null;
162 $this->attributes[
'enabled'] =
'yes';
178 _elgg_services()->logger->error(
"Failed to clone entity with GUID $this->guid");
183 'guid' => $this->guid,
187 $this->attributes[
'guid'] = null;
188 $this->attributes[
'time_created'] = null;
189 $this->attributes[
'time_updated'] = null;
190 $this->attributes[
'last_action'] = null;
192 $this->attributes[
'subtype'] = $orig_entity->getSubtype();
196 if (is_array($metadata_array)) {
198 $metadata_names = [];
200 $metadata_names[] = $metadata->name;
204 $metadata_names = array_unique($metadata_names);
207 foreach ($metadata_names as
$name) {
208 $this->
__set($name, $orig_entity->$name);
234 if (array_key_exists(
$name, $this->attributes)) {
236 if (is_int($this->attributes[
$name])
238 && ((
string) $this->attributes[$name] ===
$value)) {
243 if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
244 $this->orig_attributes[
$name] = $this->attributes[
$name];
260 case 'container_guid':
264 $this->attributes[
$name] = null;
300 if (array_key_exists(
$name, $this->attributes)) {
301 return $this->attributes[
$name];
345 return array_map(
function($values) {
346 return count($values) > 1 ? $values : $values[0];
350 $this->_cached_metadata =
_elgg_services()->metadataCache->getAll($this->guid);
386 return !is_null($var);
389 if (empty($this->guid)) {
398 if ((is_array($current_metadata) ||
count(
$value) > 1 ||
$value === []) && isset($current_metadata)) {
404 'guid' => $this->guid,
405 'metadata_name' => $name,
410 if ($delete_result ===
false) {
422 foreach (
$value as $value_tmp) {
428 if (!empty($value_type)) {
433 if ($md_id ===
false) {
454 unset($this->temp_metadata[$name]);
463 if (!isset($this->temp_metadata[$name])) {
464 $this->temp_metadata[
$name] = [];
467 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[$name],
$value);
488 if (isset($this->temp_metadata[
$name])) {
489 unset($this->temp_metadata[$name]);
492 $this->temp_metadata = [];
499 'guid' => $this->guid,
501 'metadata_name' =>
$name,
513 return array_key_exists($name, $this->
volatile) ? $this->
volatile[
$name] : null;
540 return _elgg_services()->relationshipsTable->add($this->guid, (
string) $relationship, (
int) $guid_two);
555 return (
bool)
_elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two);
568 return _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two) ?: null;
596 'relationship' => $relationship,
597 'relationship_guid' => $this->guid,
598 'inverse_relationship' => $inverse_relationship,
611 return _elgg_services()->relationshipsTable->remove($this->guid, (
string) $relationship, (
int) $guid_two);
655 'guid' => $this->guid,
657 'annotation_name' =>
$name,
662 unset($this->temp_annotations[
$name]);
664 $this->temp_annotations = [];
683 'annotation_owner_guid' => $this->guid,
685 'annotation_name' =>
$name,
699 'guid' => $this->guid,
701 'annotation_name' =>
$name,
714 'guid' => $this->guid,
716 'annotation_name' =>
$name,
727 private function getAnnotationCalculation(
$name, $calculation) {
731 'annotation_name' =>
$name,
732 'annotation_calculation' => $calculation
774 if (!empty($value_type)) {
804 if (isset($this->temp_annotations[
$name])) {
805 return [$this->temp_annotations[
$name]];
820 return $this->getAnnotationCalculation(
$name,
'count');
831 return $this->getAnnotationCalculation($name,
'avg');
842 return $this->getAnnotationCalculation($name,
'sum');
853 return $this->getAnnotationCalculation($name,
'min');
864 return $this->getAnnotationCalculation($name,
'max');
885 return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
914 if ($subtype ===
'') {
919 'subtype' => $subtype,
1042 if ($this->guid && !array_key_exists(
'subtype', $this->orig_attributes)) {
1043 $this->orig_attributes[
'subtype'] = $this->attributes[
'subtype'];
1046 $this->attributes[
'subtype'] =
$subtype;
1055 return (
string) $this->attributes[
'subtype'];
1073 return $this->owner_guid ?
get_entity($this->owner_guid) : null;
1144 return _elgg_services()->iconService->saveIconFromUploadedFile($this, $input_name,
$type, $coords);
1156 return _elgg_services()->iconService->saveIconFromLocalFile($this, $filename,
$type, $coords);
1235 if ($this->guid > 0) {
1262 $type = $this->attributes[
'type'];
1263 if (!in_array(
$type, \
Elgg\Config::ENTITY_TYPES)) {
1267 $subtype = $this->attributes[
'subtype'];
1272 $owner_guid = (int) $this->attributes[
'owner_guid'];
1273 $access_id = (int) $this->attributes[
'access_id'];
1275 $time_created = isset($this->attributes[
'time_created']) ? (int) $this->attributes[
'time_created'] : $now;
1299 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
1300 $error .=
" but the given owner {$owner_guid} could not be loaded.";
1306 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}) with owner {$owner_guid},";
1307 $error .=
" but the user wasn't permitted to write to the owner's container.";
1316 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
1317 $error .=
" but the given container {$container_guid} could not be loaded.";
1322 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
1323 $error .=
" but was not permitted to write to container {$container_guid}.";
1328 if (!
_elgg_services()->events->triggerBefore(
'create', $this->type, $this)) {
1340 'time_updated' => $now,
1341 'last_action' => $now,
1342 ], $this->attributes);
1345 throw new IOException(
"Unable to save new object's base entity information!");
1348 $this->attributes[
'subtype'] =
$subtype;
1349 $this->attributes[
'guid'] = (int)
$guid;
1351 $this->attributes[
'time_updated'] = (int) $now;
1352 $this->attributes[
'last_action'] = (int) $now;
1361 if (
count($this->temp_metadata) > 0) {
1362 foreach ($this->temp_metadata as
$name =>
$value) {
1367 $this->temp_metadata = [];
1371 if (
count($this->temp_annotations) > 0) {
1372 foreach ($this->temp_annotations as
$name =>
$value) {
1376 $this->temp_annotations = [];
1387 _elgg_services()->events->triggerAfter(
'create', $this->type, $this);
1406 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
1413 $guid = (int) $this->guid;
1434 'time_updated' =>
$time,
1437 if ($ret ===
false) {
1441 $this->attributes[
'time_updated'] =
$time;
1443 _elgg_services()->events->triggerAfter(
'update', $this->type, $this);
1445 $this->orig_attributes = [];
1460 protected function load(stdClass $row): bool {
1461 $attributes = array_merge($this->attributes, (array) $row);
1463 if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys(
$attributes)) !== []) {
1469 if (!in_array(
$name, self::PRIMARY_ATTR_NAMES)) {
1475 if (in_array(
$name, static::INTEGER_ATTR_NAMES)) {
1504 public function disable(
string $reason =
'',
bool $recursive =
true): bool {
1509 if (!
_elgg_services()->events->trigger(
'disable', $this->type, $this)) {
1517 if ($this instanceof
ElggUser && !$this->isBanned()) {
1520 $unban_after =
true;
1522 $unban_after =
false;
1525 if (!empty($reason)) {
1526 $this->disable_reason = $reason;
1529 $guid = (int) $this->guid;
1541 'batch_inc_offset' =>
false,
1544 foreach ([
'owner_guid',
'container_guid'] as $db_column) {
1550 foreach ($subentities as $subentity) {
1551 if (!$subentity->isEnabled()) {
1555 $subentity->addRelationship(
$guid,
'disabled_with');
1556 $subentity->disable($reason,
true);
1573 $this->attributes[
'enabled'] =
'no';
1574 _elgg_services()->events->triggerAfter(
'disable', $this->type, $this);
1587 public function enable(
bool $recursive =
true): bool {
1588 if (empty($this->guid)) {
1592 if (!
_elgg_services()->events->trigger(
'enable', $this->type, $this)) {
1608 'relationship' =>
'disabled_with',
1609 'relationship_guid' => $this->guid,
1610 'inverse_relationship' =>
true,
1613 'batch_inc_offset' =>
false,
1616 foreach ($disabled_with_it as $e) {
1617 $e->enable($recursive);
1618 $e->removeRelationship($this->guid,
'disabled_with');
1626 $this->attributes[
'enabled'] =
'yes';
1627 _elgg_services()->events->triggerAfter(
'enable', $this->type, $this);
1639 return $this->enabled ==
'yes';
1659 public function delete(
bool $recursive =
true):
bool {
1697 $object->type = $this->
getType();
1703 $object->url = $this->
getURL();
1704 $object->read_access = (int) $this->
access_id;
1717 $this->{
'geo:lat'} = $lat;
1718 $this->{
'geo:long'} = $long;
1727 return (
float) $this->{
'geo:lat'};
1736 return (
float) $this->{
'geo:long'};
1747 return (
int) $this->
getGUID();
1770 if (!isset($tag_names)) {
1771 $tag_names = [
'tags'];
1774 if ($tag_names && !is_array($tag_names)) {
1775 $tag_names = [$tag_names];
1779 foreach ($tag_names as $tag_name) {
1780 $tags = $this->$tag_name;
1787 if (is_array(
$tags)) {
1788 $entity_tags = array_merge($entity_tags,
$tags);
1790 $entity_tags[] =
$tags;
1794 return $entity_tags;
1809 if ($this->type !==
'user') {
1815 $collections = $ac->getCollectionsByMember($this->guid);
1816 if (empty($collections)) {
1821 foreach ($collections as $collection) {
1822 $result &= $ac->removeUser($this->guid, $collection->id);
1841 if (empty($collections)) {
1846 foreach ($collections as $collection) {
1866 $this->attributes[
'last_action'] =
$posted;
1879 $this->_is_cacheable =
false;
1892 $this->_is_cacheable =
true;
1935 $this->
volatile = [];
1937 _elgg_services()->sessionCache->entities->save($this->guid, $this);
1939 $this->
volatile = $tmp;
1954 _elgg_services()->dataCache->get(
'metadata')->delete($this->guid);
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
getSubtype()
Get the entity subtype.
setMetadata(string $name, $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
getOwnerGUID()
Get the guid of the entity's owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Entities that support icons should implement this interface.
enableAnnotations(string $name=null)
Enables annotations for this entity, optionally based on name.
__clone()
Clone an entity.
$params
Saves global plugin settings.
saveIconFromLocalFile(string $filename, string $type= 'icon', array $coords=[])
Saves icons using a local file as the source.
setVolatileData(string $name, $value)
Set a piece of volatile (non-persisted) data on this entity.
__get($name)
Get an attribute or metadata value.
getOwnerEntity()
Gets the that owns this entity.
const ACCESS_DEFAULT
Controls access levels on entities, metadata, and annotations.
getIconLastChange(string $size, string $type= 'icon')
Returns the timestamp of when the icon was changed.
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.
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
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
saveIconFromElggFile(\ElggFile $file, string $type= 'icon', array $coords=[])
Saves icons using a file located in the data store as the source.
deleteOwnedAnnotations(string $name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
elgg_get_annotations(array $options=[])
Fetch annotations or perform a calculation on them.
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
countEntitiesFromRelationship(string $relationship, bool $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
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.
$relationship
Elgg default relationship view.
if(!$annotation instanceof ElggAnnotation) $time
cache(bool $persist=true)
Cache the entity in a session and persisted caches.
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
Database abstraction query builder.
getGUID()
Returns the guid.
getIconURL(string|array $params=[])
Get the URL for this entity's icon.
getContainerGUID()
Gets the container GUID for this entity.
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
enableCaching()
Enable runtime caching for entity.
deleteAnnotations(string $name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
addRelationship(int $guid_two, string $relationship)
Add a relationship between this an another entity.
canAnnotate(int $user_guid=0, string $annotation_name= '')
Can a user annotate an entity?
disableAnnotations(string $name=null)
Disables annotations for this entity, optionally based on name.
canEdit(int $user_guid=0)
Can a user edit this entity?
getEntitiesFromRelationship(array $options=[])
Gets an array of entities with a relationship to this entity.
setTempMetadata(string $name, $value, bool $multiple=false)
Set temp metadata on this entity.
const ELGG_HIDE_DISABLED_ENTITIES
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getAnnotationsSum(string $name)
Get the sum of integer type annotations of a given name.
elgg_disable_annotations(array $options)
Disables annotations based on $options.
getObjectFromID(int $id)
For a given ID, return the object associated with it.
countAnnotations(string $name= '')
Count annotations.
getCurrentTime($modifier= '')
Get the (cloned) time.
const ELGG_IGNORE_ACCESS
elgg_call() flags
getTags($tag_names=null)
Returns tags for this entity.
getRelationship(int $guid_two, string $relationship)
Return the relationship if this entity has a relationship with another entity.
disableCaching()
Disable runtime caching for entity.
hasRelationship(int $guid_two, string $relationship)
Check if this entity has a relationship with another entity.
setSubtype(string $subtype)
Set the subtype of the entity.
getAnnotationsMin(string $name)
Get the minimum of integer type annotations of given name.
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.
getAnnotationsAvg(string $name)
Get the average of an integer type annotation.
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.
elgg_generate_entity_url(ElggEntity $entity, string $resource= 'view', string $subresource=null, array $parameters=[])
Generate entity URL from a named route.
elgg_count_entities(array $options=[])
Returns a count of entities.
A generic parent class for database exceptions.
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
__set($name, $value)
Set an attribute or metadata value for this entity.
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
saveIconFromUploadedFile(string $input_name, string $type= 'icon', array $coords=[])
Saves icons using an uploaded file as the source.
getIcon(string $size, string $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
toObject(array $params=[])
Export an entity.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
getAnnotations(array $options=[])
Gets an array of annotations.
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 .
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
update()
Update the entity in the database.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type= '')
Adds an annotation to an entity.
if($email instanceof\Elgg\Email) $object
removeAllRelationships(string $relationship= '', bool $inverse_relationship=false)
Remove all relationships to or from this entity.
getType()
Returns the entity type.
getOwnedAccessCollection(string $subtype)
Returns the first ACL owned by the entity with a given subtype.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
removeRelationship(int $guid_two, string $relationship)
Remove a relationship.
create()
Create a new entry in the entities table.
setContainerGUID(int $container_guid)
Set the container for this object.
getAllMetadata()
Get all entity metadata.
_elgg_services()
Get the global service provider.
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
isCacheable()
Is entity cacheable in the runtime cache.
getLatitude()
Return the entity's latitude.
__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.
getAnnotationsMax(string $name)
Get the maximum of integer type annotations of a given name.
getOwnedAccessCollections(array $options=[])
Returns the ACLs owned by the entity.
getURL()
Gets the URL for this entity.
setDisplayName(string $display_name)
Sets the title or name of this entity.
getMetadata(string $name)
Return the value of a piece of metadata.
getDisplayName()
Get the entity's display name.
deleteIcon(string $type= 'icon')
Removes all icon files and metadata for the passed type of icon.
$guid
Reset an ElggUpgrade.
getLongitude()
Return the entity's longitude.
hasIcon(string $size, string $type= 'icon')
Returns if the entity has an icon of the passed type.