103 parent::initializeAttributes();
105 $this->attributes[
'guid'] =
null;
106 $this->attributes[
'type'] =
null;
107 $this->attributes[
'subtype'] =
null;
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_log(
"Failed to clone entity with GUID $this->guid",
"ERROR");
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,
335 if ($md && !is_array($md)) {
337 } elseif (count($md) == 1) {
339 }
else if ($md && is_array($md)) {
359 if (array_key_exists(
$name, $this->attributes)) {
360 $this->attributes[
$name] =
"";
402 'metadata_name' =>
$name,
418 $access_id = ($access_id ===
null) ? $this->getAccessId() : (int)$access_id;
423 foreach (
$value as $value_tmp) {
440 $msg =
"owner guid and access id cannot be used in ElggEntity::setMetadata() until entity is saved.";
441 throw new InvalidArgumentException($msg);
445 if (!$multiple || !isset($this->temp_metadata[
$name])) {
446 $this->temp_metadata[
$name] = array();
450 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[
$name],
$value);
472 'guid' => $this->guid,
495 'metadata_owner_guid' => $this->guid,
530 'guid' => $this->guid,
551 'guid' => $this->guid,
569 if (!is_array($this->
volatile)) {
570 $this->
volatile = array();
573 if (array_key_exists(
$name, $this->
volatile)) {
574 return $this->
volatile[
$name];
589 if (!is_array($this->
volatile)) {
590 $this->
volatile = array();
610 $relationship = (string)$relationship;
670 if ((
int) $this->guid > 0) {
686 if ((
int) ($this->guid) > 0) {
689 if (isset($this->temp_private_settings[
$name])) {
690 return $this->temp_private_settings[
$name];
719 'guid' => $this->guid,
742 'annotation_owner_guid' => $this->guid,
763 'guid' => $this->guid,
784 'guid' => $this->guid,
801 private function getAnnotationCalculation(
$name, $calculation) {
804 'annotation_name' =>
$name,
805 'annotation_calculation' => $calculation
828 if ((
int) $this->guid > 0) {
856 if ((
int) ($this->guid) > 0) {
859 'guid' => $this->guid,
865 if ($order !=
'asc') {
866 $options[
'reverse_order_by'] =
true;
880 if (isset($this->temp_annotations[
$name])) {
881 return array($this->temp_annotations[
$name]);
911 return $this->getAnnotationCalculation(
$name,
'count');
922 return $this->getAnnotationCalculation(
$name,
'avg');
933 return $this->getAnnotationCalculation(
$name,
'sum');
944 return $this->getAnnotationCalculation(
$name,
'min');
955 return $this->getAnnotationCalculation(
$name,
'max');
965 $params = array(
'entity' => $this);
973 'subtype' =>
'comment',
974 'container_guid' => $this->
getGUID(),
1001 'relationship_guid' => $this->
getGUID(),
1002 'inverse_relationship' => $inverse,
1019 'relationship' => $relationship,
1020 'relationship_guid' => $this->
getGUID(),
1021 'inverse_relationship' => $inverse_relationship,
1180 'annotation_name' => $annotation_name,
1191 return $this->access_id;
1219 if ($this->attributes[
'guid']) {
1222 return $this->attributes[
'subtype'];
1284 return (
int)$this->container_guid;
1314 return $this->time_updated;
1332 if (isset(
$CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1334 if (is_callable($function)) {
1335 $url = call_user_func($function, $this);
1337 } elseif (isset(
$CONFIG->entity_url_handler[$this->getType()][
'all'])) {
1338 $function =
$CONFIG->entity_url_handler[$this->
getType()][
'all'];
1339 if (is_callable($function)) {
1340 $url = call_user_func($function, $this);
1342 } elseif (isset(
$CONFIG->entity_url_handler[
'all'][
'all'])) {
1343 $function =
$CONFIG->entity_url_handler[
'all'][
'all'];
1344 if (is_callable($function)) {
1345 $url = call_user_func($function, $this);
1355 $params = array(
'entity' => $this);
1359 if (!empty($this->url_override)) {
1378 $this->url_override =
$url;
1396 if (isset($this->icon_override[
$size])) {
1398 return $this->icon_override[
$size];
1409 $url =
"_graphics/icons/default/$size.png";
1445 if (!$this->icon_override) {
1446 $this->icon_override = array();
1469 return $site->addEntity($this);
1487 return $site->removeEntity($this);
1503 $options[
'relationship'] =
'member_of_site';
1505 $options[
'inverse_relationship'] =
false;
1572 $subtype = $this->attributes[
'subtype'];
1574 $owner_guid = (int)$this->attributes[
'owner_guid'];
1575 $access_id = (int)$this->attributes[
'access_id'];
1576 $now = (string)time();
1577 $time_created = isset($this->attributes[
'time_created']) ? (int)$this->attributes[
'time_created'] : $now;
1579 $site_guid = $this->attributes[
'site_guid'];
1580 if ($site_guid == 0) {
1581 $site_guid =
$CONFIG->site_guid;
1583 $site_guid = (int)$site_guid;
1585 $container_guid = $this->attributes[
'container_guid'];
1586 if ($container_guid == 0) {
1589 $container_guid = (int)$container_guid;
1608 (type, subtype, owner_guid, site_guid, container_guid,
1609 access_id, time_created, time_updated, last_action)
1611 ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1612 $access_id, $time_created, $now, $now)");
1615 throw new IOException(
"Unable to save new object's base entity information!");
1619 $this->attributes[
'subtype'] = (int)$subtype_id;
1620 $this->attributes[
'guid'] = (int)
$result;
1622 $this->attributes[
'time_updated'] = (int)$now;
1623 $this->attributes[
'last_action'] = (int)$now;
1624 $this->attributes[
'site_guid'] = (int)$site_guid;
1625 $this->attributes[
'container_guid'] = (int)$container_guid;
1628 if (
sizeof($this->temp_metadata) > 0) {
1629 foreach ($this->temp_metadata as
$name =>
$value) {
1633 $this->temp_metadata = array();
1637 if (
sizeof($this->temp_annotations) > 0) {
1638 foreach ($this->temp_annotations as
$name =>
$value) {
1642 $this->temp_annotations = array();
1646 if (
sizeof($this->temp_private_settings) > 0) {
1647 foreach ($this->temp_private_settings as
$name =>
$value) {
1651 $this->temp_private_settings = array();
1673 if (!$persisted_entity) {
1679 $allow_edit = $persisted_entity->canEdit();
1680 unset($persisted_entity);
1693 $guid = (int)$this->guid;
1701 throw new InvalidParameterException(
'ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1704 $ret = $this->
getDatabase()->updateData(
"UPDATE {$CONFIG->dbprefix}entities
1705 set owner_guid='$owner_guid', access_id='$access_id',
1706 container_guid='$container_guid', time_created='$time_created',
1707 time_updated='$time' WHERE guid=$guid");
1715 static $newentity_cache;
1717 $newentity_cache =
new ElggMemcache(
'new_entity_cache');
1719 if ($newentity_cache) {
1720 $newentity_cache->delete(
$guid);
1723 if ($ret !==
false) {
1724 $this->attributes[
'time_updated'] = $time;
1730 return $ret !==
false;
1741 if (
$guid instanceof stdClass) {
1749 if (!is_array($this->attributes)) {
1750 $this->attributes = array();
1754 $objarray = (array)
$row;
1761 $this->tables_loaded++;
1765 $this->attributes[
'guid'] = (int)$this->attributes[
'guid'];
1768 $this->attributes[
'subtype'] = (int)$this->attributes[
'subtype'];
1771 if ($this->attributes[
'guid']) {
1806 if (
$row instanceof stdClass) {
1807 return $this->
load($row);
1831 public function disable($reason =
"", $recursive =
true) {
1847 $this->disable_reason = $reason;
1851 $guid = (int)$this->guid;
1858 $sub_entities = $this->
getDatabase()->getData(
"SELECT * FROM {$CONFIG->dbprefix}entities
1860 container_guid = $guid
1861 OR owner_guid = $guid
1862 OR site_guid = $guid
1863 ) AND enabled='yes'",
'entity_row_to_elggstar');
1865 if ($sub_entities) {
1866 foreach ($sub_entities as
$e) {
1868 $e->disable($reason);
1879 $res = $this->
getDatabase()->updateData(
"UPDATE {$CONFIG->dbprefix}entities
1881 WHERE guid = $guid");
1884 $this->attributes[
'enabled'] =
'no';
1902 $guid = (int)$this->guid;
1923 WHERE guid = $guid");
1931 'relationship' =>
'disabled_with',
1932 'relationship_guid' =>
$guid,
1933 'inverse_relationship' =>
true,
1937 foreach ($disabled_with_it as
$e) {
1946 $this->attributes[
'enabled'] =
'yes';
1959 return $this->enabled ==
'yes';
1979 public function delete($recursive =
true) {
1998 static $newentity_cache;
2000 $newentity_cache =
new ElggMemcache(
'new_entity_cache');
2002 if ($newentity_cache) {
2003 $newentity_cache->delete(
$guid);
2010 static $__RECURSIVE_DELETE_TOKEN;
2023 "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
2024 .
" AND guid != $guid)"
2030 $batch->setIncrementOffset(
false);
2032 foreach ($batch as
$e) {
2037 $__RECURSIVE_DELETE_TOKEN =
null;
2060 $res = $this->
getDatabase()->deleteData(
"DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = $guid");
2065 switch ($this->
type) {
2067 $sub_table =
$CONFIG->dbprefix .
'objects_entity';
2070 $sub_table =
$CONFIG->dbprefix .
'users_entity';
2073 $sub_table =
$CONFIG->dbprefix .
'groups_entity';
2076 $sub_table =
$CONFIG->dbprefix .
'sites_entity';
2081 $this->
getDatabase()->deleteData(
"DELETE FROM $sub_table WHERE guid = $guid");
2093 $params = array(
'entity' => $this);
2128 return $this->location;
2139 $this->location = $location;
2152 $this->
set(
'geo:lat', $lat);
2153 $this->
set(
'geo:long', $long);
2163 return (
float)$this->
get(
'geo:lat');
2173 return (
float)$this->
get(
'geo:long');
2195 $day =
null, $month =
null, $year =
null, $duration =
null) {
2198 $start = mktime($hour, $minute, $second, $month, $day, $year);
2199 $end = $start + abs($duration);
2204 $this->calendar_start = $start;
2205 $this->calendar_end = $end;
2218 return (
int)$this->calendar_start;
2229 return (
int)$this->calendar_end;
2274 $this->attributes[
'type'],
2283 foreach ($this->attributes as $k => $v) {
2293 case 'time_created':
2294 $odd->setAttribute(
'published', date(
"r", $v));
2300 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2303 case 'container_guid':
2304 $k =
'container_uuid';
2306 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2312 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2316 $meta =
new ODDMetaData($uuid .
"attr/$k/", $uuid, $k, $v);
2321 $meta->setAttribute(
'published', date(
"r", $this->time_created));
2336 $tmp[] =
new ODDMetaData($uuid .
"volatile/renderedentity/", $uuid,
2337 'renderedentity',
$view,
'volatile');
2363 $this->attributes[
'type'] =
$data->getAttribute(
'class');
2364 $this->attributes[
'subtype'] =
$data->getAttribute(
'subclass');
2370 $this->attributes[
'time_created'] = strtotime(
$data->getAttribute(
'published'));
2371 $this->attributes[
'time_updated'] = time();
2411 if ($tag_names && !is_array($tag_names)) {
2412 $tag_names = array($tag_names);
2416 $entity_tags = array();
2418 foreach ($valid_tags as $tag_name) {
2419 if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2423 if (
$tags = $this->$tag_name) {
2426 if (is_array(
$tags)) {
2427 $entity_tags = array_merge($entity_tags,
$tags);
2429 $entity_tags[] =
$tags;
2434 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.
$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.
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?
refresh(stdClass $row)
Load new data from database into existing 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.
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_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event,...
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_log($message, $level='NOTICE')
Display or log a message.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type.
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_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_cache_entity(ElggEntity $entity)
Cache an entity.
_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_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.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
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.