diff --git a/admin/roles/classes/check_capability_table.php b/admin/roles/classes/check_capability_table.php index de9eaae248c..20f93702d30 100644 --- a/admin/roles/classes/check_capability_table.php +++ b/admin/roles/classes/check_capability_table.php @@ -41,7 +41,7 @@ class core_role_check_capability_table extends core_role_capability_table_base { * Constructor * @param object $context the context this table relates to. * @param object $user the user we are generating the results for. - * @param string $contextname print_context_name($context) - to save recomputing. + * @param string $contextname $context->get_context_name() - to save recomputing. */ public function __construct($context, $user, $contextname) { parent::__construct($context, 'explaincaps'); diff --git a/admin/roles/classes/permissions_table.php b/admin/roles/classes/permissions_table.php index 4d317f5cad8..aa9a2f49253 100644 --- a/admin/roles/classes/permissions_table.php +++ b/admin/roles/classes/permissions_table.php @@ -38,7 +38,7 @@ class core_role_permissions_table extends core_role_capability_table_base { /** * Constructor. * @param context $context the context this table relates to. - * @param string $contextname print_context_name($context) - to save recomputing. + * @param string $contextname $context->get_context_name() - to save recomputing. * @param array $allowoverrides * @param array $allowsafeoverrides * @param array $overridableroles diff --git a/blocks/edit_form.php b/blocks/edit_form.php index 31eadf60521..44e514a4ee7 100644 --- a/blocks/edit_form.php +++ b/blocks/edit_form.php @@ -91,7 +91,7 @@ class block_edit_form extends moodleform { $mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id); $mform->setType('bui_parentcontextid', PARAM_INT); - $mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext)); + $mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), $parentcontext->get_context_name()); $mform->addHelpButton('bui_homecontext', 'createdat', 'block'); // For pre-calculated (fixed) pagetype lists @@ -142,7 +142,7 @@ class block_edit_form extends moodleform { // module context doesn't have child contexts, so display in current context only $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT); } else { - $parentcontextname = print_context_name($parentcontext); + $parentcontextname = $parentcontext->get_context_name(); $contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname); $contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname); $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions); diff --git a/filter/manage.php b/filter/manage.php index 0bea014ba08..c4b2f565568 100644 --- a/filter/manage.php +++ b/filter/manage.php @@ -53,7 +53,7 @@ if (!in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, C $isfrontpage = ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID); -$contextname = print_context_name($context); +$contextname = $context->get_context_name(); if ($context->contextlevel == CONTEXT_COURSECAT) { $heading = "$SITE->fullname: ".get_string("categories"); diff --git a/lib/accesslib.php b/lib/accesslib.php index 56077c9f558..711fa5f1cfe 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -7302,21 +7302,6 @@ function delete_context($contextlevel, $instanceid, $deleterecord = true) { return true; } -/** - * Prints human readable context identifier. - * - * @deprecated since 2.2 - * @param context $context the context. - * @param boolean $withprefix whether to prefix the name of the context with the - * type of context, e.g. User, Course, Forum, etc. - * @param boolean $short whether to user the short name of the thing. Only applies - * to course contexts - * @return string the human readable context name. - */ -function print_context_name(context $context, $withprefix = true, $short = false) { - return $context->get_context_name($withprefix, $short); -} - /** * Get a URL for a context, if there is a natural one. For example, for * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9ba5a297ab9..18577005759 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4474,7 +4474,7 @@ function blog_get_context_url($context=null) { break; case CONTEXT_MODULE: $filterparam = 'modid'; - $strlevel = print_context_name($context); + $strlevel = $context->get_context_name(); break; case CONTEXT_USER: $filterparam = 'userid'; @@ -5106,3 +5106,20 @@ function get_contextlevel_name($contextlevel) { debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER); return context_helper::get_level_name($contextlevel); } + +/** + * Prints human readable context identifier. + * + * @deprecated since 2.2 + * @see context::get_context_name() + * @param context $context the context. + * @param boolean $withprefix whether to prefix the name of the context with the + * type of context, e.g. User, Course, Forum, etc. + * @param boolean $short whether to user the short name of the thing. Only applies + * to course contexts + * @return string the human readable context name. + */ +function print_context_name(context $context, $withprefix = true, $short = false) { + debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER); + return $context->get_context_name($withprefix, $short); +} diff --git a/lib/navigationlib.php b/lib/navigationlib.php index e4393d5d35c..258d2731dde 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -4143,7 +4143,7 @@ class settings_navigation extends navigation_node { protected function load_block_settings() { global $CFG; - $blocknode = $this->add(print_context_name($this->context)); + $blocknode = $this->add($this->context->get_context_name()); $blocknode->force_open(); // Assign local roles @@ -4172,7 +4172,7 @@ class settings_navigation extends navigation_node { protected function load_category_settings() { global $CFG; - $categorynode = $this->add(print_context_name($this->context), null, null, null, 'categorysettings'); + $categorynode = $this->add($this->context->get_context_name(), null, null, null, 'categorysettings'); $categorynode->force_open(); $onmanagepage = $this->page->url->compare(new moodle_url('/course/manage.php'), URL_MATCH_BASE); diff --git a/lib/pagelib.php b/lib/pagelib.php index 28967fab86e..fd29d8f5438 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -819,7 +819,7 @@ class moodle_page { $summary = ''; $summary .= 'General type: ' . $this->pagelayout . '. '; if (!during_initial_install()) { - $summary .= 'Context ' . print_context_name($this->_context) . ' (context id ' . $this->_context->id . '). '; + $summary .= 'Context ' . $this->context->get_context_name() . ' (context id ' . $this->_context->id . '). '; } $summary .= 'Page type ' . $this->pagetype . '. '; if ($this->subpage) { diff --git a/lib/questionlib.php b/lib/questionlib.php index ecbbb473059..71734e51f59 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -448,7 +448,7 @@ function question_delete_course_category($category, $newcategory, $feedback=true } if (!$rescueqcategory = question_save_from_deletion( array_keys($questionids), $parentcontextid, - print_context_name($context), $rescueqcategory)) { + $context->get_context_name(), $rescueqcategory)) { return false; } $feedbackdata[] = array($category->name, @@ -482,8 +482,8 @@ function question_delete_course_category($category, $newcategory, $feedback=true array('contextid'=>$context->id)); if ($feedback) { $a = new stdClass(); - $a->oldplace = print_context_name($context); - $a->newplace = print_context_name($newcontext); + $a->oldplace = $context->get_context_name(); + $a->newplace = $newcontext->get_context_name(); echo $OUTPUT->notification( get_string('movedquestionsandcategories', 'question', $a), 'notifysuccess'); } @@ -1064,7 +1064,7 @@ function question_make_default_categories($contexts) { array('contextid' => $context->id))) { // Otherwise, we need to make one $category = new stdClass(); - $contextname = print_context_name($context, false, true); + $contextname = $context->get_context_name(false, true); $category->name = get_string('defaultfor', 'question', $contextname); $category->info = get_string('defaultinfofor', 'question', $contextname); $category->contextid = $context->id; diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 74294a53d72..e4d292b1fca 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2469,6 +2469,7 @@ class accesslib_testcase extends advanced_testcase { $context = context_course::instance($testcourses[2]); $name = print_context_name($context); + $this->assertDebuggingCalled('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER); $this->assertFalse(empty($name)); $url = get_context_url($coursecontext); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index a9082e644cf..ebc204d8320 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -21,6 +21,7 @@ information provided here is intended especially for developers. * context_moved() is deprecated, please use context::update_moved(). * context_instance_preload() is deprecated, please use context_helper::preload_from_record(). * get_contextlevel_name() is deprecated, please use context_helper::get_level_name(). +* print_context_name() is deprecated, please use $context->get_context_name(). === 2.5.1 === diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 391f7aedbc8..efddb100929 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -6460,7 +6460,7 @@ class assign_portfolio_caller extends portfolio_module_caller_base { } else if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $this->exporter->get('format')->leap2a_writer(); $entry = new portfolio_format_leap2a_entry($this->area . $this->cmid, - print_context_name($context), + $context->get_context_name(), 'resource', $html); @@ -6509,7 +6509,7 @@ class assign_portfolio_caller extends portfolio_module_caller_base { // If we have multiple files, they should be grouped together into a folder. $entry = new portfolio_format_leap2a_entry($baseid . 'group', - print_context_name($context), + $context->get_context_name(), 'selection'); $leapwriter->add_entry($entry); $leapwriter->make_selection($entry, $entryids, 'Folder'); diff --git a/question/category_class.php b/question/category_class.php index 8fb88cf9b09..f6ef2bc7a41 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -83,12 +83,12 @@ class question_category_list_item extends list_item { if (($this->parentlist->nextlist !== null) && $last && $toplevel && (count($this->parentlist->items)>1)){ $url = new moodle_url($this->parentlist->pageurl, array('movedowncontext'=>$this->id, 'tocontext'=>$this->parentlist->nextlist->context->id, 'sesskey'=>sesskey())); $this->icons['down'] = $this->image_icon( - get_string('shareincontext', 'question', print_context_name($this->parentlist->nextlist->context)), $url, 'down'); + get_string('shareincontext', 'question', $this->parentlist->nextlist->context->get_context_name()), $url, 'down'); } if (($this->parentlist->lastlist !== null) && $first && $toplevel && (count($this->parentlist->items)>1)){ $url = new moodle_url($this->parentlist->pageurl, array('moveupcontext'=>$this->id, 'tocontext'=>$this->parentlist->lastlist->context->id, 'sesskey'=>sesskey())); $this->icons['up'] = $this->image_icon( - get_string('shareincontext', 'question', print_context_name($this->parentlist->lastlist->context)), $url, 'up'); + get_string('shareincontext', 'question', $this->parentlist->lastlist->context->get_context_name()), $url, 'up'); } } @@ -255,7 +255,8 @@ class question_category_object { $listhtml = $list->to_html(0, array('str'=>$this->str)); if ($listhtml){ echo $OUTPUT->box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel' . $list->context->contextlevel); - echo $OUTPUT->heading(get_string('questioncatsfor', 'question', print_context_name(context::instance_by_id($context))), 3); + $fullcontext = context::instance_by_id($context); + echo $OUTPUT->heading(get_string('questioncatsfor', 'question', $fullcontext->get_context_name()), 3); echo $listhtml; echo $OUTPUT->box_end(); } diff --git a/report/security/locallib.php b/report/security/locallib.php index d6e6bef2a2c..c49f15e5f2a 100644 --- a/report/security/locallib.php +++ b/report/security/locallib.php @@ -822,7 +822,7 @@ function report_security_check_riskbackup($detailed=false) { $role->name = $role->localname; $context = context::instance_by_id($role->contextid); $role->name = role_get_name($role, $context, ROLENAME_BOTH); - $role->contextname = print_context_name($context); + $role->contextname = $context->get_context_name(); $role->url = "$CFG->wwwroot/$CFG->admin/roles/override.php?contextid=$role->contextid&roleid=$role->id"; $links[] = '