Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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...
 
 getUserForPermissionsCheck ($guid=0)
 Get a user by GUID even if the entity is hidden or disabled. 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 16 of file EntityTable.php.

Constructor & Destructor Documentation

Elgg\Database\EntityTable::__construct ( )

Constructor.

Definition at line 27 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 528 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 213 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 191 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
\LogicException

Definition at line 584 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 150 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 1124 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 to match the default subtype.
         Use ELGG_ENTITIES_ANY_VALUE to match any subtype.

type_subtype_pairs => null|ARR (array('type' => 'subtype'))
                   array(
                       'object' => array('blog', 'file'), // All objects with subtype of 'blog' or 'file'
                       'user' => ELGG_ENTITY_ANY_VALUE, // All users irrespective of subtype
                   );

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 311 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 964 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 1007 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 903 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 687 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 855 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 46 of file EntityTable.php.

Elgg\Database\EntityTable::getUserForPermissionsCheck (   $guid = 0)

Get a user by GUID even if the entity is hidden or disabled.

Parameters
int$guidUser GUID. Default is logged in user
Returns
|false
Exceptions
UserFetchFailureExceptionprivate

Definition at line 1253 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
\ClassException|\InstallationException

Definition at line 74 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 1221 of file EntityTable.php.


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