Permalink
Browse files

MDL-34464 mod_data Replace all instances of get_context_instance() wi…

…th respective context_XXXX class in mod/data
  • Loading branch information...
dmonllao committed Jul 26, 2012
1 parent 55a568f commit 0b3b8c30e2eaa66dda52bb59e312fa6bd80f25bd
View
@@ -74,7 +74,7 @@
redirect('view.php?d='.$data->id);
}
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
/// If it's hidden then it doesn't show anything. :)
if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
@@ -122,7 +122,7 @@
/// RSS and CSS and JS meta
if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
$rsspath = rss_get_url($context->id, $USER->id, 'mod_data', $data->id);
- $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$PAGE->add_alternate_version($courseshortname . ': %fullname%', $rsspath, 'application/rss+xml');
}
if ($data->csstemplate) {
View
@@ -49,9 +49,7 @@
$data->cmidnumber = $cm->idnumber;
$data->instance = $cm->instance;
-if (! $context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('invalidcontext', '');
-}
+$context = context_module::instance($cm->id);
require_login($course, false, $cm);
require_capability(DATA_CAP_EXPORT, $context);
@@ -60,7 +58,6 @@
$fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
if(empty($fieldrecords)) {
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (has_capability('mod/data:managetemplates', $context)) {
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id);
} else {
View
@@ -88,7 +88,7 @@
require_login($course, true, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/data:managetemplates', $context);
/************************************
@@ -43,7 +43,7 @@ function display_add_field($recordid=0) {
if (!empty($content->content)) {
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
- $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
+ $usercontext = context_user::instance($USER->id);
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false)) {
return false;
}
@@ -166,7 +166,7 @@ function update_content($recordid, $value, $name='') {
// delete existing files
$fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id);
- $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
+ $usercontext = context_user::instance($USER->id);
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value, 'timecreated DESC');
if (count($files)<2) {
@@ -76,7 +76,7 @@
require_course_login($course, true, $cm);
/// If it's hidden then it's don't show anything. :)
-if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities',get_context_instance(CONTEXT_MODULE, $cm->id))) {
+if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities',context_module::instance($cm->id))) {
$PAGE->set_title($data->name);
echo $OUTPUT->header();
notice(get_string("activityiscurrentlyhidden"));
@@ -42,7 +42,7 @@ function display_add_field($recordid=0) {
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
if (!empty($content->content)) {
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
- $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
+ $usercontext = context_user::instance($USER->id);
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false)) {
return false;
}
@@ -214,7 +214,7 @@ function update_content($recordid, $value, $name='') {
case 'file':
$fs = get_file_storage();
$fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id);
- $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
+ $usercontext = context_user::instance($USER->id);
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value);
if (count($files)<2) {
// no file
View
@@ -62,7 +62,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/data:manageentries', $context);
$form = new mod_data_import_form(new moodle_url('/mod/data/import.php'));
View
@@ -37,7 +37,7 @@
require_course_login($course);
$PAGE->set_pagelayout('incourse');
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
add_to_log($course->id, "data", "view all", "index.php?id=$course->id", "");
View
@@ -114,7 +114,7 @@ function __construct($field=0, $data=0, $cm=0) { // Field or data or both, eac
$this->define_default_field();
}
- $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ $this->context = context_module::instance($this->cm->id);
}
@@ -783,7 +783,7 @@ function data_add_record($data, $groupid=0){
global $USER, $DB;
$cm = get_coursemodule_from_instance('data', $data->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$record = new stdClass();
$record->userid = $USER->id;
@@ -898,7 +898,7 @@ function data_delete_instance($id) { // takes the dataid
}
$cm = get_coursemodule_from_instance('data', $data->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
/// Delete all the associated information
@@ -1160,7 +1160,7 @@ function data_grade_item_delete($data) {
function data_print_template($template, $records, $data, $search='', $page=0, $return=false) {
global $CFG, $DB, $OUTPUT;
$cm = get_coursemodule_from_instance('data', $data->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
static $fields = NULL;
static $isteacher;
@@ -1418,7 +1418,7 @@ function data_rating_validate($params) {
$course = $DB->get_record('course', array('id'=>$info->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('data', $info->dataid, $course->id, false, MUST_EXIST);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
+ $context = context_module::instance($cm->id);
// if the supplied context doesnt match the item's context
if ($context->id != $params['context']->id) {
@@ -1466,7 +1466,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
global $CFG, $DB, $PAGE, $OUTPUT;
$cm = get_coursemodule_from_instance('data', $data->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
echo '<br /><div class="datapreferences">';
echo '<form id="options" action="view.php" method="get">';
echo '<div>';
@@ -1741,7 +1741,7 @@ function data_convert_to_roles($data, $teacherroles=array(), $studentroles=array
$cmid = $cm->id;
}
}
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
// $data->participants:
@@ -2005,7 +2005,7 @@ function data_user_can_add_entry($data, $currentgroup, $groupmode, $context = nu
if (empty($context)) {
$cm = get_coursemodule_from_instance('data', $data->id, 0, false, MUST_EXIST);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
}
if (has_capability('mod/data:manageentries', $context)) {
@@ -2377,7 +2377,7 @@ class data_preset_existing_importer extends data_preset_importer {
public function __construct($course, $cm, $module, $fullname) {
global $USER;
list($userid, $shortname) = explode('/', $fullname, 2);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if ($userid && ($userid != $USER->id) && !has_capability('mod/data:manageuserpresets', $context) && !has_capability('mod/data:viewalluserpresets', $context)) {
throw new coding_exception('Invalid preset provided');
}
@@ -2402,7 +2402,7 @@ public function get_userid() {
function data_preset_path($course, $userid, $shortname) {
global $USER, $CFG;
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
$userid = (int)$userid;
@@ -2512,7 +2512,7 @@ function data_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
continue;
}
- $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $datacontext = context_module::instance($cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$rm->delete_ratings($ratingdeloptions);
@@ -2534,7 +2534,7 @@ function data_reset_userdata($data) {
LEFT JOIN {user} u ON r.userid = u.id
WHERE d.course = ? AND r.userid > 0";
- $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
+ $course_context = context_course::instance($data->courseid);
$notenrolled = array();
$fields = array();
$rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
@@ -2545,7 +2545,7 @@ function data_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) {
continue;
}
- $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $datacontext = context_module::instance($cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$ratingdeloptions->itemid = $record->id;
$rm->delete_ratings($ratingdeloptions);
@@ -2578,7 +2578,7 @@ function data_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
continue;
}
- $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $datacontext = context_module::instance($cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$rm->delete_ratings($ratingdeloptions);
@@ -2998,7 +2998,7 @@ function data_extend_navigation($navigation, $course, $module, $cm) {
$numentries = data_numentries($data);
/// Check the number of entries required against the number of entries already made (doesn't apply to teachers)
- if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', context_module::instance($cm->id))) {
$data->entriesleft = $data->requiredentries - $numentries;
$entriesnode = $navigation->add(get_string('entrieslefttoadd', 'data', $data));
$entriesnode->add_class('note');
@@ -3360,7 +3360,7 @@ function data_comment_validate($comment_param) {
if (!$data->comments) {
throw new comment_exception('commentsoff', 'data');
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
//check if approved
if ($data->approval and !$record->approved and !data_isowner($record) and !has_capability('mod/data:approve', $context)) {
View
@@ -101,7 +101,7 @@ public function load_data() {
$this->records[] = $tmp;
} else {
$where = array('dataid' => $this->data->id);
- if (!has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
+ if (!has_capability('mod/data:exportallentries', context_module::instance($this->cm->id))) {
$where['userid'] = $USER->id; // get them all in case, we'll unset ones that aren't ours later if necessary
}
$tmp = $DB->get_records('data_records', $where);
@@ -241,14 +241,14 @@ public function prepare_package() {
public function check_permissions() {
if ($this->recordid) {
if (data_isowner($this->recordid)) {
- return has_capability('mod/data:exportownentry', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ return has_capability('mod/data:exportownentry', context_module::instance($this->cm->id));
}
- return has_capability('mod/data:exportentry', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ return has_capability('mod/data:exportentry', context_module::instance($this->cm->id));
}
if ($this->has_export_config() && !$this->get_export_config('mineonly')) {
- return has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ return has_capability('mod/data:exportallentries', context_module::instance($this->cm->id));
}
- return has_capability('mod/data:exportownentry', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ return has_capability('mod/data:exportownentry', context_module::instance($this->cm->id));
}
/**
@@ -284,7 +284,6 @@ private function exportentry($record) {
// Replacing tags
$patterns = array();
$replacement = array();
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
$files = array();
// Then we generate strings to replace for normal tags
@@ -385,7 +384,7 @@ public function has_export_config() {
return (empty($this->recordid) // multi-entry export
&& $this->minecount > 0 // some of them are mine
&& $this->minecount != count($this->records) // not all of them are mine
- && has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->cm->id))); // they actually have a choice in the matter
+ && has_capability('mod/data:exportallentries', context_module::instance($this->cm->id))); // they actually have a choice in the matter
}
public function export_config_form(&$mform, $instance) {
View
@@ -44,7 +44,7 @@ function data_rss_get_feed($context, $args) {
$dataid = clean_param($args[3], PARAM_INT);
$cm = get_coursemodule_from_instance('data', $dataid, 0, false, MUST_EXIST);
if ($cm) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
//context id from db should match the submitted one
if ($context->id != $modcontext->id || !has_capability('mod/data:viewentry', $modcontext)) {
@@ -107,7 +107,7 @@ function data_rss_get_feed($context, $args) {
array_push($items, $item);
}
$course = $DB->get_record('course', array('id'=>$data->course));
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
// First all rss feeds common headers.
View
@@ -30,7 +30,7 @@
print_error('cannotcallscript');
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$inactive = NULL;
$activetwo = NULL;
View
@@ -66,7 +66,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/data:managetemplates', $context);
if (!$DB->count_records('data_fields', array('dataid'=>$data->id))) { // Brand new database!
View
@@ -84,7 +84,7 @@
require_once($CFG->dirroot . '/comment/lib.php');
comment::init();
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
require_capability('mod/data:viewentry', $context);
/// If we have an empty Database then redirect because this page is useless without data
@@ -275,7 +275,7 @@
$USER->editing = $edit;
}
- $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
/// RSS and CSS and JS meta
$meta = '';

0 comments on commit 0b3b8c3

Please sign in to comment.