mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-36255 core_grade: fix to ensure correct context used for filters
Some grade object (outcomes,scales) can be created at site or course context, so this patch just makes sure we use the respective context when applying format_string to the name in the get_name() function.
This commit is contained in:
parent
d5bf22ecd1
commit
7e93539cf6
@ -92,7 +92,8 @@ switch ($action) {
|
||||
'sesskey' => sesskey(),
|
||||
'deleteconfirmed'=> 1));
|
||||
|
||||
echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->name), $confirmurl, "index.php?id={$courseid}");
|
||||
echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->get_name()), $confirmurl,
|
||||
"index.php?id={$courseid}");
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
} else {
|
||||
@ -115,7 +116,7 @@ if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
|
||||
$data = array();
|
||||
foreach($scales as $scale) {
|
||||
$line = array();
|
||||
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
|
||||
$line[] = $scale->get_name() .'<div class="scale_options">'.str_replace(",", ", ", $scale->scale).'</div>';
|
||||
|
||||
$used = $scale->is_used();
|
||||
$line[] = $used ? get_string('yes') : get_string('no');
|
||||
@ -141,7 +142,7 @@ if ($scales = grade_scale::fetch_all_global()) {
|
||||
$data = array();
|
||||
foreach($scales as $scale) {
|
||||
$line = array();
|
||||
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
|
||||
$line[] = $scale->get_name().'<div class="scale_options">'.str_replace(",", ", ", $scale->scale).'</div>';
|
||||
|
||||
$used = $scale->is_used();
|
||||
$line[] = $used ? get_string('yes') : get_string('no');
|
||||
|
@ -1172,16 +1172,18 @@ function get_my_remotehosts() {
|
||||
function get_scales_menu($courseid=0) {
|
||||
global $DB;
|
||||
|
||||
$sql = "SELECT id, name
|
||||
$sql = "SELECT id, name, courseid
|
||||
FROM {scale}
|
||||
WHERE courseid = 0 or courseid = ?
|
||||
ORDER BY courseid ASC, name ASC";
|
||||
$params = array($courseid);
|
||||
$scales = array();
|
||||
$results = $DB->get_records_sql_menu($sql, $params);
|
||||
foreach ($results as $i => $scalename) {
|
||||
$scales[$i] = format_string($scalename, false, array("context" => context_course::instance($courseid)));
|
||||
$results = $DB->get_records_sql($sql, $params);
|
||||
foreach ($results as $index => $record) {
|
||||
$context = empty($record->courseid) ? context_system::instance() : context_course::instance($record->courseid);
|
||||
$scales[$index] = format_string($record->name, false, ["context" => $context]);
|
||||
}
|
||||
// Format: [id => 'scale name'].
|
||||
return $scales;
|
||||
}
|
||||
|
||||
|
@ -2312,6 +2312,8 @@ class grade_category extends grade_object {
|
||||
return format_string($course->fullname, false, array("context" => context_course::instance($this->courseid)));
|
||||
|
||||
} else {
|
||||
// Grade categories can't be set up at system context (unlike scales and outcomes)
|
||||
// We therefore must have a courseid, and don't need to handle system contexts when filtering.
|
||||
return format_string($this->fullname, false, array("context" => context_course::instance($this->courseid)));
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,9 @@ class grade_outcome extends grade_object {
|
||||
* @return string name
|
||||
*/
|
||||
public function get_name() {
|
||||
return format_string($this->fullname, false, array("context" => context_course::instance($this->courseid)));
|
||||
// Grade outcomes can be created at site or course context, so set the filter context appropriately.
|
||||
$context = empty($this->courseid) ? context_system::instance() : context_course::instance($this->courseid);
|
||||
return format_string($this->fullname, false, ["context" => $context]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,7 +214,9 @@ class grade_scale extends grade_object {
|
||||
* @return string name
|
||||
*/
|
||||
public function get_name() {
|
||||
return format_string($this->name);
|
||||
// Grade scales can be created at site or course context, so set the filter context appropriately.
|
||||
$context = empty($this->courseid) ? context_system::instance() : context_course::instance($this->courseid);
|
||||
return format_string($this->name, false, ['context' => $context]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user