PHP Класс Elgg\Database\RelationshipsTable

С версии: 1.10.0
Наследование: use trait Elgg\TimeUsing
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$db Elgg\Database
$entities EntityTable
$events Elgg\EventsService
$metadata MetadataTable

Открытые методы

Метод Описание
__construct ( Database $db, EntityTable $entities, MetadataTable $metadata, EventsService $events ) Constructor
add ( integer $guid_one, string $relationship, integer $guid_two, boolean $return_id = false ) : boolean | integer Create a relationship between two entities. E.g. friendship, group membership, site membership.
check ( integer $guid_one, string $relationship, integer $guid_two ) : ElggRelationship | false Check if a relationship exists between two entities. If so, the relationship object is returned.
delete ( integer $id, boolean $call_event = true ) : boolean Delete a relationship by its ID
get ( integer $id ) : ElggRelationship | false Get a relationship by its ID
getAll ( integer $guid, boolean $inverse_relationship = false ) : ElggRelationship[] Get all the relationships for a given GUID.
getEntities ( array $options ) : ElggEntity[] | mixed Return entities matching a given query joining against a relationship.
getEntitiesFromCount ( array $options = [] ) : ElggEntity[] | integer | boolean Gets the number of entities by a the number of entities related to them in a particular way.
getEntityRelationshipWhereSql ( string $column, string $relationship = null, integer $relationship_guid = null, boolean $inverse_relationship = false ) : mixed Returns SQL appropriate for relationship joins and wheres
getRow ( integer $id ) : stdClass | false Get a database row from the relationship table
remove ( integer $guid_one, string $relationship, integer $guid_two ) : boolean Delete a relationship between two entities.
removeAll ( integer $guid, string $relationship = "", boolean $inverse_relationship = false, string $type = '' ) : true Removes all relationships originating from a particular entity
rowToElggRelationship ( stdClass $row ) : ElggRelationship | false Convert a database row to a new \ElggRelationship

Описание методов

__construct() публичный Метод

Constructor
public __construct ( Database $db, EntityTable $entities, MetadataTable $metadata, EventsService $events )
$db Elgg\Database Elgg Database
$entities EntityTable Entity table
$metadata MetadataTable Metadata table
$events Elgg\EventsService Events service

add() публичный Метод

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.
public add ( integer $guid_one, string $relationship, integer $guid_two, boolean $return_id = false ) : boolean | integer
$guid_one integer GUID of the subject entity of the relationship
$relationship string Type of the relationship
$guid_two integer GUID of the target entity of the relationship
$return_id boolean Return the ID instead of bool?
Результат boolean | integer

check() публичный Метод

This function lets you ask "Is $guid_one a $relationship of $guid_two?"
public check ( integer $guid_one, string $relationship, integer $guid_two ) : ElggRelationship | false
$guid_one integer GUID of the subject entity of the relationship
$relationship string Type of the relationship
$guid_two integer GUID of the target entity of the relationship
Результат ElggRelationship | false Depending on success

delete() публичный Метод

Delete a relationship by its ID
public delete ( integer $id, boolean $call_event = true ) : boolean
$id integer Relationship ID
$call_event boolean Call the delete event before deleting
Результат boolean

get() публичный Метод

Get a relationship by its ID
public get ( integer $id ) : ElggRelationship | false
$id integer The relationship ID
Результат ElggRelationship | false False if not found

getAll() публичный Метод

Get all the relationships for a given GUID.
public getAll ( integer $guid, boolean $inverse_relationship = false ) : ElggRelationship[]
$guid integer GUID of the subject or target entity (see $inverse)
$inverse_relationship boolean Is $guid the target of the deleted relationships? By default $guid is the subject of the relationships.
Результат ElggRelationship[]

getEntities() публичный Метод

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' )";
См. также: elgg_get_entities
См. также: elgg_get_entities_from_metadata
public getEntities ( array $options ) : ElggEntity[] | mixed
$options array Array 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
Результат ElggEntity[] | mixed If count, int. If not count, array. false on errors.

getEntitiesFromCount() публичный Метод

This is a good way to get out the users with the most friends, or the groups with the most members.
public getEntitiesFromCount ( array $options = [] ) : ElggEntity[] | integer | boolean
$options array An options array compatible with elgg_get_entities_from_relationship()
Результат ElggEntity[] | integer | boolean If count, int. If not count, array. false on errors.

getEntityRelationshipWhereSql() публичный Метод

Returns SQL appropriate for relationship joins and wheres
public getEntityRelationshipWhereSql ( string $column, string $relationship = null, integer $relationship_guid = null, boolean $inverse_relationship = false ) : mixed
$column string Column name the GUID should be checked against. Provide in table.column format.
$relationship string Type of the relationship
$relationship_guid integer Entity GUID to check
$inverse_relationship boolean Is $relationship_guid the target of the relationship?
Результат mixed

getRow() публичный Метод

Get a database row from the relationship table
public getRow ( integer $id ) : stdClass | false
$id integer The relationship ID
Результат stdClass | false False if no row found

remove() публичный Метод

This function lets you say "$guid_one is no longer a $relationship of $guid_two."
public remove ( integer $guid_one, string $relationship, integer $guid_two ) : boolean
$guid_one integer GUID of the subject entity of the relationship
$relationship string Type of the relationship
$guid_two integer GUID of the target entity of the relationship
Результат boolean

removeAll() публичный Метод

Removes all relationships originating from a particular entity
public removeAll ( integer $guid, string $relationship = "", boolean $inverse_relationship = false, string $type = '' ) : true
$guid integer GUID of the subject or target entity (see $inverse)
$relationship string Type of the relationship (optional, default is all relationships)
$inverse_relationship boolean Is $guid the target of the deleted relationships? By default, $guid is the subject of the relationships.
$type string The type of entity related to $guid (defaults to all)
Результат true

rowToElggRelationship() публичный Метод

Convert a database row to a new \ElggRelationship
public rowToElggRelationship ( stdClass $row ) : ElggRelationship | false
$row stdClass Database row from the relationship table
Результат ElggRelationship | false

Описание свойств

$db защищенное свойство

protected Database,Elgg $db
Результат Elgg\Database

$entities защищенное свойство

protected EntityTable,Elgg\Database $entities
Результат EntityTable

$events защищенное свойство

protected EventsService,Elgg $events
Результат Elgg\EventsService

$metadata защищенное свойство

protected MetadataTable,Elgg\Database $metadata
Результат MetadataTable