Elgg  Version 1.9
Namespaces | Functions | Variables
entities.php File Reference

Go to the source code of this file.

Namespaces

 Elgg\Core
 Activate a plugin or plugins.
 

Functions

 _elgg_disable_caching_for_entity ($guid)
 Remove this entity from the entity cache and make sure it is not re-added. More...
 
 _elgg_enable_caching_for_entity ($guid)
 Allow this entity to be stored in the entity cache. More...
 
 _elgg_invalidate_cache_for_entity ($guid)
 Invalidate this class's entry in the cache. More...
 
 _elgg_cache_entity (ElggEntity $entity)
 Cache an entity. More...
 
 _elgg_retrieve_cached_entity ($guid)
 Retrieve a entity from the cache. More...
 
 get_subtype_id ($type, $subtype)
 Return the id for a given subtype. More...
 
 get_subtype_from_id ($subtype_id)
 Gets the denormalized string for a given subtype ID. More...
 
 _elgg_retrieve_cached_subtype ($type, $subtype)
 Retrieve subtype from the cache. More...
 
 _elgg_populate_subtype_cache ()
 Fetch all suptypes from DB to local cache. More...
 
 get_subtype_class ($type, $subtype)
 Return the class name for a registered type and subtype. More...
 
 get_subtype_class_from_id ($subtype_id)
 Returns the class name for a subtype id. More...
 
 add_subtype ($type, $subtype, $class="")
 Register ElggEntities with a certain type and subtype to be loaded as a specific class. More...
 
 remove_subtype ($type, $subtype)
 Removes a registered ElggEntity type, subtype, and classname. More...
 
 update_subtype ($type, $subtype, $class= '')
 Update a registered ElggEntity type, subtype, and class name. More...
 
 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. More...
 
 get_entity_as_row ($guid)
 Returns a database row from the entities table. More...
 
 entity_row_to_elggstar ($row)
 Create an Elgg* object from a given entity row. More...
 
 get_entity ($guid)
 Loads and returns an entity object from a guid. More...
 
 elgg_entity_exists ($guid)
 Does an entity exist? More...
 
 elgg_enable_entity ($guid, $recursive=true)
 Enable an entity. More...
 
 elgg_get_entities (array $options=array())
 Returns an array of entities with optional filtering. More...
 
 _elgg_fetch_entities_from_sql ($sql, ElggBatch $batch=null)
 Return entities from an SQL query generated by elgg_get_entities. More...
 
 _elgg_get_entity_type_subtype_where_sql ($table, $types, $subtypes, $pairs)
 Returns SQL where clause for type and subtype on main entity table. More...
 
 _elgg_get_guid_based_where_sql ($column, $guids)
 Returns SQL where clause for owner and containers. More...
 
 _elgg_get_entity_time_where_sql ($table, $time_created_upper=null, $time_created_lower=null, $time_updated_upper=null, $time_updated_lower=null)
 Returns SQL where clause for entity time limits. More...
 
 elgg_list_entities (array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
 Returns a string of rendered entities. More...
 
 elgg_get_entities_from_attributes (array $options=array())
 Gets entities based upon attributes in secondary tables. More...
 
 _elgg_get_entity_attribute_where_sql (array $options=array())
 Get the join and where clauses for working with entity attributes. More...
 
 get_entity_dates ($type= '', $subtype= '', $container_guid=0, $site_guid=0, $order_by= 'time_created')
 Returns a list of months in which entities were updated or created. More...
 
 elgg_register_entity_type ($type, $subtype=null)
 Registers an entity type and subtype as a public-facing entity that should be shown in search and by elgg_list_registered_entities(). More...
 
 elgg_unregister_entity_type ($type, $subtype=null)
 Unregisters an entity type and subtype as a public-facing type. More...
 
 get_registered_entity_types ($type=null)
 Returns registered entity types and subtypes. More...
 
 is_registered_entity_type ($type, $subtype=null)
 Returns if the entity type and subtype have been registered with elgg_register_entity_type(). More...
 
 elgg_list_registered_entities (array $options=array())
 Returns a viewable list of entities based on the registered types. More...
 
 elgg_instanceof ($entity, $type=null, $subtype=null, $class=null)
 Checks if $entity is an ElggEntity and optionally for type and subtype. More...
 
 update_entity_last_action ($guid, $posted=null)
 Update the last_action column in the entities table for $guid. More...
 
 _elgg_entities_gc ()
 Garbage collect stub and fragments from any broken delete/create calls. More...
 
 _elgg_entities_test ($hook, $type, $value)
 Runs unit tests for the entity objects. More...
 
 _elgg_entities_init ()
 Entities init function; establishes the default entity page handler. More...
 

Variables

global $ENTITY_CACHE = array()
 Cache entities in memory once loaded. More...
 
global $ENTITY_CACHE_DISABLED_GUIDS = array()
 GUIDs of entities banned from the entity cache (during this request) More...
 
global $SUBTYPE_CACHE = null
 Cache subtypes and related class names. More...
 

Function Documentation

_elgg_cache_entity ( ElggEntity  $entity)

Cache an entity.

Stores an entity in $ENTITY_CACHE;

Parameters
ElggEntity$entityEntity to cache
Returns
void
See also
_elgg_retrieve_cached_entity()
_elgg_invalidate_cache_for_entity() private

Definition at line 101 of file entities.php.

_elgg_disable_caching_for_entity (   $guid)

Remove this entity from the entity cache and make sure it is not re-added.

Parameters
int$guidThe entity guid

private

Definition at line 44 of file entities.php.

_elgg_enable_caching_for_entity (   $guid)

Allow this entity to be stored in the entity cache.

Parameters
int$guidThe entity guid

private

Definition at line 58 of file entities.php.

_elgg_entities_gc ( )

Garbage collect stub and fragments from any broken delete/create calls.

Returns
void gc system private

Definition at line 1947 of file entities.php.

_elgg_entities_init ( )

Entities init function; establishes the default entity page handler.

Returns
void init system private

Definition at line 1995 of file entities.php.

_elgg_entities_test (   $hook,
  $type,
  $value 
)

Runs unit tests for the entity objects.

Parameters
string$hookunit_test
string$typesystem
array$valueArray of tests
Returns
array private

Definition at line 1975 of file entities.php.

_elgg_fetch_entities_from_sql (   $sql,
ElggBatch  $batch = null 
)

Return entities from an SQL query generated by elgg_get_entities.

Parameters
string$sql
ElggBatch$batch
Returns
ElggEntity[]

private

Exceptions
LogicException

Definition at line 967 of file entities.php.

_elgg_get_entity_attribute_where_sql ( array  $options = array())

Get the join and where clauses for working with entity attributes.

Returns
false|array False on fail, array('joins', 'wheres')
Since
1.9.0 private
Exceptions
InvalidArgumentException

Definition at line 1459 of file entities.php.

_elgg_get_entity_time_where_sql (   $table,
  $time_created_upper = null,
  $time_created_lower = null,
  $time_updated_upper = null,
  $time_updated_lower = null 
)

Returns SQL where clause for entity time limits.

Parameters
string$tableEntity table prefix as defined in SELECT...FROM entities $table
null | int$time_created_upperTime created upper limit
null | int$time_created_lowerTime created lower limit
null | int$time_updated_upperTime updated upper limit
null | int$time_updated_lowerTime updated lower limit
Returns
false|string false on fail, string on success.
Since
1.7.0 private

Definition at line 1287 of file entities.php.

_elgg_get_entity_type_subtype_where_sql (   $table,
  $types,
  $subtypes,
  $pairs 
)

Returns SQL where clause for type and subtype on main entity table.

Parameters
string$tableEntity table prefix as defined in SELECT...FROM entities $table
null | array$typesArray of types or null if none.
null | array$subtypesArray of subtypes or null if none
null | array$pairsArray of pairs of types and subtypes
Returns
false|string
Since
1.7.0 private

Definition at line 1069 of file entities.php.

_elgg_get_guid_based_where_sql (   $column,
  $guids 
)

Returns SQL where clause for owner and containers.

Parameters
string$columnColumn name the guids should be checked against. Usually best to provide in table.column format.
null | array$guidsArray of GUIDs.
Returns
false|string
Since
1.8.0 private

Definition at line 1238 of file entities.php.

_elgg_invalidate_cache_for_entity (   $guid)

Invalidate this class's entry in the cache.

Parameters
int$guidThe entity guid
Returns
void private

Definition at line 72 of file entities.php.

_elgg_populate_subtype_cache ( )

Fetch all suptypes from DB to local cache.

private

Definition at line 241 of file entities.php.

_elgg_retrieve_cached_entity (   $guid)

Retrieve a entity from the cache.

Parameters
int$guidThe guid
Returns
ElggEntity|bool false if entity not cached, or not fully loaded
See also
_elgg_cache_entity()
_elgg_invalidate_cache_for_entity() private

Definition at line 134 of file entities.php.

_elgg_retrieve_cached_subtype (   $type,
  $subtype 
)

Retrieve subtype from the cache.

Parameters
string$type
string$subtype
Returns
stdClass|null

private

Definition at line 221 of file entities.php.

add_subtype (   $type,
  $subtype,
  $class = "" 
)

Register ElggEntities with a certain type and subtype to be loaded as a specific class.

By default entities are loaded as one of the 4 parent objects: site, user, object, or group. If you subclass any of these you can register the classname with add_subtype() so it will be loaded as that class automatically when retrieved from the database with get_entity().

Warning
This function cannot be used to change the class for a type-subtype pair. Use update_subtype() for that.
Parameters
string$typeThe type you're subtyping (site, user, object, or group)
string$subtypeThe subtype
string$classOptional class name for the object
Returns
int
See also
update_subtype()
remove_subtype()
get_entity()

Definition at line 331 of file entities.php.

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.

An entity can be a container for any other entity by setting the container_guid. container_guid can differ from owner_guid.

A plugin hook container_permissions_check:$entity_type is emitted to allow granular access controls in plugins.

Parameters
int$user_guidThe user guid, or 0 for logged in user.
int$container_guidThe container, or 0 for the current page owner.
string$typeThe type of entity we want to create (default: 'all')
string$subtypeThe subtype of the entity we want to create (default: 'all')
Returns
bool

Definition at line 449 of file entities.php.

elgg_enable_entity (   $guid,
  $recursive = true 
)

Enable an entity.

Parameters
int$guidGUID of entity to enable
bool$recursiveRecursively enable all entities disabled with the entity?
Returns
bool
Since
1.9.0

Definition at line 696 of file entities.php.

elgg_entity_exists (   $guid)

Does an entity exist?

This function checks for the existence of an entity independent of access permissions. It is useful for situations when a user cannot access an entity and it must be determined whether entity has been deleted or the access level has changed.

Parameters
int$guidThe GUID of the entity
Returns
bool
Since
1.8.0

Definition at line 673 of file entities.php.

elgg_get_entities ( array  $options = array())

Returns an array of entities with optional filtering.

Entities are the basic unit of storage in Elgg. This function provides the simplest way to get an array of entities. There are many options available that can be passed to filter what sorts of entities are returned.

To output formatted strings of entities, use elgg_list_entities() and its cousins.

Plural arguments can be written as singular if only specifying a single element. ('type' => 'object' vs 'types' => array('object')).

Parameters
array$optionsArray in format:
types => null|STR entity type (type IN ('type1', 'type2')
      Joined with subtypes by AND. See below)

subtypes => null|STR entity subtype (SQL: subtype IN ('subtype1', 'subtype2))
         Use ELGG_ENTITIES_NO_VALUE for no subtype.

type_subtype_pairs => null|ARR (array('type' => 'subtype'))
                   (type = '$type' AND subtype = '$subtype') pairs

guids => null|ARR Array of entity guids

owner_guids => null|ARR Array of owner guids

container_guids => null|ARR Array of container_guids

site_guids => null (current_site)|ARR Array of site_guid

order_by => null (time_created desc)|STR SQL order by clause

reverse_order_by => BOOL Reverse the default order by clause

limit => null (10)|INT SQL limit clause (0 means no limit)

offset => null (0)|INT SQL offset clause

created_time_lower => null|INT Created time lower boundary in epoch time

created_time_upper => null|INT Created time upper boundary in epoch time

modified_time_lower => null|INT Modified time lower boundary in epoch time

modified_time_upper => null|INT Modified time upper boundary in epoch time

count => true|false return a count instead of entities

wheres => array() Additional where clauses to AND together

joins => array() Additional joins

callback => string A callback function to pass each row through

Returns
mixed If count, int. If not count, array. false on errors.
Since
1.7.0
See also
elgg_get_entities_from_metadata()
elgg_get_entities_from_relationship()
elgg_get_entities_from_access_id()
elgg_get_entities_from_annotations()
elgg_list_entities()

Definition at line 777 of file entities.php.

elgg_get_entities_from_attributes ( array  $options = array())

Gets entities based upon attributes in secondary tables.

Also accepts all options available to elgg_get_entities(), elgg_get_entities_from_metadata(), and elgg_get_entities_from_relationship().

Warning
requires that the entity type be specified and there can only be one type.
See also
elgg_get_entities
elgg_get_entities_from_metadata
elgg_get_entities_from_relationship
Parameters
array$optionsArray in format:
attribute_name_value_pairs => ARR (
                              'name' => 'name',
                              'value' => 'value',
                              'operand' => '=', (optional)
                              'case_sensitive' => false (optional)
                             )
                             If multiple values are sent via
                          an array ('value' => array('value1', 'value2')
                          the pair's operand will be forced to "IN".

attribute_name_value_pairs_operator => null|STR The operator to use for combining
                                   (name = value) OPERATOR (name = value); default is AND
Returns
ElggEntity[]|mixed If count, int. If not count, array. false on errors.
Since
1.9.0
Exceptions
InvalidArgumentException

Definition at line 1415 of file entities.php.

elgg_instanceof (   $entity,
  $type = null,
  $subtype = null,
  $class = null 
)

Checks if $entity is an ElggEntity and optionally for type and subtype.

Use this function in actions and views to check that you are dealing with the correct type of entity.

Parameters
mixed$entityEntity
string$typeEntity type
string$subtypeEntity subtype
string$classClass name
Returns
bool
Since
1.8.0

Definition at line 1886 of file entities.php.

elgg_list_entities ( array  $options = array(),
  $getter = 'elgg_get_entities',
  $viewer = 'elgg_view_entity_list' 
)

Returns a string of rendered entities.

Displays list of entities with formatting specified by the entity view.

Pagination is handled automatically.

Definition at line 1343 of file entities.php.

elgg_list_registered_entities ( array  $options = array())

Returns a viewable list of entities based on the registered types.

See also
elgg_view_entity_list
Parameters
array$optionsAny elgg_get_entity() options plus:
full_view => BOOL Display full view entities

list_type_toggle => BOOL Display gallery / list switch

allowed_types => true|ARRAY True to show all types or an array of valid types.

pagination => BOOL Display pagination links
Returns
string A viewable list of entities
Since
1.7.0

Definition at line 1815 of file entities.php.

elgg_register_entity_type (   $type,
  $subtype = null 
)

Registers an entity type and subtype as a public-facing entity that should be shown in search and by elgg_list_registered_entities().

Warning
Entities that aren't registered here will not show up in search.

Add a language string item:type:subtype to make sure the items are display properly.

Parameters
string$typeThe type of entity (object, site, user, group)
string$subtypeThe subtype to register (may be blank)
Returns
bool Depending on success
See also
get_registered_entity_types()

Definition at line 1675 of file entities.php.

elgg_unregister_entity_type (   $type,
  $subtype = null 
)

Unregisters an entity type and subtype as a public-facing type.

Warning
With a blank subtype, it unregisters that entity type including all subtypes. This must be called after all subtypes have been registered.
Parameters
string$typeThe type of entity (object, site, user, group)
string$subtypeThe subtype to register (may be blank)
Returns
bool Depending on success
See also
elgg_register_entity_type()

Definition at line 1710 of file entities.php.

entity_row_to_elggstar (   $row)

Create an Elgg* object from a given entity row.

Handles loading all tables into the correct class.

Parameters
stdClass$rowThe row of the entry in the entities table.
Returns
ElggEntity|false
See also
get_entity_as_row()
add_subtype()
get_entity() private
Exceptions
ClassException|InstallationException

Definition at line 530 of file entities.php.

get_entity (   $guid)

Loads and returns an entity object from a guid.

Parameters
int$guidThe GUID of the entity
Returns
ElggEntity The correct Elgg or custom object based upon entity type and subtype

Definition at line 604 of file entities.php.

get_entity_as_row (   $guid)

Returns a database row from the entities table.

Use get_entity() to return the fully loaded entity.

Warning
This will only return results if a) it exists, b) you have access to it. see _elgg_get_access_where_sql().
Parameters
int$guidThe GUID of the object to extract
Returns
stdClass|false
See also
entity_row_to_elggstar() private

Definition at line 502 of file entities.php.

get_entity_dates (   $type = '',
  $subtype = '',
  $container_guid = 0,
  $site_guid = 0,
  $order_by = 'time_created' 
)

Returns a list of months in which entities were updated or created.

Use this to generate a list of archives by month for when entities were added or updated.

Warning
Months are returned in the form YYYYMM.
Parameters
string$typeThe type of entity
string$subtypeThe subtype of entity
int$container_guidThe container GUID that the entities belong to
int$site_guidThe site GUID
string$order_byOrder_by SQL order by clause
Returns
array|false Either an array months as YYYYMM, or false on failure

Definition at line 1576 of file entities.php.

get_registered_entity_types (   $type = null)

Returns registered entity types and subtypes.

Parameters
string$typeThe type of entity (object, site, user, group) or blank for all
Returns
array|false Depending on whether entities have been registered
See also
elgg_register_entity_type()

Definition at line 1748 of file entities.php.

get_subtype_class (   $type,
  $subtype 
)

Return the class name for a registered type and subtype.

Entities can be registered to always be loaded as a certain class with add_subtype() or update_subtype(). This function returns the class name if found and null if not.

Parameters
string$typeThe type
string$subtypeThe subtype
Returns
string|null a class name or null
See also
get_subtype_from_id()
get_subtype_class_from_id() private

Definition at line 267 of file entities.php.

get_subtype_class_from_id (   $subtype_id)

Returns the class name for a subtype id.

Parameters
int$subtype_idThe subtype id
Returns
string|null
See also
get_subtype_class()
get_subtype_from_id() private

Definition at line 293 of file entities.php.

get_subtype_from_id (   $subtype_id)

Gets the denormalized string for a given subtype ID.

Parameters
int$subtype_idSubtype ID from database
Returns
string|false Subtype name, false if subtype not found
See also
get_subtype_id() private

Definition at line 194 of file entities.php.

get_subtype_id (   $type,
  $subtype 
)

Return the id for a given subtype.

ElggEntity objects have a type and a subtype. Subtypes are defined upon creation and cannot be changed.

Plugin authors generally don't need to use this function unless writing their own SQL queries. Use ElggEntity::getSubtype() to return the string subtype.

Definition at line 166 of file entities.php.

is_registered_entity_type (   $type,
  $subtype = null 
)

Returns if the entity type and subtype have been registered with elgg_register_entity_type().

Parameters
string$typeThe type of entity (object, site, user, group)
string$subtypeThe subtype (may be blank)
Returns
bool Depending on whether or not the type has been registered

Definition at line 1776 of file entities.php.

remove_subtype (   $type,
  $subtype 
)

Removes a registered ElggEntity type, subtype, and classname.

Warning
You do not want to use this function. If you want to unregister a class for a subtype, use update_subtype(). Using this function will permanently orphan all the objects created with the specified subtype.
Parameters
string$typeType
string$subtypeSubtype
Returns
bool
See also
add_subtype()
update_subtype()

Definition at line 377 of file entities.php.

update_entity_last_action (   $guid,
  $posted = null 
)

Update the last_action column in the entities table for $guid.

Warning
This is different to time_updated. Time_updated is automatically set, while last_action is only set when explicitly called.
Parameters
int$guidEntity annotation|relationship action carried out on
int$postedTimestamp of last action
Returns
bool private

Definition at line 1917 of file entities.php.

update_subtype (   $type,
  $subtype,
  $class = '' 
)

Update a registered ElggEntity type, subtype, and class name.

Parameters
string$typeType
string$subtypeSubtype
string$classClass name to use when loading this entity
Returns
bool

Definition at line 403 of file entities.php.

Variable Documentation

$ENTITY_CACHE = array()

Cache entities in memory once loaded.

ElggEntity[] $ENTITY_CACHE private

Definition at line 15 of file entities.php.

$ENTITY_CACHE_DISABLED_GUIDS = array()

GUIDs of entities banned from the entity cache (during this request)

array $ENTITY_CACHE_DISABLED_GUIDS private

Definition at line 24 of file entities.php.

$SUBTYPE_CACHE = null

Cache subtypes and related class names.

array|null $SUBTYPE_CACHE array once populated from DB, initially null private

Definition at line 33 of file entities.php.