aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/group.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-01 16:11:08 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-01 16:11:08 +0000
commitf970c658bbc3bce3b3dddffa10c7cb78a694a098 (patch)
tree945e2ec2471fd4daeba509f2eaa817a275dc8b55 /engine/lib/group.php
parentbc8e5ed636b26ed979a38ca56508a65079b9f9eb (diff)
downloadelgg-f970c658bbc3bce3b3dddffa10c7cb78a694a098.tar.gz
elgg-f970c658bbc3bce3b3dddffa10c7cb78a694a098.tar.bz2
Membership functions, and introducing can_write_to_container, and its hook group_permission_check. Refs #106.
git-svn-id: https://code.elgg.org/elgg/trunk@1247 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/group.php')
-rw-r--r--engine/lib/group.php134
1 files changed, 134 insertions, 0 deletions
diff --git a/engine/lib/group.php b/engine/lib/group.php
index e8a68aada..db8f3227c 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -109,6 +109,17 @@
}
/**
+ * Returns whether the given user (or current user) has the ability to write to this group.
+ *
+ * @param int $user_guid The user.
+ * @return bool
+ */
+ public function can_write_to_container($user_guid = 0)
+ {
+ return can_write_to_container($user_guid, $this->getGUID());
+ }
+
+ /**
* Get objects contained in this group.
*
* @param int $limit
@@ -125,6 +136,50 @@
}
/**
+ * Get a list of group members.
+ *
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ public function getMembers($limit = 10, $offset = 0)
+ {
+ return get_group_members($this->getGUID(), $limit, $offset);
+ }
+
+ /**
+ * Return whether a given user is a member of this group or not.
+ *
+ * @param ElggUser $user The user
+ * @return bool
+ */
+ public function isMember(ElggUser $user)
+ {
+ return is_group_member($this->getGUID(), $user->getGUID());
+ }
+
+ /**
+ * Join an elgg user to this group.
+ *
+ * @param ElggUser $user
+ * @return bool
+ */
+ public function join(ElggUser $user)
+ {
+ return join_group($this->getGUID(), $user->getGUID());
+ }
+
+ /**
+ * Remove a user from the group.
+ *
+ * @param int $guid GUID of the user
+ */
+ public function leave($guid)
+ {
+ return leave_group($this->getGUID(), $user->getGUID());
+ }
+
+ /**
* Delete this group.
*/
public function delete()
@@ -180,6 +235,37 @@
}
/**
+ * Determine whether a given user is able to write to a given group.
+ *
+ * @param int $user_guid The user guid, or 0 for $_SESSION['user']->getGUID()
+ * @param int $container_guid The container, or 0 for the current page owner.
+ */
+ function can_write_to_container($user_guid = 0, $container_guid = 0)
+ {
+ global $CONFIG;
+
+ $user_guid = (int)$user_guid;
+ if (!$user_guid) $user_guid = $_SESSION['user']->getGUID();
+ $user = get_entity($user_guid);
+
+ $container_guid = (int)$container_guid;
+ if (!$container_guid) $container_guid = page_owner();
+ $container = get_entity($container_guid);
+
+ if (($container) && ($user))
+ {
+ // Basics, see if the user is a member of the group.
+ if (!$container->isMember($user)) return false;
+
+ // See if anyone else has anything to say
+ return trigger_plugin_hook('group_permissions_check',$entity->type,array('container' => $container, 'user' => $user), false);
+
+ }
+
+ return false;
+ }
+
+ /**
* Get the group entity.
*
* @param int $guid
@@ -413,5 +499,53 @@
return $total->total;
}
+ /**
+ * Return a list of this group's members.
+ *
+ * @param int $group_guid The ID of the container/group.
+ * @param int $limit The limit
+ * @param int $offset The offset
+ * @param int $site_guid The site
+ * @param bool $count Return the users (false) or the count of them (true)
+ * @return mixed
+ */
+ function get_group_members($group_guid, $limit = 10, $offset = 0, $site_guid = 0, $count = false)
+ {
+ return get_entities_from_relationship('member', $group_guid, true, 'user', '', 0, "", $limit, $offset, $count, $site_guid);
+ }
+
+ /**
+ * Return whether a given user is a member of the group or not.
+ *
+ * @param int $group_guid The group ID
+ * @param int $user_guid The user guid
+ * @return bool
+ */
+ function is_group_member($group_guid, $user_guid)
+ {
+ return check_entity_relationship($user_guid, 'member', $group_guid);
+ }
+
+ /**
+ * Join a user to a group.
+ *
+ * @param int $group_guid The group.
+ * @param int $user_guid The user.
+ */
+ function join_group($group_guid, $user_guid)
+ {
+ return add_entity_relationship($user_guid, 'member', $group_guid);
+ }
+
+ /**
+ * Remove a user from a group.
+ *
+ * @param int $group_guid The group.
+ * @param int $user_guid The user.
+ */
+ function leave_group($group_guid, $user_guid)
+ {
+ return remove_entity_relationship($user_guid, 'member', $group_guid);
+ }
}
?> \ No newline at end of file