Time for action - automating enrollment with external database plugin

A more robust method for automating enrollments is the external database enrollment plugin. The external database enrollment plugin is similar to the external database authentication plugin, which we discussed earlier in this chapter. Moodle can use a table in an external database to assign users to courses with the proper role. You or your IT department can create the table from a number of sources, including HR, portal, or e-commerce systems. The table can be relatively simple, with just a few columns with the necessary data.

Using a database table has a few advantages over using a flat file. While the flat file is easy to create, database enrollment is usually easier to manage. Adding or removing a user can be done with a simple SQL command, instead of editing a text file. The database plugin can also create new courses if the course in the enrollment table doesn't already exist in Moodle.

To configure the database plugin:

  1. Log in to Moodle as a system administrator.
  2. In the Site Administration menu, select Plugins and then select Enrollments.
  3. On the Manage Enroll Plugins, click on the eye icon in the Enable column of the External Database row to set the eye to "open".
  4. Open the plugin settings page by clicking on the Settings link in the External Database row. You will now be on the settings page for the external database enrollment plugin. See the following figure.
    Time for action - automating enrollment with external database plugin
  5. We will begin configuring the plugin by telling Moodle how to connect to the external database. Begin by selecting the database type from the Database driver drop-down menu.
  6. In the Database Host field, enter the URL for the database server hosting your external database.
  7. In the Database User field, enter the username for the user Moodle should use to log in to your external database. In the Database Password field, enter the password for this user.
  8. The Database Encoding field should be set to the string encoding scheme for the database. Most modern databases use utf-8, so you can probably leave this at the default.
  9. Some database systems need a special command to set up the encoding for the communication between Moodle and the database. If your system needs a command, enter the SQL statement in the Database setup command. If you don't know what this is, consult your IT department.
  10. Oracle, MS SQL, and a few other database systems use Sybase quote escaping for handling quotes in strings (like apostrophes in names). If you are using one of these systems, check the Use sybase quotes box, otherwise leave it unchecked.
  11. The Debug ADOdb option will print debug messages to help you troubleshoot your connection to the external database. Do not leave this on after you have finished debugging the connection.
  12. Now that we have Moodle talking to the external database, we need to tell Moodle how to use the data in the external database. The Local Field Mapping section lets us select which Moodle fields we will use to match up the database to Moodle's internal systems. In each of the three settings below, we will set the field which Moodle will use to match the reference to a user, course, or role in the external database to an entity in Moodle's database. The system creating the external database will need to have access to the data we plan to use as the key. In most instances, the ID Number can be used if the external system is also used for creating users and courses.
  13. The Local Course Field drop-down menu determines which field in the course settings we will use as the key to find the course in which the user should be enrolled. The ID option will match the data in your database to Moodle's internal ID number for the course (you can find this number by navigating to a course and looking at the URL. At the end of the URL, you will see course/view.php?id=<some number>. The number at the end of the string is Moodle's internal course ID for identifying the course). The ID Number option is the ID Number stored in the ID Number field in the course settings. This is a much more convenient field to use as you can set it when you create the course and don't have to rely on Moodle's internal ID number. As this is the default, you should probably not change it unless you have a good reason. The final option is to use the Course Short Name as found in the course settings page. The short name is not guaranteed to be unique, so unless you have good controls as part of the course creation process, this may not be the best option.
  14. The options for matching up users in the Local user field are similar to the Local course field. ID is the internal Moodle id number for the user. This information will be difficult for an external system to extract from Moodle. The ID Number, again the default, is probably the best choice, as you can add the ID Number when the user is created. The user's email is another useful key to use as Moodle requires each user to have a unique e-mail address. Of course, your external database system will need to have the same e-mail address for the user as Moodle. The final option, Username, will use the user's login to match users.
  15. When a user is enrolled in a course, we need to give them a role. The options for the key (using which the external database can tell Moodle which role the user should have) include—ID, shortname and fullname. The ID number is the number of the role. You can find the ID number by going to the role definition page and checking the URL. At the end of the URL string, you will see roleid=<some number>. The number at the end is the role ID. The role shortname and the role fullname both appear on the role definition page. Usually, the shortname is the best option as it tends to contain fewer special characters and it's easier to have a unique shortname.
  16. The Remote Enrollment Sync section tells Moodle how to match up the data in the external table to the internal data we specified in the Local Field Mapping section. Start by entering the name of the table containing the enrollment information (in the remote database), in the Remote user enrollment table field.
  17. The Remote course field tells Moodle which column the external database uses to store the course key.
  18. In the Remote user field, set the external database field where the user key is stored.
  19. The Remote role field determines which field Moodle will check for the role the user should have in the course.
  20. If your table doesn't always specify a role, set the Default role to the role you want users to have, if there is no other role specified.
  21. You will usually leave the Ignore hidden courses unchecked to allow the system to set up users in courses before they are available. It's usually a good idea to pre-populate courses before users have access.
  22. The External unenrol action determines what Moodle will do if a user enrollment disappears from the enrollment table. The Unenrol user from course option will remove the user from the course. This could result in the loss of some user-data specific to the course. A better option, Disable course enrollment, will prevent the user from accessing the course and also ensure that the data is not deleted. The Disable course enrollment and remove role will disable the user's enrollment and remove their role in the course. This is useful for users whose role would otherwise enable them to ignore the disabled enrollment.
  23. The final section of the configuration allows us to specify a table to create new courses. Specify the table containing the course information in the Remote new courses table.
  24. The New course full name field, New course shortname field, and the New course ID number field all determine where Moodle will look for the required course information in the table.
  25. The New course category ID field sets the category for the course when it is created. The Default new course category will determine the category if one is not set in the database.
  26. The New course template allows you to use a course in Moodle as a template to be copied every time a new course is created by the database. Enter the course shortname here to enable this feature.
  27. Click on Save Changes at the bottom of the screen.

Run the cron script as specified at the end of the Flat file (CSV) Enrollment section to test your new enrollment plugin configuration.

What just happened?

Now you know of the different enrollment options available in Moodle. You have also learned how to automate enrollment with the Flat file (CSV) and External database enrollment plugins.

Depending on where your data is coming from, you may select to use one of the enrollment plugins instead of another. Some systems may be difficult to tie directly to a database or your IT department might not be able to support the tables Moodle needs for database enrollment. In this case, you may decide the flat file enrollment plugin will suit your needs better. However, if you're using a system that supports the ability to create a table that Moodle can use for enrollment, the external database enrollment plugin is usually a more manageable and robust option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.12.156