MDL-46123 accesslib: improve get_component_string
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
7ad7505e2f
commit
45c4d4aa8c
+32
-26
@@ -2560,43 +2560,49 @@ function get_capability_string($capabilityname) {
|
||||
*/
|
||||
function get_component_string($component, $contextlevel) {
|
||||
|
||||
if ($component === 'moodle' or $component === 'core') {
|
||||
switch ($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');
|
||||
}
|
||||
if ($component === 'moodle' || $component === 'core') {
|
||||
return context_helper::get_level_name($contextlevel);
|
||||
}
|
||||
|
||||
list($type, $name) = core_component::normalize_component($component);
|
||||
$dir = core_component::get_plugin_directory($type, $name);
|
||||
if (!file_exists($dir)) {
|
||||
// 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) {
|
||||
// TODO MDL-46123: this is really hacky and should be improved.
|
||||
case 'quiz': return get_string($name.':componentname', $component);// insane hack!!!
|
||||
case 'repository': return get_string('repository', 'repository').': '.get_string('pluginname', $component);
|
||||
case 'gradeimport': return get_string('gradeimport', 'grades').': '.get_string('pluginname', $component);
|
||||
case 'gradeexport': return get_string('gradeexport', 'grades').': '.get_string('pluginname', $component);
|
||||
case 'gradereport': return get_string('gradereport', 'grades').': '.get_string('pluginname', $component);
|
||||
case 'webservice': return get_string('webservice', 'webservice').': '.get_string('pluginname', $component);
|
||||
case 'block': return get_string('block').': '.get_string('pluginname', basename($component));
|
||||
case 'quiz':
|
||||
$prefix = get_string('quizreport', 'quiz') . ': ';
|
||||
break;
|
||||
case 'repository':
|
||||
$prefix = get_string('repository', 'repository') . ': ';
|
||||
break;
|
||||
case 'gradeimport':
|
||||
$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':
|
||||
if (get_string_manager()->string_exists('pluginname', $component)) {
|
||||
return get_string('activity').': '.get_string('pluginname', $component);
|
||||
} else {
|
||||
return get_string('activity').': '.get_string('modulename', $component);
|
||||
}
|
||||
default: return get_string('pluginname', $component);
|
||||
$prefix = get_string('activity') . ': ';
|
||||
break;
|
||||
|
||||
// Default case, just use the plugin name.
|
||||
default:
|
||||
$prefix = '';
|
||||
}
|
||||
return $prefix . get_string('pluginname', $component);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -735,6 +735,7 @@ $string['quizordernotrandom'] = 'Order of quiz not shuffled';
|
||||
$string['quizorderrandom'] = '* Order of quiz is shuffled';
|
||||
$string['quiz:preview'] = 'Preview quizzes';
|
||||
$string['quiz:regrade'] = 'Regrade quiz attempts';
|
||||
$string['quizreport'] = 'Quiz report';
|
||||
$string['quiz:reviewmyattempts'] = 'Review your own attempts';
|
||||
$string['quizsettings'] = 'Quiz settings';
|
||||
$string['quiz:view'] = 'View quiz information';
|
||||
|
||||
@@ -48,7 +48,6 @@ $string['graded'] = '(graded)';
|
||||
$string['gradenextungraded'] = 'Grade next {$a} ungraded attempts';
|
||||
$string['gradeungraded'] = 'Grade all {$a} ungraded attempts';
|
||||
$string['grading'] = 'Manual grading';
|
||||
$string['grading:componentname'] = 'Manual grading report';
|
||||
$string['grading:viewidnumber'] = 'See student ID numbers while grading';
|
||||
$string['grading:viewstudentnames'] = 'See student names while grading';
|
||||
$string['gradingall'] = 'All {$a} attempts on this question.';
|
||||
|
||||
@@ -112,7 +112,6 @@ $string['standarddeviation'] = 'Standard deviation (for {$a})';
|
||||
$string['standarddeviationq'] = 'Standard deviation';
|
||||
$string['standarderror'] = 'Standard error (for {$a})';
|
||||
$string['statistics'] = 'Statistics';
|
||||
$string['statistics:componentname'] = 'Quiz statistics report';
|
||||
$string['statisticsreport'] = 'Statistics report';
|
||||
$string['statisticsreportgraph'] = 'Statistics for question positions';
|
||||
$string['statistics:view'] = 'View statistics report';
|
||||
|
||||
@@ -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
|
||||
|
||||
=== 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 ===
|
||||
|
||||
* New quiz_attempts_report_table method: \quiz_attempts_report_table::checkbox_col_header()
|
||||
|
||||
Reference in New Issue
Block a user