Moodle parent portal implementation

Moodle does not offer a parent portal. This maybe necessary in K-12 schools where confidential communications with the parents maybe required on a separate channel form the normal one that the student also has access to.

There is a backdoor way to implementing a Moodle parent portal. This consists of several steps as outlined in Moodle documentation for Parent role. There are some limitations to this implementation but nevertheless it gives parents a way to see what the child is doing including access to its messages and grades.

The main problem with this approach is that Moodle does not provide for bulk parent enrollment (and unenrollment). We describe two such methods of bulk enrollment using Moodle plugins:

enrol_csvparentrole

The moodle-enrol_csvparentrole plugin for Moodle synchronizes user role assignments relative to each other using a CSV file and it works as follows (Click here for detailed documentation):

  1. Install: You need to install the plugin by cloning a repository from github using the above link or downloading the zip directory and uploading into a directory called csvparentrole in /your-moodle-path/enrol directory. Installation instructions can also be found in the readme file in the github link above. Now go to notifications and complete the plugin discovery and configuration settings.
  2. Activate: Go to site admin->plugins->enrollments->manage enrol plugins and activate this plugin.
  3. Create your CSV file: Create your CSV file. The 1st row should be the heading row. After this your user relative role assignments should be one per line. Each line should have 3 entries: subject user ID, object user ID, and desired role to be assigned. Subject can be for example: parent, mentor and object is usually student. The headings can be anything as long as they are correctly entered into the plugins settings so it knows how to identify data. The user ID’s can be anything unique that Moodle keeps such as: username, email, id, etc. We use username as default. The column containing the role to be assigned should also be specified in the plugin settings and it defaults to desiredrole. Here is an example:
    1. parentusername,studentusername,desiredrole
    2. john.smith,jane.smith,parent
    3. john.avasarala,espirit.avasarala,parent
  4. Preexisting users and roles: Make sure that all users pre-exist in Moodle already. Also ensure that the desired role to be assigned (parent for example) is already existing in Moodle.
  5. Execute sync.php CLI command: In your moodle server:
    1. cd /your-moodle-docroot/enrol/csvparentrole/cli
    2. run the following php command: php sync.php -v -s The -v option is for verbose output and -s option is for simulation only.  For real, do not use the -s option.
    3. Optionally you can setup a cron job as described in the readme documentation.

A neat feature of this plugin is that the CSV file can even be on Google Drive as long as it is published to web as a CSV file (which means that anyone with link can see it as a CSV file). Make sure you follow Google instructions for publishing CSV file properly or your CSV google file won’t be properly read and the PHP program may go into a loop.

enrol_dbuserrel

Unfortunately, this officially maintained plugin in the Moodle plugins directory is outdated and does not work for Moodle 3.5. I modified this plugin to enable it to work with Moodle 3.5 and this code is located at GitHub.

The plugin works as follows: You first need to a create and populate a table in an external (outside of Moodle) database with the required relationship. This is read into Moodle by this plugin and the enrollment established by a sync script. I will explain all this in detail below. For this implementation your students and their parent(s) need to be authenticated users in Moodle and the role “parent” needs to exist as explained in the Moodle documentation for parent role.

Download the modified plugin from GitHib and follow the installation instructions in the README.txt  After discovery and installation configure the plugin as follows:

Go to Site–>plugins–>Enrollments and click on settings for plugin DB User role assignment.

Settings for External database connection

I only tested this plugin using MYSQL database. It is important to choose mysqli (default) as the Database type in the configuration above.

Input your database settings. This database is separate from the Moodle database although it can be on the same server. I will show you how to create this table on a database using phpMyAdmin and a CSV file later on.

Database field mapping

This plugin terminology has subject for parent and object for student. What this is saying is that we will be providing username for our parent and student, we will be providing the role shortname (such as parent) and in the remote database our table will have fields: parentname, studentname, desiredrole under which we should have our data located appropriately.

(You can use this plugin for mapping mentor mentee relationships too in a similar fashion.)

This is pretty much it for the settings to use the plugin.

Table structure in remote database

Using say phpMyAdmin you can create the desired table called mdl_parents (as specified in the settings above) and create the table structure as shown above. We have added an id field that is auto-incrementing and serves as a unique primary key for ease of record manipulation. This field is not used by our plugin.  Now you can create the records you need directly or if you have a lot of records it is best to do this by a CSV file upload as shown next.

Setting up the CSV file for upload to database using phpmyadmin

Setup your CSV file as shown below:

The 1st column corresponds to the id, the 2nd to the parent’s username (as in Moodle), the 3rd column contains the student’s username (as in Moodle) and finally the shortname of the role mapping desired which is parent. So, here, we are saying that (sritoni4 and sritoni5) are parents of sritoni2 and sritoni3.

Read the CSV file into the table in the database using phpMyAdmin

Click on Import in phpMyAdmin and then click on choose File. Select your CSV file from the file picker. Once the file is uploaded the options automatically change to CSV and the format setup is auto filled. Just click GO at the bottom of the screen.

The imported data can be seen in your table as shown in picture below:

Now we have our remote database prepared with our data and ready for running the CLI script for synchronization.

Sync using CLI script

This is the final step wherein we have to run a CLI (Command Line Interface) PHP script to so the parent enrollment. Later on I will show how this can be automatically run using CRON. For now it is good to know how to run this CLI script on demand.

From your Linux terminal type the following command:

/path to your php executable  /path to your moodle/enrol/dbuserrel/cli/sync.php

This will perform the synchronization. In Moodle you can go to the concerned student and check that they have associated parents.

Setting up CRON for the Sync

You can trigger this script to run automatically on desired schedule. For example,

*/1 * * * * /usr/bin/php /var/www/html/moodle/enrol/dbuserrel/cli/sync.php > /dev/null 2>&1/cli/sync.php

The CRON should be run as user www-data. So edit the cron for user www-data using the command with sudo:

sudo crontab -u www-data -e

and insert the cron task with schedule and paths suitably modified to suit your case.

Posted in Configurable Reports, moodle, parent portal and tagged , , , .

4 Comments

  1. Thanks for updating this plugin. I paid for a plugin to be updated called block tutorlink and was in the process of having it updated by someone else when I saw your plugin was updated today.
    https://moodle.org/plugins/pluginversions.php?plugin=block_tutorlink

    One feature I liked about my previous plugin was the ability to upload a csv file right to moodle as we can with adding uploading new users. I see how you use csv to upload to a database that syncs with moodle through cron/cli script.

    My question is if you think it would be possible to skip the steps of creating an external database and directly upload a csv file as was possible from the plugin block tutorlink I used before? That would be ideal.
    If not, how can I cut out the step of logging into my server and uploading a csv file – can I share the csv file from say google or an ftp site and have your cli script pull it from there? if so can you please help me with that process with steps? Thanks again for your hard work!

  2. Hello,
    In the writeup I describe 2 plugins. The 1st one called csvenrol enroles the parent/mentor role directly from a CSV file. The 2nd plugin called dbuserrel is the one that synchronizes to an external database. I just show a useful way of creating the external database also using a CSV. The 2 plugins accomplish the same function but in different ways. Most people would prefer the direct CSV upload of user context roles I would think.

Comments are closed.