103 parent::initializeAttributes();
105 $this->attributes[
'guid'] =
null;
106 $this->attributes[
'type'] =
null;
107 $this->attributes[
'subtype'] =
null;
109 $this->attributes[
'owner_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
110 $this->attributes[
'container_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
112 $this->attributes[
'site_guid'] =
null;
114 $this->attributes[
'time_updated'] =
null;
115 $this->attributes[
'last_action'] =
null;
116 $this->attributes[
'enabled'] =
"yes";
133 $this->tables_split = 1;
134 $this->tables_loaded = 0;
153 _elgg_services()->logger->error(
"Failed to clone entity with GUID $this->guid");
158 'guid' => $this->guid,
162 $this->attributes[
'guid'] =
"";
164 $this->attributes[
'subtype'] = $orig_entity->getSubtype();
168 if (is_array($metadata_array)) {
170 $metadata_names = array();
175 $metadata_names = array_unique($metadata_names);
178 foreach ($metadata_names as
$name) {
179 $this->
__set($name, $orig_entity->$name);
202 if (array_key_exists(
$name, $this->attributes)) {
212 case 'container_guid':
216 $this->attributes[
$name] =
null;
257 if (array_key_exists(
$name, $this->attributes)) {
258 if (
$name ===
'subtype' && $this->attributes[
'guid']) {
262 return $this->attributes[
$name];
306 if (isset($this->temp_metadata[
$name])) {
308 if (count($this->temp_metadata[
$name]) == 1) {
309 return $this->temp_metadata[
$name][0];
311 return $this->temp_metadata[
$name];
321 if ($cache->isLoaded(
$guid)) {
324 $cache->populateFromEntities(array(
$guid));
326 if ($cache->isLoaded(
$guid)) {
333 'metadata_name' =>
$name,
340 if ($md && !is_array($md)) {
342 } elseif (count($md) == 1) {
344 }
else if ($md && is_array($md)) {
362 if (array_key_exists(
$name, $this->attributes)) {
363 $this->attributes[
$name] =
"";
405 'metadata_name' =>
$name,
421 $access_id = ($access_id ===
null) ? $this->getAccessId() : (int)$access_id;
426 foreach (
$value as $value_tmp) {
443 $msg =
"owner guid and access id cannot be used in \ElggEntity::setMetadata() until entity is saved.";
444 throw new \InvalidArgumentException($msg);
448 if (!$multiple || !isset($this->temp_metadata[
$name])) {
449 $this->temp_metadata[
$name] = array();
453 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[
$name],
$value);
475 'guid' => $this->guid,
498 'metadata_owner_guid' => $this->guid,
533 'guid' => $this->guid,
554 'guid' => $this->guid,
572 if (!is_array($this->
volatile)) {
573 $this->
volatile = array();
576 if (array_key_exists(
$name, $this->
volatile)) {
577 return $this->
volatile[
$name];
592 if (!is_array($this->
volatile)) {
593 $this->
volatile = array();
613 $relationship = (string)$relationship;
627 elgg_deprecated_notice(
'\ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8);
673 if ((
int) $this->guid > 0) {
689 if ((
int) ($this->guid) > 0) {
692 if (isset($this->temp_private_settings[
$name])) {
693 return $this->temp_private_settings[
$name];
722 'guid' => $this->guid,
745 'annotation_owner_guid' => $this->guid,
766 'guid' => $this->guid,
787 'guid' => $this->guid,
804 private function getAnnotationCalculation(
$name, $calculation) {
808 'annotation_name' =>
$name,
809 'annotation_calculation' => $calculation
832 if ((
int) $this->guid > 0) {
860 if ((
int) ($this->guid) > 0) {
863 'guid' => $this->guid,
869 if ($order !=
'asc') {
870 $options[
'reverse_order_by'] =
true;
884 if (isset($this->temp_annotations[
$name])) {
885 return array($this->temp_annotations[
$name]);
915 return $this->getAnnotationCalculation(
$name,
'count');
926 return $this->getAnnotationCalculation(
$name,
'avg');
937 return $this->getAnnotationCalculation(
$name,
'sum');
948 return $this->getAnnotationCalculation(
$name,
'min');
959 return $this->getAnnotationCalculation(
$name,
'max');
969 $params = array(
'entity' => $this);
977 'subtype' =>
'comment',
978 'container_guid' => $this->
getGUID(),
1006 'relationship_guid' => $this->
getGUID(),
1007 'inverse_relationship' => $inverse,
1024 'relationship' => $relationship,
1025 'relationship_guid' => $this->
getGUID(),
1026 'inverse_relationship' => $inverse_relationship,
1228 'annotation_name' => $annotation_name,
1230 if ($annotation_name !==
'') {
1244 return $this->access_id;
1272 if ($this->attributes[
'guid']) {
1275 return $this->attributes[
'subtype'];
1367 return $this->time_updated;
1385 if (isset(
$CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1387 if (is_callable($function)) {
1388 $url = call_user_func($function, $this);
1390 } elseif (isset(
$CONFIG->entity_url_handler[$this->getType()][
'all'])) {
1391 $function =
$CONFIG->entity_url_handler[$this->
getType()][
'all'];
1392 if (is_callable($function)) {
1393 $url = call_user_func($function, $this);
1395 } elseif (isset(
$CONFIG->entity_url_handler[
'all'][
'all'])) {
1396 $function =
$CONFIG->entity_url_handler[
'all'][
'all'];
1397 if (is_callable($function)) {
1398 $url = call_user_func($function, $this);
1408 $params = array(
'entity' => $this);
1412 if (!empty($this->url_override)) {
1431 $this->url_override =
$url;
1455 if (isset($this->icon_override[
$size])) {
1457 return $this->icon_override[
$size];
1467 $url =
"_graphics/icons/default/$size.png";
1503 if (!$this->icon_override) {
1504 $this->icon_override = array();
1527 return $site->addEntity($this);
1545 return $site->removeEntity($this);
1561 $options[
'relationship'] =
'member_of_site';
1563 $options[
'inverse_relationship'] =
false;
1627 throw new \InvalidParameterException(
"Entity type must be set.");
1630 $subtype = $this->attributes[
'subtype'];
1632 $owner_guid = (int)$this->attributes[
'owner_guid'];
1633 $access_id = (int)$this->attributes[
'access_id'];
1634 $now = (string)time();
1635 $time_created = isset($this->attributes[
'time_created']) ? (int)$this->attributes[
'time_created'] : $now;
1637 $site_guid = $this->attributes[
'site_guid'];
1638 if ($site_guid == 0) {
1639 $site_guid =
$CONFIG->site_guid;
1641 $site_guid = (int)$site_guid;
1651 throw new \InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1667 (type, subtype, owner_guid, site_guid, container_guid,
1668 access_id, time_created, time_updated, last_action)
1670 ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1671 $access_id, $time_created, $now, $now)");
1674 throw new \IOException(
"Unable to save new object's base entity information!");
1678 $this->attributes[
'subtype'] = (int)$subtype_id;
1679 $this->attributes[
'guid'] = (int)
$result;
1681 $this->attributes[
'time_updated'] = (int)$now;
1682 $this->attributes[
'last_action'] = (int)$now;
1683 $this->attributes[
'site_guid'] = (int)$site_guid;
1687 if (
sizeof($this->temp_metadata) > 0) {
1688 foreach ($this->temp_metadata as
$name =>
$value) {
1692 $this->temp_metadata = array();
1696 if (
sizeof($this->temp_annotations) > 0) {
1697 foreach ($this->temp_annotations as
$name =>
$value) {
1701 $this->temp_annotations = array();
1705 if (
sizeof($this->temp_private_settings) > 0) {
1706 foreach ($this->temp_private_settings as
$name =>
$value) {
1710 $this->temp_private_settings = array();
1732 if (!$persisted_entity) {
1738 $allow_edit = $persisted_entity->canEdit();
1739 unset($persisted_entity);
1753 $guid = (int)$this->guid;
1761 throw new \InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1764 $ret = $this->
getDatabase()->updateData(
"UPDATE {$CONFIG->dbprefix}entities
1765 set owner_guid='$owner_guid', access_id='$access_id',
1766 container_guid='$container_guid', time_created='$time_created',
1767 time_updated='$time' WHERE guid=$guid");
1777 static $newentity_cache;
1779 $newentity_cache = new \ElggMemcache(
'new_entity_cache');
1781 if ($newentity_cache) {
1782 $newentity_cache->delete(
$guid);
1785 if ($ret !==
false) {
1786 $this->attributes[
'time_updated'] = $time;
1792 return $ret !==
false;
1803 if (
$guid instanceof \stdClass) {
1811 if (!is_array($this->attributes)) {
1812 $this->attributes = array();
1816 $objarray = (array)
$row;
1823 $this->tables_loaded++;
1827 $this->attributes[
'guid'] = (int)$this->attributes[
'guid'];
1830 $this->attributes[
'subtype'] = (int)$this->attributes[
'subtype'];
1833 if ($this->attributes[
'guid']) {
1868 if (
$row instanceof \stdClass) {
1869 return $this->
load($row);
1893 public function disable($reason =
"", $recursive =
true) {
1906 if ($this instanceof
ElggUser && $this->banned ===
'no') {
1909 $unban_after =
true;
1911 $unban_after =
false;
1917 $this->disable_reason = $reason;
1921 $guid = (int)$this->guid;
1930 FROM {$CONFIG->dbprefix}entities
1932 container_guid = $guid
1933 OR owner_guid = $guid
1934 OR site_guid = $guid
1938 $sub_entities = $this->
getDatabase()->getData($query,
'entity_row_to_elggstar');
1940 if ($sub_entities) {
1942 foreach ($sub_entities as
$e) {
1944 $e->disable($reason);
1956 UPDATE {$CONFIG->dbprefix}entities
1966 $this->attributes[
'enabled'] =
'no';
1984 $guid = (int)$this->guid;
2005 WHERE guid = $guid");
2013 'relationship' =>
'disabled_with',
2014 'relationship_guid' =>
$guid,
2015 'inverse_relationship' =>
true,
2019 foreach ($disabled_with_it as
$e) {
2028 $this->attributes[
'enabled'] =
'yes';
2041 return $this->enabled ==
'yes';
2061 public function delete($recursive =
true) {
2090 static $newentity_cache;
2092 $newentity_cache = new \ElggMemcache(
'new_entity_cache');
2094 if ($newentity_cache) {
2095 $newentity_cache->delete(
$guid);
2110 "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
2111 .
" AND guid != $guid)"
2116 $batch = new \ElggBatch(
'elgg_get_entities',
$options);
2117 $batch->setIncrementOffset(
false);
2119 foreach ($batch as
$e) {
2149 DELETE FROM {$CONFIG->dbprefix}entities
2153 if ($res && in_array($this->
type, [
'object',
'user',
'group',
'site'])) {
2155 $sub_table =
"{$CONFIG->dbprefix}{$this->type}s_entity";
2158 DELETE FROM $sub_table
2173 $params = array(
'entity' => $this);
2208 return $this->location;
2219 $this->location = $location;
2232 $this->{
"geo:lat"} = $lat;
2233 $this->{
"geo:long"} = $long;
2243 return (
float)$this->{
"geo:lat"};
2253 return (
float)$this->{
"geo:long"};
2275 $day =
null, $month =
null, $year =
null, $duration =
null) {
2278 $start = mktime($hour, $minute, $second, $month, $day, $year);
2279 $end = $start + abs($duration);
2284 $this->calendar_start = $start;
2285 $this->calendar_end = $end;
2298 return (
int)$this->calendar_start;
2309 return (
int)$this->calendar_end;
2354 $this->attributes[
'type'],
2363 foreach ($this->attributes as $k => $v) {
2373 case 'time_created':
2374 $odd->setAttribute(
'published', date(
"r", $v));
2380 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2383 case 'container_guid':
2384 $k =
'container_uuid';
2386 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2392 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2396 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2401 $meta->setAttribute(
'published', date(
"r", $this->time_created));
2416 $tmp[] =
new ODDMetaData($uuid .
"volatile/renderedentity/", $uuid,
2417 'renderedentity',
$view,
'volatile');
2439 throw new \InvalidParameterException(
"import() passed an unexpected ODD class");
2443 $this->attributes[
'type'] =
$data->getAttribute(
'class');
2444 $this->attributes[
'subtype'] =
$data->getAttribute(
'subclass');
2447 $this->attributes[
'owner_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
2450 $this->attributes[
'time_created'] = strtotime(
$data->getAttribute(
'published'));
2451 $this->attributes[
'time_updated'] = time();
2491 if ($tag_names && !is_array($tag_names)) {
2492 $tag_names = array($tag_names);
2496 $entity_tags = array();
2498 foreach ($valid_tags as $tag_name) {
2499 if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2503 if (
$tags = $this->$tag_name) {
2506 if (is_array(
$tags)) {
2507 $entity_tags = array_merge($entity_tags,
$tags);
2509 $entity_tags[] =
$tags;
2514 return $entity_tags;
2529 if ($this->
type !==
'user') {
2535 $collections = $ac->getCollectionsByMember($this->guid);
2536 if (empty($collections)) {
2562 $collections = $ac->getEntityCollections($this->guid);
2563 if (empty($collections)) {
if(! $collection_name) $id
if($guid==elgg_get_logged_in_user_guid()) $name
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
elgg_disable_annotations(array $options)
Disables annotations based on $options.
create_annotation($entity_guid, $name, $value, $value_type='', $owner_guid=0, $access_id=ACCESS_PRIVATE)
Create a new annotation.
elgg_get_annotations(array $options=array())
Returns annotations.
$user_guid
Avatar remove action.
getDatabase()
Provides a pointer to the database object.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
initializeAttributes()
Initialize the attributes array.
setLocation($location)
Sets the 'location' metadata for the entity.
getSites($options=array())
Gets the sites this entity is a member of.
$url_override
If set, overrides the value of getURL()
getType()
Returns the entity type.
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
__set($name, $value)
Set an attribute or metadata value for this entity.
toObject()
{Get a plain old object copy for public consumption.\stdClass}
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
$volatile
Volatile data structure for this object, allows for storage of data in-memory that isn't sync'd back ...
getSystemLogID()
Return an identification for the object for storage in the system log.
clearAnnotations($name="")
Remove an annotation or all annotations for this entity.
refresh(\stdClass $row)
Load new data from database into existing entity.
getCalendarStartTime()
Returns the start timestamp.
$temp_private_settings
Holds private settings until entity is saved.
$temp_annotations
Holds annotations until entity is saved.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $vartype="")
Adds an annotation to an entity.
setPrivateSetting($name, $value)
Adds a private setting to this entity.
removePrivateSetting($name)
Removes private setting.
getSubtype()
Get the entity subtype.
getIcon($size='medium')
Returns a URL for the entity's icon.
$icon_override
Icon override, overrides the value of getIcon().
getTags($tag_names=null)
Returns tags for this entity.
canEditMetadata($metadata=null, $user_guid=0)
Can a user edit metadata on this entity?
getExportableValues()
Returns an array of fields which can be exported.
enableAnnotations($name='')
Enables annotations for this entity, optionally based on name.
getContainerGUID()
Gets the container GUID for this entity.
__get($name)
Get an attribute or metadata value.
canAnnotate($user_guid=0, $annotation_name='')
Can a user annotate an entity?
$temp_metadata
Holds metadata until entity is saved.
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
countAnnotations($name="")
Count annotations.
enable($recursive=true)
Enable the entity.
prepareObject($object)
Prepare an object copy for toObject()
setDisplayName($displayName)
Sets the title or name of this entity.
load($guid)
Loads attributes from the entities table into the object.
export()
Export this class into an array of ODD Elements containing all necessary fields.
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
update()
Update the entity in the database.
getDisplayName()
Get the entity's display name.
getOwnerEntity()
Gets the \ElggEntity that owns this entity.
create()
Create a new entry in the entities table.
addToSite($site)
Add this entity to a site.
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
getContainerEntity()
Get the container entity for this object.
getURL()
Gets the URL for this entity.
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user)
disable($reason="", $recursive=true)
Disable this entity.
__unset($name)
Unset a property from metadata or attribute.
getLongitude()
Return the entity's longitude.
canEdit($user_guid=0)
Can a user edit this entity?
loadAdditionalSelectValues(array $data)
Stores non-attributes from the loading of the entity as volatile data.
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
removeRelationship($guid_two, $relationship)
Remove a relationship.
isEnabled()
Is this entity enabled?
getPrivateSetting($name)
Returns a private setting value.
getLocation()
Gets the 'location' metadata for the entity.
setCalendarTimeAndDuration($hour=null, $minute=null, $second=null, $day=null, $month=null, $year=null, $duration=null)
Set the time and duration of an object.
canWriteToContainer($user_guid=0, $type='all', $subtype='all')
Can a user add an entity to this container.
clearRelationships()
Remove all relationships to and from this entity.
disableMetadata($name='')
Disables metadata for this entity, optionally based on name.
getAnnotations($options=array(), $limit=50, $offset=0, $order="asc")
Gets an array of annotations.
setIcon($url, $size='medium')
Set an icon override for an icon and size.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
getGUID()
Returns the guid.
setURL($url)
Overrides the URL returned by getURL()
getContainer()
Gets the container GUID for this entity.
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
getObjectFromID($id)
For a given ID, return the object associated with it.
isFullyLoaded()
Tests to see whether the object has been fully loaded.
disableAnnotations($name='')
Disables annotations for this entity, optionally based on name.
getCalendarEndTime()
Returns the end timestamp.
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
setContainerGUID($container_guid)
Set the container for this object.
removeFromSite($site)
Remove this entity from a site.
getAnnotationsAvg($name)
Get the average of an integer type annotation.
enableMetadata($name='')
Enables metadata for this entity, optionally based on name.
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
__clone()
Clone an entity.
setContainer($container_guid)
Set the container for this object.
getOwner()
Return the guid of the entity's owner.
getOwnerGUID()
Get the guid of the entity's owner.
canDelete($user_guid=0)
Can a user delete this entity?
setMetadata($name, $value, $value_type='', $multiple=false, $owner_guid=0, $access_id=null)
Set metadata on this entity.
getLatitude()
Return the entity's latitude.
countComments()
Count the number of comments attached to this entity.
clearMetadata($name='')
Remove metadata.
getAccessID()
Returns the access_id.
getEntitiesFromRelationship($options=array(), $inverse=false, $limit=50, $offset=0)
Gets an array of entities with a relationship to this entity.
getMetadata($name)
Return the value of a piece of metadata.
deleteOwnedMetadata($name=null)
Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
getIconURL($params=array())
Get the URL for this entity's icon.
setLatLong($lat, $long)
Set latitude and longitude metadata tags for a given entity.
canComment($user_guid=0)
Can a user comment on an entity?
$CONFIG site_guid
The guid of the current site object.
$guid
Removes an admin notice.
events($event="", $object_type="", $function="", $priority=500, $call=false, $object=null)
Deprecated events core function.
get_day_end($day=null, $month=null, $year=null)
Return a timestamp for the end of a given day (defaults today).
guid_to_uuid($guid)
Generate a UUID from a given GUID.
const ELGG_ENTITIES_ANY_VALUE
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
access_get_show_hidden_status()
Return current status of showing disabled entities.
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
sanitise_string($string)
Wrapper function for alternate English spelling (.
update_river_access_by_object($object_guid, $access_id)
Sets the access ID on river items for a particular object.
elgg_delete_river(array $options=array())
Delete river items.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an \ElggEntity and optionally for type and subtype.
_elgg_cache_entity(\ElggEntity $entity)
Cache an entity.
_elgg_disable_caching_for_entity($guid)
Remove this entity from the entity cache and make sure it is not re-added.
get_entity($guid)
Loads and returns an entity object from a guid.
_elgg_invalidate_cache_for_entity($guid)
Invalidate this class's entry in the cache.
_elgg_enable_caching_for_entity($guid)
Allow this entity to be stored in the entity cache.
get_subtype_from_id($subtype_id)
Gets the denormalized string for a given subtype ID.
get_entity_as_row($guid)
Returns a database row from the entities table.
can_write_to_container($user_guid=0, $container_guid=0, $type='all', $subtype='all')
Determine if a given user can write to an entity container.
add_subtype($type, $subtype, $class="")
Register \ElggEntities with a certain type and subtype to be loaded as a specific class.
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
_elgg_clear_entity_files($entity)
Removes all entity files.
elgg_strtolower()
Wrapper function for mb_strtolower().
is_memcache_available()
Return true if memcache is available and configured.
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
remove_all_private_settings($entity_guid)
Deletes all private settings for an entity.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
set_private_setting($entity_guid, $name, $value)
Sets a private setting for an entity.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type='')
Removes all relationships originating from a particular entity.
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
get_user($guid)
Get a user object from a GUID.
elgg_view_entity(\ElggEntity $entity, $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
elgg_set_viewtype($viewtype="")
Manually set the viewtype.