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

Add support for marking groups as ones that users should be automatically added to.

The UI for this still needs to be implemented.
parent fc89251a
......@@ -266,6 +266,7 @@
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="public" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="usersautoadded" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
......
......@@ -1457,6 +1457,16 @@ function xmldb_core_upgrade($oldversion=0) {
set_field('grouptype_roles', 'see_submitted_views', 1, 'grouptype', 'course', 'role', 'admin');
}
if ($oldversion < 2008111200) {
// Event subscription for auto adding users to groups
insert_record('event_subscription', (object)array('event' => 'createuser', 'callfunction' => 'add_user_to_autoadd_groups'));
$table = new XMLDBTable('group');
$field = new XMLDBField('usersautoadded');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
}
......
......@@ -669,6 +669,10 @@ function core_install_firstcoredata_defaults() {
'event' => 'createuser',
'callfunction' => 'activity_set_defaults',
),
array(
'event' => 'createuser',
'callfunction' => 'add_user_to_autoadd_groups',
),
);
foreach ($subs as $sub) {
......
......@@ -1208,6 +1208,25 @@ function copy_view_for_user($userid, $templateid) {
}
/**
* Given a user, makes sure they have been added to all groups that are marked
* as ones that users should be auto-added to
*
* @param array $eventdata Event data passed from activity_occured, the key 'id' = userid
*/
function add_user_to_autoadd_groups($eventdata) {
require_once('group.php');
$userid = $eventdata['id'];
if ($autoaddgroups = get_column('group', 'id', 'usersautoadded', true)) {
foreach ($autoaddgroups as $groupid) {
if (!group_user_access($groupid, $userid)) {
group_add_user($groupid, $userid);
}
}
}
}
function copy_views_for_user($userid, $templateids) {
if (!$templateids) {
return;
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008111102;
$config->version = 2008111200;
$config->release = '1.1.0beta3dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
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