144 if ($row && !$this->
load($row)) {
145 $msg =
"Failed to load new " . get_class() .
" for GUID:" . $row->guid;
158 parent::initializeAttributes();
160 $this->attributes[
'guid'] = null;
161 $this->attributes[
'type'] = $this->
getType();
162 $this->attributes[
'subtype'] = null;
164 $this->attributes[
'owner_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
165 $this->attributes[
'container_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
168 $this->attributes[
'time_updated'] = null;
169 $this->attributes[
'last_action'] = null;
170 $this->attributes[
'enabled'] =
"yes";
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;
211 $metadata_names = array_unique($metadata_names);
214 foreach ($metadata_names as
$name) {
215 $this->
__set($name, $orig_entity->$name);
241 if (array_key_exists(
$name, $this->attributes)) {
243 if (is_int($this->attributes[
$name])
245 && ((
string) $this->attributes[$name] ===
$value)) {
250 if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
251 $this->orig_attributes[
$name] = $this->attributes[
$name];
267 case 'container_guid':
271 $this->attributes[
$name] = null;
306 if (array_key_exists(
$name, $this->attributes)) {
307 return $this->attributes[
$name];
351 return array_map(
function($values) {
352 return count($values) > 1 ? $values : $values[0];
356 $this->_cached_metadata =
_elgg_services()->metadataCache->getAll($this->guid);
398 return !is_null($var);
401 if (empty($this->guid)) {
410 if ((is_array($current_metadata) ||
count(
$value) > 1 ||
$value === []) && isset($current_metadata)) {
416 'guid' => $this->guid,
417 'metadata_name' =>
$name,
422 if (
false === $delete_result) {
434 foreach (
$value as $value_tmp) {
440 if (!empty($value_type)) {
445 if ($md_id ===
false) {
466 unset($this->temp_metadata[
$name]);
474 if (!isset($this->temp_metadata[
$name])) {
475 $this->temp_metadata[
$name] = [];
478 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[$name],
$value);
500 if (!isset($this->temp_metadata[
$name])) {
503 unset($this->temp_metadata[$name]);
507 $this->temp_metadata = [];
531 return array_key_exists(
$name, $this->
volatile) ? $this->
volatile[
$name] : null;
573 return (
bool)
_elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two);
586 return _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two) ?: null;
615 'relationship_guid' => $this->guid,
616 'inverse_relationship' => $inverse_relationship,
663 elgg_deprecated_notice(__METHOD__ .
' has been deprecated. Use \ElggEntity->removeAllRelationships()',
'4.3');
750 unset($this->temp_private_settings[
$name]);
764 $this->temp_private_settings = [];
768 return _elgg_services()->privateSettings->removeAllForEntity($this);
806 unset($this->temp_annotations[
$name]);
808 $this->temp_annotations = [];
827 'annotation_owner_guid' => $this->guid,
829 'annotation_name' =>
$name,
879 private function getAnnotationCalculation(
$name, $calculation) {
883 'annotation_name' =>
$name,
884 'annotation_calculation' => $calculation
926 if (!empty($value_type)) {
956 if (isset($this->temp_annotations[
$name])) {
957 return [$this->temp_annotations[
$name]];
972 return $this->getAnnotationCalculation(
$name,
'count');
983 return $this->getAnnotationCalculation(
$name,
'avg');
994 return $this->getAnnotationCalculation(
$name,
'sum');
1005 return $this->getAnnotationCalculation(
$name,
'min');
1016 return $this->getAnnotationCalculation(
$name,
'max');
1030 $params = [
'entity' => $this];
1037 return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
1207 if ($this->guid && !array_key_exists(
'subtype', $this->orig_attributes)) {
1208 $this->orig_attributes[
'subtype'] = $this->attributes[
'subtype'];
1211 $this->attributes[
'subtype'] =
$subtype;
1220 return $this->attributes[
'subtype'];
1402 if ($this->guid > 0) {
1406 if (
$guid ===
false) {
1410 if (!
_elgg_services()->events->trigger(
'create', $this->type, $this)) {
1413 return $this->
delete();
1440 $type = $this->attributes[
'type'];
1441 if (!in_array(
$type, \
Elgg\Config::ENTITY_TYPES)) {
1446 $subtype = $this->attributes[
'subtype'];
1451 $owner_guid = (int) $this->attributes[
'owner_guid'];
1452 $access_id = (int) $this->attributes[
'access_id'];
1454 $time_created = isset($this->attributes[
'time_created']) ? (int) $this->attributes[
'time_created'] : $now;
1464 throw new InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1468 throw new InvalidParameterException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1477 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but the given" 1478 .
" owner $owner_guid could not be loaded.");
1485 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype) with owner" 1486 .
" $owner_guid, but the user wasn't permitted to write to the owner's container.");
1495 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but the given" 1496 .
" container $container_guid could not be loaded.");
1501 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but was not" 1502 .
" permitted to write to container $container_guid.");
1515 'time_updated' => $now,
1516 'last_action' => $now,
1517 ], $this->attributes);
1520 throw new IOException(
"Unable to save new object's base entity information!");
1523 $this->attributes[
'subtype'] =
$subtype;
1524 $this->attributes[
'guid'] = (int)
$guid;
1526 $this->attributes[
'time_updated'] = (int) $now;
1527 $this->attributes[
'last_action'] = (int) $now;
1536 if (
sizeof($this->temp_metadata) > 0) {
1537 foreach ($this->temp_metadata as
$name =>
$value) {
1542 $this->temp_metadata = [];
1546 if (
sizeof($this->temp_annotations) > 0) {
1547 foreach ($this->temp_annotations as
$name =>
$value) {
1551 $this->temp_annotations = [];
1555 if (
sizeof($this->temp_private_settings) > 0) {
1556 foreach ($this->temp_private_settings as
$name =>
$value) {
1560 $this->temp_private_settings = [];
1585 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
1592 $guid = (int) $this->guid;
1600 throw new InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1604 throw new InvalidParameterException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1613 'time_updated' =>
$time,
1616 if ($ret ===
false) {
1620 $this->attributes[
'time_updated'] =
$time;
1622 _elgg_services()->events->triggerAfter(
'update', $this->type, $this);
1624 $this->orig_attributes = [];
1639 protected function load(stdClass $row) {
1640 $attributes = array_merge($this->attributes, (array) $row);
1642 if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys(
$attributes)) !== []) {
1648 if (!in_array(
$name, self::PRIMARY_ATTR_NAMES)) {
1654 if (in_array(
$name, static::INTEGER_ATTR_NAMES)) {
1683 public function disable($reason =
"", $recursive =
true) {
1688 if (!
_elgg_services()->events->trigger(
'disable', $this->type, $this)) {
1696 if ($this instanceof
ElggUser && !$this->isBanned()) {
1699 $unban_after =
true;
1701 $unban_after =
false;
1705 $this->disable_reason = $reason;
1708 $guid = (int) $this->guid;
1720 'batch_inc_offset' =>
false,
1723 foreach ([
'owner_guid',
'container_guid'] as $db_column) {
1729 foreach ($subentities as $subentity) {
1731 if (!$subentity->isEnabled()) {
1734 $subentity->addRelationship(
$guid,
'disabled_with');
1735 $subentity->disable($reason,
true);
1752 $this->attributes[
'enabled'] =
'no';
1753 _elgg_services()->events->triggerAfter(
'disable', $this->type, $this);
1767 if (empty($this->guid)) {
1771 if (!
_elgg_services()->events->trigger(
'enable', $this->type, $this)) {
1787 'relationship' =>
'disabled_with',
1788 'relationship_guid' => $this->guid,
1789 'inverse_relationship' =>
true,
1792 'batch_inc_offset' =>
false,
1795 foreach ($disabled_with_it as $e) {
1796 $e->enable($recursive);
1797 $e->removeRelationship($this->guid,
'disabled_with');
1805 $this->attributes[
'enabled'] =
'yes';
1806 _elgg_services()->events->triggerAfter(
'enable', $this->type, $this);
1818 return $this->enabled ==
'yes';
1838 public function delete($recursive =
true) {
1876 $object->type = $this->
getType();
1882 $object->url = $this->
getURL();
1883 $object->read_access = (int) $this->
access_id;
1896 $this->{
"geo:lat"} = $lat;
1897 $this->{
"geo:long"} = $long;
1906 return (
float) $this->{
"geo:lat"};
1915 return (
float) $this->{
"geo:long"};
1951 if (!isset($tag_names)) {
1952 $tag_names = [
'tags'];
1955 if ($tag_names && !is_array($tag_names)) {
1956 $tag_names = [$tag_names];
1960 foreach ($tag_names as $tag_name) {
1961 $tags = $this->$tag_name;
1968 if (is_array(
$tags)) {
1969 $entity_tags = array_merge($entity_tags,
$tags);
1971 $entity_tags[] =
$tags;
1975 return $entity_tags;
1990 if ($this->type !==
'user') {
1996 $collections = $ac->getCollectionsByMember($this->guid);
1997 if (empty($collections)) {
2002 foreach ($collections as $collection) {
2003 $result &= $ac->removeUser($this->guid, $collection->id);
2022 if (empty($collections)) {
2027 foreach ($collections as $collection) {
2047 $this->attributes[
'last_action'] =
$posted;
2060 $this->_is_cacheable =
false;
2073 $this->_is_cacheable =
true;
2101 public function cache($persist =
true) {
2115 $this->
volatile = [];
2117 _elgg_services()->sessionCache->entities->save($this->guid, $this);
2119 $this->
volatile = $tmp;
2141 _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.
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.
__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.
__get($name)
Get an attribute or metadata value.
getOwnerEntity()
Gets the that owns this entity.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
setTempMetadata($name, $value, $multiple=false)
Set temp metadata on this entity.
removePrivateSetting($name)
Removes private setting.
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
An IO Exception, throw when an IO Exception occurs.
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
if(!$user||!$user->canDelete()) $name
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.
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).
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
$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.
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?
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
getIcon($size, $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
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.
const ELGG_HIDE_DISABLED_ENTITIES
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.
getCurrentTime($modifier= '')
Get the (cloned) time.
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
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.
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.
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.
getAnnotationsAvg($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_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.
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.
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?
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.
removeAllRelationships(string $relationship=null, bool $inverse_relationship=false)
Remove all relationships to or from this entity.
if($email instanceof\Elgg\Email) $object
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.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
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.
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.
$id
Generic annotation delete action.
disable($reason="", $recursive=true)
Disable this entity.
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.
$guid
Reset an ElggUpgrade.
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.
canWriteToContainer($user_guid=0, $type= '', $subtype= '')
Can a user add an entity to this container.