Skip to content

Commit

Permalink
MDL-29187 multilang Reviewed the uses of category name and ensured th…
Browse files Browse the repository at this point in the history
…ings are being formatted correctly
  • Loading branch information
Sam Hemelryk committed Sep 7, 2011
1 parent 5d2db8a commit 6339048
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backup/util/ui/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public function render_restore_category_search(restore_category_search $componen
}
$row->cells = array(
html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)),
$category->name,
format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id))),
format_text($category->description, $category->descriptionformat, array('overflowdiv'=>true))
);
$table->data[] = $row;
Expand Down
5 changes: 3 additions & 2 deletions blocks/course_list/block_course_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ function get_content() {
if ($categories) { //Check we have categories
if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links
foreach ($categories as $category) {
$categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
$this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">".$icon . format_string($category->name) . "</a>";
$this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">".$icon . $categoryname . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
Expand All @@ -75,7 +76,7 @@ function get_content() {
$this->content->items[]="<a $linkcss title=\""
. format_string($course->shortname)."\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
.$icon. format_string($course->fullname) . "</a>";
.$icon. format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
Expand Down
2 changes: 1 addition & 1 deletion course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
}
$catlinkcss = $subcategory->visible ? '' : ' class="dimmed" ';
echo '<a '.$catlinkcss.' href="category.php?id='.$subcategory->id.'">'.
format_string($subcategory->name).'</a><br />';
format_string($subcategory->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $subcategory->id))).'</a><br />';
}
}
if (!$firstentry) {
Expand Down
3 changes: 2 additions & 1 deletion course/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
}

$category = $DB->get_record("course_categories", array("id"=>$course->category));
$categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));

$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/'));
$PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
$PAGE->navbar->add($category->name, new moodle_url('/course/category.php', array('id'=>$course->category)));
$PAGE->navbar->add($categoryname, new moodle_url('/course/category.php', array('id'=>$course->category)));
if (! $delete) {
$strdeletecheck = get_string("deletecheck", "", $course->shortname);
$strdeletecoursecheck = get_string("deletecoursecheck");
Expand Down
4 changes: 2 additions & 2 deletions course/delete_category_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ function definition() {
}

/// Now build the form.
$mform->addElement('header','general', get_string('categorycurrentcontents', '', format_string($category->name)));
$mform->addElement('header','general', get_string('categorycurrentcontents', '', format_string($category->name, true, array('context' => $categorycontext))));

if ($containscourses || $containscategories || $containsquestions) {
if (empty($options)) {
print_error('youcannotdeletecategory', 'error', 'index.php', format_string($category->name));
print_error('youcannotdeletecategory', 'error', 'index.php', format_string($category->name, true, array('context' => $categorycontext)));
}

/// Describe the contents of this category.
Expand Down
6 changes: 3 additions & 3 deletions course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
require_capability('moodle/category:manage', $context);
require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent));

