User Enrollable Groups

User Enrollable Groups

by Rashan Anushka -
Number of replies: 6
Dear All,
Recently we had a requirement that the student can enroll in a group that he/she likes without the intervene of the techers. Since the current grouping system does not cater that (correct me if am wrong!) I have comeup with a small script along with some minor modifications to the existing code. I am going to publish this here hoping that this will be usefull to some others smile

Tested moodle version: 1.9.2+ (Build: 20080819)

Features
- The group settings page now has an additional setting called userenrollable to enable this feature (by default this is set to NO to make compatible with the existing groups)
- A new page call "My Groups" now shows the existing groups in the course and the membership status.
- if the users are allowed to enroll to the group (teacher can enable this by the first option), they will see a button to get enroll to that group.

Modifications
- Added a new field to the groups table (usually mdl_groups)
| userenrollable | tinyint(1) | UNSIGNED | NOT NULL | DEFAULT 0 |

- Added a new field to the group seetings page ( /group/group_form.php)
$options = array(get_string('no'), get_string('yes'));
$mform->addElement('select', 'userenrollable', get_string('userenrollable'), $options);

- Added the following code segment under existing groups link of admin block (block_admin.php)

/// My groups by Rashan
if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:groupenrollable', $context)) {
$strgroups = get_string('mygroups');
$this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/mygroups.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
}

- Added a new capability 'moodle/course:groupenrollable' by adding the following into <>/lib/db/access.php (under 'moodle/course:managegroups')

'moodle/course:groupenrollable' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

- Increment $version at <>/version.php and visit admin notifications to update the capabilities.

- a new file called mygroups.php saved under group folder (the file is attached)

So every one is wellcome to test this and/or make suggestions big grin.


Average of ratings: -
In reply to Rashan Anushka

Re: User Enrollable Groups

by Nicolas Dunand -
Picture of Core developers Picture of Plugin developers
Hello Rashan,

Thanks for this ! I was precisely looking for something similar, as teachers began to require such a functionnality.

I just tested it on my Moodle (1.9.1+, build: 20080702), and it seems to be working well. I will be testing it further during December, and will let you know what comes out of it.

Until now, my remarks are:
  1. it's nice that the teacher still may manage groups memberships manually : that gives more flexibility;
  2. it would be even better if there would be an optional "enrolment period", within which students could unenrol from their group, and enrol into another one.
Regards,

Nicolas
In reply to Rashan Anushka

Re: User Enrollable Groups

by Nicolas Dunand -
Picture of Core developers Picture of Plugin developers
Hello Rashan,

Today I took some time to add the "unenrol self" functionality :

  • MySQL :
    ALTER TABLE `mdl_groups`
     ADD `userenrolstart` INT(11) NULL DEFAULT NULL ,
     ADD `userenrolstop` INT(11) NULL DEFAULT NULL ;
  • modify further group_form.php :
    $mform->addElement('select', 'userenrollable', get_string('userenrollable'), array(get_string('no'), get_string('yes')));
    $mform->addElement('date_selector', 'userenrolstart', get_string('userenrolstartdate'));
    $mform->setDefault('userenrolstart', time());
    $mform->addElement('date_selector', 'userenrolstop', get_string('userenrolstopdate'));
    $mform->setDefault('userenrolstop', time() + 3600 * 24 * 7);
  • modifiy mygroups.php (attached file)
Result :
  1. the teacher has to define an "user-enrolment period", during which students can enrol and unenrol ... after this period, the teacher woud have to manually make any further changes ;
  2. the students may enrol/unenrol groups during this period.

I still have to test it, though.


Regards,

Nicolas
In reply to Nicolas Dunand

Re: User Enrollable Groups

by Nicolas Dunand -
Picture of Core developers Picture of Plugin developers
In a reply to myself, here's the new mygroups.php file, which corrects a bad behaviour caused by MDL-10787 : the list of group members displayed only one record per lastname if several group members had the same last name.
In reply to Nicolas Dunand

Re: User Enrollable Groups

by Jeff Church -
This looks so good. Thanks to both of you for your work. Just starting testing on this but it looks great. Is there a lang file for this? I get mygroups and other things like it which is usually a lang file issue.

As a student or teacher I don't get the MyGroups link in the Administration block. Any ideas on what I did wrong. I do get it as Admin. I think I made a mistake in the access.php file change.

Here is what I put in access.php

'moodle/course:managegroups' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

'moodle/course:groupenrollable' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

Any help on where I went wrong would be a blessing.

Thanks
Jeff
In reply to Jeff Church

Re: User Enrollable Groups

by Nicolas Dunand -
Picture of Core developers Picture of Plugin developers
Hello Jeff,

I just wenth through all my documentation about this. To sum it up (info across several previous posts, porbably some missing), here's my working setup (this is working within Moodle 1.9) :
  1. alter Moodle database with attached mygroups_mysql.sql file
  2. modify group/group_form.php, add contents of attached group_form.php.addings file (just before "$this->add_action_buttons()"
  3. add contents of the attached block_admin.php.addings file to your blocks/admin/block_admin.php file (exact insert position depending on where you want the "My Groups" link to appear)
  4. add one capacity to your lib/db/access.php file, as coded in the attached capacity.txt file (about your post : "moodle/course:managegroups" should already exist, so things might break down if defined twice)
  5. increment your $version variable in your moodle/version.php by 1
  6. upload the attached mygroups.php file into your moodle/group/ subfolder
  7. Log into Moodle as an administrator, and visit the "Notifications page" (admin block) ; Moodle should notice the $version increment and ask you if it should upgrade ; answering Yes here triggers the capabilities cache re-creation.
I previously forgot to post the lang file : it's now within the attached zip file.


In reply to Nicolas Dunand

Re: User Enrollable Groups

by Donna Graves -

Thank you all so very much.  I have been scratching my head trying to make this happen then I came upon this blog

THANK YOU.