You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/apis/plugintypes/mod/courseoverview.md
+32
Original file line number
Diff line number
Diff line change
@@ -202,6 +202,38 @@ class overview extends activityoverviewbase {
202
202
}
203
203
```
204
204
205
+
### Custom grade overview items
206
+
207
+
If the activity has a grade item, the course overview will display the grade of the activity to the student. If your plugin has one single grade item, you don't need to do anything.
208
+
209
+
For activities with more than one grade item (for example, mod_workshop), no grade will be shown by default because the system doesn't know the meaning of each grade item. For those cases, the plugin must implement `get_grade_item_names` to provide the generic name for each grade item. The overview report will show only the grade items with a generic name.
210
+
211
+
This is an example of a plugin with two grade items:
212
+
213
+
```php
214
+
#[\Override]
215
+
protected function get_grade_item_names(array $items): array {
216
+
// Add some fallback in case some grade item is missing.
217
+
if (count($items) != 2) {
218
+
return parent::get_grade_item_names($items);
219
+
}
220
+
$names = [];
221
+
foreach ($items as $item) {
222
+
// Use the itemnunmber to know which grade item is.
It is not recommended to override the `get_grades_overviews` method. The method is used to provide the grade information to the course overview, but it is not intended to be used to provide extra information. If you don't want to show the grade information in your plugin, you can override the `get_grade_item_names` method and return an empty array.
234
+
235
+
:::
236
+
205
237
## Dependency Injection
206
238
207
239
The `overview` class will be loaded using [dependency injection](../../core/di/index.md). The constructor must accept a `cm_info` object to initialize the parent class, however, the constructor can also accept other dependencies that the plugin needs.
Copy file name to clipboardexpand all lines: docs/apis/subsystems/output/index.md
+36
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,42 @@ echo $output->footer();
106
106
107
107
This prints the HTML for the bottom of the page. It is very important because it also prints out things that were added to the `page_requirements_manager` and that need to be printed in the footer; things like JavaScript includes, navigation tree setup, closing open containers tags etc. The reason all JavaScripts are added to the footer of the page is for performance. If you add JavaScript includes to the top of the page, or inline with the content, the browser must stop and execute the JavaScript before it can render the page. See https://developers.google.com/speed/docs/insights/BlockingJS for more information.
108
108
109
+
### Accessing renderers with dependency injection
110
+
111
+
<Sinceversion="5.0"issueNumber="MDL-83888" />
112
+
113
+
In the example above, we used `$PAGE->get_renderer('tool_demo')` to get an instance of the renderer. This is the traditional way to get a renderer. However, if you are in a class designed for dependency injection, the use of global variables is discouraged. You can read more about dependency injection in the [Dependency Injection](../../../concepts/dependency-injection/index.md) guide.
114
+
115
+
Instead, you can use the `core\output\renderer_helper` class to get any renderer instance without using the global. This is an example of how to use the `renderer_helper` class to get a renderer instance:
116
+
117
+
```php
118
+
class my_di_example {
119
+
public function __construct(
120
+
/** @var \core\output\renderer_helper $rendererhelper the renderer helper */
The `core\output\renderer_helper` class serves as a wrapper around the global `$PAGE` object. This is necessary because the `$PAGE` object can change during script execution, making direct injection impossible. Dependency injection relies on singletons, and the `renderer_helper` class provides a workaround for this limitation.
142
+
143
+
:::
144
+
109
145
### Renderable
110
146
111
147
In the code above, we created a renderable. This is a class that you have to add to your plugin. It holds all the data required to display something on the page. Here is the renderable for this example:
0 commit comments