$heading = get_string('deletecategory', 'moodle', format_string($deletecat->name));
$heading = get_string('deletecategory', 'moodle', format_string($deletecat->name, true, array('context' => $context)));
require_once('delete_category_form.php');
$mform = new delete_category_form(null, $deletecat);
$mform->set_data(array('delete'=>$delete));
Expand All @@ -151,7 +151,7 @@
foreach($deletedcourses as $course) {
echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess');
}
echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name)), 'notifysuccess');
echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name, true, array('context' => $context))), 'notifysuccess');

} else {
category_delete_move($deletecat, $data->newparent, true);
Expand Down Expand Up @@ -315,7 +315,7 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $
$linkcss = $category->visible ? '' : ' class="dimmed" ';
echo '<a '.$linkcss.' title="'.$str->edit.'" '.
' href="category.php?id='.$category->id.'&amp;categoryedit=on&amp;sesskey='.sesskey().'">'.
format_string($category->name).'</a>';
format_string($category->name, true, array('context' => $category->context)).'</a>';
echo '</td>';

echo '<td class="count">'.$category->coursecount.'</td>';
Expand Down
17 changes: 11 additions & 6 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1997,21 +1997,23 @@ function make_categories_list(&$list, &$parents, $requiredcapability = '',
return;
}

$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
$categoryname = format_string($category->name, true, array('context' => $context));

// Update $path.
if ($path) {
$path = $path.' / '.format_string($category->name);
$path = $path.' / '.$categoryname;
} else {
$path = format_string($category->name);
$path = $categoryname;
}

// Add this category to $list, if the permissions check out.
if (empty($requiredcapability)) {
$list[$category->id] = $path;

} else {
ensure_context_subobj_present($category, CONTEXT_COURSECAT);
$requiredcapability = (array)$requiredcapability;
if (has_all_capabilities($requiredcapability, $category->context)) {
if (has_all_capabilities($requiredcapability, $context)) {
$list[$category->id] = $path;
}
}
Expand Down Expand Up @@ -2184,11 +2186,14 @@ function print_category_info($category, $depth=0, $showcourses = false) {
}

$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary');
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
$fullname = format_string($category->name, true, array('context' => $context));

if ($showcourses and $coursecount) {
echo '<div class="categorylist clearfix">';
$cat = '';
$cat .= html_writer::tag('div', $catimage, array('class'=>'image'));
$catlink = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), format_string($category->name), $catlinkcss);
$catlink = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss);
$cat .= html_writer::tag('div', $catlink, array('class'=>'name'));

$html = '';
Expand Down Expand Up @@ -2246,7 +2251,7 @@ function print_category_info($category, $depth=0, $showcourses = false) {
} else {
echo '<div class="categorylist">';
$html = '';
$cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), format_string($category->name), $catlinkcss);
$cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss);
$cat .= html_writer::tag('span', ' ('.count($courses).')', array('title'=>get_string('numberofcourses'), 'class'=>'numberofcourse'));

if ($depth > 0) {
Expand Down
4 changes: 3 additions & 1 deletion course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ protected function course_category_tree_category(stdClass $category, $depth=1) {
$classes[] = 'collapsed';
}
}
$categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));

$content .= html_writer::start_tag('div', array('class'=>join(' ', $classes)));
$content .= html_writer::start_tag('div', array('class'=>'category_label'));
$content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $category->name, array('class'=>'category_link'));
$content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $categoryname, array('class'=>'category_link'));
$content .= html_writer::end_tag('div');
if ($hassubcategories) {
$content .= html_writer::start_tag('div', array('class'=>'subcategories'));
Expand Down
2 changes: 1 addition & 1 deletion lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3584,7 +3584,7 @@ function print_context_name($context, $withprefix = true, $short = false) {
if ($withprefix){
$name = get_string('category').': ';
}
$name .=format_string($category->name);
$name .= format_string($category->name, true, array('context' => $context));
}
break;

Expand Down
4 changes: 3 additions & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,9 @@ protected function add_category(stdClass $category, navigation_node $parent) {
continue;
}
$url = new moodle_url('/course/category.php', array('id' => $category->id));
$categorynode = $parent->add($category->name, $url, self::TYPE_CATEGORY, $category->name, $category->id);
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
$categoryname = format_string($category->name, true, array('context' => $context));
$categorynode = $parent->add($categoryname, $url, self::TYPE_CATEGORY, $categoryname, $category->id);
if (empty($category->visible)) {
if (has_capability('moodle/category:viewhiddencategories', get_system_context())) {
$categorynode->hidden = true;
Expand Down
4 changes: 2 additions & 2 deletions mod/feedback/item/info/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function print_item_preview($item) {
$itemshowvalue = $itemvalue;
break;
case 3:
$itemvalue = $coursecategory->name;
$itemvalue = format_string($coursecategory->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $coursecategory->id)));
$itemshowvalue = $itemvalue;
break;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ function print_item_complete($item, $value = '', $highlightrequire = false) {
$itemshowvalue = $itemvalue;
break;
case 3:
$itemvalue = $coursecategory->name;
$itemvalue = format_string($coursecategory->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $coursecategory->id)));
$itemshowvalue = $itemvalue;
break;
}
Expand Down

0 comments on commit 6339048

Please sign in to comment.