Note:

This site is no longer used and is in read-only mode. Instead please go to our new Moodle Developer Resource site.

Meta enrolment plugin with multiple courses selection

From MoodleDocs

GSOC 2015

Problem description

Current enrol_meta plugin provides functionality to automatically synchronise enrolments between two courses. See Course meta link. Teacher creates an instance of enroment method in the meta course and links it to one child course. Later cron job ensures that any enrolment change in the child course is pushed to the parent.

Unfortunately user interface is very inconvenient. The main problem is inability to bulk select courses and/or order courses on the Enrolment methods page. Plus it lacks important functionality to synchronise suspended/expired enrolments. See the number of highly voted issues MDL-27628, MDL-17929, MDL-32161, MDL-31451

The proposal is to re-write this enrolment plugin completely. One instance of the plugin should allow to link multiple child courses and additionally synchronise each of them with a group in the meta course. Ideally it should also allow to synchronise all courses in the category.

This project requires development of both user interface (JS) and backend (PHP).

Author: Mihir Thakkar
Mentor: Marina Glancy

Synopsis

The project is about improving Moodle's enrol_meta plugin and user interface by completely re-writing it. The current problems as described in the problem description, if solved, would improve the plugin to outperform all the previous versions of Moodle in terms of user-friendliness. The bulk enrolment feature and improved auto-synchronization of expired/suspended users will be implemented to save the time consumed for manual enrolments and unenrolments. Moreover, easy searching of courses will also be implemented which will greatly improve the experience for meta course users. As an optional project, the nesting of meta courses would be implemented.

Problems

Linking/Removing one or more courses in one operation not possible : As described in MDL-27628, Pre-2.0 it was possible to add many "child" courses in one operation. The revised (current) interface makes adding/removing multiple courses via meta linking very time intensive.

No search option to find courses by name : The current plugin has a drop-down by which we can select a course. The course list in the drop down is not sorted and there's no way to search for a course by name. It is evident from the discussion in MDL-32161, that if there are hundreds or thousands of courses, the plugin would be of no use.

Improper synchronization of enrolments : Currently, the meta course automatically enrols users from child course but lacks in an important functionality to automatically remove/unenrol the suspended/expired users from meta course.

Auto-create Groups in a Meta Course is required : It is a new feature which is voted by users. The current plugin doesn't allow to auto-create groups in meta course, from the child courses, and thus it is time consuming to manually create groups. A functionality by which users can select “create groups from child courses” and automatically populate groups in the meta course, is required, as can be seen in the highly voted issue MDL-17929.

Project Details and deliverables

Moodle's current enrol meta plugin provides the functionality of linking courses and automatically synchronize enrolments between them. The plugin is widely used by many organizations (including my college). The underlying concept of meta courses is a great solution to save time and synchronize courses in institutions where there are large number of courses and students.

A meta course comes into play when we need associations between different courses. The plugin makes it possible for one course, called a metacourse, to automatically bring in enrolments from other courses called child courses. The current enrol_meta lacks some functionalities and has inconvenient user interface. The project is to re-write it completely with improved functionalities. It describes the user-interface modifications as well as use of moodle APIs to improve the enrol_meta plugin.

Implementation Details

Initial phase of implementation process would be to study which parts of current plugin are appropriate and to include them as-it-is to the new plugin. Brief descriptions on implementation of new features are described below.

(1) Designing a user-interface for new enrol_meta plugin. In order to improve the user-interface, there needs to be a modified form for creating links, which will enable bulk enrolments and course search. Lets call that form, “enrol/meta/linkmultiple_form.php” which will replace old “enrol/meta/addinstance_form.php”. For multiple select functionality, a backend needs to be implemented in “enrol/meta/linkmultiple.php” as replacement of “enrol/meta/addinstance.php”, which will fetch the list of courses selected and create a link between those child courses and the associated meta course.

(2) Adding a search box in the enrolments page. This component has two solutions. Basically, we need a list of courses that matches a search. First, a search box needs to be present in the enrolment page, as shown in the figure. Then a list of courses matching that search string should be displayed in the corresponding area.

Searching courses can be implemented using Google AJAX search APIs. However, this method is a best bet when it is used to send small payloads. But as per discussions, it turns out that we need a fast searching method in case of large number of courses. Another limitations of this are that the search can be done by course name and results are not sorted by name or start-date.

Another way to do this can be using “get_courses_search($searchterms, $sort, $page, $recordsperpage, &$totalcount)”. Moodle's course search project, developed in GSoC 2013 is implemented with a third party search engine API, Apache Solr. As per my study, this is the most apt solution because of the following reasons:

- It provides a functionality to search courses by idnumber, shortname, fullname or summary. - The course search has auto-complete, spell checking, keyword matching and many other capabilities. - Sorting results by relevance, startdate or shortname. This will outperform the AJAX search method. And moreover, why to re-invent the things which are already up working and available.

(3) Bulk enrolments and bulk removal will be implemented as part of this project. This component requires modifying the enrolments form to use two lists for “Linked courses” and “Not linked courses” along with “Add” and “Remove” button, instead of a drop down where only one course could be linked. When a user wants to select more than one course, user can “Ctrl+Click” on all courses that he wants to link.

Implementation requires extending the functionality of creating links and synchronizing enrolments for all courses selected in the list instead of just one course. A similar form is available for manual enrolments. Implementation of bulk select courses will be similar to manual enrolments bulk select form. The base class, “enrol_bulk_enrolment_change_form” inherited from “moodle_forms” provides easy construction of forms for bulk operations. For multiple selection, say “enrol/meta/manage.js” will need to be created to implement the course selector. The difference in this form will be the event handlers' tasks. Event handlers will be included in the “enrol/meta/classes/observer.php”. Event handlers which gets triggered by enrolments events will be modified so as to enrol or remove users from all the “selected” courses. Users from all the selected courses will be retrieved from the database and enrolled in the meta course on user_enrol event. Similarly, user_unenrol event will cause the handler to remove users from meta course. A major difference in the new proposed plugin is that there will be just one instance of plugin to create links to all selected courses in the list, facilitated by a list which allows multiple selection.

(4) Improved synchronization. This component deals with solving the problem of lacking synchronization of expired/suspended students.

In enrol/meta/cli/sync.php a CLI file is used for immediate enrolments when the link between a meta course and child course is created. Later on, in case of updating enrolments, the automatic enrolments in a meta course are done through a cron job. The enrol/meta/lib/php has a cron() method and the child enrolments would be enrolled in meta course, when cron method is invoked by standard Moodle cron. The time interval between cron jobs is defined in enrol/meta/version.php, which is 1 hour in the latest version.

As synchronization of enrolment works well in the current plugin, same handlers can be used in the new plugin as well. In order to implement automatic removal of expired/suspended users, the enrol meta event observer should be able to handle the event of “user_expired” or “user_suspended” and unenroll/remove that user from the course. A new event handler will be defined in “enrol/meta/classes/observer.php” to look for the events to un-enroll the user from a course when the user's enrolment is expired or when the user is suspended.

(5) Allow creating groups in meta course based on child course. The groups in meta course should not be confused with Cohorts which are a group of users treated as a single entity. The meta course groups find its use to differentiate their enrolment in meta course based on the child course enrolments.

To implement this feature we need an event handler in “enrol/meta/classes/observer.php” triggered when a course is linked. A function say “get_child_courses” shall return the list of all courses by course id. In the event handler, a function will be defined which will iterate through all the child courses and check all the users of each child course. In the handler, a new meta group will be created ( $metagroup = new \stdClass() ) for each child course. The users will be added to the group on enrolment event. Note, that if there are groups already created in child course, running CLI script to synchronize groups would be needed to populate the groups in meta course. Implementation of this can be done simply by adding a conditional statement before auto-creation. A little improvement can be done by enabling or disabling this event handler by a configurable settings option in form of check box. Value of enable/disable option will decide whether to automatically create the groups or not.

After importing some portions of the current plugin and adding new features to the new plugin, the last phase of implementation will be writing unit tests and behat tests for all new functions and features included. Moodle uses PHPUnit for unit testing and Behat tests are behavioral tests. Writing full coverage tests is an important part of the implementation phase in order to reduce bugs as much as possible.

Deliverables: Apart from current features, the following improved functionalities will be present in the new enrol_meta plugin: (1) New user interface design. (2) Bulk enrolment and bulk removal. (3) Search box for searching courses from the list. (4) Improved synchronization of expired/suspended users. (5) Auto-create group in meta course based on child course.

Project Timeline

Community Bonding Period (April 27 – May 25) :

- Further discuss the project and get a deeper insight.

- Create a specification for the project in Moodle Docs and post in forum asking for feedback.

- Read and understand plugin development documentation.

- Create an issue for project in the Tracker. Start to creating sub-tasks pertaining to my project.

- Set up the development and testing environment.


( Interim Period )


Week 1, 2 (25 May to 7 June) :

- Start Coding!

- Import fundamental features of current enrol_meta plugin to new one which will remain consistent.

- Design a User Interface for bulk enrolments as discussed with the mentor during community bonding period.

- Implement multiple selection of courses for current master, similar to Moodle 1.9 (because 1.9 UI is desired by most of the users.)

Week 3, 4 (8 June to 21 June) :

- Read documentation and Study Moodle's course search.

- Create and implement a search box beneath the course list.

- Display proper search results in the course lists.

Week 5 (22 June to 28 June) :

- Testing the two features of searching and selecting multiple courses.

- Code scrubbing as much as possible to avoid any bugs.

- Bulk selection and search ready to be merged with master.

- Write a documentation of work done till now.


( Mid Term Evaluation )


Submit code of completed tasks along with documentation.


( Interim Period )


Week 6, 7, 8 (1 July to 19 July):

- Study auto enrol synchronization in current plugin.

- Implement an auto-unenroll cron job.

- Debugging and testing of the feature.

- Study manual group creation in meta courses.

Week 9, 10, 11 (20 July to 9 August):

- Implement automatic creation of a group of all users of a particular course.

- Implement event handler to auto-create meta group based on child courses.

- Add configurable settings to enable/disable auto-create groups.

Week 12 (10 August to 16 August):

- Test the implemented features.

- Write documentation for the work done till now.

- Debug and try to reduce code complexity.

- Start to implement extra feature (if time permits).

Brush-Up Week (17 August to 21 August)

- Blog post summarizing the GSoC project.

- Finalize tracker issue with the download link to the final code.

- Write a user documentation for my project in Moodle Docs.


( Pencils Down )


- Final Release.

See also