Commit 7f7b6f47 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie

Rename the 'roletype' column of group_member to 'role', and fix associated code.

Better to do this now, when the changeset is minimal.
parent 9bc36f19
......@@ -115,30 +115,13 @@ function creategroup_submit(Pieform $form, $values) {
true
);
// Clone role instances for group type and put in the right table
foreach (call_static_method('GroupType' . $grouptype, 'get_role_types') as $roletype) {
$roleinstanceid = insert_record(
'group_role_instance',
(object) array(
'group' => $id,
'roletype' => $roletype,
),
'id',
true
);
if ($roletype == 'admin') {
$adminroleinstance = $roleinstanceid;
}
}
// Make the user an admin (must have some way of establishing the 'admin' role instance)
// Make the user an admin
insert_record(
'group_member',
(object) array(
'group' => $id,
'member' => $USER->get('id'),
'roleinstance' => $adminroleinstance,
'role' => 'admin',
'ctime' => $now,
)
);
......
......@@ -96,18 +96,17 @@ if ($groups['data']) {
LEFT JOIN (
SELECT g.id, 'admin' AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ?)
INNER JOIN {group_role_instance} gri ON (gri.group = g.id AND gri.roletype = 'admin' AND gri.id = gm.roleinstance)
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
INNER JOIN {group_role_instance} gri ON (gri.group = g.id AND gri.roletype != 'admin' AND gri.id = gm.roleinstance)
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, 'request' AS membershiptype
UNION
SELECT g.id, 'request' AS membershiptype
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
......
......@@ -58,7 +58,7 @@ if ($filter == 'admin') {
INNER JOIN (
SELECT g.id, $adminsql AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.roletype = 'admin')
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
) t ON t.id = g.id";
$values = array($USER->get('id'));
}
......@@ -67,11 +67,11 @@ else if ($filter == 'member') {
INNER JOIN (
SELECT g.id, 'admin' AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.roletype = 'admin')
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS type
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.roletype != 'admin')
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role != 'admin')
) t ON t.id = g.id";
$values = array($USER->get('id'), $USER->get('id'));
}
......@@ -99,11 +99,11 @@ else { // all or some other text
INNER JOIN (
SELECT g.id, 'admin' AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.roletype = 'admin')
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.roletype != 'admin')
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype
FROM {group} g
......
......@@ -983,7 +983,7 @@ function xmldb_core_upgrade($oldversion=0) {
log_debug('GROUP TYPE REFACTOR');
execute_sql('ALTER TABLE {group} ADD grouptype CHARACTER VARYING(20)');
execute_sql('ALTER TABLE {group_member} ADD roletype TEXT');
execute_sql('ALTER TABLE {group_member} ADD role TEXT');
$groups = get_records_array('group');
if ($groups) {
......@@ -1003,17 +1003,17 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql('UPDATE {group} SET grouptype = ? WHERE id = ?', array($group->grouptype, $group->id));
log_debug(' * new group type is ' . $group->grouptype);
// Insert roleinstances for each role type for the group
foreach (call_static_method('GroupType' . $group->grouptype, 'get_role_types') as $roletype) {
if ($roletype == 'admin') {
// Convert group membership information to roles
foreach (call_static_method('GroupType' . $group->grouptype, 'get_roles') as $role) {
if ($role == 'admin') {
// It would be nice to use ensure_record_exists here,
// but because ctime is not null we have to provide it
// as data, which means the ctime would be updated if
// the record _did_ exist
if (get_record('group_member', 'group', $group->id, 'member', $group->owner)) {
execute_sql("UPDATE {group_member}
SET roletype = 'admin'
WHERE group = ?
SET role = 'admin'
WHERE \"group\" = ?
AND member = ?", array($group->id, $group->owner));
}
else {
......@@ -1024,17 +1024,17 @@ function xmldb_core_upgrade($oldversion=0) {
'group' => $group->id,
'member' => $group->owner,
'ctime' => db_format_timestamp(time()),
'roletype' => 'admin',
'role' => 'admin',
);
insert_record('group_member', $data);
}
log_debug(" * marked user {$group->owner} as having the admin roletype");
log_debug(" * marked user {$group->owner} as having the admin role");
}
else {
// Setting role instances for tutors and members
$tutorflag = ($roletype == 'tutor') ? 1 : 0;
$tutorflag = ($role == 'tutor') ? 1 : 0;
execute_sql('UPDATE {group_member}
SET roletype = ?
SET role = ?
WHERE "group" = ?
AND member != ?
AND member IN (
......@@ -1042,8 +1042,8 @@ function xmldb_core_upgrade($oldversion=0) {
FROM {group_member}
WHERE "group" = ?
AND tutor = ?
)', array($roletype, $group->id, $group->owner, $group->id, $tutorflag));
log_debug(" * marked appropriate users as being {$roletype}s");
)', array($role, $group->id, $group->owner, $group->id, $tutorflag));
log_debug(" * marked appropriate users as being {$role}s");
}
}
}
......@@ -1051,7 +1051,7 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql('ALTER TABLE {group} ALTER grouptype SET NOT NULL');
execute_sql('ALTER TABLE {group_member} ALTER roletype SET NOT NULL');
execute_sql('ALTER TABLE {group_member} ALTER role SET NOT NULL');
execute_sql('ALTER TABLE {group} DROP owner');
execute_sql('ALTER TABLE {group_member} DROP tutor');
}
......
......@@ -331,7 +331,7 @@ function group_user_access($groupid, $userid=null) {
throw new InvalidArgumentException("group_user_access: user argument appears to be invalid: $userid");
}
return get_field('group_member', 'roletype', 'group', $groupid, 'member', $userid);
return get_field('group_member', 'role', 'group', $groupid, 'member', $userid);
}
/**
......@@ -384,7 +384,7 @@ function group_prepare_usergroups_for_display($groups, $returnto='mygroups') {
$groupadmins = (array)get_records_sql_array('SELECT "group", member
FROM {group_member}
WHERE "group" IN (' . implode(',', db_array_to_ph($groupids)) . ")
AND roletype = 'admin'", $groupids);
AND role = 'admin'", $groupids);
}
$i = 0;
......@@ -485,9 +485,9 @@ abstract class GroupType {
}
/**
* Returns the role types this group type implements
* Returns the roles this group type implements
*/
public static abstract function get_role_types();
public static abstract function get_roles();
}
......
......@@ -40,7 +40,7 @@ class GroupTypeCourse extends GroupType {
|| $USER->is_institutional_staff();
}
public static function get_role_types() {
public static function get_roles() {
return array('member', 'tutor', 'admin');
}
......
......@@ -34,7 +34,7 @@ class GroupTypeStandard extends GroupType {
return array('open', 'request', 'invite');
}
public static function get_role_types() {
public static function get_roles() {
return array('member', 'admin');
}
......
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