Merge branch 'MDL-34472-master' of git://github.com/ankitagarwal/moodle
Conflicts: lib/upgrade.txt
This commit is contained in:
+1
-31
@@ -717,7 +717,7 @@ function has_capability_in_accessdata($capability, context $context, array &$acc
|
||||
* @see has_capability()
|
||||
*
|
||||
* @param string $capability the name of the capability to check. For example mod/forum:view
|
||||
* @param context $context the context to check the capability in. You normally get this with {@link get_context_instance}.
|
||||
* @param context $context the context to check the capability in. You normally get this with context_xxxx::instance().
|
||||
* @param int $userid A user id. By default (null) checks the permissions of the current user.
|
||||
* @param bool $doanything If false, ignore effect of admin role assignment
|
||||
* @param string $errormessage The error string to to user. Defaults to 'nopermissions'.
|
||||
@@ -7265,36 +7265,6 @@ function get_system_context($cache = true) {
|
||||
return context_system::instance(0, IGNORE_MISSING, $cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context instance as an object. This function will create the
|
||||
* context instance if it does not exist yet.
|
||||
*
|
||||
* @deprecated since 2.2, use context_course::instance() or other relevant class instead
|
||||
* @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
|
||||
* @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
|
||||
* for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
|
||||
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
|
||||
* MUST_EXIST means throw exception if no record or multiple records found
|
||||
* @return context The context object.
|
||||
*/
|
||||
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
|
||||
$instances = (array)$instance;
|
||||
$contexts = array();
|
||||
|
||||
$classname = context_helper::get_class_for_level($contextlevel);
|
||||
|
||||
// we do not load multiple contexts any more, PAGE should be responsible for any preloading
|
||||
foreach ($instances as $inst) {
|
||||
$contexts[$inst] = $classname::instance($inst, $strictness);
|
||||
}
|
||||
|
||||
if (is_array($instance)) {
|
||||
return $contexts;
|
||||
} else {
|
||||
return $contexts[$instance];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a context instance as an object, from a given context id.
|
||||
*
|
||||
|
||||
@@ -4849,3 +4849,37 @@ function can_use_rotated_text() {
|
||||
debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context instance as an object. This function will create the
|
||||
* context instance if it does not exist yet.
|
||||
*
|
||||
* @deprecated since 2.2, use context_course::instance() or other relevant class instead
|
||||
* @todo This will be deleted in Moodle 2.8, refer MDL-34472
|
||||
* @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
|
||||
* @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
|
||||
* for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
|
||||
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
|
||||
* MUST_EXIST means throw exception if no record or multiple records found
|
||||
* @return context The context object.
|
||||
*/
|
||||
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
|
||||
|
||||
debugging('get_context_instance() is deprecated, please use respective context_xxxx::instance().', DEBUG_DEVELOPER);
|
||||
|
||||
$instances = (array)$instance;
|
||||
$contexts = array();
|
||||
|
||||
$classname = context_helper::get_class_for_level($contextlevel);
|
||||
|
||||
// we do not load multiple contexts any more, PAGE should be responsible for any preloading
|
||||
foreach ($instances as $inst) {
|
||||
$contexts[$inst] = $classname::instance($inst, $strictness);
|
||||
}
|
||||
|
||||
if (is_array($instance)) {
|
||||
return $contexts;
|
||||
} else {
|
||||
return $contexts[$instance];
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -899,7 +899,7 @@ class moodle_page {
|
||||
/**
|
||||
* Set the main context to which this page belongs.
|
||||
*
|
||||
* @param context $context a context object, normally obtained with get_context_instance.
|
||||
* @param context $context a context object. You normally get this with context_xxxx::instance().
|
||||
*/
|
||||
public function set_context($context) {
|
||||
if ($context === null) {
|
||||
|
||||
@@ -2367,6 +2367,10 @@ class accesslib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(count($children), $DB->count_records('context')-1);
|
||||
unset($children);
|
||||
|
||||
// Make sure a debugging is thrown.
|
||||
get_context_instance($record->contextlevel, $record->instanceid);
|
||||
$this->assertDebuggingCalled('get_context_instance() is deprecated, please use respective context_xxxx::instance().', DEBUG_DEVELOPER);
|
||||
|
||||
$DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK));
|
||||
create_contexts();
|
||||
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_BLOCK)));
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ information provided here is intended especially for developers.
|
||||
=== 2.6 ===
|
||||
* Use new core_component::* plugin listing and component normalisation methods.
|
||||
* Use core_text::* instead of textlib:: and also core_collator::* instead of collatorlib::*.
|
||||
|
||||
* get_context_instance() now throws deprecated warning.
|
||||
|
||||
=== 2.5.1 ===
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class assign_feedback_offline extends assign_feedback_plugin {
|
||||
|
||||
$gradeimporter = new assignfeedback_offline_grade_importer($importid, $this->assignment);
|
||||
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
redirect(new moodle_url('view.php',
|
||||
|
||||
+2
-2
@@ -527,11 +527,11 @@ function user_get_user_details_courses($user) {
|
||||
*/
|
||||
function can_view_user_details_cap($user, $course = null) {
|
||||
// Check $USER has the capability to view the user details at user context.
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
||||
$usercontext = context_user::instance($user->id);
|
||||
$result = has_capability('moodle/user:viewdetails', $usercontext);
|
||||
// Otherwise can $USER see them at course context.
|
||||
if (!$result && !empty($course)) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
$result = has_capability('moodle/user:viewdetails', $context);
|
||||
}
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user