140 if ($row && !$this->
load($row)) {
141 $msg =
"Failed to load new " . get_class() .
" for GUID:" . $row->guid;
142 throw new \IOException($msg);
154 parent::initializeAttributes();
156 $this->attributes[
'guid'] = null;
157 $this->attributes[
'type'] = $this->
getType();
158 $this->attributes[
'subtype'] = null;
160 $this->attributes[
'owner_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
161 $this->attributes[
'container_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
164 $this->attributes[
'time_updated'] = null;
165 $this->attributes[
'last_action'] = null;
166 $this->attributes[
'enabled'] =
"yes";
182 _elgg_services()->logger->error(
"Failed to clone entity with GUID $this->guid");
187 'guid' => $this->guid,
191 $this->attributes[
'guid'] = null;
192 $this->attributes[
'time_created'] = null;
193 $this->attributes[
'time_updated'] = null;
194 $this->attributes[
'last_action'] = null;
196 $this->attributes[
'subtype'] = $orig_entity->getSubtype();
200 if (is_array($metadata_array)) {
202 $metadata_names = [];
204 $metadata_names[] = $metadata->name;
207 $metadata_names = array_unique($metadata_names);
210 foreach ($metadata_names as
$name) {
211 $this->
__set($name, $orig_entity->$name);
235 if (array_key_exists(
$name, $this->attributes)) {
237 if (is_int($this->attributes[
$name])
239 && ((
string) $this->attributes[$name] ===
$value)) {
244 if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
245 $this->orig_attributes[
$name] = $this->attributes[
$name];
256 case 'container_guid':
260 $this->attributes[
$name] = null;
295 if (array_key_exists(
$name, $this->attributes)) {
296 return $this->attributes[
$name];
340 return array_map(
function($values) {
341 return count($values) > 1 ? $values : $values[0];
345 $this->_cached_metadata =
_elgg_services()->metadataCache->getAll($this->guid);
382 return !is_null($var);
385 if (empty($this->guid)) {
394 if ((is_array($current_metadata) || count(
$value) > 1 ||
$value === []) && isset($current_metadata)) {
400 'guid' => $this->guid,
401 'metadata_name' =>
$name,
406 if (
false === $delete_result) {
418 foreach (
$value as $value_tmp) {
425 if ($md_id ===
false) {
446 unset($this->temp_metadata[
$name]);
454 if (!isset($this->temp_metadata[
$name])) {
455 $this->temp_metadata[
$name] = [];
458 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[$name],
$value);
480 if (!isset($this->temp_metadata[
$name])) {
483 unset($this->temp_metadata[$name]);
487 $this->temp_metadata = [];
511 return array_key_exists(
$name, $this->
volatile) ? $this->
volatile[
$name] : null;
540 $relationship = (string) $relationship;
657 unset($this->temp_private_settings[
$name]);
672 $this->temp_private_settings = [];
676 return _elgg_services()->privateSettings->removeAllForEntity($this);
714 unset($this->temp_annotations[
$name]);
716 $this->temp_annotations = [];
735 $callback =
function() use (
$name) {
737 'annotation_owner_guid' => $this->guid,
739 'annotation_name' =>
$name,
793 private function getAnnotationCalculation(
$name, $calculation) {
797 'annotation_name' =>
$name,
798 'annotation_calculation' => $calculation
861 if (isset($this->temp_annotations[
$name])) {
862 return [$this->temp_annotations[
$name]];
877 return $this->getAnnotationCalculation(
$name,
'count');
888 return $this->getAnnotationCalculation(
$name,
'avg');
899 return $this->getAnnotationCalculation(
$name,
'sum');
910 return $this->getAnnotationCalculation(
$name,
'min');
921 return $this->getAnnotationCalculation(
$name,
'max');
940 'subtype' =>
'comment',
941 'container_guid' => $this->
getGUID(),
1008 'relationship' => $relationship,
1009 'relationship_guid' => $this->
getGUID(),
1010 'inverse_relationship' => $inverse_relationship,
1142 return $this->attributes[
'subtype'];
1199 return $this->time_updated;
1329 if (
$guid !==
false && !
_elgg_services()->events->trigger(
'create', $this->type, $this)) {
1332 return $this->
delete();
1357 $type = $this->attributes[
'type'];
1358 if (!in_array(
$type, \
Elgg\Config::getEntityTypes())) {
1359 throw new \InvalidParameterException(
'Entity type must be one of the allowed types: ' 1360 . implode(
', ', \
Elgg\Config::getEntityTypes()));
1363 $subtype = $this->attributes[
'subtype'];
1365 throw new \InvalidParameterException(
"All entities must have a subtype");
1368 $owner_guid = (int) $this->attributes[
'owner_guid'];
1369 $access_id = (int) $this->attributes[
'access_id'];
1371 $time_created = isset($this->attributes[
'time_created']) ? (int) $this->attributes[
'time_created'] : $now;
1381 throw new \InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1385 throw new \InvalidParameterException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1394 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but the given" 1395 .
" owner $owner_guid could not be loaded.");
1402 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype) with owner" 1403 .
" $owner_guid, but the user wasn't permitted to write to the owner's container.");
1412 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but the given" 1413 .
" container $container_guid could not be loaded.");
1418 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but was not" 1419 .
" permitted to write to container $container_guid.");
1432 'time_updated' => $now,
1433 'last_action' => $now,
1434 ], $this->attributes);
1437 throw new \IOException(
"Unable to save new object's base entity information!");
1440 $this->attributes[
'subtype'] =
$subtype;
1441 $this->attributes[
'guid'] = (int)
$guid;
1443 $this->attributes[
'time_updated'] = (int) $now;
1444 $this->attributes[
'last_action'] = (int) $now;
1453 if (
sizeof($this->temp_metadata) > 0) {
1454 foreach ($this->temp_metadata as
$name =>
$value) {
1455 if (count(
$value) == 1) {
1463 $this->temp_metadata = [];
1467 if (
sizeof($this->temp_annotations) > 0) {
1468 foreach ($this->temp_annotations as
$name =>
$value) {
1472 $this->temp_annotations = [];
1476 if (
sizeof($this->temp_private_settings) > 0) {
1477 foreach ($this->temp_private_settings as
$name =>
$value) {
1481 $this->temp_private_settings = [];
1501 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
1508 $guid = (int) $this->guid;
1516 throw new \InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1520 throw new \InvalidParameterException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1529 'time_updated' =>
$time,
1532 if ($ret ===
false) {
1536 $this->attributes[
'time_updated'] =
$time;
1538 _elgg_services()->events->triggerAfter(
'update', $this->type, $this);
1540 $this->orig_attributes = [];
1556 $attributes = array_merge($this->attributes, (array) $row);
1558 if (array_diff(self::$primary_attr_names, array_keys(
$attributes)) !== []) {
1564 if (!in_array(
$name, self::$primary_attr_names)) {
1570 if (in_array(
$name, self::$integer_attr_names)) {
1596 return $this->
load($row);
1618 public function disable($reason =
"", $recursive =
true) {
1623 if (!
_elgg_services()->events->trigger(
'disable', $this->type, $this)) {
1631 if ($this instanceof
ElggUser && !$this->isBanned()) {
1634 $unban_after =
true;
1636 $unban_after =
false;
1640 $this->disable_reason = $reason;
1645 $guid = (int) $this->guid;
1649 $callback =
function () use (
$guid, $reason) {
1659 foreach ([
'owner_guid',
'container_guid'] as $db_column) {
1663 $subentities = new \ElggBatch(
'elgg_get_entities',
$options);
1664 $subentities->setIncrementOffset(
false);
1666 foreach ($subentities as $subentity) {
1668 if (!$subentity->isEnabled()) {
1672 $subentity->disable($reason);
1683 UPDATE {$dbprefix}entities 1699 $this->attributes[
'enabled'] =
'no';
1700 _elgg_services()->events->triggerAfter(
'disable', $this->type, $this);
1703 return (
bool) $disabled;
1717 $guid = (int) $this->guid;
1722 if (!
_elgg_services()->events->trigger(
'enable', $this->type, $this)) {
1731 $callback =
function() use (
$guid, $recursive) {
1734 UPDATE {$db->prefix}entities 1744 'relationship' =>
'disabled_with',
1745 'relationship_guid' =>
$guid,
1746 'inverse_relationship' =>
true,
1750 foreach ($disabled_with_it as $e) {
1762 $this->attributes[
'enabled'] =
'yes';
1763 _elgg_services()->events->triggerAfter(
'enable', $this->type, $this);
1775 return $this->enabled ==
'yes';
1795 public function delete($recursive =
true) {
1833 $object->type = $this->
getType();
1839 $object->url = $this->
getURL();
1840 $object->read_access = (int) $this->
access_id;
1878 $this->{
"geo:lat"} = $lat;
1879 $this->{
"geo:long"} = $long;
1889 return (
float) $this->{
"geo:lat"};
1899 return (
float) $this->{
"geo:long"};
1937 if ($tag_names && !is_array($tag_names)) {
1938 $tag_names = [$tag_names];
1944 foreach ($valid_tags as $tag_name) {
1945 if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
1949 if (
$tags = $this->$tag_name) {
1952 if (is_array(
$tags)) {
1953 $entity_tags = array_merge($entity_tags,
$tags);
1955 $entity_tags[] =
$tags;
1960 return $entity_tags;
1975 if ($this->type !==
'user') {
1981 $collections = $ac->getCollectionsByMember($this->guid);
1982 if (empty($collections)) {
1987 foreach ($collections as $collection) {
1988 $result &= $ac->removeUser($this->guid, $collection->id);
2007 if (empty($collections)) {
2012 foreach ($collections as $collection) {
2032 $this->attributes[
'last_action'] =
$posted;
2045 $this->_is_cacheable =
false;
2058 $this->_is_cacheable =
true;
2086 public function cache($persist =
true) {
2100 $this->
volatile = [];
2104 $this->
volatile = $tmp;
2127 _elgg_services()->dataCache->get($namespace)->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...
saveIconFromUploadedFile($input_name, $type= 'icon', array $coords=[])
Saves icons using an uploaded file as the source.
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
enable($recursive=true)
Enable the entity.
removeAllPrivateSettings()
Removes all private settings.
getSubtype()
Get the entity subtype.
canEditMetadata($metadata=null, $user_guid=0)
Can a user edit metadata on this entity?
getDatabase()
Provides a pointer to the database object.
if(!$item instanceof ElggRiverItem) $object
if(!$user||!$user->canDelete()) $name
getOwnerGUID()
Get the guid of the entity's owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
if(!array_key_exists($filename, $text_files)) $file
Entities that support icons should implement this interface.
__clone()
Clone an entity.
deleteIcon($type= 'icon')
Removes all icon files and metadata for the passed type of icon.
$params
Saves global plugin settings.
getAllPrivateSettings()
Returns all private settings.
$annotation
Elgg default annotation view.
__get($name)
Get an attribute or metadata value.
getOwnerEntity()
Gets the that owns this entity.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
setTempMetadata($name, $value, $multiple=false)
Set temp metadata on this entity.
setLatLong($lat, $long)
Set latitude and longitude metadata tags for a given entity.
removePrivateSetting($name)
Removes private setting.
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
countAnnotations($name="")
Count annotations.
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
invalidateCache()
Invalidate cache for entity.
setPrivateSetting($name, $value)
Adds a private setting to this entity.
initializeAttributes()
Initialize the attributes array.
canWriteToContainer($user_guid=0, $type= 'all', $subtype= 'all')
Can a user add an entity to this container.
refresh(stdClass $row)
Load new data from database into existing entity.
getPrivateSetting($name)
Returns a private setting value.
elgg_get_annotations(array $options=[])
Fetch annotations or perform a calculation on them.
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
countComments()
Count the number of comments attached to this entity.
elgg_delete_river(array $options=[])
Delete river items based on $options.
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
Database abstraction query builder.
getGUID()
Returns the guid.
getCurrentTime($modifier= '')
Get the (cloned) time.
$guid
Removes an admin notice.
getContainerGUID()
Gets the container GUID for this entity.
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
enableCaching()
Enable runtime caching for entity.
cache($persist=true)
Cache the entity in a session and persisted caches.
canEdit($user_guid=0)
Can a user edit this entity?
getIcon($size, $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type= '')
Removes all relationships originating from a particular entity.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
getEntitiesFromRelationship(array $options=[])
Gets an array of entities with a relationship to this entity.
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
setContainerGUID($container_guid)
Set the container for this object.
removeRelationship($guid_two, $relationship)
Remove a relationship.
elgg_disable_annotations(array $options)
Disables annotations based on $options.
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
$user_guid
Validate a user.
getMetadata($name)
Return the value of a piece of metadata.
const ELGG_IGNORE_ACCESS
elgg_call() flags
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
saveIconFromElggFile(\ElggFile $file, $type= 'icon', array $coords=[])
Saves icons using a file located in the data store as the source.
getTags($tag_names=null)
Returns tags for this entity.
disableCaching()
Disable runtime caching for entity.
$id
River item delete action.
static $primary_attr_names
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
const ELGG_SHOW_DISABLED_ENTITIES
removeAllRelatedRiverItems()
Removes all river items related to this entity.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
static $integer_attr_names
if(!$entity instanceof ElggEntity) $time
getAnnotationsAvg($name)
Get the average of an integer type annotation.
load(stdClass $row)
Loads attributes from the entities table into the object.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
setLocation($location)
Sets the 'location' metadata for the entity.
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.
canAnnotate($user_guid=0, $annotation_name= '')
Can a user annotate an entity?
toObject(array $params=[])
Export an entity.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
getAnnotations(array $options=[])
Gets an array of annotations.
getOwnedAccessCollections($options=[])
Returns the ACLs owned by the entity.
$attributes
The main attributes of an entity.
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getIconURL($params=[])
Get the URL for this entity's icon.
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
setMetadata($name, $value, $value_type= '', $multiple=false)
Set metadata on this entity.
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
_elgg_config()
Get the Elgg config service.
canDelete($user_guid=0)
Can a user delete this entity?
setDisplayName($display_name)
Sets the title or name of this entity.
hasIcon($size, $type= 'icon')
Returns if the entity has an icon of the passed type.
getOwnedAccessCollection($subtype)
Returns the first ACL owned by the entity with a given subtype.
getType()
Returns the entity type.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type="")
Adds an annotation to an entity.
create()
Create a new entry in the entities table.
getAllMetadata()
Get all entity metadata.
getIconLastChange($size, $type= 'icon')
Returns the timestamp of when the icon was changed.
_elgg_services()
Get the global service provider.
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
updateLastAction($posted=null)
Update the last_action column in the entities table.
getLocation()
Gets the 'location' metadata for the entity.
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.
canComment($user_guid=0, $default=null)
Can a user comment on an entity?
getSystemLogID()
Return an identification for the object for storage in the system log.
disable($reason="", $recursive=true)
Disable this entity.
if(!$owner||!$owner->canEdit()) if(!$owner->hasIcon('master')) $coords
elgg_generate_entity_url(ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
Generate entity URL from a named route.
getURL()
Gets the URL for this entity.
getDisplayName()
Get the entity's display name.
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
getLongitude()
Return the entity's longitude.
get_entity($guid)
Loads and returns an entity object from a guid.
getObjectFromID($id)
For a given ID, return the object associated with it.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=[])
Saves icons using a local file as the source.