Skip to content

Commit 1274a83

Browse files
committed
[docs] activity overview grade item
1 parent 424b909 commit 1274a83

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/apis/plugintypes/mod/courseoverview.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ class overview extends activityoverviewbase {
202202
}
203203
```
204204

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.
223+
$stridentifier = ($item->itemnumber == 0) ? 'submission_gradenoun' : 'assessment_gradenoun';
224+
// Names must be indexed by the grade item id.
225+
$names[$item->id] = get_string($stridentifier, 'mod_YOURPLUGIN');
226+
}
227+
return $names;
228+
}
229+
```
230+
231+
:::note
232+
233+
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+
205237
## Dependency Injection
206238

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

0 commit comments

Comments
 (0)