18 if (
$row instanceof stdClass) {
54 return get_data_row(
"SELECT * FROM {$CONFIG->dbprefix}entity_relationships WHERE id = $id");
72 return delete_data(
"DELETE FROM {$CONFIG->dbprefix}entity_relationships WHERE id = $id");
96 throw InvalidArgumentException($msg);
99 $guid_one = (int)$guid_one;
101 $guid_two = (int)$guid_two;
109 $id =
insert_data(
"INSERT INTO {$CONFIG->dbprefix}entity_relationships 110 (guid_one, relationship, guid_two, time_created) 111 VALUES ($guid_one, '$relationship', $guid_two, $time)");
144 $guid_one = (int)$guid_one;
146 $guid_two = (int)$guid_two;
148 $query =
"SELECT * FROM {$CONFIG->dbprefix}entity_relationships 149 WHERE guid_one=$guid_one 150 AND relationship='$relationship' 151 AND guid_two=$guid_two limit 1";
175 $guid_one = (int)$guid_one;
177 $guid_two = (int)$guid_two;
189 $query =
"DELETE FROM {$CONFIG->dbprefix}entity_relationships 190 WHERE guid_one = $guid_one 191 AND relationship = '$relationship' 192 AND guid_two = $guid_two";
216 if (!empty($relationship)) {
218 $where =
"AND er.relationship = '$relationship'";
225 if (!$inverse_relationship) {
226 $join =
"JOIN {$CONFIG->dbprefix}entities e ON e.guid = er.guid_two";
228 $join =
"JOIN {$CONFIG->dbprefix}entities e ON e.guid = er.guid_one";
231 $where .=
" AND e.type = '$type'";
236 $guid_col = $inverse_relationship ?
"guid_two" :
"guid_one";
239 DELETE er FROM {$CONFIG->dbprefix}entity_relationships AS er 241 WHERE $guid_col = $guid 262 $where = ($inverse_relationship ?
"guid_two='$guid'" :
"guid_one='$guid'");
264 $query =
"SELECT * from {$CONFIG->dbprefix}entity_relationships where {$where}";
266 return get_data($query,
"row_to_elggrelationship");
306 'relationship' => null,
307 'relationship_guid' => null,
308 'inverse_relationship' =>
false,
309 'relationship_join_on' =>
'guid',
314 $join_column =
"e.{$options['relationship_join_on']}";
322 } elseif (!isset(
$options[
'wheres'])) {
331 } elseif (!isset(
$options[
'joins'])) {
339 } elseif (!isset(
$options[
'selects'])) {
343 $select = array(
'r.id');
348 $options[
'group_by'] = $clauses[
'group_by'];
371 $relationship_guid = null, $inverse_relationship =
false) {
373 if ($relationship == null && $relationship_guid == null) {
383 if ($inverse_relationship) {
384 $joins[] =
"JOIN {$CONFIG->dbprefix}entity_relationships r on r.guid_one = $column";
386 $joins[] =
"JOIN {$CONFIG->dbprefix}entity_relationships r on r.guid_two = $column";
390 $wheres[] =
"r.relationship = '" .
sanitise_string($relationship) .
"'";
393 if ($relationship_guid) {
394 if ($inverse_relationship) {
395 $wheres[] =
"r.guid_two = '$relationship_guid'";
397 $wheres[] =
"r.guid_one = '$relationship_guid'";
405 if ($where_str = implode(
' AND ', $wheres)) {
407 return array(
'wheres' => array(
"($where_str)"),
'joins' => $joins,
'group_by' => $group_by);
438 $options[
'selects'][] =
"COUNT(e.guid) as total";
439 $options[
'group_by'] =
'r.guid_two';
440 $options[
'order_by'] =
'total desc';
get_relationship($id)
Get a relationship by its ID.
get_data_row($query, $callback="")
Retrieve a single row from the database.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
elgg_list_entities_from_relationship_count($options)
Returns a list of entities by relationship count.
$guid
Removes an admin notice.
delete_data($query)
Remove a row from the database.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type= '')
Removes all relationships originating from a particular entity.
sanitize_string($string)
Sanitize a string for database use.
insert_data($query)
Insert a row into the database.
get_entity_relationships($guid, $inverse_relationship=false)
Get all the relationships for a given GUID.
sanitise_string($string)
Wrapper function for alternate English spelling (.
elgg_get_entity_relationship_where_sql($column, $relationship=null, $relationship_guid=null, $inverse_relationship=false)
Returns SQL appropriate for relationship joins and wheres.
check_entity_relationship($guid_one, $relationship, $guid_two)
Check if a relationship exists between two entities.
elgg global
Pointer to the global context.
delete_relationship($id)
Delete a relationship by its ID.
elgg_list_entities_from_relationship(array $options=array())
Returns a viewable list of entities by relationship.
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
get_data($query, $callback="")
Retrieve rows from the database.
row_to_elggrelationship($row)
Convert a database row to a new ElggRelationship.
elgg_get_entities_from_relationship_count(array $options=array())
Gets the number of entities by a the number of entities related to them in a particular way...
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
_elgg_get_relationship_row($id)
Get a database row from the relationship table.
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
if(!$collection_name) $id