Elgg  Version 1.11
Public Member Functions | Protected Member Functions | List of all members
Elgg\Database\EntityTable Class Reference

Public Member Functions

 __construct ()
 Constructor. More...
 
 getRow ($guid)
 Returns a database row from the entities table. More...
 
 rowToElggStar ($row)
 Create an Elgg* object from a given entity row. More...
 
 get ($guid, $type= '')
 Loads and returns an entity object from a guid. More...
 
 exists ($guid)
 Does an entity exist? More...
 
 enable ($guid, $recursive=true)
 Enable an entity. More...
 
 getEntities (array $options=array())
 Returns an array of entities with optional filtering. More...
 
 fetchFromSql ($sql,\ElggBatch $batch=null)
 Return entities from an SQL query generated by elgg_get_entities. More...
 
 getEntityTypeSubtypeWhereSql ($table, $types, $subtypes, $pairs)
 Returns SQL where clause for type and subtype on main entity table. More...
 
 getGuidBasedWhereSql ($column, $guids)
 Returns SQL where clause for owner and containers. More...
 
 getEntityTimeWhereSql ($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...
 
 getEntitiesFromAttributes (array $options=array())
 Gets entities based upon attributes in secondary tables. More...
 
 getEntityAttributeWhereSql (array $options=array())
 Get the join and where clauses for working with entity attributes. More...
 
 getDates ($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...
 
 updateLastAction ($guid, $posted=null)
 Update the last_action column in the entities table for $guid. More...
 

Protected Member Functions

 autoJoinTables (array $options)
 Decorate getEntities() options in order to auto-join secondary tables where it's safe to do so. More...
 

Detailed Description

Definition at line 15 of file EntityTable.php.

Constructor & Destructor Documentation

Elgg\Database\EntityTable::__construct ( )

Constructor.

Definition at line 26 of file EntityTable.php.

Member Function Documentation

Elgg\Database\EntityTable::autoJoinTables ( array  $options)
protected

Decorate getEntities() options in order to auto-join secondary tables where it's safe to do so.

Parameters
array$optionsOptions array in getEntities() after normalization
Returns
array

Definition at line 523 of file EntityTable.php.

Elgg\Database\EntityTable::enable (   $guid,
  $recursive = true 
)

Enable an entity.

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

Definition at line 212 of file EntityTable.php.

Elgg\Database\EntityTable::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

Definition at line 190 of file EntityTable.php.

Elgg\Database\EntityTable::fetchFromSql (   $sql,
\ElggBatch  $batch = null 
)

Return entities from an SQL query generated by elgg_get_entities.

Parameters
string$sql
\ElggBatch$batch
Returns
[]

private

Exceptions

Definition at line 579 of file EntityTable.php.

Elgg\Database\EntityTable::get (   $guid,
  $type = '' 
)

Loads and returns an entity object from a guid.

Parameters
int$guidThe GUID of the entity
string$typeThe type of the entity. If given, even an existing entity with the given GUID will not be returned unless its type matches.
Returns
The correct Elgg or custom object based upon entity type and subtype

Definition at line 149 of file EntityTable.php.

Elgg\Database\EntityTable::getDates (   $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 1119 of file EntityTable.php.

Elgg\Database\EntityTable::getEntities ( 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

preload_owners => bool (false) If set to true, this function will preload all the owners of the returned entities resulting in better performance if those owners need to be displayed

preload_containers => bool (false) If set to true, this function will preload all the containers of the returned entities resulting in better performance if those containers need to be displayed

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

distinct => bool (true) If set to false, Elgg will drop the DISTINCT clause from
        the MySQL query, which will improve performance in some situations.
        Avoid setting this option without a full understanding of the underlying
        SQL query Elgg creates.
Returns
mixed If count, int. If not count, array. false on errors.
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 306 of file EntityTable.php.

Elgg\Database\EntityTable::getEntitiesFromAttributes ( 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
[]|mixed If count, int. If not count, array. false on errors.
Exceptions
InvalidArgumentException

Definition at line 959 of file EntityTable.php.

Elgg\Database\EntityTable::getEntityAttributeWhereSql ( array  $options = array())

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

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

Definition at line 1002 of file EntityTable.php.

Elgg\Database\EntityTable::getEntityTimeWhereSql (   $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. private

Definition at line 898 of file EntityTable.php.

Elgg\Database\EntityTable::getEntityTypeSubtypeWhereSql (   $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 private

Definition at line 682 of file EntityTable.php.

Elgg\Database\EntityTable::getGuidBasedWhereSql (   $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 private

Definition at line 850 of file EntityTable.php.

Elgg\Database\EntityTable::getRow (   $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
|false
See also
entity_row_to_elggstar() private

Definition at line 45 of file EntityTable.php.

Elgg\Database\EntityTable::rowToElggStar (   $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
|false
See also
get_entity_as_row()
add_subtype()
get_entity() private
Exceptions

Definition at line 73 of file EntityTable.php.

Elgg\Database\EntityTable::updateLastAction (   $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 1216 of file EntityTable.php.


The documentation for this class was generated from the following file: