Categories
Learn enrolments

External database enrolment

CONTENTS

 [hide

Using an external database to control enrolments

You may use a external database (of nearly any kind) to control your enrolments. It is assumed your external database contains a field containing a course ID, a field containing a user ID, and optionally a field containing a role. These are compared against fields that you choose in the local course, user tables, and role tables.

The following are the supported data sources, but note that you will need to have to compiled PHP with the appropriate options or through ODBC.

  • access
  • ado
  • mssql
  • borland_ibase
  • csv
  • db2
  • fbsql
  • firebird
  • ibase
  • informix72
  • informix
  • mysql (deprecated, please use mysqli instead)
  • mysqli
  • mysqlt
  • oci805
  • oci8
  • oci8po
  • odbc
  • odbc_mssql
  • odbc_oracle
  • oracle
  • postgres64
  • postgres7
  • postgres
  • proxy
  • sqlanywhere
  • sybase
  • vfp

Enrolment and unenrolment

External database enrolment happens at the moment when a user logs into Moodle. The plugin will attempt to automatically enrol the student in all their courses according to the data in the external database and, optionally, create empty courses where they do not already exist. To check if it is working, you can log in as a student and then check that their list of courses is as you would expect.

The process also unenrols users from courses if they are no longer in the database. User records are marked according to their original enrolment method. Therefore the external database plugin can only unenrol users who were enroled by the plugin in the first place.

Hidden courses

Courses that are set to “Course is not available to students” can be ignored for enrolment purposes by setting the “enrol_db_ignorehiddencourse” to yes.

Enrolment and roles

The “enrol_database | defaultrole” setting in the plugin settings page specifies the role that the user will take when they are added to the course. The default setting will set them to the course default setting (initially “student”). However, you can specify a field in the external table (specified in the “enrol_database | remoterolefield” setting) that contains the short name or id for the user’s role. This could, for example, be used to enrol both students and teachers into courses using a suitably configured database.

Unenrolment

The External unenrol action (“enrol_database | unenrolaction”) setting in the plugin settings page defines what action should be taken when a user enrolment disappears from external enrolment source. Each setting does the following:

  1. “Unenrol user from course” When the user disappears from the external source, the enrolment is completely removed and all the roles removed. This means some user data and settings are purged from course during course unenrolment (that usually include grades, activity attempts, etc.)
  2. “Keep user enrolled” When the user disappears from the external source, the enrolment is kept as is, and the user is still able to enter the course and perform activities, access resources, etc. It’s a “do nothing” option.
  3. “Disable course enrolment” When the user disappears from the external source, user enrolment is suspended (the user can’t access the course, but user data and settings are kept), and roles are kept as is. You might use this because in some cases the user needs a role with some capability to be visible in UI – such has in gradebook, assignments, etc.
  4. “Disable course enrolment and remove roles” When the user disappears from the external source, the enrolment is suspended and roles assigned by enrol instance are removed. Please note that user may “disappear” from gradebook and other areas.

Creating courses

Optionally courses that do not exist in the Moodle site can be created.

You can additionally specify the Category into which the new course will be placed, in the New course category id field. The data in this field must be the id of a currently existing category; it will not create a new category. The id number is number assigned by Moodle in the database when the category is created (e.g. mdl_course_categories.id).

  • Do not confuse this category id with the new custom category id number field that you can manually assign to a category. (See Trackers http://tracker.moodle.org/browse/MDL-28518 and http://tracker.moodle.org/browse/MDL-31845).
  • Leaving the category id data empty means that a course will be assigned to the default category.
  • If you assign data to categories that do not exist already in Moodle, the courses will not be created.

Default new course category is the category to which courses will be assigned and created in, unless you set up and so indicate in the data field of the “New course category id field.”

You may also specify a New course template: a “template” course from which the new course will be copied. The data for this field should be the shortname of the template course.

Synchronising external database enrolments (scheduled task and deprecated script)

A scheduled task called “Synchronise external database enrolments task” synchronises all user enrolments at once – both adding and removing user enrolments (and creating courses if specified) (MDL-59986).

Note that you need to make sure all the users present in the external enrolments are already created in Moodle, because users not existing in Moodle can’t be enrolled in a course. If you are using external authentication plugins (db, ldap, etc.) you can use the scripts provided by those plugins to synchronise your users before running this script.

A deprecated script is also provided that can do this task if the scheduled task is disabled (if the scheduled task is enabled the script won’t do anything). The script is called sync.php and is found in the enrol/database/cli folder.

This script is meant to be called from a system cronjob to sync moodle enrolments with enrolments in the external database.

Example cron entry

   # 5 minutes past 4am
   5 4 * * * /usr/bin/php -c /path/to/php.ini /path/to/moodle/enrol/database/cli/sync.php

Notes:

  • If you have a large number of enrolments, you may want to raise the memory limits by passing -d memory_limit=256M
  • For debugging and better logging, you are encouraged to use in the command line: -d log_errors=1 -d error_reporting=E_ALL -d display_errors=0 -d html_errors=0
  • This only works for users that already exist in your Moodle site (see comment above)

Setting up enrolment sync (How to)

You will need to perform (as a minimum) the following steps to enable external database enrolment – only a single table is required in the database which contains a record for every user/course combination. If the table is large it is a good idea to make sure appropriate indexes have been created:

  • Use an existing database or create a new one. Use an existing table or create a new one with the following minimum fields.
    1. A unique course identifier to match one of the following fields.
      • the “idnumber” field in Moodle’s course table (varchar 100), which is manually specified as the “Course ID number” when editing a course’s settings
      • the “shortname” field in Moodle’s course table (varchar 255), which is manually specified as the “Course short name” when editing a course’s settings
      • the “id” field in Moodle’s course table (int 10), which is based on course creation order
    2. A unique user identifier to match one of the following fields.
      • the “idnumber” field in Moodle’s user table (varchar 255), which is manually specified as the “ID number” when editing a user’s profile
      • the “username” field in Moodle’s user table (varchar 100), which is manually specified as the “Username” when editing a user’s profile
      • the “email” field in Moodle’s user table (varchar 100), which is manually specified as the “Email address” when editing a user’s profile
      • the “id” field in Moodle’s user table (int 10), which is based on user creation order
    3. (optional) A unique role identifier to match one of the following fields.
      • the “shortname” field in Moodle’s role table (varchar 100), for example editingteacher, coursecreator, student, …
      • the “name” field in Moodle’s role table (varchar 255), for example Teacher, Course creator, Student, …
      • the “id” field in Moodle’s role table (int 10), which is based on initial installation and new role creation order
  • Populate the database table. Each user/course combination to have a record in the table.
  • In Moodle, go to Site administration > Plugins > Enrolments > Manage enrol plugins, find External Database in the list, enable it (click the closed-eye icon) and click Settings.
  • In the top panel, select the database type (make sure you have the necessary configuration in PHP for that type) and then supply the information to connect to the database.
  • The middle panel creates the mapping between Moodle and the external database. The first three settings are for the local (Moodle) field names and the last three for the remote (external database) settings. They are in the same order.
    • enrol_localcoursefield / enrol_remotecoursefield – in Moodle the name of the field in the course settings the uniquely identifies the course (e.g., idnumber). In the external database the name of the matching field.
    • enrol_localuserfield / enrol_remoteuserfield – in Moodle the name of the field in the user profile that uniquely identified the user (e.g., idnumber). In the external database the name of the matching field.
    • enrol_db_localrolefield / enrol_db_remoterolefield – (optional) in Moodle the name of the field in the role edit page the uniquely identifies the role (e.g., shortname). In the external database the name of the matching field.
  • The Roles panel specifies the role that the user will get in the course if their role is not specified in the external database.
  • A new optional field enrol_database | remoteotheruserfield allows those with the role “Other users” to be added but not to be included as course participants.
  • The final panel enables auto creation of courses.
  • Save changes, and then tick the box to enable external database enrolment.

Field Mapping Example:

Choose your fields from the Moodle database:

  • enrol_localcoursefield: A course identifier from mdl_course, e.g. “idnumber”
  • enrol_localuserfield: A user identifier from mdl_user, e.g. “idnumber”
  • enrol_localrolefield: (optional) A role identifier from mdl_role, e.g. “shortname”

Create a view in your external database which matches the chosen field values from Moodle:

  • enrol_remotecoursefield: A matching course identifier from your external database table, e.g. “course_number”
  • enrol_remoteuserfield: A matching user identifier from your external database table, e.g. “userid”
  • enrol_remoterolefield: (optional) A matching role identifier from your external database table, e.g. “role_name”

Potential gotchas

  • It almost goes without saying that the integrity of the external database is important. If data is missing from the database then there is a potential for users being unenrolled from some or all of their courses. The unenrollment process will remove them from any group assignments and also poll each module type to give the module the option of removing that user’s data if appropriate (for example, however, forum posts are never deleted). It is therefore prudent that you take the utmost care to ensure that the data in the external database is correct at all times.
  • Minor Security Issue Consider that if the ID number field you use to identify your students is editable by the students (in their profile), then there is a potential for them changing this to the id of another valid student and gaining access to resources that they should not. (However, they will still appear as themselves, they cannot impersonate the other user or otherwise gain access to their resources.) To prevent this and similar issues, you can lock the ID number as well as other fields so the user can not change them. Do this in the Data mapping section of Site administration > Plugins > Authentication > External database.

Errors and diagnostics

The plugin produces a number of diagnostic messages and/or errors which are recorded to the PHP error log (as defined in the php.ini file). In addition messages about courses that are in the database for the user but that do not exist in the Moodle site will only be produced if debugging is set to ALL or DEVELOPER.

You can get detailed progress information by executing the sync script with -v parameter:

 php /path/to/moodle/enrol/database/cli/sync.php -v

See also

Categories
Learn enrolments

Guest access

The Guest access facility allows users with the Guest role to view the contents of a course. This might be used, for example, if a Moodle site serves as a website where certain courses contain publicly available information, or else with a commercial Moodle site where courses with guest access can offers a “taster” of the kind of courses which may be purchased. (Note that the guest cannot participate in any activities; they can only view content.)

CONTENTS

 [hide

Course settings for guest access

How to allow guests into courses

  1. With the Boost theme, from the navigation drawer on the left, click ‘Participants’, and then from the gear menu on the right, click ‘Enrolment method> Guest access’. With other themes, click Administration > Course administration > Users > Enrolment methods and then Guest access.
  2. Enable guest access by clicking on the “eye” icon or by choosing it in the ‘Add method’ dropdown menu.
  3. If you wish to set a password, then click the configure icon and type in your password here.

Admin settings for guest access

How to allow guests onto your Moodle site

  • In Administration > Site administration > Plugins > Enrolments > Manage enrol plugins,ensure Guest access is enabled (has its eye open.) This enables Guest access.
  • In Administration > Site administration > Plugins > Authentication > Manage authentication set the Guest login button to Show if you want the button on the Front page.
  • Also Guest accounts can be logged – check the Administration> Site administration > Plugins > Logging > Log guest access setting
  • A site policy for guests may be set in Site administration > Security > Site policies. Guests then have to agree to the site policy before accessing a course with guest access.

Default settings for guest access

  • Clicking on Administration > Site administration > Plugins > Enrolments > Guest access brings up the screen where admin can set defaults for guest access in courses.
    • Clicking the ‘Advanced’ button next to ‘Allow guest access’ will hide this setting in a course and will instead display a ‘Show more’ link to click on to access the setting.
    • Guest access can be turned on by default in all new courses and you can also:
    • require each course with guest access to have a password for guests. (Note: this can confuse teachers who are not aware of the requirement.)
    • use or ignore your Moodle’s standard password policy for guest access passwords
    • offer if needed the first letter of the password as a hint.

Auto-login guests

  • In Administration > Site administration > Users > Permissions > User policies, you can tick the box so that visitors are automatically logged in as guests when accessing a course with guest access (i.e. they don’t have to click the “login as guest button”.
  • In Administration > Site administration > Plugins > Authentication > Manage Authentication, you must have “Guest login button” set to “Show”.
  • In Administration > Site administration > Security > Site policies you can check “Open to Google” setting so that the Google search robot will be allowed to enter your site as a Guest. In addition, people coming in to your site via a Google search will automatically be logged in as a Guest.

See also

Categories
Learn enrolments

Course meta link

CONTENTS

 [hide

About the Course meta link

The Course meta link makes it possible for all users enrolled in one course to be automatically enrolled in one or more other courses. The Course meta link plugin needs to be enabled both on the site level by the site admin and has to be enabled within the course.

Course settings for Course meta link

  • In a course, go to Administration > Course administration > Users > Enrolment methods.
  • Click the dropdown menu under the enrolment methods and select ‘Course meta link’.
enrolmentmethods29c.png
  • In the screen that comes up next, either type in a search term to find your course, or select from the dropdown box the course or courses you wish to bring enrolments from, and then click ‘Add method’:

Several courses may be selected at once

  • For each linked course, the users may be added to an existing group in the new course, or a new group may be created for them. (Groups from the linked courses are not synced to groups in the new courses. All users will be added to one group when the link is made.)

Note: A teacher in a course will only be able to choose from courses they are teachers in elsewhere.

  • The users from the source (child) course will now be enrolled in the current course – see the numbers in the screenshot below:
NFCoursemetalinkusers.png
  • When new users are enrolled to the source (child) course, they will be automatically brought into the current target (meta)course.

Site settings for Course meta link

The Course meta link plugin may be enabled or disabled throughout the site in Administration > Site administration > Plugins > Enrolments > Manage enrol plugins.

The page Administration > Site administration > Plugins > Enrolments > Course meta link contains options for defaults that admin can set. (It can be also be accessed by clicking the Settings link on on the course meta link section of Administration > Site administration > Plugins > Enrolments > Manage enrol plugins)

By default all role assignments from child courses are synchronised to meta courses. However, the “Roles that are not synchronised to metacourses” setting enables administrators to exclude particular roles.

Course meta link capabilities

Enabling teachers to add meta links

An administrator can enable teachers to add course meta links as follows:

  • Go to Site Administration > Users > Permissions > Define Roles
  • Select the Teacher Role and click on the Edit button
  • Scroll down to Course Meta Link as shown in the images below:
The default setting is “Not Set”
When the Edit button is clicked, the panel changes to “Allow” and a checkbox
Change to “Allow” by a click on the checkbox.
  • Scroll to the bottom of the page to save your changes.

Examples of meta-linked courses

Created – a child course and a meta course.Associating one child course and one meta course.

Examples: one “child” course (a course linked to a meta course) can be associated with many meta courses. Or one meta course can have many child courses associated with it. Both the child courses (non-meta courses) and the meta courses are independent and can be recycled many times, that is, each can be associated with many of the other.

2 child courses and a meta course.1 child course and 2 meta courses.3 child courses and 2 meta courses.

There is one limitation: you cannot ‘nest’ metacourses. In other words, if you have child course A linked to meta course B, and you then link B as a child course to meta course C, a student enrolled in A will be added to B, but not to C. In this situation, you would need to add a meta link directly between A and C instead of trying to nest them. (Another option might be to use Cohorts.)

See also

Some known issues:

  • MDL-34938 – Important Open Issue: Enrolment expiration date settings in child course do not properly unenrol students from the Meta-course – (old: FIXED as of Moodle 2.9)
  • MDL-27628 – A workaround in the tracker for adding more than one course at a time (old: FIXED as of Moodle 3.1)

How to use:

Categories
Learn enrolments

Cohort sync

CONTENTS

 [hide

About cohort sync

Cohort sync is for automatically enrolling members of a cohort in a course. If a user is added or removed from the cohort, they are automatically enrolled or unenrolled respectively. In other words, cohort sync synchronises cohort membership with course enrolment.

Enabling cohort sync

To use cohort sync, it must be enabled by an administrator in Site administration > Plugins > Enrolments > Manage enrol plugins.

Cohort themes

If cohort themes have been enabled in the Theme settings page of Site administration, then a specific cohort theme may be selected when creating or editing the cohort:

Cohorttheme1.png
Categories
Learn enrolments

Enrolment plugins

Moodle provides a number of ways of managing course enrolment, called enrolment plugins.

Manageenrolplugins1.png
Setting the enrolment method(s)
To set an enrolment method:
Click on Administration > Site administration > Plugins > Enrolments > Manage enrol plugins.
Click on the enable checkboxes opposite your chosen enrolment plugin(s). If you wish, you may choose more than one enrolment method. For example if you have some courses which students must pay for and some free courses, you can use PayPal and self enrolment.
Click the “Save changes” button.
Click the settings link opposite the enrolment plugin(s) you have chosen.
Configure the required settings and click the “Save changes” button.
Repeat until you have edited all the plugins you have enabled.
The order in which enrolment plugins are applied can be set. This may be important for some plugins. It also affects the order of enrolment options on the course enrol page.
Enrolment capabilities
Category enrolments:
Role assignments synchronised to course enrolment
Cohort sync:
Configure cohort instances
Guest access:
Configure guest access instances
LDAP enrolments:
Manage LDAP enrol instances
Manual enrolments:
Configure manual enrol instances
Enrol users
Manage user enrolments
Unenrol users from the course
Unenrol self from the course
Course meta link:
Configure meta enrol instances
Select course as meta linked
PayPal:
Configure PayPal enrol instances
Manage enrolled users
Unenrol users from course
Unenrol self from the course
Self enrolment:
Configure self enrol instances
Manage enrolled users
Unenrol users from course
Unenrol self from the course
Course:
Configure enrol instances in courses
Review course enrolments
See also
Unenrolment
Enrolment FAQ
Using Moodle Enrolment Plugins forum
Categories
Learn enrolments

Category enrolments

About category enrolments

The category enrolments plugin allows users to be enrolled in all courses within a category. The plugin will synchronise any role assignments at category context with the capability enrol/category:synchronised set to allow.

Warning: The use of the category enrolments plugin may cause performance problems. If so, it is recommended that you use Cohort sync instead, though this will require a cohort sync enrolment method to be added to each course in the category.

Enabling category enrolments

To use category enrolments, it must be enabled by an administrator in ‘Manage enrol plugins’ in the Site administration.

Enroling users to a category

  • Go to the category into which you wish to enrol users. Note: You need to have category rights (manager or administrator)
  • In the Administration block,click Assign roles. The list of possible roles you can assign will appear:
Categoryassign.png
Categories
Learn enrolments

Self enrolment

Note: If you want your learners to create accounts on your site and have access to your courses, then you first need to enable Email-based self registration so they can create accounts, and then enable self enrolment within your course(s) so they can enrol. These are two separate steps.

Self enrolment is the method whereby users can choose to enrol themselves into a course, either immediately by clicking “\enrol me in this course” or by typing in an enrolment key they have been given. The enrolment plugin needs to be enabled by the site admin in Enrolment plugins and has to be enabled within the course. The manual enrolment plugin has to be enabled in the same course as well.

Manual enrolment

The manual enrolments plugin allows users to be enrolled manually via a link in the course administration settings. The plugin has to be enabled by the site administrator (see Enrolment plugins) and should normally be enabled as certain other enrolment plugins, such as self enrolment, require it.

Categories
Learn enrolments

Enrolments

Enrolment, or ‘enrollment’, is the process of marking users as participants in the course, in other words assigning them a role such as student or teacher.

Categories
Learn users

Add users

Users may be added to a Moodle site in a number of ways. When user accounts are created on a site, the process is called Authentication and when users join a course, the process is called Enrolment. Normally only the administrator is allowed to add users to a site. Course teachers are only able to add students to their course and do not have permission to add users to the site. (If you’re a teacher looking for instructions on how to add students to your course, read Add students.)

Users sign up to the site themselves

If you wish people to create their own accounts on your site, you must enable Email-based self-registration. This features is disabled by default because of the possibility of spammers accessing your site.