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;
676 unset($this->temp_private_settings[
$name]);
690 $this->temp_private_settings = [];
694 return _elgg_services()->privateSettings->removeAllForEntity($this);
732 unset($this->temp_annotations[
$name]);
734 $this->temp_annotations = [];
753 'annotation_owner_guid' => $this->guid,
755 'annotation_name' =>
$name,
805 private function getAnnotationCalculation(
$name, $calculation) {
809 'annotation_name' =>
$name,
810 'annotation_calculation' => $calculation
852 if (!empty($value_type)) {
882 if (isset($this->temp_annotations[
$name])) {
883 return [$this->temp_annotations[
$name]];
898 return $this->getAnnotationCalculation(
$name,
'count');
909 return $this->getAnnotationCalculation(
$name,
'avg');
920 return $this->getAnnotationCalculation(
$name,
'sum');
931 return $this->getAnnotationCalculation(
$name,
'min');
942 return $this->getAnnotationCalculation(
$name,
'max');
963 return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
1028 'relationship_guid' => $this->
getGUID(),
1029 'inverse_relationship' => $inverse_relationship,
1150 if ($this->guid && !array_key_exists(
'subtype', $this->orig_attributes)) {
1151 $this->orig_attributes[
'subtype'] = $this->attributes[
'subtype'];
1154 $this->attributes[
'subtype'] =
$subtype;
1163 return $this->attributes[
'subtype'];
1345 if ($this->guid > 0) {
1349 if (
$guid ===
false) {
1353 if (!
_elgg_services()->events->trigger(
'create', $this->type, $this)) {
1356 return $this->
delete();
1383 $type = $this->attributes[
'type'];
1384 if (!in_array(
$type, \
Elgg\Config::ENTITY_TYPES)) {
1389 $subtype = $this->attributes[
'subtype'];
1394 $owner_guid = (int) $this->attributes[
'owner_guid'];
1395 $access_id = (int) $this->attributes[
'access_id'];
1397 $time_created = isset($this->attributes[
'time_created']) ? (int) $this->attributes[
'time_created'] : $now;
1407 throw new InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1411 throw new InvalidParameterException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1420 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but the given" 1421 .
" owner $owner_guid could not be loaded.");
1428 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype) with owner" 1429 .
" $owner_guid, but the user wasn't permitted to write to the owner's container.");
1438 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but the given" 1439 .
" container $container_guid could not be loaded.");
1444 _elgg_services()->logger->error(
"User $user_guid tried to create a ($type, $subtype), but was not" 1445 .
" permitted to write to container $container_guid.");
1458 'time_updated' => $now,
1459 'last_action' => $now,
1460 ], $this->attributes);
1463 throw new IOException(
"Unable to save new object's base entity information!");
1466 $this->attributes[
'subtype'] =
$subtype;
1467 $this->attributes[
'guid'] = (int)
$guid;
1469 $this->attributes[
'time_updated'] = (int) $now;
1470 $this->attributes[
'last_action'] = (int) $now;
1479 if (
sizeof($this->temp_metadata) > 0) {
1480 foreach ($this->temp_metadata as
$name =>
$value) {
1485 $this->temp_metadata = [];
1489 if (
sizeof($this->temp_annotations) > 0) {
1490 foreach ($this->temp_annotations as
$name =>
$value) {
1494 $this->temp_annotations = [];
1498 if (
sizeof($this->temp_private_settings) > 0) {
1499 foreach ($this->temp_private_settings as
$name =>
$value) {
1503 $this->temp_private_settings = [];
1528 if (!
_elgg_services()->events->trigger(
'update', $this->type, $this)) {
1535 $guid = (int) $this->guid;
1543 throw new InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1547 throw new InvalidParameterException(
'ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1556 'time_updated' =>
$time,
1559 if ($ret ===
false) {
1563 $this->attributes[
'time_updated'] =
$time;
1565 _elgg_services()->events->triggerAfter(
'update', $this->type, $this);
1567 $this->orig_attributes = [];
1582 protected function load(stdClass $row) {
1583 $attributes = array_merge($this->attributes, (array) $row);
1585 if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys(
$attributes)) !== []) {
1591 if (!in_array(
$name, self::PRIMARY_ATTR_NAMES)) {
1597 if (in_array(
$name, static::INTEGER_ATTR_NAMES)) {
1626 public function disable($reason =
"", $recursive =
true) {
1631 if (!
_elgg_services()->events->trigger(
'disable', $this->type, $this)) {
1639 if ($this instanceof
ElggUser && !$this->isBanned()) {
1642 $unban_after =
true;
1644 $unban_after =
false;
1648 $this->disable_reason = $reason;
1651 $guid = (int) $this->guid;
1663 'batch_inc_offset' =>
false,
1666 foreach ([
'owner_guid',
'container_guid'] as $db_column) {
1672 foreach ($subentities as $subentity) {
1674 if (!$subentity->isEnabled()) {
1678 $subentity->disable($reason,
true);
1695 $this->attributes[
'enabled'] =
'no';
1696 _elgg_services()->events->triggerAfter(
'disable', $this->type, $this);
1710 if (empty($this->guid)) {
1714 if (!
_elgg_services()->events->trigger(
'enable', $this->type, $this)) {
1730 'relationship' =>
'disabled_with',
1731 'relationship_guid' => $this->guid,
1732 'inverse_relationship' =>
true,
1735 'batch_inc_offset' =>
false,
1738 foreach ($disabled_with_it as $e) {
1739 $e->enable($recursive);
1748 $this->attributes[
'enabled'] =
'yes';
1749 _elgg_services()->events->triggerAfter(
'enable', $this->type, $this);
1761 return $this->enabled ==
'yes';
1781 public function delete($recursive =
true) {
1819 $object->type = $this->
getType();
1825 $object->url = $this->
getURL();
1826 $object->read_access = (int) $this->
access_id;
1839 $this->{
"geo:lat"} = $lat;
1840 $this->{
"geo:long"} = $long;
1849 return (
float) $this->{
"geo:lat"};
1858 return (
float) $this->{
"geo:long"};
1894 if (!isset($tag_names)) {
1895 $tag_names = [
'tags'];
1898 if ($tag_names && !is_array($tag_names)) {
1899 $tag_names = [$tag_names];
1903 foreach ($tag_names as $tag_name) {
1904 $tags = $this->$tag_name;
1911 if (is_array(
$tags)) {
1912 $entity_tags = array_merge($entity_tags,
$tags);
1914 $entity_tags[] =
$tags;
1918 return $entity_tags;
1933 if ($this->type !==
'user') {
1939 $collections = $ac->getCollectionsByMember($this->guid);
1940 if (empty($collections)) {
1945 foreach ($collections as $collection) {
1946 $result &= $ac->removeUser($this->guid, $collection->id);
1965 if (empty($collections)) {
1970 foreach ($collections as $collection) {
1990 $this->attributes[
'last_action'] =
$posted;
2003 $this->_is_cacheable =
false;
2016 $this->_is_cacheable =
true;
2044 public function cache($persist =
true) {
2058 $this->
volatile = [];
2060 _elgg_services()->sessionCache->entities->save($this->guid, $this);
2062 $this->
volatile = $tmp;
2084 _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.
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.
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.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
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.
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.
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.
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.
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.
disableCaching()
Disable runtime caching for 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.
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.
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?
$id
Generic annotation delete action.
getSystemLogID()
Return an identification for the object for storage in the system log.
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.