OverviewΒΆ

What the plugin doesΒΆ

tool_sga is an admin/tool-type plugin for Moodle. It does not change the login flow or the end-user interface: it exists to expose an HTTP API consumed by the SGA (Academic Management System) and to keep, inside Moodle, the data structure (categories, courses, classes, users, enrolments) and the custom profile fields that the rest of the AVA/SUAP suite (for example painel_ava, integrador_ava) expects to find.

In short, the plugin offers:

  • Upload synchronization (SGA β†’ Moodle): a single HTTP endpoint that receives a large JSON payload with categories, courses, users, cohorts, enrolment methods, enrolments and groups, and creates/updates each of these records in Moodle. See Upload synchronization (SGA β†’ Moodle).

  • Grade synchronization (Moodle β†’ SGA): an HTTP endpoint that returns, for a specific class (diΓ‘rio), the list of enrolled students and their grades recorded in Moodle. See Grade synchronization (Moodle β†’ SGA).

  • Custom fields: on install/upgrade, creates dozens of custom course and user profile fields (campus, course, class, hub etc.), used by other components of the suite to display/filter institutional information. See Custom fields.

  • Administrative panel: two simple pages (outside Moodle’s standard admin tree) to list and inspect the history of received upload synchronizations. See Administrative panel.

API authenticationΒΆ

All API endpoints (except those that rely on an administrator session, such as the panel) require an HTTP header Authentication: Token <token>, compared against the value configured in Integrador SGA auth token (integration_token, see Installation). Requests without the header receive 400; with an incorrect token, 401.

RequirementsΒΆ

Item

Value

Moodle

$plugin->requires = 2024100710 in version.php.

PHP

The CI pipeline (ci.yml) tests PHP 7.4, 8.0 and 8.1.

Database

PostgreSQL or MariaDB (both tested in CI).

Note

The comment next to $plugin->requires in version.php says # 3.9.25, php >= 7.4, but the numeric value (2024100710) corresponds to a Moodle version from October 2024, not to Moodle 3.9. Likewise, the CI matrix (ci.yml) tests against MOODLE_401_STABLE, MOODLE_402_STABLE and MOODLE_403_STABLE β€” all earlier than the version required by $plugin->requires. Both inconsistencies appear to be leftovers from a requirements update that was not replicated in the comment or in the CI matrix; this documentation does not attempt to resolve the discrepancy, it only records it.

Repository structureΒΆ

tool_sga/
β”œβ”€β”€ adminlib.php                  # Settings screen (sga_admin_settingspage)
β”œβ”€β”€ locallib.php                  # Generic database helpers (get_or_create, create_or_update...)
β”œβ”€β”€ settings.php                  # Registers the settings screen in Moodle admin
β”œβ”€β”€ version.php                   # Plugin version/release/maturity
β”œβ”€β”€ admin/
β”‚   β”œβ”€β”€ index.php                 # Panel: lists the history of received synchronizations
β”‚   └── view.php                  # Panel: detail of a specific synchronization
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ index.php                 # Query-string dispatcher (?health, among others)
β”‚   β”œβ”€β”€ servicelib.php            # Base `service` class + dispatch and authentication logic
β”‚   β”œβ”€β”€ health.php                # Diagnostic service (plugin/Moodle version)
β”‚   β”œβ”€β”€ sync/up/index.php         # Upload synchronization endpoint (SGA β†’ Moodle)
β”‚   β”œβ”€β”€ sync/down/index.php       # Grade synchronization endpoint (Moodle β†’ SGA)
β”‚   β”œβ”€β”€ schemas/                  # JSON Schema definitions (reference only, not used for active validation)
β”‚   └── examples/                 # Upload synchronization payload examples
β”œβ”€β”€ classes/
β”‚   β”œβ”€β”€ observer.php              # tool_sga_observer: enrolment event handlers (empty)
β”‚   └── Jsv4/                     # Vendored JSON Schema validation library (Draft 4)
β”œβ”€β”€ db/
β”‚   β”œβ”€β”€ access.php                # Capability tool/sga:adminview
β”‚   β”œβ”€β”€ events.php                # Observers for user_enrolment_created/updated/deleted
β”‚   β”œβ”€β”€ install.php               # Calls tool_sga_migrate(0) on install
β”‚   β”œβ”€β”€ install.xml               # Two tables (see note in campos-customizados)
β”‚   β”œβ”€β”€ migrate.php               # Shared install/upgrade logic (tables + fields)
β”‚   β”œβ”€β”€ tasks.php                 # List of scheduled tasks (currently empty/commented out)
β”‚   └── uninstall.php             # No-op
β”œβ”€β”€ lang/{en,pt_br}/tool_sga.php  # Language strings
β”œβ”€β”€ docs/                         # This documentation (Sphinx)
└── .github/workflows/
    β”œβ”€β”€ ci.yml                    # moodle-plugin-ci (lint, PHPCS, PHPUnit, Behat)
    └── docs.yml                  # Publishes this documentation to GitHub Pages

OrganizationΒΆ

The repository lives in the suap-ava-suite organization as moodle-tool_sga, alongside other components of the AVA/SUAP suite used by IFRN β€” for example painel_ava and integrador_ava, which consume part of the custom fields described in Custom fields.