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

Entity table database service. More...

Public Member Functions

 __construct (protected Config $config, protected Database $db, protected EntityCache $entity_cache, protected MetadataCache $metadata_cache, protected EventsService $events, protected SessionManagerService $session_manager, protected Translator $translator)
 Constructor. More...
 
 setEntityClass (string $type, string $subtype, string $class= '')
 Sets class constructor name for entities with given type and subtype. More...
 
 getEntityClass (string $type, string $subtype)
 Returns class name registered as a constructor for a given type and subtype The classname is also validated to exist and to be an extension of an . More...
 
 getRow (int $guid, int $user_guid=null)
 Returns a database row from the entities table. More...
 
 insertRow (\stdClass $row, array $attributes=[])
 Adds a new row to the entity table. More...
 
 updateRow (int $guid,\stdClass $row)
 Update entity table row. More...
 
 rowToElggStar (\stdClass $row)
 Create an Elgg* object from a given entity row. More...
 
 invalidateCache (int $guid)
 Invalidate cache for entity. More...
 
 get (int $guid, string $type=null, string $subtype=null)
 Loads and returns an entity object from a guid. More...
 
 exists (int $guid)
 Does an entity exist? More...
 
 fetch (QueryBuilder $query, array $options=[])
 Returns an array of entities with optional filtering. More...
 
 updateTimeDeleted (\ElggEntity $entity, int $deleted=null)
 Update the time_deleted column in the entities table for $entity. More...
 
 updateLastAction (\ElggEntity $entity, int $posted=null)
 Update the last_action column in the entities table for $entity. More...
 
 getUserForPermissionsCheck (int $guid=null)
 Get a user by GUID even if the entity is hidden or disabled. More...
 
 restore (\ElggEntity $entity)
 Restore entity. More...
 
 enable (\ElggEntity $entity)
 Enables entity. More...
 
 disable (\ElggEntity $entity)
 Disables entity. More...
 
 delete (\ElggEntity $entity, bool $recursive=true)
 Delete entity and all of its properties. More...
 
 trash (\ElggEntity $entity, bool $recursive=true)
 Trash an entity (not quite delete but close) More...
 

Public Attributes

const TABLE_NAME = 'entities'
 
const DEFAULT_JOIN_ALIAS = 'e'
 

Protected Member Functions

 deleteRelatedEntities (\ElggEntity $entity)
 Deletes entities owned or contained by the entity being deletes. More...
 
 trashRelatedEntities (\ElggEntity $entity)
 Trash entities owned or contained by the entity being trashed. More...
 
 deleteEntityProperties (\ElggEntity $entity)
 Clear data from secondary tables. More...
 

Protected Attributes

array $deleted_guids = []
 
array $trashed_guids = []
 
array $entity_classes = []
 

Detailed Description

Entity table database service.

Definition at line 24 of file EntityTable.php.

Constructor & Destructor Documentation

Elgg\Database\EntityTable::__construct ( protected Config  $config,
protected Database  $db,
protected EntityCache  $entity_cache,
protected MetadataCache  $metadata_cache,
protected EventsService  $events,
protected SessionManagerService  $session_manager,
protected Translator  $translator 
)

Constructor.

Parameters
Config$configConfig
Database$dbDatabase
EntityCache$entity_cacheEntity cache
MetadataCache$metadata_cacheMetadata cache
EventsService$eventsEvents service
SessionManagerService$session_managerSession manager
Translator$translatorTranslator

Definition at line 53 of file EntityTable.php.

Member Function Documentation

Elgg\Database\EntityTable::delete ( \ElggEntity  $entity,
bool  $recursive = true 
)

Delete entity and all of its properties.

Parameters
\ElggEntity$entityEntity
bool$recursiveDelete all owned and contained entities
Returns
bool

Definition at line 469 of file EntityTable.php.

Elgg\Database\EntityTable::deleteEntityProperties ( \ElggEntity  $entity)
protected

Clear data from secondary tables.

Parameters
\ElggEntity$entityEntity
Returns
void

Definition at line 656 of file EntityTable.php.

Elgg\Database\EntityTable::deleteRelatedEntities ( \ElggEntity  $entity)
protected

Deletes entities owned or contained by the entity being deletes.

Parameters
\ElggEntity$entityEntity
Returns
void

Definition at line 568 of file EntityTable.php.

Elgg\Database\EntityTable::disable ( \ElggEntity  $entity)

Disables entity.

Parameters
\ElggEntity$entityEntity to disable
Returns
bool

Definition at line 453 of file EntityTable.php.

Elgg\Database\EntityTable::enable ( \ElggEntity  $entity)

Enables entity.

Parameters
\ElggEntity$entityEntity to enable
Returns
bool

Definition at line 438 of file EntityTable.php.

Elgg\Database\EntityTable::exists ( int  $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 290 of file EntityTable.php.

Elgg\Database\EntityTable::fetch ( QueryBuilder  $query,
array  $options = [] 
)

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.

Parameters
QueryBuilder$queryQuery
array$optionsOptions
Returns
[]

Definition at line 310 of file EntityTable.php.

Elgg\Database\EntityTable::get ( int  $guid,
string  $type = null,
string  $subtype = null 
)

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
string$subtypeThe subtype of the entity If given, even an existing entity with the given GUID will not be returned unless its subtype matches
Returns
|null The correct Elgg or custom object based upon entity type and subtype

Definition at line 248 of file EntityTable.php.

Elgg\Database\EntityTable::getEntityClass ( string  $type,
string  $subtype 
)

Returns class name registered as a constructor for a given type and subtype The classname is also validated to exist and to be an extension of an .

Parameters
string$typeEntity type
string$subtypeEntity subtype
Returns
string

Definition at line 91 of file EntityTable.php.

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

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.
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
|null

Definition at line 134 of file EntityTable.php.

Elgg\Database\EntityTable::getUserForPermissionsCheck ( int  $guid = null)

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

Parameters
int$guidUser GUID. Default is logged in user
Returns
|null
Exceptions
UserFetchFailureException

Definition at line 394 of file EntityTable.php.

Elgg\Database\EntityTable::insertRow ( \stdClass  $row,
array  $attributes = [] 
)

Adds a new row to the entity table.

Parameters
\stdClass$rowEntity base information
array$attributesAll primary table attributes Used by database mock services to allow mocking entities that were instantiated using new keyword and calling ElggEntity::save()
Returns
int

Definition at line 161 of file EntityTable.php.

Elgg\Database\EntityTable::invalidateCache ( int  $guid)

Invalidate cache for entity.

Parameters
int$guidGUID
Returns
void

Definition at line 226 of file EntityTable.php.

Elgg\Database\EntityTable::restore ( \ElggEntity  $entity)

Restore entity.

Parameters
\ElggEntity$entityEntity to restore
Returns
bool

Definition at line 422 of file EntityTable.php.

Elgg\Database\EntityTable::rowToElggStar ( \stdClass  $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
|null

Definition at line 206 of file EntityTable.php.

Elgg\Database\EntityTable::setEntityClass ( string  $type,
string  $subtype,
string  $class = '' 
)

Sets class constructor name for entities with given type and subtype.

Parameters
string$typeEntity type
string$subtypeEntity subtype
string$classEntity class
Returns
void
Exceptions
DomainException

Definition at line 74 of file EntityTable.php.

Elgg\Database\EntityTable::trash ( \ElggEntity  $entity,
bool  $recursive = true 
)

Trash an entity (not quite delete but close)

Parameters
\ElggEntity$entityEntity
bool$recursiveTrash all owned and contained entities
Returns
bool

Definition at line 506 of file EntityTable.php.

Elgg\Database\EntityTable::trashRelatedEntities ( \ElggEntity  $entity)
protected

Trash entities owned or contained by the entity being trashed.

Parameters
\ElggEntity$entityEntity
Returns
void

Definition at line 611 of file EntityTable.php.

Elgg\Database\EntityTable::updateLastAction ( \ElggEntity  $entity,
int  $posted = null 
)

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

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

Definition at line 372 of file EntityTable.php.

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

Update entity table row.

Parameters
int$guidEntity guid
\stdClass$rowUpdated data
Returns
bool

Definition at line 185 of file EntityTable.php.

Elgg\Database\EntityTable::updateTimeDeleted ( \ElggEntity  $entity,
int  $deleted = null 
)

Update the time_deleted column in the entities table for $entity.

Parameters
\ElggEntity$entityEntity to update
int$deletedTimestamp when the entity was deleted
Returns
int

Definition at line 347 of file EntityTable.php.

Member Data Documentation

array Elgg\Database\EntityTable::$deleted_guids = []
protected

Definition at line 36 of file EntityTable.php.

array Elgg\Database\EntityTable::$entity_classes = []
protected

Definition at line 40 of file EntityTable.php.

array Elgg\Database\EntityTable::$trashed_guids = []
protected

Definition at line 38 of file EntityTable.php.

const Elgg\Database\EntityTable::DEFAULT_JOIN_ALIAS = 'e'

Definition at line 34 of file EntityTable.php.

const Elgg\Database\EntityTable::TABLE_NAME = 'entities'

Definition at line 32 of file EntityTable.php.


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