Automatically adding parents to your Moodle

Published April 16, 2009

After the core process of adding students and faculty, many K12 institutions are keen to add parents to their Moodle site. There are generally two levels at which this can occur:

  1. Adding parents to courses
  2. Assigning parents to their children – to view their profile, activity reports, grades, etc.

While the first of these two is relatively simple using existing functionality – either manually (eek) via Assign Roles, or automatically, using a Moodle enrolment plugin, the second is a little more tricky. For a while, it has been possible to add parents to a Moodle site, using the “Assign Roles in User” functionality to effectively “enrol” users in other users.

This is outlined in the MoodleDocs… and is profiled in various articles and videos, including this great one by Julian. The issue, however is that it isn’t really possible to do this en masse, i.e. to make it automatic. Discussions such as that at http://moodle.org/mod/forum/discuss.php?d=70539 highlight some approaches, but they’re generally too hacky to use in production.

At Catalyst we recently completed a project for a corporate client in Australia & New Zealand where we needed to automate the process – with a specially crafted Moodle enrolment plugin. As part of that, Catalyst agreed to release the amazing work the developer, Penny Leach to the user contributed (“contrib”) area of Moodle: http://cvs.moodle.org/contrib/plugins/enrol/dbuserrel/

This is how I’ve gone about adding this capability to the Moodle sites at NBCS

Getting the plugin

There are (at least) three ways to get the plugin, and install it in /enrol/ :

  1. Download the zip and unpack so it’s in /enrol/dbuserrel
  2. Add to a CVS-managed site
  3. Transfer from CVS to Git and add as a submodule

Downloading as a zip

As (from what I could see) the plugin hasn’t been profiled in the Modules and Plugins database, there’s no direct link for it… but Moodle’s packaging scripts automatically build it – I guessed the URL at http://download.moodle.org/download.php/plugins19/enrol/dbuserrel.zip

You can grab it and unzip it… and away you go.

Managing with CVS

If you want to get it from CVS, you can, with (for the latest Moodle 1.9 version):

cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -r MOODLE_19_STABLE contrib

replacing SERVER with your local mirror. E.g.

cvs -z3 -d:pserver:anonymous@uk.cvs.moodle.org:/cvsroot/moodle co -r MOODLE_19_STABLE contrib

Tracking with Git

Adapting the process from Dan P’s Docs page http://docs.moodle.org/en/Development:Importing_Moodle_CVS_history_into_git

#!/bin/bash
CVSROOT=:pserver:anonymous@uk.cvs.moodle.org:/cvsroot/moodle
MODULE=contrib/plugins/enrol/dbuserrel
INSTALLDIR=dbuserrel
git-cvsimport -p x -v -k -o cvshead -d $CVSROOT -C $INSTALLDIR $MODULE &> cvsimport.log

Let’s get a branch to work on – we want to track the 1.9 stable branch. If you’ve already got a local branch (i.e. with your regular customisations, themes, etc) then you’ll of course want to branch from that for this test.

git checkout -b mdl19-parent-test origin/MOODLE_19_STABLE

We’ll add the submodule

git submodule add /path/to/my/contrib_module enrol/dbuserrel

git submodule init
git submodule update

git status

shows

new file:   .gitmodules
new file:   enrol/dbuserrel

let’s commit the changes to this branch

git commit -am "enrol/dbuserrel: added local git repo as submodule"

Updating to keep track of upstream changes is a matter of

  1. running our import script again (to do CVS > GIT)
  2. switching to our git branch and running
    git submodule update
    
The code is now in my repository, and ready to deploy with my moodle code. Hold on just a tick, and I’ll be back with another post on the user end of things – i.e. how to enable and configure it in the browser.
.