PHP Class Elgg\Database\EntityTable

Since: 1.10.0
ファイルを表示 Open project: elgg/elgg Class Usage Examples

Protected Properties

Property Type Description
$config Elgg\Config
$db Elgg\Database
$entity_cache Elgg\Cache\EntityCache
$entity_preloader Elgg\EntityPreloader
$events Elgg\EventsService
$logger Elgg\Logger
$metadata_cache Elgg\Cache\MetadataCache
$session ElggSessio\ElggSession
$subtype_table SubtypeTable
$table string
$translator Elgg\I18n\Translator

Public Methods

Method Description
__construct ( Config $config, Database $db, EntityCache $entity_cache, MetadataCache $metadata_cache, SubtypeTable $subtype_table, EventsService $events, ElggSessio\ElggSession $session, Translator $translator, Logger $logger ) Constructor
disableEntities ( integer $owner_guid ) : boolean Disables all entities owned and contained by a user (or another entity)
enable ( integer $guid, boolean $recursive = true ) : boolean Enable an entity.
exists ( integer $guid ) : boolean Does an entity exist?
fetchFromSql ( string $sql, ElggBatch $batch = null ) : ElggEntit\ElggEntity[] Return entities from an SQL query generated by elgg_get_entities.
get ( integer $guid, string $type = '' ) : ElggEntit\ElggEntity | stdClas\stdClass | false Loads and returns an entity object from a guid.
getDates ( string $type = '', string $subtype = '', integer $container_guid, string $order_by = 'time_created' ) : array | false Returns a list of months in which entities were updated or created.
getEntities ( array $options = [] ) : ElggEntity[] | integer | mixed Returns an array of entities with optional filtering.
getEntitiesFromAttributes ( array $options = [] ) : ElggEntit\ElggEntity[] | mixed Gets entities based upon attributes in secondary tables.
getEntityAttributeWhereSql ( array $options = [] ) : false | array Get the join and where clauses for working with entity attributes
getEntityTimeWhereSql ( string $table, null | integer $time_created_upper = null, null | integer $time_created_lower = null, null | integer $time_updated_upper = null, null | integer $time_updated_lower = null ) : false | string Returns SQL where clause for entity time limits.
getEntityTypeSubtypeWhereSql ( string $table, null | array $types, null | array $subtypes, null | array $pairs ) : false | string Returns SQL where clause for type and subtype on main entity table
getGuidBasedWhereSql ( string $column, null | array $guids ) : false | string Returns SQL where clause for owner and containers.
getRow ( integer $guid, integer $user_guid = null ) : stdClas\stdClass | false Returns a database row from the entities table.
getUserForPermissionsCheck ( integer $guid ) : ElggUse\ElggUser | false Get a user by GUID even if the entity is hidden or disabled
insertRow ( stdClas\stdClass $row, array $attributes = [] ) : integer | false Adds a new row to the entity table
rowToElggStar ( stdClas\stdClass $row ) : ElggEntit\ElggEntity | false Create an Elgg* object from a given entity row.
updateLastAction ( ElggEntit\ElggEntity $entity, integer $posted = null ) : integer | false Update the last_action column in the entities table for $guid.
updateRow ( integer $guid, stdClas\stdClass $row ) : integer | false Update entity table row

Protected Methods

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

Method Details

__construct() public method

Constructor
public __construct ( Config $config, Database $db, EntityCache $entity_cache, MetadataCache $metadata_cache, SubtypeTable $subtype_table, EventsService $events, ElggSessio\ElggSession $session, Translator $translator, Logger $logger )
$config Elgg\Config Config
$db Elgg\Database Database
$entity_cache Elgg\Cache\EntityCache Entity cache
$metadata_cache Elgg\Cache\MetadataCache Metadata cache
$subtype_table SubtypeTable Subtype table
$events Elgg\EventsService Events service
$session ElggSessio\ElggSession Session
$translator Elgg\I18n\Translator Translator
$logger Elgg\Logger Logger

