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);
198 if (array_key_exists(
$name, $this->attributes)) {
208 case 'container_guid':
212 $this->attributes[
$name] =
null;
253 if (array_key_exists(
$name, $this->attributes)) {
254 if (
$name ===
'subtype' && $this->attributes[
'guid']) {
258 return $this->attributes[
$name];
302 if (isset($this->temp_metadata[
$name])) {
304 if (count($this->temp_metadata[
$name]) == 1) {
305 return $this->temp_metadata[
$name][0];
307 return $this->temp_metadata[
$name];
320 $cache->populateFromEntities(array(
$guid));
329 'metadata_name' =>
$name,
336 if ($md && !is_array($md)) {
338 } elseif (count($md) == 1) {
340 }
else if ($md && is_array($md)) {
360 if (array_key_exists(
$name, $this->attributes)) {
361 $this->attributes[
$name] =
"";
403 'metadata_name' =>
$name,
419 $access_id = ($access_id ===
null) ? $this->getAccessId() : (int)$access_id;
424 foreach (
$value as $value_tmp) {
441 $msg =
"owner guid and access id cannot be used in \ElggEntity::setMetadata() until entity is saved.";
442 throw new \InvalidArgumentException($msg);
446 if (!$multiple || !isset($this->temp_metadata[
$name])) {
447 $this->temp_metadata[
$name] = array();
451 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[
$name],
$value);
473 'guid' => $this->guid,
496 'metadata_owner_guid' => $this->guid,
531 'guid' => $this->guid,
552 'guid' => $this->guid,
570 if (!is_array($this->
volatile)) {
571 $this->
volatile = array();
574 if (array_key_exists(
$name, $this->
volatile)) {
575 return $this->
volatile[
$name];
590 if (!is_array($this->
volatile)) {
591 $this->
volatile = array();
611 $relationship = (string)$relationship;
625 elgg_deprecated_notice(
'\ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8);
671 if ((
int) $this->guid > 0) {
687 if ((
int) ($this->guid) > 0) {
690 if (isset($this->temp_private_settings[
$name])) {
691 return $this->temp_private_settings[
$name];
720 'guid' => $this->guid,
743 'annotation_owner_guid' => $this->guid,
764 'guid' => $this->guid,
785 'guid' => $this->guid,
802 private function getAnnotationCalculation(
$name, $calculation) {
806 'annotation_name' =>
$name,
807 'annotation_calculation' => $calculation
830 if ((
int) $this->guid > 0) {
858 if ((
int) ($this->guid) > 0) {
861 'guid' => $this->guid,
867 if ($order !=
'asc') {
868 $options[
'reverse_order_by'] =
true;
882 if (isset($this->temp_annotations[
$name])) {
883 return array($this->temp_annotations[
$name]);
913 return $this->getAnnotationCalculation(
$name,
'count');
924 return $this->getAnnotationCalculation(
$name,
'avg');
935 return $this->getAnnotationCalculation(
$name,
'sum');
946 return $this->getAnnotationCalculation(
$name,
'min');
957 return $this->getAnnotationCalculation(
$name,
'max');
967 $params = array(
'entity' => $this);
975 'subtype' =>
'comment',
976 'container_guid' => $this->
getGUID(),
1004 'relationship_guid' => $this->
getGUID(),
1005 'inverse_relationship' => $inverse,
1022 'relationship' => $relationship,
1023 'relationship_guid' => $this->
getGUID(),
1024 'inverse_relationship' => $inverse_relationship,
1183 'annotation_name' => $annotation_name,
1194 return $this->access_id;
1222 if ($this->attributes[
'guid']) {
1225 return $this->attributes[
'subtype'];
1287 return (
int)$this->container_guid;
1317 return $this->time_updated;
1335 if (isset(
$CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1337 if (is_callable($function)) {
1338 $url = call_user_func($function, $this);
1340 } elseif (isset(
$CONFIG->entity_url_handler[$this->getType()][
'all'])) {
1341 $function =
$CONFIG->entity_url_handler[$this->
getType()][
'all'];
1342 if (is_callable($function)) {
1343 $url = call_user_func($function, $this);
1345 } elseif (isset(
$CONFIG->entity_url_handler[
'all'][
'all'])) {
1346 $function =
$CONFIG->entity_url_handler[
'all'][
'all'];
1347 if (is_callable($function)) {
1348 $url = call_user_func($function, $this);
1358 $params = array(
'entity' => $this);
1362 if (!empty($this->url_override)) {
1381 $this->url_override =
$url;
1399 if (isset($this->icon_override[
$size])) {
1401 return $this->icon_override[
$size];
1412 $url =
"_graphics/icons/default/$size.png";
1448 if (!$this->icon_override) {
1449 $this->icon_override = array();
1472 return $site->addEntity($this);
1490 return $site->removeEntity($this);
1506 $options[
'relationship'] =
'member_of_site';
1508 $options[
'inverse_relationship'] =
false;
1572 throw new \InvalidParameterException(
"Entity type must be set.");
1575 $subtype = $this->attributes[
'subtype'];
1577 $owner_guid = (int)$this->attributes[
'owner_guid'];
1578 $access_id = (int)$this->attributes[
'access_id'];
1579 $now = (string)time();
1580 $time_created = isset($this->attributes[
'time_created']) ? (int)$this->attributes[
'time_created'] : $now;
1582 $site_guid = $this->attributes[
'site_guid'];
1583 if ($site_guid == 0) {
1584 $site_guid =
$CONFIG->site_guid;
1586 $site_guid = (int)$site_guid;
1588 $container_guid = $this->attributes[
'container_guid'];
1589 if ($container_guid == 0) {
1592 $container_guid = (int)$container_guid;
1595 throw new \InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1611 (type, subtype, owner_guid, site_guid, container_guid,
1612 access_id, time_created, time_updated, last_action)
1614 ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1615 $access_id, $time_created, $now, $now)");
1618 throw new \IOException(
"Unable to save new object's base entity information!");
1622 $this->attributes[
'subtype'] = (int)$subtype_id;
1623 $this->attributes[
'guid'] = (int)
$result;
1625 $this->attributes[
'time_updated'] = (int)$now;
1626 $this->attributes[
'last_action'] = (int)$now;
1627 $this->attributes[
'site_guid'] = (int)$site_guid;
1628 $this->attributes[
'container_guid'] = (int)$container_guid;
1631 if (
sizeof($this->temp_metadata) > 0) {
1632 foreach ($this->temp_metadata as
$name =>
$value) {
1636 $this->temp_metadata = array();
1640 if (
sizeof($this->temp_annotations) > 0) {
1641 foreach ($this->temp_annotations as
$name =>
$value) {
1645 $this->temp_annotations = array();
1649 if (
sizeof($this->temp_private_settings) > 0) {
1650 foreach ($this->temp_private_settings as
$name =>
$value) {
1654 $this->temp_private_settings = array();
1676 if (!$persisted_entity) {
1682 $allow_edit = $persisted_entity->canEdit();
1683 unset($persisted_entity);
1696 $guid = (int)$this->guid;
1704 throw new \InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1707 $ret = $this->
getDatabase()->updateData(
"UPDATE {$CONFIG->dbprefix}entities
1708 set owner_guid='$owner_guid', access_id='$access_id',
1709 container_guid='$container_guid', time_created='$time_created',
1710 time_updated='$time' WHERE guid=$guid");
1718 static $newentity_cache;
1720 $newentity_cache = new \ElggMemcache(
'new_entity_cache');
1722 if ($newentity_cache) {
1723 $newentity_cache->delete(
$guid);
1726 if ($ret !==
false) {
1727 $this->attributes[
'time_updated'] = $time;
1733 return $ret !==
false;
1744 if (
$guid instanceof \stdClass) {
1752 if (!is_array($this->attributes)) {
1753 $this->attributes = array();
1757 $objarray = (array)
$row;
1764 $this->tables_loaded++;
1768 $this->attributes[
'guid'] = (int)$this->attributes[
'guid'];
1771 $this->attributes[
'subtype'] = (int)$this->attributes[
'subtype'];
1774 if ($this->attributes[
'guid']) {
1809 if (
$row instanceof \stdClass) {
1810 return $this->
load($row);
1834 public function disable($reason =
"", $recursive =
true) {
1850 $this->disable_reason = $reason;
1854 $guid = (int)$this->guid;
1861 $sub_entities = $this->
getDatabase()->getData(
"SELECT * FROM {$CONFIG->dbprefix}entities
1863 container_guid = $guid
1864 OR owner_guid = $guid
1865 OR site_guid = $guid
1866 ) AND enabled='yes'",
'entity_row_to_elggstar');
1868 if ($sub_entities) {
1869 foreach ($sub_entities as
$e) {
1871 $e->disable($reason);
1882 $res = $this->
getDatabase()->updateData(
"UPDATE {$CONFIG->dbprefix}entities
1884 WHERE guid = $guid");
1887 $this->attributes[
'enabled'] =
'no';
1905 $guid = (int)$this->guid;
1926 WHERE guid = $guid");
1934 'relationship' =>
'disabled_with',
1935 'relationship_guid' =>
$guid,
1936 'inverse_relationship' =>
true,
1940 foreach ($disabled_with_it as
$e) {
1949 $this->attributes[
'enabled'] =
'yes';
1962 return $this->enabled ==
'yes';
1982 public function delete($recursive =
true) {
2006 static $newentity_cache;
2008 $newentity_cache = new \ElggMemcache(
'new_entity_cache');
2010 if ($newentity_cache) {
2011 $newentity_cache->delete(
$guid);
2026 "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
2027 .
" AND guid != $guid)"
2032 $batch = new \ElggBatch(
'elgg_get_entities',
$options);
2033 $batch->setIncrementOffset(
false);
2035 foreach ($batch as
$e) {
2062 $res = $this->
getDatabase()->deleteData(
"DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = $guid");
2067 switch ($this->
type) {
2069 $sub_table =
$CONFIG->dbprefix .
'objects_entity';
2072 $sub_table =
$CONFIG->dbprefix .
'users_entity';
2075 $sub_table =
$CONFIG->dbprefix .
'groups_entity';
2078 $sub_table =
$CONFIG->dbprefix .
'sites_entity';
2083 $this->
getDatabase()->deleteData(
"DELETE FROM $sub_table WHERE guid = $guid");
2097 $params = array(
'entity' => $this);
2132 return $this->location;
2143 $this->location = $location;
2156 $this->{
"geo:lat"} = $lat;
2157 $this->{
"geo:long"} = $long;
2167 return (
float)$this->{
"geo:lat"};
2177 return (
float)$this->{
"geo:long"};
2199 $day =
null, $month =
null, $year =
null, $duration =
null) {
2202 $start = mktime($hour, $minute, $second, $month, $day, $year);
2203 $end = $start + abs($duration);
2208 $this->calendar_start = $start;
2209 $this->calendar_end = $end;
2222 return (
int)$this->calendar_start;
2233 return (
int)$this->calendar_end;
2278 $this->attributes[
'type'],
2287 foreach ($this->attributes as $k => $v) {
2297 case 'time_created':
2298 $odd->setAttribute(
'published', date(
"r", $v));
2304 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2307 case 'container_guid':
2308 $k =
'container_uuid';
2310 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2316 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2320 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2325 $meta->setAttribute(
'published', date(
"r", $this->time_created));
2340 $tmp[] =
new ODDMetaData($uuid .
"volatile/renderedentity/", $uuid,
2341 'renderedentity',
$view,
'volatile');
2363 throw new \InvalidParameterException(
"import() passed an unexpected ODD class");
2367 $this->attributes[
'type'] =
$data->getAttribute(
'class');
2368 $this->attributes[
'subtype'] =
$data->getAttribute(
'subclass');
2371 $this->attributes[
'owner_guid'] =
_elgg_services()->session->getLoggedInUserGuid();
2374 $this->attributes[
'time_created'] = strtotime(
$data->getAttribute(
'published'));
2375 $this->attributes[
'time_updated'] = time();
2415 if ($tag_names && !is_array($tag_names)) {
2416 $tag_names = array($tag_names);
2420 $entity_tags = array();
2422 foreach ($valid_tags as $tag_name) {
2423 if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2427 if (
$tags = $this->$tag_name) {
2430 if (is_array(
$tags)) {
2431 $entity_tags = array_merge($entity_tags,
$tags);
2433 $entity_tags[] =
$tags;
2438 return $entity_tags;
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.
if(! $autoload_available) _elgg_services()
$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.
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.
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.
getIconURL($size='medium')
Get the URL for this entity's icon.
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.
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).
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 $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends 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.