Web service API¶
tool_painelava registers a single function in Moodle’s native web services subsystem:
tool_painelava_get_user_courses, implemented in
classes/external/get_user_courses.php and registered in db/services.php.
Service registration¶
Property |
Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Target user ID. |
Permissions¶
A user can always query their own courses (
userid == $USER->id, oruserid = 0).Querying another user’s courses requires the
tool/painelava:viewothercoursescapability in the system context (require_capability) — granted by default only to themanagerrole.The target user must exist and not be marked as deleted (
deleted = 0); otherwise the function throws amoodle_exceptionwith the error codeinvaliduser.
Course classification¶
For each course the user is enrolled in (via enrol_get_users_courses()), the type is
resolved by resolve_course_type() in the following priority order:
Course custom field whose shortname matches
get_config('tool_painelava', 'coursetypefield')— if absent, falls back to the built-in default'tipo_curso'. The field value is normalised (lowercase, accents handled) bynormalise_type_value()into one of the known types.If the field does not determine the type, the course’s shortname is compared (
stripos, prefix match) against the configurable prefixesprefix_fic(defaultFIC-),prefix_coordenacao(defaultCOORD-),prefix_laboratorio(defaultLAB-) andprefix_modelo(defaultMODELO-); then againstprefix_diario(default empty — therefore normally inactive).If nothing matches, the type falls back to
outros.
Warning
None of these configuration keys (coursetypefield, prefix_fic,
prefix_coordenacao, prefix_laboratorio, prefix_modelo, prefix_diario) has a
corresponding field in settings.php — see the warning in Installation. In practice,
without manual editing of the config_plugins table, classification depends entirely on
the built-in default values, and the tests in tests/external/external_test.php cover
exactly these defaults (prefixes FIC-, COORD-, LAB-, MODELO-).
Return structure¶
The response is an object with six lists, one per recognised course type:
{
"diario": [...], "fic": [...], "coordenacao": [...],
"laboratorio": [...], "modelo": [...], "outros": [...]
}
Each course item follows this structure:
Field |
Type |
Description |
|---|---|---|
|
— |
Standard fields from the Moodle course record. |
|
|
One of |
|
|
Shortname of the first role returned by |
|
list of objects |
All of the user’s roles in the course: |
|
list of objects |
All course custom fields: |
Triggered event¶
If the enablelogging setting is enabled (see the warning above about this setting’s absence
from the UI), each call triggers the tool_painelava\event\user_courses_requested event
(classes/event/user_courses_requested.php), registered with crud = 'r' and associated
with the user who made the call and the relateduserid (target user).
Note
This is the only event defined by the plugin. db/events.php registers the list of
observers the plugin listens to from other components — currently empty
($observers = [];).
Tests¶
tests/external/external_test.php covers, via externallib_advanced_testcase: permissions
(a regular user cannot see another user’s courses without the capability; manager can; a
deleted user throws invaliduser), classification by shortname prefix for each of the four
configurable types, aggregation of multiple courses and the presence of all expected keys in the
return structure. Local run (from the Moodle root):
vendor/bin/phpunit admin/tool/painelava/tests/external/external_test.php