aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/relationships.php
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-30 11:20:10 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-30 11:20:10 +0000
commitc0412aa41a1efe0be21bdd6807280b6a55005053 (patch)
tree44804a801abed2909b6e35e7a1296d525e2a43ba /engine/lib/relationships.php
parentf1ab5b38c75ad4cad18cf6f53f5e22b70441b4b5 (diff)
downloadelgg-c0412aa41a1efe0be21bdd6807280b6a55005053.tar.gz
elgg-c0412aa41a1efe0be21bdd6807280b6a55005053.tar.bz2
Introducing getEntitiesFromRelationship and countEntitiesFromRelationship methods on ElggEntity
git-svn-id: https://code.elgg.org/elgg/trunk@577 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/relationships.php')
-rw-r--r--engine/lib/relationships.php28
1 files changed, 21 insertions, 7 deletions
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index c1d2af71f..a3bb10ca1 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -372,9 +372,11 @@
* @param int $owner_guid
* @param string $order_by
* @param int $limit
- * @param int $offset
+ * @param int $offset
+ * @param boolean $count Set to true if you want to count the number of entities instead (default false)
+ * @return array|int|false An array of entities, or the number of entities, or false on failure
*/
- function get_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0)
+ function get_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0, $count = false)
{
global $CONFIG;
@@ -407,14 +409,26 @@
$joinon = "r.guid_two=e.guid";
if (!$inverse_relationship)
$joinon = "r.guid_one=e.guid";
-
- $query = "SELECT * from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}entity_relationships r on $joinon where ";
+
+ if ($count) {
+ $query = "select count(distinct e.id) as total ";
+ } else {
+ $query = "select distinct e.* ";
+ }
+ $query .= " from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}entity_relationships r on $joinon where ";
foreach ($where as $w)
$query .= " $w and ";
- $query .= " (e.access_id in {$access} or (e.access_id = 0 and e.owner_guid = {$_SESSION['id']}))"; // Add access controls
- $query .= " order by $order_by limit $limit, $offset"; // Add order and limit
+ $query .= " (e.access_id in {$access} or (e.access_id = 0 and e.owner_guid = {$_SESSION['id']}))"; // Add access controls
+ if (!$count) {
+ $query .= " order by $order_by limit $limit, $offset"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($count = get_data_row($query)) {
+ return $count->total;
+ }
+ }
+ return false;
- return get_data($query, "entity_row_to_elggstar");
}
/**