Skip to content

Commit

Permalink
MDL-40430 - Libraries: Deprecate print_context_name().
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Jul 9, 2013
1 parent b4482df commit 329846f
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion admin/roles/classes/check_capability_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/classes/permissions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions blocks/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function definition() {
$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
Expand Down Expand Up @@ -142,7 +142,7 @@ function definition() {
// 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);
Expand Down
2 changes: 1 addition & 1 deletion filter/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

$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");
Expand Down
15 changes: 0 additions & 15 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4143,7 +4143,7 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
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
Expand Down Expand Up @@ -4172,7 +4172,7 @@ protected function load_block_settings() {
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);

Expand Down
2 changes: 1 addition & 1 deletion lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public function debug_summary() {
$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) {
Expand Down
8 changes: 4 additions & 4 deletions lib/questionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,7 @@ public function test_permission_evaluation() {

$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);
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===

Expand Down
4 changes: 2 additions & 2 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6460,7 +6460,7 @@ public function prepare_package() {
} 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);

Expand Down Expand Up @@ -6509,7 +6509,7 @@ public function prepare_package() {

// 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');
Expand Down
7 changes: 4 additions & 3 deletions question/category_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ public function set_icon_html($first, $last, $lastitem){
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');
}
}

Expand Down Expand Up @@ -255,7 +255,8 @@ public function output_edit_lists() {
$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();
}
Expand Down
4 changes: 2 additions & 2 deletions report/security/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = '<li>'.get_string('check_riskbackup_editoverride', 'report_security', $role).'</li>';
}
Expand All @@ -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)) {
Expand Down

0 comments on commit 329846f

Please sign in to comment.