Commit 45c4d4aa authored by Tim Hunt's avatar Tim Hunt Committed by Eloy Lafuente
Browse files

MDL-46123 accesslib: improve get_component_string

parent 7ad7505e
...@@ -2560,43 +2560,49 @@ function get_capability_string($capabilityname) { ...@@ -2560,43 +2560,49 @@ function get_capability_string($capabilityname) {
*/ */
function get_component_string($component, $contextlevel) { function get_component_string($component, $contextlevel) {
if ($component === 'moodle' or $component === 'core') { if ($component === 'moodle' || $component === 'core') {
switch ($contextlevel) { return context_helper::get_level_name($contextlevel);
// TODO MDL-46123: this should probably use context level names instead
case CONTEXT_SYSTEM: return get_string('coresystem');
case CONTEXT_USER: return get_string('users');
case CONTEXT_COURSECAT: return get_string('categories');
case CONTEXT_COURSE: return get_string('course');
case CONTEXT_MODULE: return get_string('activities');
case CONTEXT_BLOCK: return get_string('block');
default: print_error('unknowncontext');
}
} }
list($type, $name) = core_component::normalize_component($component); list($type, $name) = core_component::normalize_component($component);
$dir = core_component::get_plugin_directory($type, $name); $dir = core_component::get_plugin_directory($type, $name);
if (!file_exists($dir)) { if (!file_exists($dir)) {
// plugin not installed, bad luck, there is no way to find the name // plugin not installed, bad luck, there is no way to find the name
return $component.' ???'; return $component . ' ???';
} }
// Some plugin types need an extra prefix to make the name easy to understand.
switch ($type) { switch ($type) {
// TODO MDL-46123: this is really hacky and should be improved. case 'quiz':
case 'quiz': return get_string($name.':componentname', $component);// insane hack!!! $prefix = get_string('quizreport', 'quiz') . ': ';
case 'repository': return get_string('repository', 'repository').': '.get_string('pluginname', $component); break;
case 'gradeimport': return get_string('gradeimport', 'grades').': '.get_string('pluginname', $component); case 'repository':
case 'gradeexport': return get_string('gradeexport', 'grades').': '.get_string('pluginname', $component); $prefix = get_string('repository', 'repository') . ': ';
case 'gradereport': return get_string('gradereport', 'grades').': '.get_string('pluginname', $component); break;
case 'webservice': return get_string('webservice', 'webservice').': '.get_string('pluginname', $component); case 'gradeimport':
case 'block': return get_string('block').': '.get_string('pluginname', basename($component)); $prefix = get_string('gradeimport', 'grades') . ': ';
break;
case 'gradeexport':
$prefix = get_string('gradeexport', 'grades') . ': ';
break;
case 'gradereport':
$prefix = get_string('gradereport', 'grades') . ': ';
break;
case 'webservice':
$prefix = get_string('webservice', 'webservice') . ': ';
break;
case 'block':
$prefix = get_string('block') . ': ';
break;
case 'mod': case 'mod':
if (get_string_manager()->string_exists('pluginname', $component)) { $prefix = get_string('activity') . ': ';
return get_string('activity').': '.get_string('pluginname', $component); break;
} else {
return get_string('activity').': '.get_string('modulename', $component); // Default case, just use the plugin name.
} default:
default: return get_string('pluginname', $component); $prefix = '';
} }
return $prefix . get_string('pluginname', $component);
} }
/** /**
......
...@@ -735,6 +735,7 @@ $string['quizordernotrandom'] = 'Order of quiz not shuffled'; ...@@ -735,6 +735,7 @@ $string['quizordernotrandom'] = 'Order of quiz not shuffled';
$string['quizorderrandom'] = '* Order of quiz is shuffled'; $string['quizorderrandom'] = '* Order of quiz is shuffled';
$string['quiz:preview'] = 'Preview quizzes'; $string['quiz:preview'] = 'Preview quizzes';
$string['quiz:regrade'] = 'Regrade quiz attempts'; $string['quiz:regrade'] = 'Regrade quiz attempts';
$string['quizreport'] = 'Quiz report';
$string['quiz:reviewmyattempts'] = 'Review your own attempts'; $string['quiz:reviewmyattempts'] = 'Review your own attempts';
$string['quizsettings'] = 'Quiz settings'; $string['quizsettings'] = 'Quiz settings';
$string['quiz:view'] = 'View quiz information'; $string['quiz:view'] = 'View quiz information';
......
...@@ -48,7 +48,6 @@ $string['graded'] = '(graded)'; ...@@ -48,7 +48,6 @@ $string['graded'] = '(graded)';
$string['gradenextungraded'] = 'Grade next {$a} ungraded attempts'; $string['gradenextungraded'] = 'Grade next {$a} ungraded attempts';
$string['gradeungraded'] = 'Grade all {$a} ungraded attempts'; $string['gradeungraded'] = 'Grade all {$a} ungraded attempts';
$string['grading'] = 'Manual grading'; $string['grading'] = 'Manual grading';
$string['grading:componentname'] = 'Manual grading report';
$string['grading:viewidnumber'] = 'See student ID numbers while grading'; $string['grading:viewidnumber'] = 'See student ID numbers while grading';
$string['grading:viewstudentnames'] = 'See student names while grading'; $string['grading:viewstudentnames'] = 'See student names while grading';
$string['gradingall'] = 'All {$a} attempts on this question.'; $string['gradingall'] = 'All {$a} attempts on this question.';
......
...@@ -112,7 +112,6 @@ $string['standarddeviation'] = 'Standard deviation (for {$a})'; ...@@ -112,7 +112,6 @@ $string['standarddeviation'] = 'Standard deviation (for {$a})';
$string['standarddeviationq'] = 'Standard deviation'; $string['standarddeviationq'] = 'Standard deviation';
$string['standarderror'] = 'Standard error (for {$a})'; $string['standarderror'] = 'Standard error (for {$a})';
$string['statistics'] = 'Statistics'; $string['statistics'] = 'Statistics';
$string['statistics:componentname'] = 'Quiz statistics report';
$string['statisticsreport'] = 'Statistics report'; $string['statisticsreport'] = 'Statistics report';
$string['statisticsreportgraph'] = 'Statistics for question positions'; $string['statisticsreportgraph'] = 'Statistics for question positions';
$string['statistics:view'] = 'View statistics report'; $string['statistics:view'] = 'View statistics report';
......
...@@ -2,6 +2,14 @@ This files describes API changes for quiz report plugins. ...@@ -2,6 +2,14 @@ This files describes API changes for quiz report plugins.
Overview of this plugin type at http://docs.moodle.org/dev/Quiz_reports Overview of this plugin type at http://docs.moodle.org/dev/Quiz_reports
=== 3.9 ===
* Quiz report plugins defining capabilities used to require an extra string like
$string['statistics:componentname'] = 'Quiz statistics report';
in addition to
$string['pluginname'] = 'Statistics';
This is no longer required.
=== 3.8 === === 3.8 ===
* New quiz_attempts_report_table method: \quiz_attempts_report_table::checkbox_col_header() * New quiz_attempts_report_table method: \quiz_attempts_report_table::checkbox_col_header()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment