Unenroll student coming from external database

Unenroll student coming from external database

by Maxime Pelletier -
Number of replies: 11

Hi,

I would greatly appreciate if someone could give me the steps to unenroll a student from a course if that user has been enrolled using the external database plugin? I mean, without telling the plugin to unenroll all students not in the external DB anymore...

I tried to grant many roles to admin and student (to use self unenrol) but without success.

Thanks

Average of ratings: -
In reply to Maxime Pelletier

Re: Unenroll student coming from external database

by John Reese -

Yes... we have the exact same question.

To be safe, we don't want to unenrol users (i.e keep enrolled) from a course through the database enrolment sync process.

How do we unenrol a user manually to those users which were enrolled in a course through the database enrolment synchronization process?

Could we do it through the database side then? are these the tables we use?

http://docs.moodle.org/dev/New_enrolments_in_2.0

 

 

Thanks

In reply to John Reese

Re: Unenroll student coming from external database

by HJWUCGA INC. -

John and Maxime,

You can do it on the database side if you're short on time.

First:

find out  which  WHICH ENROLMENT METHODS OR PLUGINS ARE AVAILABLE for that course

mysql> select * from mdl_enrol where courseid = '9999';

Look for "database" under the enrol field and make a note of it's id field value (i.e 5025)

Second:

Next, let's find out who the enrolled users are in that course that were enrolled through database enrolment method big grin

mysql> select u.id, u.username, u.firstname, u.lastname, u.email, e.id as EnrolmentIDRecord , e.status, e.enrolid, e.userid, ep.id, ep.enrol, c.id, c.fullname, c.shortname, c.idnumber as CourseIDNumber from mdl_user u, mdl_user_enrolments e, mdl_enrol ep, mdl_course c  where u.id = e.userid and ep.id = e.enrolid and e.enrolid = '5025' and c.id = ep.courseid and ep.courseid = '9999' order by u.lastname asc, u.firstname asc;

There you have it...

Third:

now delete the record you don't need using the "EnrolmentIDRecord" value (ie. 246810) which belongs to the table mdl_user_enrolments.

mysql> delete from mdl_user_enrolments where enrolid = '5025' and id = '246810';

 

Let me know how it went for you. Hope this helps and good luck.

 

 

 

 

 

 

 

 

Average of ratings: Useful (1)
In reply to Maxime Pelletier

Re: Unenroll student coming from external database

by erika alarcon -
Picture of Testers

Hi!.

I have the same problem, I tried to unenroll the students withe the Reset option, but doesn't works withe the database plugin.

It will be fantastic if there were an option in the Reset option to unenroll this type of registration.

In reply to Maxime Pelletier

Re: Unenroll student coming from external database

by Evan Donovan -

So, based on the responses to date, is there no way through the Moodle interface to unenroll a specific student from a course? It seems like this would be key functionality to have, since sometimes a Moodle admin might not be privileged to make changes to the external source, but might still be responsible for managing course enrollments.

Our use case for this is that we have the enrollments coming in automatically via course purchases through Drupal's Ubercart e-commerce package, but sometimes students will not be qualified for a course, may be taking too many courses, or may simply change their mind. It would be helpful on the administration side if we could unenroll them in Moodle while not having to change the original record of their order in Ubercart.

Average of ratings: Useful (1)
In reply to Evan Donovan

Re: Unenroll student coming from external database

by Evan Donovan -

Ultimately, I coded a Drupal module to do this. PM me if you need it.

In reply to Maxime Pelletier

Re: Unenroll student coming from external database

by Blair F. -
Picture of Particularly helpful Moodlers

We are looking to do the same thing.  Hopefully, someone will come up with a way to do this.

In reply to Maxime Pelletier

Re: Unenroll student coming from external database

by Roger Morris -

We use LDAP to store the course enrollment information.   The teachers requested *they* have the ability to keep a student in the course for X number of days after being dropped from the class.   Since LDAP is updated daily, we set it up so that LDAP gets updated from the student info system, but only *add* the student.  the sync process does not remove the student.  (we set to unenroll the student when they go missing from external db)

I created a special role called "unenroll student" that has no special privileges at all.  When a teacher wants the student removed from the class, then they assign 'unenroll student' role to that student.     I have a script that runs daily (just prior to the LDAP sync process), that looks for that specific role.  When it finds a student with that role, I remove the student from LDAP, and remove the 'unenroll student' role.   a short time later, the LDAP sync script is run.   SInce the student is no longer in LDAP for that course, the student is removed.

 

only catch is that some teachers haven't listened and set 'unenroll' at the meta course.  My method only works if they set unenroll on the actual course.

In reply to Roger Morris

Re: Unenroll student coming from external database

by erika alarcon -
Picture of Testers

Hi Roger, your comment is interesting.

Can you detail the script you use to remove the 'unenroll student' role?

 

Thanks

In reply to erika alarcon

Re: Unenroll student coming from external database

by Roger Morris -

There seems to be a single table altered when you add a role assignment.  I had to run a query to pull the required items I needed:

$sth=$dbh->prepare("select mdl_role_assignments.id,username,mdl_course.idnumber,contextid from mdl_role_assignments left join mdl_context on contextid=mdl_context.id  left join mdl_course on instanceid=mdl_course.id left join mdl_user on userid=mdl_user.id where roleid=15 ");

somebody that knows what they're doing will probably tell me that query could be different.

 

that query gets me 'mdl_course.idnumber' which is the 'gidnumber' in ldap and the username of student which is one of the 'memberuid' of the group.  I then do an LDAP modify call to remove that user from the group. 

Once the student is removed from ldap, I run a 'delete' statement to remove the student from the mdl_role_assignments table.   I use the mdl_role_assignment.id  and roleid to be sure I have the exact record.

 

the script is run once before the nightly sync,   once the sync is run, the student is removed from the course.    

If you run the script during the day, the student is removed from LDAP, but won't disappear from moodle.    since my script removes the role assignment, the teacher might think they forgot to remove the student and remove them again.   In that case, when my script runs, it wouldn't find the student in LDAP and not complete that student properly. 

 

 


1.9 was even uglier.   I altered the code slightly when it logged an 'unenroll' function.  I then scanned the logs looking for 'unenroll' and then removed the student based on what it found. 

In reply to Maxime Pelletier

Re: Unenroll student coming from external database

by Mike Green -

I want to do the same thing as the Original Poster -

In my current 1.9 moodle, External database enrols students to courses, but teachers can unenrol those students when they like. Is that not possible in moodle 2 without inventing and running scripts to directly manipulate the moodle database? People seem to be agreed on this thread that it isn't, which is an unfortunate step backward for us.

In reply to Mike Green

Re: Unenroll student coming from external database

by Cindy Weber -

I am using 2.4.  I also need a way to unenroll a student that is enrolled via external database and additionally enrolled into another class via meta link.