Configure the connection with Moodle for training
Smartosh allows the transmission of training data between Smartosh and Moodle. Smartosh calculates the training each person must undertake based on the PPE they use, their job position, work centre, etc. Based on this calculation, it registers the user in Moodle, launches the session and subsequently collects the attendance date and evaluation results when applicable.
The training needs workflow is identical to that of manual training needs: certificate generation and the other steps are governed by exactly the same rules.
Prerequisites in Moodle
Section titled “Prerequisites in Moodle”Although the internal configuration of Moodle is beyond the scope of this guide, there are essential points for the integration to work:
- Enable web services (extensions in Moodle).
- Create a user, a set of services and a token that will be used in the connection.
- The defined protocols must be REST and XML-RPC.
- The course completion conditions must be correctly defined in Moodle, as Moodle determines whether a user has completed a course.
The details of these operations are explained in the official Moodle documentation: Web service settings.
Configure the connection in Smartosh
Section titled “Configure the connection in Smartosh”Each connection uniquely links a course from a specific Moodle server with a Smartosh session.
Preliminary step: define the session
Section titled “Preliminary step: define the session”Before creating the connection, the training and session to be linked with Moodle must exist in Smartosh. It is recommended to define a session with training and a training session to simplify management.
Create the connection
Section titled “Create the connection”Go to Settings → Moodle Connection and fill in the following fields:
| Field | Description |
|---|---|
| Name | Internal name identifying this connection. |
| Training | Selected from the trainings defined in Smartosh. |
| Session | Only sessions including the training from the previous field can be selected. |
| Service URL | Provided by the Moodle administrator. Page where the webservice request is launched. |
| Token | Token to access the service, defined in Moodle. |
| Training identifier in Moodle | Number identifying the course in Moodle. |
| Status | When the operation is launched, it changes to Importing and upon completion shows: Finished with error, Finished with warnings or Finished successfully. |
| Email for error notification | If defined, when a daily process detects errors, a notification is sent by email (without details; the history must be consulted). |
| Moodle exclusive for this tenant | Activates additional alerts that only make sense when Smartosh employees coincide with those in Moodle. |
| Disabled | If checked, the nightly process does not run. The connection can still be launched manually. |
| History | Details of the dates and results of each execution. |
| Functions | Reserved for future uses and other Moodle versions. |
Run the synchronization
Section titled “Run the synchronization”Once the Moodle connection, training, session and necessary Moodle settings (courses, surveys, etc.) are configured, the synchronization process can be launched in three ways:
- Automatically every night via the
ConexionDatosWorker.SincronizarTodasConexionesprocess, provided the Disabled checkbox is unchecked. - Manually from Settings → Moodle Connections, using the Perform Connection operation. The result is shown in the connection’s History upon completion.
- From Training → Sessions, selecting a session with an active Moodle connection. The Synchronize with Moodle button and a tab with status and history appear.
The transfer process is divided into two clearly differentiated blocks: exporting participants to Moodle and collecting results from Moodle.
Block 1: export participants to Moodle
Section titled “Block 1: export participants to Moodle”The system reviews all training needs marked as Not Called for the training linked to the connection and, for each, executes:
1. Search for the employee in Moodle
Section titled “1. Search for the employee in Moodle”The application searches for the employee in Moodle using the identifier they have in Smartosh (DNI, NIE, etc.). The search is done by:
- Identifier = username
- Identifier = IdNumber (additional Moodle field)
- email = Smartosh email
If the employee is not found, Smartosh sends the following data to Moodle to register them:
- Username (identifier)
- Password (generated by the application)
- First name
- Last name 1
- Email (mandatory in Moodle and cannot be duplicated; the system verifies this)
- Identifier
- Order to reset the password on first access
The log records: User {First name and last name 1} ({Identifier}) - registered in the system.
2. Enrolment in the course
Section titled “2. Enrolment in the course”It checks if the employee is already enrolled in the course. If not, the application enrols them.
The log records: User {First name and last name 1} ({Identifier}) - enrolment in the Moodle course.
3. Update in Smartosh
Section titled “3. Update in Smartosh”The training need is updated with the session and the session date, and marked as In Progress.
The log records: User {First name and last name 1} ({Identifier}) - called in SmartOSH.
4. Email notification to the user
Section titled “4. Email notification to the user”Each called employee is sent an email, unless they have the “Disable email sending” checkbox marked:
- New user → template «User registration in Moodle», with username and password to start the training.
- Existing user, new training → template «Enrolment in Moodle».
Block 2: collect results from Moodle
Section titled “Block 2: collect results from Moodle”The application queries Moodle for the course participants and, for each:
- Identify the user in Smartosh within that session, by
idnumber(NIF) or byusername. - Retrieve attendance date and score: the information is saved as evaluation grade and attendance date, marking as attended in the corresponding session. If the training is marked “must be evaluated”, the evaluation date and grade are also recorded.
- Retrieve completion: if Moodle indicates the course is completed, the action is marked as completed in Smartosh and the person is unenrolled from the course in Moodle (they will no longer be able to access it).
Upon completion, the system saves the list of operations and incidents generated in the Moodle connection history.
Required permissions in Moodle
Section titled “Required permissions in Moodle”The user associated with the token must have permissions to run the following Moodle API functions:
core_completion_get_activities_completion_statuscore_completion_get_course_completion_statuscore_course_get_coursescore_enrol_get_enrolled_userscore_enrol_get_users_coursescore_grades_get_gradesorgradereport_user_get_grade_items(for versions above 3.2)core_webservice_get_site_infoenrol_manual_enrol_usersenrol_manual_unenrol_userscore_user_create_userscore_user_get_userscore_user_update_users
General considerations
Section titled “General considerations”- When a session is linked with Moodle, evaluation exams are conducted in Moodle.
- Upon completion of a training action, the system generates the certificate (if configured), exactly as in a manual session.
Considerations for SmartOSH SPA PRO
Section titled “Considerations for SmartOSH SPA PRO”In SPA environments, a session and a Moodle connection must be created per course in each environment, even when the Moodle course exists only in Spanish.
Source: KB029 «Configuration and operation of the Moodle connection for training», Training module, version 1.0.00, 17-09-2025.