-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
5.1
-
MOODLE_501_STABLE
-
5
-
C->HQ 2025 Sprint I2.2 Moppies
The new activities overview page needs to be compatible with the mobile APP. We need a new "core_courseformat_get_overview_information" webservice to get as much raw data as possible from the current overview items.
Webservice contract
The webservice only requires two paràmeters:
- courseid (PARAM_INT)
- pluginname (PARAM_PLUGIN)
The result of the webservice will be:
- courseid (int)
- activities (object[])
- name (string)
- pluginname (string)
- contextid (int)
- cmid (int)
- URL (string)
- items (object[])
- Key (string) - > this is unique at array level
- name (string) -> this name will be unique in the array
- contentytpe (string) -> has the name of the content output class, or "string" if the content is a prerendered HTML.
- data (object encoded in json) --> will depend on the output type.
Only the overview items that are not null will be exported.
Overview item data export
While all the result data will be coded using an exported class, the main challenge is to export every item's data. The overview item can handle content as a string, null, or renderable. The trick will be:
- Create a new interface "exportable" with a method: export_for_external (renderer_base $output): stdClass --> the method can be used to get the raw data and can be implemented by any class, even output ones.
- The activityoverviewbase will have a new optional attribute called "data" (stdClass) and its getter and setter, so any activity can store data inside it to export. However, this attribute is optional and may not be informed.
- The activityoverviewbase will implement "exportable" following this logic:
- If the item has data defined, it will be returned.
- If the output element implements exportable, the exported output data will be returned.
- In any other case, it will generate an object with the item attributes: value, alert, and alertcount.
The rationale of this design is:
- Differentiating export_for_template and export_for_external will guarantee the webservices will not break because of template changes or new requirements.
- All export_for_external will have their PHPUnit tests to ensure nobody accidentally modifies the data structure.
- By having export_for_external in outputs, classes like "humandate" can be easily reused by many items and could be used in more contexts.
- Because the data for each overview item depends on the output type, JSON encoding is the most versatile option.