Commit cede5624 authored by Nigel McNie's avatar Nigel McNie
Browse files

A few changes:

* Remove a couple of functions from the group libs that are only used in one or two places:
 - get_owned_groups was only used on user/view and for the sideblock showing the groups you owned. We're going to show more than that now, meaning the function is wasted indirection for the one remaining place it would be used.
 - get_tutor_groups was only used on user/view, and has been broken by the group schema changes.
* Fix adding users to controlled communities. Still have to provide the ability to do this by dropdown.
* Fixed a bug caused by my misunderstanding of how (array) false works - it seems to make an array with 'false' as one value.
parent 260bf49a
......@@ -100,30 +100,6 @@ function get_member_groups($userid=0, $offset=0, $limit=0) {
}
/**
* all groups the user owns
*
* @param int userid (optional, defaults to $USER id)
* @param string $jointype (optional), will filter by jointype.
* @return array of group db rows
*/
function get_owned_groups($userid=0, $jointype=null) {
$userid = optional_userid($userid);
// TODO: select groups where role in group is admin
$sql = 'SELECT g.* FROM {group} g
WHERE g.deleted = ? LIMIT 1';
$values = array(0);
if (!empty($jointype)) {
$sql .= ' AND jointype = ?';
$values[] = $jointype;
}
return get_records_sql_array($sql, $values);
}
/**
* all groups the user has pending invites to
*
......@@ -158,29 +134,6 @@ function get_requested_group($userid=0) {
}
/**
* gets groups the user is a tutor in, or the user owns
*
* @param int $userid (optional, defaults to $USER id)
* @param string $jointype (optional, will filter by jointype
*/
function get_tutor_groups($userid=0, $jointype=null) {
$userid = optional_userid($userid);
$sql = 'SELECT DISTINCT g.*, gm.ctime
FROM {group} g
LEFT JOIN {group_member} gm ON gm.group = g.id
WHERE (g.owner = ? OR (gm.member = ? AND gm.tutor = ?)) AND g.deleted = ?';
$values = array($userid, $userid, 1, 0);
if (!empty($jointype)) {
$sql .= ' AND g.jointype = ? ';
$values[] = $jointype;
}
return get_records_sql_array($sql, $values);
}
// constants for group membership type
define('GROUP_MEMBERSHIP_ADMIN', 1);
define('GROUP_MEMBERSHIP_STAFF', 2);
......
......@@ -1810,7 +1810,7 @@ function profile_sideblock() {
$data['invitedgroupsmessage'] = $data['invitedgroups'] == 1 ? get_string('invitedgroup') : get_string('invitedgroups');
$data['pendingfriends'] = count_records('usr_friend_request', 'owner', $USER->get('id'));
$data['pendingfriendsmessage'] = $data['pendingfriends'] == 1 ? get_string('pendingfriend') : get_string('pendingfriends');
$data['groups'] = get_owned_groups();
$data['groups'] = array();
$data['views'] = get_records_sql_array(
'SELECT v.id, v.title
FROM {view} v
......
......@@ -153,7 +153,9 @@ WHERE
AND g.deleted = 0
ORDER BY
g.name";
$userassocgroups = (array) get_records_sql_assoc($sql, array($userid));
if (!$userassocgroups = get_records_sql_assoc($sql, array($userid))) {
$userassocgroups = array();
}
foreach ($userassocgroups as $group) {
$group->description = str_shorten($group->description, 100, true);
......@@ -223,11 +225,19 @@ SELECT gm.group, gm.role AS type
) AS a ON a.group = g.id
WHERE g.deleted = 0
ORDER BY g.name";
$allusergroups = (array)get_records_sql_assoc($sql, array($userid, $userid, $userid));
if (!$allusergroups = get_records_sql_assoc($sql, array($userid, $userid, $userid))) {
$allusergroups = array();
}
if ($loggedinid != $userid) {
// Get the logged in user's "invite only" groups
if ($groups = get_owned_groups($loggedinid, 'invite')) {
if ($groups = get_records_sql_array("SELECT g.*
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
WHERE gm.member = ?
AND g.jointype = 'invite'
AND gm.role = 'admin'
AND g.deleted = 0", array($loggedinid))) {
$invitelist = array();
foreach ($groups as $group) {
if (array_key_exists($group->id, $allusergroups)) {
......@@ -264,8 +274,17 @@ if ($loggedinid != $userid) {
}
}
// Get the "controlled membership" groups in which the logged in user is a tutor
if ($groups = get_tutor_groups($loggedinid, 'controlled')) {
// Get the controlled membership groups of which the logged in user is either:
// 1. an admin of, or;
// 2. has a role in the list of roles who are allowed to assess submitted views for the given grouptype
if ($groups = get_records_sql_array("SELECT g.*, gm.ctime
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON (gtr.grouptype = g.grouptype AND gtr.role = gm.role)
WHERE gm.member = ?
AND g.jointype = 'controlled'
AND (gm.role = 'admin' OR gtr.see_submitted_views = 1)
AND g.deleted = 0", array($loggedinid))) {
$controlledlist = array();
foreach ($groups as $group) {
if (array_key_exists($group->id, $userassocgroups)) {
......@@ -389,7 +408,7 @@ function addmember_submit(Pieform $form, $values) {
$data->group = $values['group'];
$data->member = $userid;
$data->ctime = db_format_timestamp(time());
$data->tutor = 0;
$data->role = 'member'; // TODO: modify the dropdown to allow the role to be chosen
$ctitle = get_field('group', 'name', 'id', $data->group);
$adduser = get_record('usr', 'id', $data->member);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment