Synchronise Users and Courses from CourseSales.com to Moodle

Tuesday, Sep 23, 2014

There are two ways you can set up CourseSales.com to interact with Moodle, by far the easiest is using the CourseSales.com Moodle Plugins, these give you control over the creation of courses, duplication of data etc. However you may wish to use Moodle export maps.

  1. CourseSales.com Moodle plugins CourseSales.com offer three Moodle plugins: Authentication (uses the username/password in CourseSales.com), Enrolment (receives registrations from CourseSales.com) and Local (where most settings are as well as managing completion).
  • Authentication: So a student logs in to Moodle using the username/password details determined at registration, maintained at CourseSales.com,

  • Enrolment: grants a student access to the courses the student is registered for, and

  • Local: among other things ensures that upon completion of a course activity by a student, a CourseSales.com process step is triggered, sending emails with PDFs, eg a certificate.

    Credentials (username and password) are maintained via the CourseSales.com student portal by the student, or the administration portal by the course administrator. Course dates can be synchronized from CourseSales.com to Moodle.

  1. Moodle Export Maps For unidirectional communication from CourseSales.com to Moodle, student accounts can be automatically created in Moodle, enabling students to be issued credentials via process steps, all Moodle user details are then maintained in Moodle.

CourseSales.com Moodle plugins

CourseSales.com can synchronize users, course dates and enrollments controlled from within CourseSales.com, a linked Moodle account is created for each student with the same username and password as the student portal. As the student logs in, Moodle checks with CourseSales.com for the courses the student is registered for, the course dates are created if they don’t already exist, and associated to the student’s Moodle profile.

Student details updated within CourseSales.com, via the administration portal or the student portal are updated in Moodle automatically on a regular basis, as can courses and enrollments. It is necessary to manually maintain the list of course categories in Moodle, as this is the link between Moodle and CourseSales.com courses.

Considerations when implementing CourseSales.com Moodle plugins

  • Versions - CourseSales.com plugins have been or are successfully running on Moodle versions 2.6.5, 2.7.2 and 2.7.5, if your Moodle is not one of these versions the plugins still might work, we recommend you test them first.

  • You may need to have 1:1 relationships between course category and course, in Moodle and CourseSales.com depending on how you want things set up. The CourseSales.com course category is used to recreate course dates within Moodle. If you don’t have one course per CourseSales.com course category and have multiple courses under one category all these CourseSales.com course dates will be replicated. It can be figured so that the name of the course created in Moodle by the plugins will be the same as the course category: all course masters under a CourseSales.com course category will be created in Moodle. eg. if you have online and face-to-face training under the same course category both will have course dates replicated with the same name in Moodle.

  • To be synchronized in Moodle Course Dates must be scheduled (not canceled nor completed) and must be public (not private), Course Masters must be public (not private). For users to be synchronized Documents must be registered and contacts must be active and have a password field. The username will be the unique identifier for the contact eg. Email, USI, Avetmiss contact id.

  • You will need to manually link Moodle courses to CourseSales.com course dates if you create courses manually in Moodle, rather than letting CourseSales.com generate them.

Note
Be careful when changing to even minor versions of Moodle, we have found that some minor versions have changes the break the plugins. For this reason please test your intended version or contact us to confirm if your intended version is supported. Upgrading to a version that does not work may mean that students no longer have access to courses.

Setting up to prepare for configuration

Install the three CourseSales.com Moodle plugins; Enrolment, Authentication and Local, these allow the credentials to be used in Moodle and ensure that the courses the student is registered for are made available to the student. The three folders where the plugins reside are:

  • yourmoodle/enrol/coursesales/ (for the CourseSales.com enrollment plugin)

  • yourmoodle/local/coursesales/ (for the CourseSales.com completion plugin)

  • yourmoodle/auth/coursesales/ (for the CourseSales.com authentication plugin)

You need to create or make active a web services user with the internal type ‘soap’. This user must have a username and password assigned (you will require these details below).

Configuring CourseSales.com for users

You need to add a password to the registration form and to the contact form to enable students to access Moodle. You will also need to create contacts (if not already created) at the point that you want students to access Moodle.

Add a password field (type ‘Password’, Validator ‘Moodle Password Format’) to the Registration form and the Contact form, for students to specify during the registration/enrolment process

  • Set up contact matching/creation at the point where Moodle login details need to be created.

  • The chosen Default Contact Id will be the Moodle username, your options are:

    • Leave Blank (when you want to create a contact but not issue Moodle nor Student Portal credentials)

    • Use customer email (recommended)

    • Assign next sequential number

    • Use AVETMISS Client Id

    • Use AVETMISS Unique Student Identifier

Note
The CourseSales.com Internal Type ‘Customer email’ must be set for the Customer email to be used as the Default Contact Id.

Updating the Default Contact Id settings will mean that the student needs to be informed; they will not be able to login with the old credentials

Configuring the Local Plugin

This stores the majority of the configuration for all plugins and manages course completion within Moodle by the student. The main configuration is the Process Step Id to execute. The Process Step has to be on the Document’s Process Path for this to work. CourseSales.com will execute the step based on the request from Moodle. Read more about how to configure course completion within Moodle here.

To confirm version and installation of the completion plugin within Moodle see Site administration> Plugins>Local Plugins>Manage local plugins

There are two ways to configure Moodle plugins, depending on where original documents reside:

  • On CourseSales.com as the originals, synchronized to Moodle, eg. when registrations are taken by CourseSales.com

  • On Moodle as the originals, synchronized to CourseSales.com, eg. when registrations are taken by Moodle

Synchronized to Moodle

To configure the Completion plugin within Moodle see Site administration> Plugins>Local Plugins>CourseSales.com

Field Name Default value Example Notes
The CourseSales.com server address - http://ccl.test.coursesales.com/rest/index Mandatory; Link to your CourseSales.com server
The CourseSales.com web services user - soap Mandatory
The CourseSales.com web services password - abc123 Mandatory

Mapping between CourseSales.com and Moodle

Field Name Default value Example Notes
CourseSales.com Course Category field holding the mapping to Moodle categories - 4764 Mandatory, (See note 4, below)
CourseSales.com Process Step Id indicating course completion - 848 Mandatory

Rules for creating new courses in Moodle using a template

Field Name Default value Example Notes
Automatically add new CourseSales.com courses to Moodle Yes Yes If you want all your students attending one Moodle course then select ‘No’, to have different Moodle courses per course select ‘Yes’
CourseSales.com Course Category field ID holding the mapping to a Moodle course to use as a template If this is not entered blank courses will be created, use the CourseId from the Moodle URL (see Note 1 below)
When creating a course using a template, include Activities Yes Yes Topics and activities contained in those Topics will be duplicated from the template (See Note 2 below)
When creating a course using a template, include Blocks Yes Yes The blocks defined on a course used as a template will be included (See Note 2 below)
When creating a course using a template, include Filters Yes Yes Filters will be duplicated from the template (see Note 3 below)

Rules for updating course details in Moodle

Field Name Default value Example Notes
Synchronise CourseSales.com course names to Moodle Synchronise CourseSales.com to BOTH Moodle Course Names Synchronise CourseSales.com to BOTH Moodle Course Names If you prefer your names on moodle (we add things like dates etc to ensure the names are unique) then you may not wish the plugins to replicate our names automatically.
Naming standard for courses in Moodle Course Category and Date Course Category and Date Names on Moodle can include the date or not, eg. online courses may not require a date. When selecting “Course Category” the course short name will include the CourseSales.com courseid and date but the course full name will be the name of the course category.

Settings for posting new enrolments to CourseSales.com

Field Name Default value Example Notes
Send new enrolments to CourseSales.com No No This moves enrolments from Moodle to CourseSales.com - which is the opposite of using the auth & enrol plugins
CourseSales.com Form Id - This is the CourseSales.com Form Id to receive the enrolment from Moodle
CourseSales.com Process Path Id - This is the process path that includes the form and process step, so that CourseSales.com can trigger the necessary process rules
CourseSales.com Process Step Id - This is the process step that the form is related to that receives the Moodle registrations
CourseSales.com Field Id for First Name - We need to know which is the internal type “Customer Name First”, include the relevant field Id here.
CourseSales.com Field Id for Surname - We need to know which is the internal type “Customer Name Surname” include the relevant field Id here
CourseSales.com Field Id for Username - We will use this as a unique identifier for the student, so they can use the same details to access the student portal.
CourseSales.com Field Id for Email Address - We need to know which is the internal type “Customer Email” include the relevant field Id here
CourseSales.com Field Id for Phone Number - Include the relevant field Id here

Plugin logging settings

Field Name Default value Example Notes
Email address to use for any warnings or issues - sysadmin@yourdomain.com Used if there is a specific problem when synchronizing. It should be someone who can fill-in missing data on a Document or correct a configuration issue.
Turn on debugging? no yes Debugging email and logs will occur at the same time if both are specified.
Location of the log file - /tmp/moodle-cs-local-log.txt Ensure that Moodle has write access to this file/location. If you can email yourself the log this is not required - it is the same information.
Email address for log - sysadmin@yourdomain.com Emails will arrive at regular intervals depending on Cron settings.

Warning
As CourseSales.com caches the data from forms you may have to wait up to 5 minutes to see any changes made to the course category forms - in the case of the Moodle plugins this might mean students are delayed in getting enrolled. For any changes please allow time for the cache to expire.

Note 1:

You may optionally configure the plugin with the Field Id of the moodle template id (get this from the URL of editing the course within Moodle eg http://192.168.0.12/moodle29/course/view.php?id=5). It will let you create a new course based on an existing course, so you have less to setup for each actual course. Note that the user configurable ‘Course ID number’ in Moodle should be blank. Create the template course and then refer to it in the Moodle Course Template field using it’s internal Moodle courseId. When CourseSales.com creates courses of that type it bases them on your template.

To get the Course Category field ID value for “CourseSales.com Course Category field ID holding the mapping to a Moodle course to use as a template” visit the course and take it from the URL in your browser:

Configure CourseSales.com: You need to add a field (Name=Moodle Category Id, Type=text), to the Course Category form to hold the mapping of CourseSales.com course categories to Moodle categories

Populate the CourseSales.com Course Category forms with the mapping to Moodle categories, When viewing the Course Category in Moodle take from the URL

http://cs.moodletest.coursesales.com/course/editcategory.php?id=4

In this example take the Course Category id is “4”, add that to the field Moodle Category Id on the relevant Course Category in CourseSales.com

Note 2

To duplicate the Blocks and Activities, you have to select “When creating a course using a template, include Blocks” and “When creating a course using a template, include Activities” respectively. Note that when you duplicate activities they will be created under the relevant topics which arealso duplicated (as topics are duplicated by default by specifying a template)

Note 3

To duplicate the filters you must select “When creating a course using a template, include Filters”:

Note 4

Configure the Moodle plugin field “CourseSales.com Course Category field holding the mapping to Moodle categories” with the Field Id of the field Moodle Category Id.

Templates

You may optionally add a field to reference a Moodle Course Template to use when creating courses within Moodle. It will let you create a new course based on an existing course, so you have less to setup for each actual course (see Note 2 and 3). Create the template course and then refer to it in the Moodle Course Template field using it’s internal Moodle Id (see Note 1). You should find that when CourseSales.com creates courses of that type it bases them on your template. If you do not select Blocks, Activities nor Filters the duplicate courses will not include content from the course used as the template, just settings. You can link a CourseSales.com course date to an existing moodle course (which has content) by using the CourseSales.com CourseDateId, see the questions section below.

Course Completion

Step 1

Create the course category

Step 2

Manage the course category, creating a new course (note that the plugins require there to be just one course per course category)

Step 3

Enable completion tracking on the Moodle Course record

Step 4

Configure completion, eg. enable Manual self completion.

Step 5

The self completion block should be added to the course if manual self completion is enabled: while viewing the course Turn editing on (top right corner)

Step 6

Add a self completion block (bottom left corner), read more about blocks here

Step 7

Login as a user enrolled on the course and use the self completion block to say you have completed the course.

Note
The update happens through cron on the Moodle server, so you have to wait for that to run, or go to www.yourmoodleserver.com/admin/cron.php to run it manually. You have to run it twice. Don’t know why, it’s just a Moodle thing. To read more about using cron to update completion read this page

Configure the Enrol Plugin

Enable the plugin within Moodle, visit Site administration> Plugins>Enrolments>Manage enrol plugins click on the ‘enable’ icon, if you can see CourseSales.com courses under the ‘Enrolments’ menu then it is already enabled.

After you have enabled CourseSales.com and moved it higher in the priority list it should appear like this:

Configure the plugin with the following variables:

Field Name Default value Example Notes
How many Course Dates should be processed each run? 1 1 Mandatory; You can change this to a greater number when you add new batches of courses
Turn on debugging? no no
Location of the debugging log file - -
Email address for debugging log - sysadmin@yourdomain.com

  • Make sure the categories of courses you want to sync already exist in Moodle

  • There is no need to set anything in the Moodle Course Category settings for the field ' Category ID number'

Configure the Auth plugin

Enable the plugin within Moodle, visit Site administration> Plugins>Enrolments>Manage enrol plugins, click on the ‘enable’ icon

After you have enabled CourseSales.com and moved it higher in the priority list

Configure in Moodle:

  • Configure the plugin with REST access to CourseSales.com

  • You may optionally configure the plugin with debugging to a file

Field name Default value Example Notes
Debug no no Turn on debugging
Debug Email - Send debug information to this email
Debug File - Save debug information to this file
Password-change URL - Here you can specify a location at which your users can recover or change their username/password if they’ve forgotten it. This will be provided to users as a button on the login page and their user page. If you leave this blank the button will not be printed.
First name Locked Unlocked if empty See note at bottom of table
Surname Locked Unlocked if empty See note at bottom of table
Email address Locked Unlocked if empty See note at bottom of table
City/town Unlocked Unlocked See note at bottom of table
Country Unlocked Unlocked See note at bottom of table
Language Unlocked Unlocked See note at bottom of table
Description Unlocked Unlocked See note at bottom of table
Web page Unlocked Unlocked See note at bottom of table
ID number Unlocked Unlocked See note at bottom of table
Institution Unlocked Unlocked See note at bottom of table
Department Unlocked Unlocked See note at bottom of table
Phone 1 Unlocked Unlocked if empty See note at bottom of table
Phone 2 Unlocked Unlocked See note at bottom of table
Address Unlocked Unlocked See note at bottom of table
First name - phonetic Unlocked Unlocked See note at bottom of table
Surname - phonetic Unlocked Unlocked See note at bottom of table
Middle name Unlocked Unlocked See note at bottom of table
Alternate name Unlocked Unlocked See note at bottom of table

*You can lock user data fields. This is useful for sites where the user data is maintained by the administrators manually by editing user records or uploading using the ‘Upload users’ facility. If you are locking fields that are required by Moodle, make sure that you provide that data when creating user accounts or the accounts will be unusable.
Consider setting the lock mode to ‘Unlocked if empty’ to avoid this problem*

Test the authentication configuration (once you have configured Moodle & CourseSales.com)

Sign up for a course, check that the correct process rules will be applied by checking the status preview

Confirm:

  • That the Contact, after a period specified for the System > Services >Email is created

  • That you can log into the student portal: https://[shortname].coursesales.com/studentportal?h=1 (replace [shortname] with your website’s short name eg. ccl)

  • That you can log into Moodle using those same credentials

  • That the correct course dates are allocated to the student

If things are not working as you expect:

  • Check that the course date is scheduled & public

  • Check that the course master is public

  • Confirm the course date has the correct matching category (and that this category is not being used for other courses in Moodle)

  • A contact exists for the student

  • Check that the password field exists on the contact form

  • The web services ‘soap’ role is set up correctly (active, with a password)

Add further functionality

You may wish to add:

  • Links to the student portal from Moodle

  • Links from the student portal to Moodle by modifying a customised javascript files

  • Configuring a course completion call-back

  • Integrating emails to notify students of the Moodle credentials

Upgrading Moodle plugins

You may find that Moodle alerts you when you login for pending upgrades or installation of plugins. At the following screen, choose ‘upgrade Moodle database now’

Updates to existing plugins, just need to be unpacked into /local/coursesales and the update settings script run.

Moodle Export Maps

Name, Username, Password and email for the Moodle login are defined in the contact record created during registration process step. These details are exported by creating a Moodle export map which is linked to the process step via a process rule. Username, password and email credentials are maintained in CourseSales.com.

Step 1

Configure Moodle as follows:

Step 2

Configure CourseSales.com:

Create a Export map of Type ‘Moodle’ (see below), include the host, eg. http://cs.moodletest.coursesales.com/, the user token eg. a5feccd14dfa1c8e8c0f6d24d15106fc and the Moodle API Function, ie moodle_user_create_users. Link the export map to a Process rule, and the Process rule to the Process step (which should be on a current process path). The Export Map must have the following fields mapped, these will therefore need to be mandatory on the CourseSales.com form, with the required validation set to ensure the Moodle account is created:

  • username (automatically made lower case)

  • firstname

  • lastname

  • email

  • password (On the contact and registration forms use the validator “Moodle password format”, The password must have at least 8 characters, at least 1 digit, at least 1 lower case letter, at least 1 upper case letter, at least 1 non-alphanumeric character)

These fields can be included in any order

Note
If for any reason the account cannot be created, eg. the fields are not passed, warnings can be found in System/Logs.

FAQ - Moodle plugins and export maps"

What happens when a new user name already exists in Moodle?

The account is not created, see System/Logs for diagnosis

How do I know credentials (username and password) have been set up correctly in Moodle?

Attempt to login to view the login details from the Administration panel within Moodle, Also you can do an API call to CourseSales.com (see below: “How can I confirm that I have CourseSales.com correctly configured?")

How does a student reset their password?

For Moodle plugins the student must request the password to be updated manually. For the export maps the student must navigate to Moodle and update the Moodle password from there.

How does a student find out their username?

Depending on the configuration of the export it could be the email address, or another field. This field will be on the registration and contact form - the student can visit that form for the original username, it should be clearly indicated on the registration form when the student books the course.

Can other details be sent via the export map to Moodle when setting up the Moodle account?

Moodle limits the information that can be setup via the account creation mechanism. There are two other custom fields that can be created.

Yes, this is possible, take the coursedateid (when editing a course date it is included in the URL, or click on the cog in the blue title bar) and add that value to the user adjustable course id field of a course you have already created (see Note 4). Be sure to have already removed that same course date from Moodle if it already exists (you cannot have two courses with the same course id). Any registrations will therefore be added to the course date following cron running (cron is a time driven running of software, used to keep all courses between CourseSales.com and Moodle synchronized).

I created a course in Moodle but it does not include ‘CourseSales.com enrol’ as an enrolment option - just “manual enrol.”

This will not matter, even courses without ‘CourseSales.com enrol’ will still enrol students from CourseSales.com

How can I confirm that I have CourseSales.com correctly configured?

You can use the following API call in your browser to confirm that the CourseSales.com side of things works, however this does not confirm that your moodle is configured correctly, just that CourseSales.com is working as expected. You will need to replace the following fields:

[short name] - with the short name of your CourseSales.com domain eg. ccl
[Soap User Name] - with the CourseSales.com user that has the internal type 'Soap'
[Soap Password] - with the CourseSales.com password of the user that has the internal type 'Soap'

https://[short name].coursesales.com/rest/index?q={"Options":{"OptionType":["Course Category"],"OptionSoapDetail":"All"},"Course Dates":{"CourseDateType":["CourseDateListNextId"],"ServiceType":"Moodle Course Date Id"},"page":1,"pageItemLimit":"1","debug":"on","LoginUsername":"[Soap User Name]","LoginPassword":"[Soap Password]"}

Output should look something like this:

{"Options":{"Course Category":[{"1":"4384","2":"Nationally Recognised Training","3":"1","5":"4281","4":"1639","6":{"8620":"40","8144":"\n

Nationally is that training that is recognised under the AQF by ASQA the National Training Authority<\/p>\n"}},{"1":"4383","2":"CPC30413 - Certificate III in Demolition","3":"2","5":"4384","4":"1639","6":{"8620":"","8144":""}}],"Course Category Forms":{"1639":{"8620":{"1":"8620","6":"0","2":"0","3":"0","5":false,"4":false,"7":"","8":"","9":"","10":"","11":"","12":"","13":false,"FieldName":"Moodle Category Id","FieldLabel":"Moodle Category Id","FieldTooltip":"","FieldType":"Text","FieldInternalId":"","FieldIdForExport":"0","FieldForeignKey":"0","FieldValidation":"0","FieldVisibility":"Internal only","FieldHeight":"0","FieldWidth":"0","FieldValLenMin":"0","FieldValLenMax":"0","FieldDependsOnId":"0","FieldListDefaultId":"0","FieldWidthClass":"fldWd50"},"8144":{"1":"8144","6":"0","2":"3","3":"0","5":false,"4":false,"7":"","8":"","9":"","10":"","11":"","12":"","13":false,"FieldName":"Description","FieldLabel":"Description","FieldTooltip":"","FieldType":"HTML","FieldInternalId":"","FieldIdForExport":"0","FieldForeignKey":"0","FieldValidation":"0","FieldVisibility":"Public","FieldHeight":"0","FieldWidth":"0","FieldValLenMin":"0","FieldValLenMax":"0","FieldDependsOnId":"0","FieldListDefaultId":"0","FieldWidthClass":"fldWd100"}}}},"Options meta":{"Course Category":{"OptionId":1,"OptionName":2,"OptionDepth":3,"OptionParentId":5,"OptionFormId":4,"OptionContent":6}},"Course Dates":{"CourseDateListNextId":{"26519":{"0":"26519","1":"2015-12-01","2":"2015-12-01","3":"1004","4":"1100.00","32":"1100.00","5":"1100.00","33":"1100.00","7":"0.00","34":"0.00","35":0,"8":"20","9":"0","10":"0","11":"0","12":"0000-00-00","13":"0.00","36":"","14":"3247","15":"1","16":"2","17":"333","18":"516","19":"1","20":"4401","21":"Asbestos Removal CPCCDE3015A - Class A","22":"4280","23":"0","24":"4301","25":"Brisbane Queensland Australia","26":"Head Office","27":null,"29":"0.0000000","28":"0.0000000","30":"","31":"","37":"","38":"","39":null,"40":null,"41":null}},"CourseDateListNextId meta":{"CourseDateId":0,"CourseDateStart":1,"CourseDateEnd":2,"CourseDateVenueId":3,"PriceCurrent":4,"PriceRRP":5,"PriceMinimum":6,"PriceResidential":7,"PlacesTotal":8,"CourseDateEnquiries":9,"CourseDateRegistrations":10,"CourseDatePriceRuleId":11,"CourseDatePriceRuleDate":12,"CourseDatePriceRuleNextPrice":13,"DescriptionId":14,"StatusId":15,"Visibility":16,"CourseMasterCourseFormatId":17,"CourseMasterCurrencyId":18,"ElapsedDays":19,"CourseMasterCourseCategoryId":20,"CourseMasterDisplayCategoryName":21,"CourseMasterSalesAgentId":22,"CourseMasterResidentialDescriptionId":23,"CourseMasterProviderId":24,"CourseDateLocation":25,"CourseDateVenueName":26,"CourseDateVenueUrl":27,"CourseDateVenueLatitude":29,"CourseDateVenueLongitude":28,"CourseDateDescriptionShort":30,"CourseDateDescriptionLong":31,"CourseDateFmtPrcCurrent":32,"CourseDateFmtPrcNext":36,"CourseDateFmtPrcResidential":34,"CourseDateFmtPrcRrp":33,"CourseDateFmtPrcSaving":35,"CourseDateFormat":37,"CourseDateCount":38,"CoursePricesPriceCurrent":39,"CoursePricesCurrencyId":40}}}

I get an error when connecting to the test environment using the Moodle plugins:

Call CourseSales.com
Synchronise Enrolments
Exception::__set_state(array(
   'message' => '',
   'string' => '',
   'code' => 0,
   'file' => '/var/www/html/moodle29/local/coursesales/cs_lib.php',
   'line' => 2978,
   'trace' =>
  array (
    0 =>
    array (
      'file' => '/var/www/html/moodle29/local/coursesales/cs_lib.php',
      'line' => 836,
      'function' => 'callCourseSales',
      'class' => 'cs_lib',
      'type' => '->',
      'args' =>
   .....<snip>
      array (
      ),
    ),
  ),
   'previous' => NULL,
))

This is known, when using <shortname>.test.coursesales.com you must use http not https