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

Public Member Functions

 __construct (Database $db, EntityTable $entities, MetadataTable $metadata, EventsService $events)
 Constructor. More...
 
 get ($id)
 Get a relationship by its ID. More...
 
 getRow ($id)
 Get a database row from the relationship table. More...
 
 delete ($id, $call_event=true)
 Delete a relationship by its ID. More...
 
 add ($guid_one, $relationship, $guid_two, $return_id=false)
 Create a relationship between two entities. More...
 
 check ($guid_one, $relationship, $guid_two)
 Check if a relationship exists between two entities. More...
 
 remove ($guid_one, $relationship, $guid_two)
 Delete a relationship between two entities. More...
 
 removeAll ($guid, $relationship="", $inverse_relationship=false, $type= '')
 Removes all relationships originating from a particular entity. More...
 
 getAll ($guid, $inverse_relationship=false)
 Get all the relationships for a given GUID. More...
 
 getEntities ($options)
 Return entities matching a given query joining against a relationship. More...
 
 getEntityRelationshipWhereSql ($column, $relationship=null, $relationship_guid=null, $inverse_relationship=false)
 Returns SQL appropriate for relationship joins and wheres. More...
 
 getEntitiesFromCount (array $options=array())
 Gets the number of entities by a the number of entities related to them in a particular way. More...
 
 rowToElggRelationship ($row)
 Convert a database row to a new . More...
 

Protected Attributes

 $db
 
 $entities
 
 $metadata
 
 $events
 

Detailed Description

Definition at line 17 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 49 of file RelationshipsTable.php.

Member Function Documentation

Elgg\Database\RelationshipsTable::add (   $guid_one,
  $relationship,
  $guid_two,
  $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

Definition at line 126 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::check (   $guid_one,
  $relationship,
  $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 186 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::delete (   $id,
  $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 96 of file RelationshipsTable.php.

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

Get a relationship by its ID.

Parameters
int$idThe relationship ID
Returns
|false False if not found

Definition at line 63 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::getAll (   $guid,
  $inverse_relationship = false 
)

Get all the relationships for a given GUID.

Parameters
int$guidGUID of the subject or target entity (see $inverse)
bool$inverse_relationshipIs $guid the target of the deleted relationships? By default $guid is the subject of the relationships.
Returns
[]

Definition at line 283 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::getEntities (   $options)

Return entities matching a given query joining against a relationship.

Also accepts all options available to elgg_get_entities() and elgg_get_entities_from_metadata().

To ask for entities that do not have a particular relationship to an entity, use a custom where clause like the following:

$options['wheres'][] = "NOT EXISTS (
    SELECT 1 FROM {$db_prefix}entity_relationships
        WHERE guid_one = e.guid
        AND relationship = '$relationship'
)";
See also
elgg_get_entities
elgg_get_entities_from_metadata
Parameters
array$optionsArray in format:

relationship => null|STR Type of the relationship. E.g. "member"

relationship_guid => null|INT GUID of the subject of the relationship, unless "inverse_relationship" is set to true, in which case this will specify the target.

inverse_relationship => false|BOOL Are we searching for relationship subjects? By default, the query finds targets of relationships.

relationship_join_on => null|STR How the entities relate: guid (default), container_guid, or owner_guid Examples using the relationship 'friend':

  1. use 'guid' if you want the user's friends
  2. use 'owner_guid' if you want the entities the user's friends own (including in groups)
  3. use 'container_guid' if you want the entities in the user's personal space (non-group)

relationship_created_time_lower => null|INT Relationship created time lower boundary in epoch time

relationship_created_time_upper => null|INT Relationship created time upper boundary in epoch time

Returns
[]|mixed If count, int. If not count, array. false on errors.

Definition at line 334 of file RelationshipsTable.php.

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

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_from_relationship()
Returns
[]|int|boolean If count, int. If not count, array. false on errors.

Definition at line 460 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::getEntityRelationshipWhereSql (   $column,
  $relationship = null,
  $relationship_guid = null,
  $inverse_relationship = false 
)

Returns SQL appropriate for relationship joins and wheres.

Parameters
string$columnColumn name the GUID should be checked against. Provide in table.column format.
string$relationshipType of the relationship
int$relationship_guidEntity GUID to check
bool$inverse_relationshipIs $relationship_guid the target of the relationship?
Returns
mixed private

Definition at line 410 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::getRow (   $id)

Get a database row from the relationship table.

Parameters
int$idThe relationship ID
Returns
|false False if no row found private

Definition at line 80 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::remove (   $guid_one,
  $relationship,
  $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 218 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::removeAll (   $guid,
  $relationship = "",
  $inverse_relationship = false,
  $type = '' 
)

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)
Returns
true

Definition at line 238 of file RelationshipsTable.php.

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

Convert a database row to a new .

Parameters
\stdClass$rowDatabase row from the relationship table
Returns
|false private

Definition at line 475 of file RelationshipsTable.php.

Member Data Documentation

Elgg\Database\RelationshipsTable::$db
protected

Definition at line 24 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::$entities
protected

Definition at line 29 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::$events
protected

Definition at line 39 of file RelationshipsTable.php.

Elgg\Database\RelationshipsTable::$metadata
protected

Definition at line 34 of file RelationshipsTable.php.


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