mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-75513 core_grades: New method that returns the grade item string
Introduces a new method get_element_type_string() in grade/lib.php which returns the appropriate string that describes the type of the grade item element.
This commit is contained in:
parent
3d1bb8e863
commit
458c1c771b
1 changed files with 42 additions and 0 deletions
|
@ -1494,6 +1494,48 @@ class grade_structure {
|
|||
return $outputstr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string that describes the type of the element.
|
||||
*
|
||||
* @param array $element An array representing an element in the grade_tree
|
||||
* @return string The string that describes the type of the grade element
|
||||
*/
|
||||
public function get_element_type_string(array $element): string {
|
||||
// If the element is a grade category.
|
||||
if ($element['type'] == 'category') {
|
||||
return get_string('category', 'grades');
|
||||
}
|
||||
// If the element is a grade item.
|
||||
if (in_array($element['type'], ['item', 'courseitem', 'categoryitem'])) {
|
||||
// If calculated grade item.
|
||||
if ($element['object']->is_calculated()) {
|
||||
return get_string('calculatedgrade', 'grades');
|
||||
}
|
||||
// If aggregated type grade item.
|
||||
if ($element['object']->is_aggregate_item()) {
|
||||
return get_string('aggregation', 'core_grades');
|
||||
}
|
||||
// If external grade item (module, plugin, etc.).
|
||||
if ($element['object']->is_external_item()) {
|
||||
// If outcome grade item.
|
||||
if ($element['object']->is_outcome_item()) {
|
||||
return get_string('outcome', 'grades');
|
||||
}
|
||||
return get_string('modulename', $element['object']->itemmodule);
|
||||
}
|
||||
// If manual grade item.
|
||||
if ($element['object']->itemtype == 'manual') {
|
||||
// If outcome grade item.
|
||||
if ($element['object']->is_outcome_item()) {
|
||||
return get_string('outcome', 'grades');
|
||||
}
|
||||
return get_string('manualitem', 'grades');
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of element optionally with icon and link
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue