MDL-40430 - Libraries: Deprecate print_context_name().
authorAdrian Greeve <adrian@moodle.com>
Fri, 5 Jul 2013 03:23:44 +0000 (11:23 +0800)
committerAdrian Greeve <adrian@moodle.com>
Tue, 9 Jul 2013 08:11:55 +0000 (16:11 +0800)
14 files changed:
admin/roles/classes/check_capability_table.php
admin/roles/classes/permissions_table.php
blocks/edit_form.php
filter/manage.php
lib/accesslib.php
lib/deprecatedlib.php
lib/navigationlib.php
lib/pagelib.php
lib/questionlib.php
lib/tests/accesslib_test.php
lib/upgrade.txt
mod/assign/locallib.php
question/category_class.php
report/security/locallib.php

index de9eaae..20f9370 100644 (file)
@@ -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');
index 4d317f5..aa9a2f4 100644 (file)
@@ -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
index 31eadf6..44e514a 100644 (file)
@@ -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);
index 0bea014..c4b2f56 100644 (file)
@@ -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");
index 56077c9..711fa5f 100644 (file)
@@ -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
index 9ba5a29..1857700 100644 (file)
@@ -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);
+}
index e4393d5..258d273 100644 (file)
@@ -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);
 
index 28967fa..fd29d8f 100644 (file)
@@ -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) {
index ecbbb47..71734e5 100644 (file)
@@ -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;
index 74294a5..e4d292b 100644 (file)
@@ -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);
index 90b0d68..cc820a7 100644 (file)
@@ -20,6 +20,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 ===
 
index 391f7ae..efddb10 100644 (file)
@@ -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');
index 8fb88cf..f6ef2bc 100644 (file)
@@ -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();
             }
index d6e6bef..c49f15e 100644 (file)
@@ -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&amp;roleid=$role->id";
                 $links[] = '<li>'.get_string('check_riskbackup_editoverride', 'report_security', $role).'</li>';
             }
@@ -841,7 +841,7 @@ function report_security_check_riskbackup($detailed=false) {
             $context = context::instance_by_id($user->contextid);
             $url = "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=$user->contextid&amp;roleid=$user->roleid";
             $a = (object)array('fullname'=>fullname($user), 'url'=>$url, 'email'=>$user->email,
-                               'contextname'=>print_context_name($context));
+                               'contextname'=>$context->get_context_name());
             $users[] = '<li>'.get_string('check_riskbackup_unassign', 'report_security', $a).'</li>';
         }
         if (!empty($users)) {