Skip to content

Commit

Permalink
Pull Request: Support multilang tags in different places. (#98)
Browse files Browse the repository at this point in the history
Code by @lucaboesch
  • Loading branch information
lucaboesch authored and Benedikt Schneider committed Jul 16, 2019
1 parent 6e70f80 commit c895d20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
34 changes: 24 additions & 10 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public static function get_user_information($userid) {
$labels = get_config('tool_supporter', 'level_labels');
$count = 1; // Root is level 0, so we begin at 1.
foreach (explode(';', $labels) as $label) {
$data['label_level_'.$count] = $label; // Each label will be available under {{label_level_0}}, {{label_level_1}}, etc.
$data['label_level_'.$count] = external_format_string($label, $context); // Each label will be available under {{label_level_0}}, {{label_level_1}}, etc.
$count++;
}

Expand Down Expand Up @@ -544,19 +544,24 @@ public static function get_courses() {
$category = $categories[$course->category];
$patharray = explode("/", $category->path);
if (isset($patharray[1])) {
$patharray[1] = $categories[$patharray[1]]->name;
// Support multilang course categories.
$patharray[1] = external_format_string($categories[$patharray[1]]->name, $context);
$course->level_one = $patharray[1];
} else {
$course->level_one = "";
}
if (isset($patharray[2])) {
$patharray[2] = $categories[$patharray[2]]->name;
// Support multilang course categories.
$patharray[2] = external_format_string($categories[$patharray[2]]->name, $context);
$course->level_two = $patharray[2];
} else {
$course->level_two = "";
}
$coursesarray[] = (array)$course;

// Support multilang course fullnames.
$course->fullname = external_format_string($course->fullname, $context);

$coursesarray[] = (array)$course;
}
}
$data['courses'] = $coursesarray;
Expand All @@ -565,10 +570,12 @@ public static function get_courses() {
$data['uniqueleveltwoes'] = [];
foreach ($categories as $category) {
if ($category->depth == 1) {
array_push($data['uniquelevelones'], $category->name);
// Support multilang course categories.
array_push($data['uniquelevelones'], external_format_string($category->name, $context));
}
if ($category->depth == 2) {
array_push($data['uniqueleveltwoes'], $category->name);
// Support multilang course categories.
array_push($data['uniqueleveltwoes'], external_format_string($category->name, $context));
}
}

Expand All @@ -580,7 +587,7 @@ public static function get_courses() {
$labels = get_config('tool_supporter', 'level_labels');
$count = 1; // Root is level 0, so we begin at 1.
foreach (explode(';', $labels) as $label) {
$data['label_level_'.$count] = $label; // Each label will be available under {{label_level_0}}, {{label_level_1}}, etc.
$data['label_level_'.$count] = external_format_string($label, $context); // Each label will be available under {{label_level_0}}, {{label_level_1}}, etc.
$count++;
}

Expand Down Expand Up @@ -666,6 +673,8 @@ public static function get_course_info($courseid) {
$coursedetails = $DB->get_record_sql($select);
$coursedetails = (array)$coursedetails;
$coursedetails['timecreated'] = date('Y-m-d H:i:s', $coursedetails['timecreated']); // Convert timestamp to readable format.
// Support course multilang fullnames.
$coursedetails['fullname'] = external_format_string($coursedetails['fullname'], $coursecontext);

// Get whole course-path.
// Extract IDs from path and remove empty values by using array_filter.
Expand All @@ -675,7 +684,8 @@ public static function get_course_info($courseid) {
$parentcatnames = $DB->get_records_list('course_categories', 'id', $parentcategoriesids, null, 'id,name');
$pathcategories = [];
foreach ($parentcatnames as $val) {
$pathcategories[] = $val->name;
// Support multilang course categories.
$pathcategories[] = external_format_string($val->name, $coursecontext);
}
$coursedetails['level_one'] = $pathcategories[0];
isset($pathcategories[1]) ? $coursedetails['level_two'] = $pathcategories[1] : $coursedetails['level_two'] = "";
Expand All @@ -692,7 +702,8 @@ public static function get_course_info($courseid) {
$rolesincourse = [];

foreach ($usedrolesincourse as $rid => $rname) {
$rolename = $rname;
// Support multilang roles.
$rolename = external_format_string($rname, $coursecontext);
$rolenumber = \count_role_users($rid, $coursecontext);
if ($rolenumber != 0) {
$roles[] = ['roleName' => $rolename, 'roleNumber' => $rolenumber];
Expand Down Expand Up @@ -729,7 +740,10 @@ public static function get_course_info($courseid) {
$modules = \get_array_of_activities($courseid);
foreach ($modules as $mo) {
$section = \get_section_name($courseid, $mo->section);
$activity = ['section' => $section, 'activity' => $mo->mod, 'name' => $mo->name, 'visible' => $mo->visible];
// Support section and activity multilang names.
$activity = ['section' => external_format_string($section, $coursecontext),
'activity' => get_string('pluginname', $mo->mod),
'name' => external_format_string($mo->name, $coursecontext), 'visible' => $mo->visible];
$activities[] = $activity;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/output/course_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function export_for_template(renderer_base $output) {
$labels = get_config('tool_supporter', 'level_labels');
$count = 1; // Root is level 0, so we begin at 1.
foreach (explode(';', $labels) as $label) {
$data['label_level_'.$count] = $label; // Each label will be available with {{label_level_0}}, {{label_level_1}}, etc.
$data['label_level_'.$count] = format_string($label); // Each label will be available with {{label_level_0}}, {{label_level_1}}, etc.
$count++;
}

Expand Down

0 comments on commit c895d20

Please sign in to comment.