Commit a64cdeb8 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Group creation implemented, as well as rudimentary role type support.

This will be broken until I write a database patch. But the appropriate data is inserted into the group tables when a group is created now.
parent 94e7bfd8
......@@ -99,13 +99,15 @@ function creategroup_submit(Pieform $form, $values) {
$now = db_format_timestamp(time());
list($grouptype, $jointype) = explode('.', $values['grouptype']);
$id = insert_record(
'group',
(object) array(
'name' => $values['name'],
'description' => $values['description'],
'grouptype' => $values['grouptype'],
'jointype' => $values['membershiptype'],
'grouptype' => $grouptype,
'jointype' => $jointype,
'ctime' => $now,
'mtime' => $now,
),
......@@ -114,18 +116,32 @@ function creategroup_submit(Pieform $form, $values) {
);
// Clone role instances for group type and put in the right table
// TODO
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)
//insert_record(
// 'group_member',
// (object) array(
// 'group' => $id,
// 'member' => $USER->get('id'),
// 'roleinstance' => ?
// 'ctime' => $now,
// )
//);
insert_record(
'group_member',
(object) array(
'group' => $id,
'member' => $USER->get('id'),
'roleinstance' => $adminroleinstance,
'ctime' => $now,
)
);
$SESSION->add_ok_msg(get_string('groupsaved', 'group'));
......
......@@ -985,8 +985,14 @@ function xmldb_core_upgrade($oldversion=0) {
// ALTER TABLE "group" DROP owner;
// ALTER TABLE "group" ADD grouptype CHARACTER VARYING(20) NOT NULL;
// ALTER TABLE "group_member" DROP tutor;
// CREATE TABLE "group_role_instance" (
// id SERIAL,
// "group" INTEGER NOT NULL REFERENCES "group"(id),
// roletype TEXT NOT NULL
// );
//
// unperformed yet:
//
// ALTER TABLE "group_member" ADD roleinstance FK group_role_instance(id);
// ?? ALTER TABLE "group_member" RENAME member TO usr;
}
......
......@@ -947,7 +947,7 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
}
else {
if (!$columns = $db->MetaColumns(get_config('dbprefix') . $table)) {
return false;
throw new SQLException('Table "' . get_config('dbprefix') . $table . '" does not appear to exist');
}
$table_columns[$table] = $columns;
}
......
......@@ -435,6 +435,11 @@ abstract class GroupType {
return true;
}
/**
* Returns the role types this group type implements
*/
public static abstract function get_role_types();
}
/**
......
......@@ -38,6 +38,10 @@ class GroupTypeCourse extends GroupType {
|| $USER->is_institutional_staff();
}
public static function get_role_types() {
return array('member', 'tutor', 'admin');
}
}
?>
......@@ -32,6 +32,10 @@ class GroupTypeStandard extends GroupType {
return array('open', 'request', 'invite');
}
public static function get_role_types() {
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