autoJoinTables() protected method

Decorate getEntities() options in order to auto-join secondary tables where it's safe to do so.
protected autoJoinTables ( array $options ) : array
$options array Options array in getEntities() after normalization
return array

disableEntities() public method

Disables all entities owned and contained by a user (or another entity)
public disableEntities ( integer $owner_guid ) : boolean
$owner_guid integer The owner GUID
return boolean

enable() public method

Enable an entity.
public enable ( integer $guid, boolean $recursive = true ) : boolean
$guid integer GUID of entity to enable
$recursive boolean Recursively enable all entities disabled with the entity?
return boolean

exists() public method

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.
public exists ( integer $guid ) : boolean
$guid integer The GUID of the entity
return boolean

fetchFromSql() public method

Return entities from an SQL query generated by elgg_get_entities.
public fetchFromSql ( string $sql, ElggBatch $batch = null ) : ElggEntit\ElggEntity[]
$sql string
$batch ElggBatch
return ElggEntit\ElggEntity[]

get() public method

Loads and returns an entity object from a guid.
public get ( integer $guid, string $type = '' ) : ElggEntit\ElggEntity | stdClas\stdClass | false
$guid integer The GUID of the entity
$type string The type of the entity. If given, even an existing entity with the given GUID will not be returned unless its type matches.
return ElggEntit\ElggEntity | stdClas\stdClass | false The correct Elgg or custom object based upon entity type and subtype

getDates() public method

Returns a list of months in which entities were updated or created.
public getDates ( string $type = '', string $subtype = '', integer $container_guid, string $order_by = 'time_created' ) : array | false
$type string The type of entity
$subtype string The subtype of entity
$container_guid integer The container GUID that the entities belong to
$order_by string Order_by SQL order by clause
return array | false Either an array months as YYYYMM, or false on failure

getEntities() public method

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.
See also: elgg_get_entities_from_metadata()
See also: elgg_get_entities_from_relationship()
See also: elgg_get_entities_from_access_id()
See also: elgg_get_entities_from_annotations()
See also: elgg_list_entities()
See also: elgg_get_entities_from_metadata()
See also: elgg_get_entities_from_relationship()
See also: elgg_get_entities_from_access_id()
See also: elgg_get_entities_from_annotations()
See also: elgg_list_entities()
public getEntities ( array $options = [] ) : ElggEntity[] | integer | mixed
$options array Array 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 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\BatchResult 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.
return ElggEntity[] | integer | mixed If count, int. Otherwise an array or an Elgg\BatchResult. false on errors.

getEntitiesFromAttributes() public method

Also accepts all options available to elgg_get_entities(), elgg_get_entities_from_metadata(), and elgg_get_entities_from_relationship().
See also: elgg_get_entities
See also: elgg_get_entities_from_metadata
See also: elgg_get_entities_from_relationship
public getEntitiesFromAttributes ( array $options = [] ) : ElggEntit\ElggEntity[] | mixed
$options array Array 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
return ElggEntit\ElggEntity[] | mixed If count, int. If not count, array. false on errors.

getEntityAttributeWhereSql() public method

Get the join and where clauses for working with entity attributes
public getEntityAttributeWhereSql ( array $options = [] ) : false | array
$options array
return false | array False on fail, array('joins', 'wheres')

getEntityTimeWhereSql() public method

Returns SQL where clause for entity time limits.
public getEntityTimeWhereSql ( string $table, null | integer $time_created_upper = null, null | integer $time_created_lower = null, null | integer $time_updated_upper = null, null | integer $time_updated_lower = null ) : false | string
$table string Entity table prefix as defined in SELECT...FROM entities $table
$time_created_upper null | integer Time created upper limit
$time_created_lower null | integer Time created lower limit
$time_updated_upper null | integer Time updated upper limit
$time_updated_lower null | integer Time updated lower limit
return false | string false on fail, string on success.

