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

Public Member Functions

 __construct (Conf $config, Database $db, EntityCache $entity_cache, MetadataCache $metadata_cache, SubtypeTable $subtype_table, EventsService $events, ElggSession $session, Translator $translator, Logger $logger)
 Constructor. More...
 
 getRow ($guid, $user_guid=null)
 Returns a database row from the entities table. More...
 
 insertRow (stdClass $row)
 Adds a new row to the entity table. More...
 
 updateRow ($guid, stdClass $row)
 Update entity table row. 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 (ElggEntity $entity, $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...
 
 disableEntities ($owner_guid)
 Disables all entities owned and contained by a user (or another entity) More...
 

Protected Member Functions

 getFromCache ($guid)
 Get an entity from the in-memory or memcache caches. More...
 
 autoJoinTables (array $options)
 Decorate getEntities() options in order to auto-join secondary tables where it's safe to do so. More...
 

Protected Attributes

 $config
 
 $db
 
 $table
 
 $subtype_table
 
 $entity_cache
 
 $entity_preloader
 
 $metadata_cache
 
 $events
 
 $session
 
 $translator
 
 $logger
 

Detailed Description

Definition at line 39 of file EntityTable.php.

Constructor & Destructor Documentation

Elgg\Database\EntityTable::__construct ( Conf  $config,
Database  $db,
EntityCache  $entity_cache,
MetadataCache  $metadata_cache,
SubtypeTable  $subtype_table,
EventsService  $events,
ElggSession  $session,
Translator  $translator,
Logger  $logger 
)

Constructor.

Parameters
Conf$configConfig
Database$dbDatabase
EntityCache$entity_cacheEntity cache
MetadataCache$metadata_cacheMetadata cache
SubtypeTable$subtype_tableSubtype table
EventsService$eventsEvents service
ElggSession$sessionSession
Translator$translatorTranslator
Logger$loggerLogger

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

Elgg\Database\EntityTable::disableEntities (   $owner_guid)

Disables all entities owned and contained by a user (or another entity)

Parameters
int$owner_guidThe owner GUID
Returns
bool

Definition at line 1489 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 388 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 367 of file EntityTable.php.

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

Return entities from an SQL query generated by elgg_get_entities.

private

Parameters
string$sql
ElggBatch$batch
Returns
ElggEntity[]
Exceptions
LogicException

Definition at line 789 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
ElggEntity|stdClass|false The correct Elgg or custom object based upon entity type and subtype
Exceptions
ClassException
InstallationException

Definition at line 323 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 1327 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')).

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()
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.

batch => bool (false) If set to true, an Elgg object will be returned instead of an array. Since 2.3

batch_inc_offset => bool (true) If "batch" is used, this tells the batch to increment the offset on each fetch. This must be set to false if you delete the batched results.

batch_size => int (25) If "batch" is used, this is the number of entities/rows to pull in before requesting more.

Returns
[]|int|mixed If count, int. Otherwise an array or an Elgg. 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 502 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
ElggEntity[]|mixed If count, int. If not count, array. false on errors.
Exceptions
InvalidArgumentException

Definition at line 1168 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 1211 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 1107 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
array$typesArray of types
array$subtypesArray of subtypes
array$pairsArray of pairs of types and subtypes
Returns
false|string private

Definition at line 892 of file EntityTable.php.

Elgg\Database\EntityTable::getFromCache (   $guid)
protected

Get an entity from the in-memory or memcache caches.

Parameters
int$guidGUID
Returns

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

Elgg\Database\EntityTable::getRow (   $guid,
  $user_guid = null 
)

Returns a database row from the entities table.

See also
entity_row_to_elggstar()

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
int$user_guidGUID of the user accessing the row Defaults to logged in user if null Builds an access query for a logged out user if 0
Returns
stdClass|false private

Definition at line 151 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
ElggUser|false
Exceptions
UserFetchFailureExceptionprivate

Definition at line 1457 of file EntityTable.php.

Elgg\Database\EntityTable::insertRow ( stdClass  $row)

Adds a new row to the entity table.

Parameters
stdClass$rowEntity base information
Returns
int|false

Definition at line 178 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.

See also
get_entity_as_row()
add_subtype()
get_entity()

private

Parameters
stdClass$rowThe row of the entry in the entities table.
Returns
ElggEntity|false
Exceptions
ClassException
InstallationException

Definition at line 246 of file EntityTable.php.

Elgg\Database\EntityTable::updateLastAction ( ElggEntity  $entity,
  $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
ElggEntity$entityEntity annotation|relationship action carried out on
int$postedTimestamp of last action
Returns
int|false private

Definition at line 1420 of file EntityTable.php.

Elgg\Database\EntityTable::updateRow (   $guid,
stdClass  $row 
)

Update entity table row.

Parameters
int$guidEntity guid
stdClass$rowUpdated data
Returns
int|false

Definition at line 207 of file EntityTable.php.

Member Data Documentation

Elgg\Database\EntityTable::$config
protected

Definition at line 46 of file EntityTable.php.

Elgg\Database\EntityTable::$db
protected

Definition at line 51 of file EntityTable.php.

Elgg\Database\EntityTable::$entity_cache
protected

Definition at line 66 of file EntityTable.php.

Elgg\Database\EntityTable::$entity_preloader
protected

Definition at line 71 of file EntityTable.php.

Elgg\Database\EntityTable::$events
protected

Definition at line 81 of file EntityTable.php.

Elgg\Database\EntityTable::$logger
protected

Definition at line 96 of file EntityTable.php.

Elgg\Database\EntityTable::$metadata_cache
protected

Definition at line 76 of file EntityTable.php.

Elgg\Database\EntityTable::$session
protected

Definition at line 86 of file EntityTable.php.

Elgg\Database\EntityTable::$subtype_table
protected

Definition at line 61 of file EntityTable.php.

Elgg\Database\EntityTable::$table
protected

Definition at line 56 of file EntityTable.php.

Elgg\Database\EntityTable::$translator
protected

Definition at line 91 of file EntityTable.php.


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