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

Relationships table database service. More...

Public Member Functions

 __construct (Database $db, EntityTable $entities, MetadataTable $metadata, EventsService $events)
 Constructor. More...
 
 get (int $id)
 Get a relationship by its ID. More...
 
 delete (int $id, bool $call_event=true)
 Delete a relationship by its ID. More...
 
 add (int $guid_one, string $relationship, int $guid_two, bool $return_id=false)
 Create a relationship between two entities. More...
 
 check (int $guid_one, string $relationship, int $guid_two)
 Check if a relationship exists between two entities. More...
 
 remove (int $guid_one, string $relationship, int $guid_two)
 Delete a relationship between two entities. More...
 
 removeAll (int $guid, string $relationship= '', bool $inverse_relationship=false, string $type= '', bool $trigger_events=true)
 Removes all relationships originating from a particular entity. More...
 
 getEntitiesFromCount (array $options=[])
 Gets the number of entities by a the number of entities related to them in a particular way. More...
 
 rowToElggRelationship (\stdClass $row)
 Convert a database row to a new . More...
 

Public Attributes

const RELATIONSHIP_COLUMN_LENGTH = 255
 

Protected Member Functions

 removeAllWithoutEvents (int $guid, string $relationship= '', bool $inverse_relationship=false, string $type= '')
 Removes all relationships originating from a particular entity. More...
 
 removeAllWithEvents (int $guid, string $relationship= '', bool $inverse_relationship=false, string $type= '')
 Removes all relationships originating from a particular entity. More...
 

Protected Attributes

Database $db
 
EntityTable $entities
 
MetadataTable $metadata
 
EventsService $events
 

Detailed Description

Relationships table database service.

Definition at line 21 of file RelationshipsTable.php.

Constructor & Destructor Documentation

Elgg\Database\RelationshipsTable::__construct ( Database  $db,
EntityTable  $entities,
MetadataTable  $metadata,
EventsService  $events 
)

Constructor.

Parameters
Database$dbElgg Database
EntityTable$entitiesEntity table
MetadataTable$metadataMetadata table
EventsService$eventsEvents service

Definition at line 46 of file RelationshipsTable.php.

Member Function Documentation

Elgg\Database\RelationshipsTable::add ( int  $guid_one,
string  $relationship,
int  $guid_two,
bool  $return_id = false 
)

Create a relationship between two entities.

E.g. friendship, group membership, site membership.

This function lets you make the statement "$guid_one is a $relationship of $guid_two". In the statement, $guid_one is the subject of the relationship, $guid_two is the target, and $relationship is the type.

Parameters
int$guid_oneGUID of the subject entity of the relationship
string$relationshipType of the relationship
int$guid_twoGUID of the target entity of the relationship
bool$return_idReturn the ID instead of bool?
Returns
bool|int
Exceptions
LengthException

Definition at line 106 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::check ( int  $guid_one,
string  $relationship,
int  $guid_two 
)

Check if a relationship exists between two entities.

If so, the relationship object is returned.

This function lets you ask "Is $guid_one a $relationship of $guid_two?"

Parameters
int$guid_oneGUID of the subject entity of the relationship
string$relationshipType of the relationship
int$guid_twoGUID of the target entity of the relationship
Returns
|false Depending on success

Definition at line 168 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::delete ( int  $id,
bool  $call_event = true 
)

Delete a relationship by its ID.

Parameters
int$idRelationship ID
bool$call_eventCall the delete event before deleting
Returns
bool

Definition at line 76 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::get ( int  $id)

Get a relationship by its ID.

Parameters
int$idThe relationship ID
Returns
|null

Definition at line 60 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::getEntitiesFromCount ( array  $options = [])

Gets the number of entities by a the number of entities related to them in a particular way.

This is a good way to get out the users with the most friends, or the groups with the most members.

Parameters
array$optionsAn options array compatible with elgg_get_entities()
Returns
[]|int|boolean If count, int. If not count, array. false on errors.

Definition at line 340 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::remove ( int  $guid_one,
string  $relationship,
int  $guid_two 
)

Delete a relationship between two entities.

This function lets you say "$guid_one is no longer a $relationship of $guid_two."

Parameters
int$guid_oneGUID of the subject entity of the relationship
string$relationshipType of the relationship
int$guid_twoGUID of the target entity of the relationship
Returns
bool

Definition at line 191 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::removeAll ( int  $guid,
string  $relationship = '',
bool  $inverse_relationship = false,
string  $type = '',
bool  $trigger_events = true 
)

Removes all relationships originating from a particular entity.

Parameters
int$guidGUID of the subject or target entity (see $inverse)
string$relationshipType of the relationship (optional, default is all relationships)
bool$inverse_relationshipIs $guid the target of the deleted relationships? By default, $guid is the subject of the relationships.
string$typeThe type of entity related to $guid (defaults to all)
bool$trigger_eventsTrigger the delete event for each relationship (default: true)
Returns
true

Definition at line 212 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::removeAllWithEvents ( int  $guid,
string  $relationship = '',
bool  $inverse_relationship = false,
string  $type = '' 
)
protected

Removes all relationships originating from a particular entity.

The does trigger the delete event for each relationship

Parameters
int$guidGUID of the subject or target entity (see $inverse)
string$relationshipType of the relationship (optional, default is all relationships)
bool$inverse_relationshipIs $guid the target of the deleted relationships? By default, $guid is the subject of the relationships.
string$typeThe type of entity related to $guid (defaults to all)
Returns
true

Definition at line 276 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::removeAllWithoutEvents ( int  $guid,
string  $relationship = '',
bool  $inverse_relationship = false,
string  $type = '' 
)
protected

Removes all relationships originating from a particular entity.

This doesn't trigger the delete event for each relationship

Parameters
int$guidGUID of the subject or target entity (see $inverse)
string$relationshipType of the relationship (optional, default is all relationships)
bool$inverse_relationshipIs $guid the target of the deleted relationships? By default, $guid is the subject of the relationships.
string$typeThe type of entity related to $guid (defaults to all)
Returns
true

Definition at line 233 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::rowToElggRelationship ( \stdClass  $row)

Convert a database row to a new .

Parameters
\stdClass$rowDatabase row from the relationship table
Returns

Definition at line 355 of file RelationshipsTable.php.

Member Data Documentation

Database Elgg\Database\RelationshipsTable::$db
protected

Definition at line 30 of file RelationshipsTable.php.

EntityTable Elgg\Database\RelationshipsTable::$entities
protected

Definition at line 32 of file RelationshipsTable.php.

EventsService Elgg\Database\RelationshipsTable::$events
protected

Definition at line 36 of file RelationshipsTable.php.

MetadataTable Elgg\Database\RelationshipsTable::$metadata
protected

Definition at line 34 of file RelationshipsTable.php.

const Elgg\Database\RelationshipsTable::RELATIONSHIP_COLUMN_LENGTH = 255

Definition at line 28 of file RelationshipsTable.php.


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