aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/users.php
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-15 16:23:25 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-15 16:23:25 +0000
commit9cc5d6d7fcd4dd3a4a6bc6309e86cd83f751b355 (patch)
tree066886e94983bd677b93eb078b5cc584b2668d6f /engine/lib/users.php
parentbf88f65d3010b11d45ab991c427376e6bf10f19f (diff)
downloadelgg-9cc5d6d7fcd4dd3a4a6bc6309e86cd83f751b355.tar.gz
elgg-9cc5d6d7fcd4dd3a4a6bc6309e86cd83f751b355.tar.bz2
get_entities now allows for arrays of GUIDs to be supplied as an owner, and can be asked to count entities rather than return them; as a result, get_user_friends_objects and count_* functionality is also now available
git-svn-id: https://code.elgg.org/elgg/trunk@468 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/users.php')
-rw-r--r--engine/lib/users.php62
1 files changed, 61 insertions, 1 deletions
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 68383d8e5..166225b9e 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -251,6 +251,16 @@
public function getObjects($subtype="", $limit = 10, $offset = 0) { return get_user_objects($this->getGUID(), $subtype, $limit, $offset); }
/**
+ * Counts the number of ElggObjects owned by this user
+ *
+ * @param string $subtype The subtypes of the objects, if any
+ * @return int The number of ElggObjects
+ */
+ public function countObjects($subtype = "") {
+ return count_user_objects($this->getGUID(), $subtype);
+ }
+
+ /**
* Get the collections associated with a user.
*
* @param string $subtype Optionally, the subtype of result we want to limit to
@@ -403,7 +413,7 @@
function get_user_friends($user_guid, $subtype = "", $limit = 10, $offset = 0) {
return get_entities_from_relationship("friend",$user_guid,false,"user",$subtype,0,"time_created desc",$limit,$offset);
}
-
+
/**
* Obtains a list of objects owned by a user
*
@@ -419,6 +429,56 @@
}
/**
+ * Counts the objects (optionally of a particular subtype) owned by a user
+ *
+ * @param int $user_guid The GUID of the owning user
+ * @param string $subtype Optionally, the subtype of objects
+ * @return int The number of objects the user owns (of this subtype)
+ */
+ function count_user_objects($user_guid, $subtype = "") {
+ $total = get_entities('object', $subtype, $user_guid, "time_created desc", null, null, true);
+ return $total;
+ }
+
+/**
+ * Obtains a list of objects owned by a user's friends
+ *
+ * @param int $user_guid The GUID of the user to get the friends of
+ * @param string $subtype Optionally, the subtype of objects
+ * @param int $limit The number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ * @return false|array An array of ElggObjects or false, depending on success
+ */
+ function get_user_friends_objects($user_guid, $subtype = "", $limit = 10, $offset = 0) {
+ if ($friends = get_user_friends($user_guid, $subtype, 999999, 0)) {
+ $friendguids = array();
+ foreach($friends as $friend) {
+ $friendguids[] = $friend->getGUID();
+ }
+ return get_entities('object',$subtype,$friendguids, "time_created desc", $limit, $offset);
+ }
+ return false;
+ }
+
+ /**
+ * Counts the number of objects owned by a user's friends
+ *
+ * @param int $user_guid The GUID of the user to get the friends of
+ * @param string $subtype Optionally, the subtype of objects
+ * @return int The number of objects
+ */
+ function count_user_friends_objects($user_guid, $subtype = "") {
+ if ($friends = get_user_friends($user_guid, $subtype, 999999, 0)) {
+ $friendguids = array();
+ foreach($friends as $friend) {
+ $friendguids[] = $friend->getGUID();
+ }
+ return get_entities('object',$subtype,$friendguids, "time_created desc", $limit, $offset, true);
+ }
+ return 0;
+ }
+
+ /**
* Get a user object from a GUID.
*
* This function returns an ElggUser from a given GUID.