Skip to content

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.

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.

Each connection uniquely links a course from a specific Moodle server with a Smartosh 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.

Go to Settings → Moodle Connection and fill in the following fields:

FieldDescription
NameInternal name identifying this connection.
TrainingSelected from the trainings defined in Smartosh.
SessionOnly sessions including the training from the previous field can be selected.
Service URLProvided by the Moodle administrator. Page where the webservice request is launched.
TokenToken to access the service, defined in Moodle.
Training identifier in MoodleNumber identifying the course in Moodle.
StatusWhen the operation is launched, it changes to Importing and upon completion shows: Finished with error, Finished with warnings or Finished successfully.
Email for error notificationIf defined, when a daily process detects errors, a notification is sent by email (without details; the history must be consulted).
Moodle exclusive for this tenantActivates additional alerts that only make sense when Smartosh employees coincide with those in Moodle.
DisabledIf checked, the nightly process does not run. The connection can still be launched manually.
HistoryDetails of the dates and results of each execution.
FunctionsReserved for future uses and other Moodle versions.

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.SincronizarTodasConexiones process, 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.

The system reviews all training needs marked as Not Called for the training linked to the connection and, for each, executes:

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.

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.

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.

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».

The application queries Moodle for the course participants and, for each:

  1. Identify the user in Smartosh within that session, by idnumber (NIF) or by username.
  2. 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.
  3. 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.

The user associated with the token must have permissions to run the following Moodle API functions:

  • core_completion_get_activities_completion_status
  • core_completion_get_course_completion_status
  • core_course_get_courses
  • core_enrol_get_enrolled_users
  • core_enrol_get_users_courses
  • core_grades_get_grades or gradereport_user_get_grade_items (for versions above 3.2)
  • core_webservice_get_site_info
  • enrol_manual_enrol_users
  • enrol_manual_unenrol_users
  • core_user_create_users
  • core_user_get_users
  • core_user_update_users
  • 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.

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.