aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/group.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/group.php')
-rw-r--r--engine/lib/group.php539
1 files changed, 64 insertions, 475 deletions
diff --git a/engine/lib/group.php b/engine/lib/group.php
index ed7aa504a..6ded8a825 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -14,6 +14,7 @@
* @param int $guid GUID for a group
*
* @return array|false
+ * @access private
*/
function get_group_entity_as_row($guid) {
global $CONFIG;
@@ -24,7 +25,7 @@ function get_group_entity_as_row($guid) {
}
/**
- * Create or update the extras table for a given group.
+ * Create or update the entities table for a given group.
* Call create_entity first.
*
* @param int $guid GUID
@@ -32,6 +33,7 @@ function get_group_entity_as_row($guid) {
* @param string $description Description
*
* @return bool
+ * @access private
*/
function create_group_entity($guid, $name, $description) {
global $CONFIG;
@@ -52,7 +54,7 @@ function create_group_entity($guid, $name, $description) {
if ($result != false) {
// Update succeeded, continue
$entity = get_entity($guid);
- if (trigger_elgg_event('update', $entity->type, $entity)) {
+ if (elgg_trigger_event('update', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete();
@@ -66,7 +68,7 @@ function create_group_entity($guid, $name, $description) {
$result = insert_data($query);
if ($result !== false) {
$entity = get_entity($guid);
- if (trigger_elgg_event('create', $entity->type, $entity)) {
+ if (elgg_trigger_event('create', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete();
@@ -78,23 +80,6 @@ function create_group_entity($guid, $name, $description) {
return false;
}
-
-/**
- * THIS FUNCTION IS DEPRECATED.
- *
- * Delete a group's extra data.
- *
- * @param int $guid The guid of the group
- *
- * @return bool
- */
-function delete_group_entity($guid) {
- system_message(sprintf(elgg_echo('deprecatedfunction'), 'delete_user_entity'));
-
- // Always return that we have deleted one row in order to not break existing code.
- return 1;
-}
-
/**
* Add an object to the given group.
*
@@ -116,12 +101,12 @@ function add_object_to_group($group_guid, $object_guid) {
}
if (!($group instanceof ElggGroup)) {
- $msg = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $group_guid, 'ElggGroup');
+ $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($group_guid, 'ElggGroup'));
throw new InvalidClassException($msg);
}
if (!($object instanceof ElggObject)) {
- $msg = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $object_guid, 'ElggObject');
+ $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($object_guid, 'ElggObject'));
throw new InvalidClassException($msg);
}
@@ -150,12 +135,12 @@ function remove_object_from_group($group_guid, $object_guid) {
}
if (!($group instanceof ElggGroup)) {
- $msg = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $group_guid, 'ElggGroup');
+ $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($group_guid, 'ElggGroup'));
throw new InvalidClassException($msg);
}
if (!($object instanceof ElggObject)) {
- $msg = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $object_guid, 'ElggObject');
+ $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($object_guid, 'ElggObject'));
throw new InvalidClassException($msg);
}
@@ -164,317 +149,6 @@ function remove_object_from_group($group_guid, $object_guid) {
}
/**
- * Return an array of objects in a given container.
- *
- * @see get_entities()
- *
- * @param int $group_guid The container (defaults to current page owner)
- * @param string $subtype The subtype
- * @param int $owner_guid Owner
- * @param int $site_guid The site
- * @param string $order_by Order
- * @param int $limit Limit on number of elements to return, by default 10.
- * @param int $offset Where to start, by default 0.
- * @param bool $count Whether to return the entities or a count of them.
- *
- * @return array|false
- */
-function get_objects_in_group($group_guid, $subtype = "", $owner_guid = 0, $site_guid = 0,
-$order_by = "", $limit = 10, $offset = 0, $count = FALSE) {
-
- global $CONFIG;
-
- if ($subtype === FALSE || $subtype === null || $subtype === 0) {
- return FALSE;
- }
-
- if ($order_by == "") {
- $order_by = "e.time_created desc";
- }
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- if ($site_guid == 0) {
- $site_guid = $CONFIG->site_guid;
- }
-
- $container_guid = (int)$group_guid;
- if ($container_guid == 0) {
- $container_guid = elgg_get_page_owner_guid();
- }
-
- $where = array();
-
- $where[] = "e.type='object'";
-
- if (!empty($subtype)) {
- if (!$subtype = get_subtype_id('object', $subtype)) {
- return FALSE;
- }
- $where[] = "e.subtype=$subtype";
- }
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_guid = (int) $owner_guid;
- $where[] = "e.container_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- // Cast every element to the owner_guid array to int
- $owner_guid = array_map("sanitise_int", $owner_guid);
- $owner_guid = implode(",", $owner_guid);
- $where[] = "e.container_guid in ({$owner_guid})";
- }
- }
- if ($site_guid > 0) {
- $where[] = "e.site_guid = {$site_guid}";
- }
-
- if ($container_guid > 0) {
- $where[] = "e.container_guid = {$container_guid}";
- }
-
- if (!$count) {
- $query = "SELECT * from {$CONFIG->dbprefix}entities e"
- . " join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where ";
- } else {
- $query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e"
- . " join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where ";
- }
- foreach ($where as $w) {
- $query .= " $w and ";
- }
-
- // Add access controls
- $query .= get_access_sql_suffix('e');
- if (!$count) {
- $query .= " order by $order_by";
-
- // Add order and limit
- if ($limit) {
- $query .= " limit $offset, $limit";
- }
-
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
- }
-}
-
-/**
- * Get all the entities from metadata from a group.
- *
- * @param int $group_guid The ID of the group.
- * @param mixed $meta_name Metadata name
- * @param mixed $meta_value Metadata value
- * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
- * @param string $entity_subtype The subtype of the entity.
- * @param int $owner_guid Owner guid
- * @param int $limit Limit
- * @param int $offset Offset
- * @param string $order_by Optional ordering.
- * @param int $site_guid Site GUID. 0 for current, -1 for any
- * @param bool $count Return count instead of entities
- *
- * @return array|false
- */
-function get_entities_from_metadata_groups($group_guid, $meta_name, $meta_value = "",
-$entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0,
-$order_by = "", $site_guid = 0, $count = false) {
- global $CONFIG;
-
- $meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
-
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
- if ($order_by == "") {
- $order_by = "e.time_created desc";
- }
- $order_by = sanitise_string($order_by);
- $site_guid = (int) $site_guid;
- if (is_array($owner_guid)) {
- foreach ($owner_guid as $key => $guid) {
- $owner_guid[$key] = (int) $guid;
- }
- } else {
- $owner_guid = (int) $owner_guid;
- }
- if ($site_guid == 0) {
- $site_guid = $CONFIG->site_guid;
- }
-
- $container_guid = (int)$group_guid;
- if ($container_guid == 0) {
- $container_guid = elgg_get_page_owner_guid();
- }
-
- $where = array();
-
- if ($entity_type != "") {
- $where[] = "e.type='$entity_type'";
- }
- if ($entity_subtype) {
- $where[] = "e.subtype=$entity_subtype";
- }
- if ($meta_name != "") {
- $where[] = "m.name_id='$meta_n'";
- }
- if ($meta_value != "") {
- $where[] = "m.value_id='$meta_v'";
- }
- if ($site_guid > 0) {
- $where[] = "e.site_guid = {$site_guid}";
- }
- if ($container_guid > 0) {
- $where[] = "e.container_guid = {$container_guid}";
- }
-
- if (is_array($owner_guid)) {
- $where[] = "e.container_guid in (" . implode(",", $owner_guid ) . ")";
- } else if ($owner_guid > 0) {
- $where[] = "e.container_guid = {$owner_guid}";
- }
-
- if (!$count) {
- $query = "SELECT distinct e.* ";
- } else {
- $query = "SELECT count(e.guid) as total ";
- }
-
- $query .= "from {$CONFIG->dbprefix}entities e"
- . " JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid "
- . " JOIN {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid where";
-
- foreach ($where as $w) {
- $query .= " $w and ";
- }
-
- // Add access controls
- $query .= get_access_sql_suffix("e");
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($row = get_data_row($query)) {
- return $row->total;
- }
- }
- return false;
-}
-
-/**
- * As get_entities_from_metadata_groups() but with multiple entities.
- *
- * @param int $group_guid The ID of the group.
- * @param array $meta_array Array of 'name' => 'value' pairs
- * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
- * @param string $entity_subtype The subtype of the entity.
- * @param int $owner_guid Owner GUID
- * @param int $limit Limit
- * @param int $offset Offset
- * @param string $order_by Optional ordering.
- * @param int $site_guid Site GUID. 0 for current, -1 for any
- * @param bool $count Return count of entities instead of entities
- *
- * @return int|array List of ElggEntities, or the total number if count is set to false
- */
-function get_entities_from_metadata_groups_multi($group_guid, $meta_array, $entity_type = "",
-$entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "",
-$site_guid = 0, $count = false) {
-
- global $CONFIG;
-
- if (!is_array($meta_array) || sizeof($meta_array) == 0) {
- return false;
- }
-
- $where = array();
-
- $mindex = 1;
- $join = "";
- foreach ($meta_array as $meta_name => $meta_value) {
- $meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
- $join .= " JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid"
- . " JOIN {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid ";
-
- if ($meta_name != "") {
- $where[] = "m{$mindex}.name_id='$meta_n'";
- }
-
- if ($meta_value != "") {
- $where[] = "m{$mindex}.value_id='$meta_v'";
- }
-
- $mindex++;
- }
-
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
- if ($order_by == "") {
- $order_by = "e.time_created desc";
- }
- $order_by = sanitise_string($order_by);
- $owner_guid = (int) $owner_guid;
-
- $site_guid = (int) $site_guid;
- if ($site_guid == 0) {
- $site_guid = $CONFIG->site_guid;
- }
-
- //$access = get_access_list();
-
- if ($entity_type != "") {
- $where[] = "e.type = '{$entity_type}'";
- }
-
- if ($entity_subtype) {
- $where[] = "e.subtype = {$entity_subtype}";
- }
-
- if ($site_guid > 0) {
- $where[] = "e.site_guid = {$site_guid}";
- }
-
- if ($owner_guid > 0) {
- $where[] = "e.owner_guid = {$owner_guid}";
- }
-
- if ($container_guid > 0) {
- $where[] = "e.container_guid = {$container_guid}";
- }
-
- if ($count) {
- $query = "SELECT count(e.guid) as total ";
- } else {
- $query = "SELECT distinct e.* ";
- }
-
- $query .= " from {$CONFIG->dbprefix}entities e {$join} where";
- foreach ($where as $w) {
- $query .= " $w and ";
- }
- $query .= get_access_sql_suffix("e"); // Add access controls
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // 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 a list of this group's members.
*
* @param int $group_guid The ID of the container/group.
@@ -496,7 +170,7 @@ function get_group_members($group_guid, $limit = 10, $offset = 0, $site_guid = 0
'relationship' => 'member',
'relationship_guid' => $group_guid,
'inverse_relationship' => TRUE,
- 'types' => 'user',
+ 'type' => 'user',
'limit' => $limit,
'offset' => $offset,
'count' => $count,
@@ -524,16 +198,18 @@ function is_group_member($group_guid, $user_guid) {
/**
* Join a user to a group.
*
- * @param int $group_guid The group.
- * @param int $user_guid The user.
+ * @param int $group_guid The group GUID.
+ * @param int $user_guid The user GUID.
*
* @return bool
*/
function join_group($group_guid, $user_guid) {
$result = add_entity_relationship($user_guid, 'member', $group_guid);
- $param = array('group' => get_entity($group_guid), 'user' => get_entity($user_guid));
- trigger_elgg_event('join', 'group', $params);
+ if ($result) {
+ $params = array('group' => get_entity($group_guid), 'user' => get_entity($user_guid));
+ elgg_trigger_event('join', 'group', $params);
+ }
return $result;
}
@@ -550,7 +226,7 @@ function leave_group($group_guid, $user_guid) {
// event needs to be triggered while user is still member of group to have access to group acl
$params = array('group' => get_entity($group_guid), 'user' => get_entity($user_guid));
- trigger_elgg_event('leave', 'group', $params);
+ elgg_trigger_event('leave', 'group', $params);
$result = remove_entity_relationship($user_guid, 'member', $group_guid);
return $result;
}
@@ -564,59 +240,65 @@ function leave_group($group_guid, $user_guid) {
*/
function get_users_membership($user_guid) {
$options = array(
+ 'type' => 'group',
'relationship' => 'member',
'relationship_guid' => $user_guid,
- 'inverse_relationship' => FALSE
+ 'inverse_relationship' => false,
+ 'limit' => false,
);
return elgg_get_entities_from_relationship($options);
}
/**
- * Checks access to a group.
+ * May the current user access item(s) on this page? If the page owner is a group,
+ * membership, visibility, and logged in status are taken into account.
*
* @param boolean $forward If set to true (default), will forward the page;
* if set to false, will return true or false.
*
- * @return true|false If $forward is set to false.
+ * @return bool If $forward is set to false.
*/
function group_gatekeeper($forward = true) {
- $allowed = true;
- $url = '';
-
- if ($group = elgg_get_page_owner()) {
- if ($group instanceof ElggGroup) {
- $url = $group->getURL();
- if (
- ((!isloggedin()) && (!$group->isPublicMembership())) ||
- ((!$group->isMember(get_loggedin_user()) && (!$group->isPublicMembership())))
- ) {
- $allowed = false;
- }
- // Admin override
- if (isadminloggedin()) {
- $allowed = true;
- }
- }
+ $page_owner_guid = elgg_get_page_owner_guid();
+ if (!$page_owner_guid) {
+ return true;
}
+ $visibility = ElggGroupItemVisibility::factory($page_owner_guid);
- if ($forward && $allowed == false) {
- register_error(elgg_echo('membershiprequired'));
- forward($url);
- exit;
+ if (!$visibility->shouldHideItems) {
+ return true;
}
+ if ($forward) {
+ // only forward to group if user can see it
+ $group = get_entity($page_owner_guid);
+ $forward_url = $group ? $group->getURL() : '';
- return $allowed;
+ if (!elgg_is_logged_in()) {
+ $_SESSION['last_forward_from'] = current_page_url();
+ $forward_reason = 'login';
+ } else {
+ $forward_reason = 'member';
+ }
+
+ register_error(elgg_echo($visibility->reasonHidden));
+ forward($forward_url, $forward_reason);
+ }
+
+ return false;
}
/**
- * Manages group tool options
+ * Adds a group tool option
+ *
+ * @see remove_group_tool_option().
*
- * @param string $name Name of the group tool option
- * @param string $label Used for the group edit form
- * @param boolean $default_on True if this option should be active by default
+ * @param string $name Name of the group tool option
+ * @param string $label Used for the group edit form
+ * @param bool $default_on True if this option should be active by default
*
* @return void
+ * @since 1.5.0
*/
function add_group_tool_option($name, $label, $default_on = true) {
global $CONFIG;
@@ -635,118 +317,25 @@ function add_group_tool_option($name, $label, $default_on = true) {
}
/**
- * Searches for a group based on a complete or partial name or description
+ * Removes a group tool option based on name
*
- * @param string $criteria The partial or full name or description
- * @param int $limit Limit of the search.
- * @param int $offset Offset.
- * @param string $order_by The order.
- * @param boolean $count Whether to return the count of results or just the results.
+ * @see add_group_tool_option()
*
- * @return mixed
- * @deprecated 1.7
+ * @param string $name Name of the group tool option
+ *
+ * @return void
+ * @since 1.7.5
*/
-function search_for_group($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false) {
- elgg_deprecated_notice('search_for_group() was deprecated by new search plugin.', 1.7);
+function remove_group_tool_option($name) {
global $CONFIG;
- $criteria = sanitise_string($criteria);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $order_by = sanitise_string($order_by);
-
- $access = get_access_sql_suffix("e");
-
- if ($order_by == "") {
- $order_by = "e.time_created desc";
- }
-
- if ($count) {
- $query = "SELECT count(e.guid) as total ";
- } else {
- $query = "SELECT e.* ";
- }
- $query .= "from {$CONFIG->dbprefix}entities e"
- . " JOIN {$CONFIG->dbprefix}groups_entity g on e.guid=g.guid where ";
-
- $query .= "(g.name like \"%{$criteria}%\" or g.description like \"%{$criteria}%\")";
- $query .= " and $access";
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($count = get_data_row($query)) {
- return $count->total;
- }
+ if (!isset($CONFIG->group_tool_options)) {
+ return;
}
- return false;
-}
-
-/**
- * Returns a formatted list of groups suitable for injecting into search.
- *
- * @deprecated 1.7
- *
- * @param string $hook Hook name
- * @param string $user User
- * @param mixed $returnvalue Previous hook's return value
- * @param string $tag Tag to search on
- *
- * @return string
- */
-function search_list_groups_by_name($hook, $user, $returnvalue, $tag) {
- elgg_deprecated_notice('search_list_groups_by_name() was deprecated by new search plugin', 1.7);
- // Change this to set the number of groups that display on the search page
- $threshold = 4;
-
- $object = get_input('object');
-
- if (!get_input('offset') && (empty($object) || $object == 'group')) {
- if ($groups = search_for_group($tag, $threshold)) {
- $countgroups = search_for_group($tag, 0, 0, "", true);
- $return = elgg_view('group/search/startblurb', array('count' => $countgroups, 'tag' => $tag));
- foreach ($groups as $group) {
- $return .= elgg_view_entity($group);
- }
- $vars = array('count' => $countgroups, 'threshold' => $threshold, 'tag' => $tag);
- $return .= elgg_view('group/search/finishblurb', $vars);
- return $return;
+ foreach ($CONFIG->group_tool_options as $i => $option) {
+ if ($option->name == $name) {
+ unset($CONFIG->group_tool_options[$i]);
}
}
}
-
-/**
- * Displays a list of group objects that have been searched for.
- *
- * @see elgg_view_entity_list
- *
- * @param string $tag Search criteria
- * @param int $limit The number of entities to display on a page
- *
- * @return string The list in a form suitable to display
- * @deprecated 1.7
- */
-function list_group_search($tag, $limit = 10) {
- elgg_deprecated_notice('list_group_search() was deprecated by new search plugin.', 1.7);
- $offset = (int) get_input('offset');
- $limit = (int) $limit;
- $count = (int) search_for_group($tag, 10, 0, '', true);
- $entities = search_for_group($tag, $limit, $offset);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, false);
-
-}
-
-/**
- * Performs initialisation functions for groups
- *
- * @return void
- */
-function group_init() {
- // Register an entity type
- register_entity_type('group', '');
-}
-
-register_elgg_event_handler('init', 'system', 'group_init');