getEntityTypeSubtypeWhereSql() public method

Returns SQL where clause for type and subtype on main entity table
public getEntityTypeSubtypeWhereSql ( string $table, null | array $types, null | array $subtypes, null | array $pairs ) : false | string
$table string Entity table prefix as defined in SELECT...FROM entities $table
$types null | array Array of types or null if none.
$subtypes null | array Array of subtypes or null if none
$pairs null | array Array of pairs of types and subtypes
return false | string

getFromCache() protected method

Get an entity from the in-memory or memcache caches
protected getFromCache ( integer $guid ) : ElggEntity
$guid integer GUID
return ElggEntity

getGuidBasedWhereSql() public method

Returns SQL where clause for owner and containers.
public getGuidBasedWhereSql ( string $column, null | array $guids ) : false | string
$column string Column name the guids should be checked against. Usually best to provide in table.column format.
$guids null | array Array of GUIDs.
return false | string

getRow() public method

Returns a database row from the entities table.
See also: entity_row_to_elggstar()
public getRow ( integer $guid, integer $user_guid = null ) : stdClas\stdClass | false
$guid integer The GUID of the object to extract
$user_guid integer GUID of the user accessing the row Defaults to logged in user if null Builds an access query for a logged out user if 0
return stdClas\stdClass | false

getUserForPermissionsCheck() public method

Get a user by GUID even if the entity is hidden or disabled
public getUserForPermissionsCheck ( integer $guid ) : ElggUse\ElggUser | false
$guid integer User GUID. Default is logged in user
return ElggUse\ElggUser | false

insertRow() public method

Adds a new row to the entity table
public insertRow ( stdClas\stdClass $row, array $attributes = [] ) : integer | false
$row stdClas\stdClass Entity base information
$attributes array All primary and secondary table attributes Used by database mock services to allow mocking entities that were instantiated using new keyword and calling ElggEntity::save()
return integer | false

rowToElggStar() public method

Handles loading all tables into the correct class.
See also: get_entity_as_row()
See also: add_subtype()
See also: get_entity()
public rowToElggStar ( stdClas\stdClass $row ) : ElggEntit\ElggEntity | false
$row stdClas\stdClass The row of the entry in the entities table.
return ElggEntit\ElggEntity | false

updateLastAction() public method

Update the last_action column in the entities table for $guid.
public updateLastAction ( ElggEntit\ElggEntity $entity, integer $posted = null ) : integer | false
$entity ElggEntit\ElggEntity Entity annotation|relationship action carried out on
$posted integer Timestamp of last action
return integer | false

updateRow() public method

Update entity table row
public updateRow ( integer $guid, stdClas\stdClass $row ) : integer | false
$guid integer Entity guid
$row stdClas\stdClass Updated data
return integer | false

Property Details

$config protected_oe property

protected Config,Elgg $config
return Elgg\Config

$db protected_oe property

protected Database,Elgg $db
return Elgg\Database

$entity_cache protected_oe property

protected EntityCache,Elgg\Cache $entity_cache
return Elgg\Cache\EntityCache

$entity_preloader protected_oe property

protected EntityPreloader,Elgg $entity_preloader
return Elgg\EntityPreloader

$events protected_oe property

protected EventsService,Elgg $events
return Elgg\EventsService

$logger protected_oe property

protected Logger,Elgg $logger
return Elgg\Logger

$metadata_cache protected_oe property

protected MetadataCache,Elgg\Cache $metadata_cache
return Elgg\Cache\MetadataCache

$session protected_oe property

protected ElggSession,ElggSessio $session
return ElggSessio\ElggSession

$subtype_table protected_oe property

protected SubtypeTable,Elgg\Database $subtype_table
return SubtypeTable

$table protected_oe property

protected string $table
return string

$translator protected_oe property

protected Translator,Elgg\I18n $translator
return Elgg\I18n\Translator