143 if (!empty($row) && !$this->
load($row)) {
144 throw new IOException(
'Failed to load new ' . get_class() .
" for GUID: {$row->guid}");
156 parent::initializeAttributes();
158 $this->attributes[
'guid'] = null;
159 $this->attributes[
'type'] = $this->
getType();
160 $this->attributes[
'subtype'] = null;
162 $this->attributes[
'owner_guid'] =
_elgg_services()->session_manager->getLoggedInUserGuid();
163 $this->attributes[
'container_guid'] =
_elgg_services()->session_manager->getLoggedInUserGuid();
166 $this->attributes[
'time_updated'] = null;
167 $this->attributes[
'last_action'] = null;
168 $this->attributes[
'enabled'] =
'yes';
169 $this->attributes[
'deleted'] =
'no';
170 $this->attributes[
'time_deleted'] = null;
186 _elgg_services()->logger->error(
"Failed to clone entity with GUID $this->guid");
191 'guid' => $this->guid,
195 $this->attributes[
'guid'] = null;
196 $this->attributes[
'time_created'] = null;
197 $this->attributes[
'time_updated'] = null;
198 $this->attributes[
'last_action'] = null;
200 $this->attributes[
'subtype'] = $orig_entity->getSubtype();
204 if (is_array($metadata_array)) {
206 $metadata_names = [];
208 $metadata_names[] = $metadata->name;
212 $metadata_names = array_unique($metadata_names);
215 foreach ($metadata_names as
$name) {
216 $this->
__set($name, $orig_entity->$name);
242 if (array_key_exists(
$name, $this->attributes)) {
244 if (is_int($this->attributes[
$name])
246 && ((
string) $this->attributes[$name] ===
$value)) {
251 if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
252 $this->orig_attributes[
$name] = $this->attributes[
$name];
271 case 'container_guid':
275 $this->attributes[
$name] = null;
312 if (array_key_exists(
$name, $this->attributes)) {
313 return $this->attributes[
$name];
358 return array_map(
function($values) {
359 return count($values) > 1 ? $values : $values[0];
363 $this->_cached_metadata =
_elgg_services()->metadataCache->getAll($this->guid);
399 return !is_null($var);
402 if (empty($this->guid)) {
411 if ((is_array($current_metadata) ||
count(
$value) > 1 ||
$value === []) && isset($current_metadata)) {
417 'guid' => $this->guid,
418 'metadata_name' => $name,
423 if ($delete_result ===
false) {
435 foreach (
$value as $value_tmp) {
441 if (!empty($value_type)) {
446 if ($md_id ===
false) {
467 unset($this->temp_metadata[$name]);
476 if (!isset($this->temp_metadata[$name])) {
477 $this->temp_metadata[
$name] = [];
480 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[$name],
$value);
501 if (isset($this->temp_metadata[
$name])) {
502 unset($this->temp_metadata[$name]);
505 $this->temp_metadata = [];
512 'guid' => $this->guid,
514 'metadata_name' =>
$name,
526 return array_key_exists($name, $this->
volatile) ? $this->
volatile[
$name] : null;
553 return _elgg_services()->relationshipsTable->add($this->guid, $relationship, $guid_two);
568 return (
bool)
_elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two);
581 return _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two) ?: null;
609 'relationship' => $relationship,
610 'relationship_guid' => $this->guid,
611 'inverse_relationship' => $inverse_relationship,
624 return _elgg_services()->relationshipsTable->remove($this->guid, (
string) $relationship, (
int) $guid_two);
669 'guid' => $this->guid,
671 'annotation_name' =>
$name,
676 unset($this->temp_annotations[
$name]);
678 $this->temp_annotations = [];
698 'annotation_owner_guid' => $this->guid,
700 'annotation_name' =>
$name,
713 private function getAnnotationCalculation(
$name, $calculation) {
717 'annotation_name' =>
$name,
718 'annotation_calculation' => $calculation
760 if (!empty($value_type)) {
790 if (isset($this->temp_annotations[
$name])) {
791 return [$this->temp_annotations[
$name]];
806 return $this->getAnnotationCalculation(
$name,
'count');
817 return $this->getAnnotationCalculation($name,
'avg');
828 return $this->getAnnotationCalculation($name,
'sum');
839 return $this->getAnnotationCalculation($name,
'min');
850 return $this->getAnnotationCalculation($name,
'max');
871 return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
900 if ($subtype ===
'') {
905 'subtype' => $subtype,
1028 if ($this->guid && !array_key_exists(
'subtype', $this->orig_attributes)) {
1029 $this->orig_attributes[
'subtype'] = $this->attributes[
'subtype'];
1032 $this->attributes[
'subtype'] =
$subtype;
1041 return (
string) $this->attributes[
'subtype'];
1059 return $this->owner_guid ?
get_entity($this->owner_guid) : null;
1112 $url =
_elgg_services()->events->triggerResults(
'entity:url',
"{$this->getType()}:{$this->getSubtype()}", [
'entity' => $this],
$url);
1125 if ($this->guid > 0) {
1152 $type = $this->attributes[
'type'];
1153 if (!in_array(
$type, \
Elgg\Config::ENTITY_TYPES)) {
1157 $subtype = $this->attributes[
'subtype'];
1162 $owner_guid = (int) $this->attributes[
'owner_guid'];
1163 $access_id = (int) $this->attributes[
'access_id'];
1165 $time_created = isset($this->attributes[
'time_created']) ? (int) $this->attributes[
'time_created'] : $now;
1166 $deleted = $this->attributes[
'deleted'];
1167 $time_deleted = (int) $this->attributes[
'time_deleted'];
1191 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
1192 $error .=
" but the given owner {$owner_guid} could not be loaded.";
1198 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}) with owner {$owner_guid},";
1199 $error .=
" but the user wasn't permitted to write to the owner's container.";
1208 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
1209 $error .=
" but the given container {$container_guid} could not be loaded.";
1214 $error =
"User {$user_guid} tried to create a ({$type}, {$subtype}),";
1215 $error .=
" but was not permitted to write to container {$container_guid}.";
1220 if (!
_elgg_services()->events->triggerBefore(
'create', $this->type, $this)) {
1232 'time_updated' => $now,
1233 'last_action' => $now,
1235 'time_deleted' => $time_deleted
1236 ], $this->attributes);
1239 throw new IOException(
"Unable to save new object's base entity information!");
1242 $this->attributes[
'subtype'] =
$subtype;
1243 $this->attributes[
'guid'] = (int)
$guid;
1245 $this->attributes[
'time_updated'] = (int) $now;
1246 $this->attributes[
'last_action'] = (int) $now;
1248 $this->attributes[
'deleted'] =
$deleted;
1249 $this->attributes[
'time_deleted'] = (int) $time_deleted;
1257 if (
count($this->temp_metadata) > 0) {
1258 foreach ($this->temp_metadata as
$name =>
$value) {
1263 $this->temp_metadata = [];
1267 if (
count($this->temp_annotations) > 0) {
1268 foreach ($this->temp_annotations as
$name =>
$value) {
1272 $this->temp_annotations = [];
1283 _elgg_services()->events->triggerAfter(
'create', $this->type, $this);
1302 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
1309 $guid = (int) $this->guid;
1316 $time_deleted = (int) $this->time_deleted;
1332 'time_updated' =>
$time,
1335 'time_deleted' => $time_deleted
1337 if ($ret ===
false) {
1341 $this->attributes[
'time_updated'] =
$time;
1343 _elgg_services()->events->triggerAfter(
'update', $this->type, $this);
1345 $this->orig_attributes = [];
1360 protected function load(stdClass $row): bool {
1361 $attributes = array_merge($this->attributes, (array) $row);
1363 if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys(
$attributes)) !== []) {
1369 if (!in_array(
$name, self::PRIMARY_ATTR_NAMES)) {
1375 if (in_array(
$name, static::INTEGER_ATTR_NAMES)) {
1404 public function disable(
string $reason =
'',
bool $recursive =
true): bool {
1409 if (!
_elgg_services()->events->trigger(
'disable', $this->type, $this)) {
1417 if ($this instanceof
ElggUser && !$this->isBanned()) {
1421 $unban_after =
true;
1423 $unban_after =
false;
1426 if (!empty($reason)) {
1427 $this->disable_reason = $reason;
1430 $guid = (int) $this->guid;
1442 'batch_inc_offset' =>
false,
1445 foreach ([
'owner_guid',
'container_guid'] as $db_column) {
1451 foreach ($subentities as $subentity) {
1452 if (!$subentity->isEnabled()) {
1456 $subentity->addRelationship(
$guid,
'disabled_with');
1457 $subentity->disable($reason,
true);
1472 $this->attributes[
'enabled'] =
'no';
1473 _elgg_services()->events->triggerAfter(
'disable', $this->type, $this);
1486 public function enable(
bool $recursive =
true): bool {
1487 if (empty($this->guid)) {
1491 if (!
_elgg_services()->events->trigger(
'enable', $this->type, $this)) {
1506 'relationship' =>
'disabled_with',
1507 'relationship_guid' => $this->guid,
1508 'inverse_relationship' =>
true,
1511 'batch_inc_offset' =>
false,
1514 foreach ($disabled_with_it as $e) {
1515 $e->enable($recursive);
1516 $e->removeRelationship($this->guid,
'disabled_with');
1524 $this->attributes[
'enabled'] =
'yes';
1525 _elgg_services()->events->triggerAfter(
'enable', $this->type, $this);
1537 return $this->enabled ==
'yes';
1557 public function delete(
bool $recursive =
true,
bool $persistent = null):
bool {
1566 if (!isset($persistent)) {
1571 if (empty($this->guid) || $persistent) {
1574 return $this->
trash($recursive);
1602 protected function trash(
bool $recursive =
true): bool {
1605 $this->attributes[
'deleted'] =
'yes';
1619 public function restore(
bool $recursive =
true): bool {
1624 if (empty($this->guid) || !$this->
canEdit()) {
1628 return _elgg_services()->events->triggerSequence(
'restore', $this->type, $this,
function () use ($recursive) {
1634 $this->attributes[
'deleted'] =
'no';
1635 $this->attributes[
'time_deleted'] = 0;
1648 'relationship' =>
'deleted_with',
1649 'relationship_guid' => $this->guid,
1650 'inverse_relationship' =>
true,
1653 'batch_inc_offset' =>
false,
1657 foreach ($deleted_with_it as $e) {
1658 if (!$e->restore($recursive)) {
1659 $deleted_with_it->reportFailure();
1675 return $this->deleted ===
'yes';
1702 $object->type = $this->
getType();
1708 $object->url = $this->
getURL();
1709 $object->read_access = (int) $this->
access_id;
1722 $this->{
'geo:lat'} = $lat;
1723 $this->{
'geo:long'} = $long;
1732 return (
float) $this->{
'geo:lat'};
1741 return (
float) $this->{
'geo:long'};
1752 return (
int) $this->
getGUID();
1779 if ($this->type !==
'user') {
1785 $collections = $ac->getCollectionsByMember($this->guid);
1786 if (empty($collections)) {
1791 foreach ($collections as $collection) {
1792 $result &= $ac->removeUser($this->guid, $collection->id);
1811 if (empty($collections)) {
1816 foreach ($collections as $collection) {
1837 $this->attributes[
'last_action'] =
$posted;
1854 $this->attributes[
'time_deleted'] =
$deleted;
1867 $this->_is_cacheable =
false;
1880 $this->_is_cacheable =
true;
1927 _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.
__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.
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
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
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.
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 and another 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?
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.
getObjectFromID(int $id)
For a given ID, return the object associated with it.
countAnnotations(string $name= '')
Count annotations.
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
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.
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.
elgg_count_entities(array $options=[])
Returns a count of entities.
A generic parent class for database exceptions.
__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).
toObject(array $params=[])
Export an entity.
getAnnotations(array $options=[])
Gets an array of annotations.
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 .
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
const ELGG_SHOW_DELETED_ENTITIES
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
trash(bool $recursive=true)
Move the entity to the trash.
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.
updateTimeDeleted(int $deleted=null)
Update the time_deleted column in the entities table.
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...
restore(bool $recursive=true)
Restore the entity.
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.
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.
$guid
Reset an ElggUpgrade.
getLongitude()
Return the entity's longitude.