aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-22 14:19:56 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-22 14:19:56 +0000
commita25ce4e3c73d36c2eb561c0dceb0168ffb54ec88 (patch)
treed084717267cb1ddb4386d7e721ff4ab9b83db42f /engine
parente02d46fc8d3eec695211fbd28add8c9ce89e62da (diff)
downloadelgg-a25ce4e3c73d36c2eb561c0dceb0168ffb54ec88.tar.gz
elgg-a25ce4e3c73d36c2eb561c0dceb0168ffb54ec88.tar.bz2
Introducing the Friendable interface
git-svn-id: https://code.elgg.org/elgg/trunk@1490 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/elgglib.php85
-rw-r--r--engine/lib/group.php127
-rw-r--r--engine/lib/users.php1
3 files changed, 176 insertions, 37 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 3854dd8dc..698ea339c 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -1622,6 +1622,91 @@
return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
}
+ /**
+ * An interface for objects that behave as elements within a social network that have a profile.
+ *
+ */
+ interface Friendable {
+
+ /**
+ * Adds a user as a friend
+ *
+ * @param int $friend_guid The GUID of the user to add
+ */
+ public function addFriend($friend_guid);
+
+ /**
+ * Removes a user as a friend
+ *
+ * @param int $friend_guid The GUID of the user to remove
+ */
+ public function removeFriend($friend_guid);
+
+ /**
+ * Determines whether or not the current user is a friend of this entity
+ *
+ */
+ public function isFriend();
+
+ /**
+ * Determines whether or not this entity is friends with a particular entity
+ *
+ * @param int $user_guid The GUID of the entity this entity may or may not be friends with
+ */
+ public function isFriendsWith($user_guid);
+
+ /**
+ * Determines whether or not a foreign entity has made this one a friend
+ *
+ * @param int $user_guid The GUID of the foreign entity
+ */
+ public function isFriendOf($user_guid);
+
+ /**
+ * Returns this entity's friends
+ *
+ * @param string $subtype The subtype of entity to return
+ * @param int $limit The number of entities to return
+ * @param int $offset Indexing offset
+ */
+ public function getFriends($subtype = "", $limit = 10, $offset = 0);
+
+ /**
+ * Returns entities that have made this entity a friend
+ *
+ * @param string $subtype The subtype of entity to return
+ * @param int $limit The number of entities to return
+ * @param int $offset Indexing offset
+ */
+ public function getFriendsOf($subtype = "", $limit = 10, $offset = 0);
+
+ /**
+ * Returns objects in this entity's container
+ *
+ * @param string $subtype The subtype of entity to return
+ * @param int $limit The number of entities to return
+ * @param int $offset Indexing offset
+ */
+ public function getObjects($subtype="", $limit = 10, $offset = 0);
+
+ /**
+ * Returns objects in the containers of this entity's friends
+ *
+ * @param string $subtype The subtype of entity to return
+ * @param int $limit The number of entities to return
+ * @param int $offset Indexing offset
+ */
+ public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0);
+
+ /**
+ * Returns the number of object entities in this entity's container
+ *
+ * @param string $subtype The subtype of entity to count
+ */
+ public function countObjects($subtype = "");
+
+ }
+
function elgg_init() {
// Important actions
register_action('comments/add');
diff --git a/engine/lib/group.php b/engine/lib/group.php
index f0ceb92fc..dee522099 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -16,7 +16,8 @@
* @class ElggGroup Class representing a container for other elgg entities.
* @author Marcus Povey
*/
- class ElggGroup extends ElggEntity
+ class ElggGroup extends ElggEntity
+ implements Friendable
{
protected function initialise_attributes()
{
@@ -118,62 +119,114 @@
{
return can_write_to_container($user_guid, $this->getGUID());
}
-
- /**
- * Get objects contained in this group.
- *
- * @param int $limit
- * @param int $offset
- * @param string $subtype
- * @param int $owner_guid
- * @param int $site_guid
- * @param string $order_by
- * @return mixed
- */
- public function getObjects($limit = 10, $offset = 0, $subtype = "", $owner_guid = 0, $site_guid = 0, $order_by = "")
- {
- return get_objects_in_group($this->getGUID(), $subtype, $owner_guid, $site_guid, $order_by, $limit, $offset, false);
- }
-
- /**
- * Get a list of group members.
- *
- * @param int $limit
- * @param int $offset
- * @return mixed
- */
- public function getMembers($limit = 10, $offset = 0, $count = false)
- {
- return get_group_members($this->getGUID(), $limit, $offset, 0 , $count);
- }
+
+ /**
+ * Start friendable compatibility block:
+ *
+ * public function addFriend($friend_guid);
+ public function removeFriend($friend_guid);
+ public function isFriend();
+ public function isFriendsWith($user_guid);
+ public function isFriendOf($user_guid);
+ public function getFriends($subtype = "", $limit = 10, $offset = 0);
+ public function getFriendsOf($subtype = "", $limit = 10, $offset = 0);
+ public function getObjects($subtype="", $limit = 10, $offset = 0);
+ public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0);
+ public function countObjects($subtype = "");
+ */
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function addFriend($friend_guid) {
+ return $this->join(get_entity($friend_guid));
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function removeFriend($friend_guid) {
+ return $this->leave(get_entity($friend_guid));
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function isFriend() {
+ return $this->isMember();
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function isFriendsWith($user_guid) {
+ return $this->isMember($user_guid);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function isFriendOf($user_guid) {
+ return $this->isMember($user_guid);
+ }
/**
- * For compatibility with ElggUser
+ * For compatibility with Friendable
*/
public function getFriends($subtype = "", $limit = 10, $offset = 0) {
return get_group_members($this->getGUID(), $limit, $offset);
}
/**
- * For compatibility with ElggUser
+ * For compatibility with Friendable
*/
public function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {
return get_group_members($this->getGUID(), $limit, $offset);
}
/**
- * For compatibility with ElggUser
+ * Get objects contained in this group.
+ *
+ * @param string $subtype
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
*/
- public function isFriend() {
- return $this->isMember();
+ public function getObjects($subtype="", $limit = 10, $offset = 0)
+ {
+ return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", $limit, $offset, false);
}
/**
- * For compatibility with ElggUser
+ * For compatibility with Friendable
*/
- public function isFriendOf() {
- return $this->isMember();
+ public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0) {
+ return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", $limit, $offset, false);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function countObjects($subtype = "") {
+ return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", 10, 0, true);
+ }
+
+ /**
+ * End friendable compatibility block
+ */
+
+ /**
+ * Get a list of group members.
+ *
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ public function getMembers($limit = 10, $offset = 0, $count = false)
+ {
+ return get_group_members($this->getGUID(), $limit, $offset, 0 , $count);
}
+
/**
* Returns whether the current group is public membership or not.
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 8dc13fafa..4514931a7 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -27,6 +27,7 @@
* @subpackage Core
*/
class ElggUser extends ElggEntity
+ implements Friendable
{
/**
* Initialise the attributes array.