MDL-34466 mod_assignment Replace all instances of get_context_instance() with respect...
authorDavid Monllao <davidm@moodle.com>
Thu, 26 Jul 2012 06:24:58 +0000 (14:24 +0800)
committerDavid Monllao <davidm@moodle.com>
Fri, 27 Jul 2012 05:25:05 +0000 (13:25 +0800)
12 files changed:
mod/assignment/grade.php
mod/assignment/lib.php
mod/assignment/locallib.php
mod/assignment/submissions.php
mod/assignment/type/online/all.php
mod/assignment/type/online/assignment.class.php
mod/assignment/type/online/file.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/type/upload/notes.php
mod/assignment/type/upload/upload.php
mod/assignment/type/uploadsingle/assignment.class.php
mod/assignment/type/uploadsingle/upload.php

index f73b88b..543b762 100644 (file)
@@ -46,7 +46,7 @@ if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
 
 require_login($course, false, $cm);
 
-if (has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+if (has_capability('mod/assignment:grade', context_module::instance($cm->id))) {
     if ($userid) {
         redirect('submissions.php?id='.$cm->id.'&userid='.$userid.'&mode=single&filter=0&offset=0');
     } else {
index 99d29c8..cd83d8f 100644 (file)
@@ -112,7 +112,7 @@ class assignment_base {
             print_error('invalidcoursemodule');
         }
 
-        $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+        $this->context = context_module::instance($this->cm->id);
 
         if ($course) {
             $this->course = $course;
@@ -121,7 +121,7 @@ class assignment_base {
         } else if (! $this->course = $DB->get_record('course', array('id'=>$this->cm->course))) {
             print_error('invalidid', 'assignment');
         }
-        $this->coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id);
+        $this->coursecontext = context_course::instance($this->course->id);
         $courseshortname = format_text($this->course->shortname, true, array('context' => $this->coursecontext));
 
         if ($assignment) {
@@ -153,7 +153,7 @@ class assignment_base {
      */
     function view() {
 
-        $context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
+        $context = context_module::instance($this->cm->id);
         require_capability('mod/assignment:view', $context);
 
         add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}",
@@ -197,7 +197,7 @@ class assignment_base {
 
         echo '<div class="reportlink">'.$this->submittedlink().'</div>';
         echo '<div class="clearer"></div>';
-        if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
+        if (has_capability('moodle/site:config', context_system::instance())) {
             echo $OUTPUT->notification(get_string('upgradenotification', 'assignment'));
             $adminurl = new moodle_url('/admin/tool/assignmentupgrade/listnotupgraded.php');
             echo $OUTPUT->single_button($adminurl, get_string('viewassignmentupgradetool', 'assignment'));
@@ -385,7 +385,7 @@ class assignment_base {
         $submitted = '';
         $urlbase = "{$CFG->wwwroot}/mod/assignment/";
 
-        $context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
+        $context = context_module::instance($this->cm->id);
         if (has_capability('mod/assignment:grade', $context)) {
             if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
                 $group = 0;
@@ -523,7 +523,7 @@ class assignment_base {
         // now get rid of all files
         $fs = get_file_storage();
         if ($cm = get_coursemodule_from_instance('assignment', $assignment->id)) {
-            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+            $context = context_module::instance($cm->id);
             $fs->delete_area_files($context->id);
         }
 
@@ -1004,7 +1004,7 @@ class assignment_base {
         $course     = $this->course;
         $assignment = $this->assignment;
         $cm         = $this->cm;
-        $context    = get_context_instance(CONTEXT_MODULE, $cm->id);
+        $context    = context_module::instance($cm->id);
 
         //reset filter to all for offline assignment
         if ($assignment->assignmenttype == 'offline' && $filter == self::FILTER_SUBMITTED) {
@@ -1239,7 +1239,7 @@ class assignment_base {
         //hook to allow plagiarism plugins to update status/print links.
         echo plagiarism_update_status($this->course, $this->cm);
 
-        $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
+        $course_context = context_course::instance($course->id);
         if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
             echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'
                 . get_string('seeallcoursegrades', 'grades') . '</a></div>';
@@ -1249,7 +1249,7 @@ class assignment_base {
             echo $message;   // display messages here if any
         }
 
-        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+        $context = context_module::instance($cm->id);
 
     /// Check to see if groups are being used in this assignment
 
@@ -1911,7 +1911,7 @@ class assignment_base {
         global $DB;
 
         // Grab the context assocated with our course module
-        $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+        $context = context_module::instance($this->cm->id);
 
         // Get ids of users enrolled in the given course.
         list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $groupid);
@@ -2329,7 +2329,7 @@ class assignment_base {
                     if (!$cm = get_coursemodule_from_instance('assignment', $assignmentid)) {
                         continue;
                     }
-                    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+                    $context = context_module::instance($cm->id);
                     $fs->delete_area_files($context->id, 'mod_assignment', 'submission');
                     $fs->delete_area_files($context->id, 'mod_assignment', 'response');
                 }
@@ -2540,7 +2540,7 @@ class assignment_grading_form extends moodleform {
                 }
             }
         }
-        $course_context = get_context_instance(CONTEXT_MODULE , $this->_customdata->cm->id);
+        $course_context = context_module::instance($this->_customdata->cm->id);
         if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
             $grade = '<a href="'.$CFG->wwwroot.'/grade/report/grader/index.php?id='. $this->_customdata->courseid .'" >'.
                         $this->_customdata->grading_info->items[0]->grades[$this->_customdata->userid]->str_grade . '</a>';
@@ -2845,7 +2845,7 @@ function assignment_cron () {
             /// mail is customised for the receiver.
             cron_setup_user($user, $course);
 
-            $coursecontext = get_context_instance(CONTEXT_COURSE, $submission->course);
+            $coursecontext = context_course::instance($submission->course);
             $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
             if (!is_enrolled($coursecontext, $user->id)) {
                 echo fullname($user)." not an active participant in " . $courseshortname . "\n";
@@ -3228,7 +3228,7 @@ function assignment_print_recent_activity($course, $viewfullnames, $timestart) {
         // the act of sumbitting of assignment may be considered private - only graders will see it if specified
         if (empty($CFG->assignment_showrecentsubmissions)) {
             if (!array_key_exists($cm->id, $grader)) {
-                $grader[$cm->id] = has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_MODULE, $cm->id));
+                $grader[$cm->id] = has_capability('moodle/grade:viewall', context_module::instance($cm->id));
             }
             if (!$grader[$cm->id]) {
                 continue;
@@ -3237,7 +3237,7 @@ function assignment_print_recent_activity($course, $viewfullnames, $timestart) {
 
         $groupmode = groups_get_activity_groupmode($cm, $course);
 
-        if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+        if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', context_module::instance($cm->id))) {
             if (isguestuser()) {
                 // shortcut - guest user does not belong into any group
                 continue;
@@ -3330,7 +3330,7 @@ function assignment_get_recent_mod_activity(&$activities, &$index, $timestart, $
     }
 
     $groupmode       = groups_get_activity_groupmode($cm, $course);
-    $cm_context      = get_context_instance(CONTEXT_MODULE, $cm->id);
+    $cm_context      = context_module::instance($cm->id);
     $grader          = has_capability('moodle/grade:viewall', $cm_context);
     $accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
     $viewfullnames   = has_capability('moodle/site:viewfullnames', $cm_context);
@@ -3705,7 +3705,7 @@ function assignment_print_overview($courses, &$htmlarray) {
         } else {
             $str .= '<div class="info">'.$strduedateno.'</div>';
         }
-        $context = get_context_instance(CONTEXT_MODULE, $assignment->coursemodule);
+        $context = context_module::instance($assignment->coursemodule);
         if (has_capability('mod/assignment:grade', $context)) {
 
             // count how many people can submit
index e2c3761..0202cad 100644 (file)
@@ -156,7 +156,7 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
     }
 
     public function check_permissions() {
-        $context = get_context_instance(CONTEXT_MODULE, $this->assignment->cm->id);
+        $context = context_module::instance($this->assignment->cm->id);
         return has_capability('mod/assignment:exportownsubmission', $context);
     }
 
index ac6961c..3f9b774 100644 (file)
@@ -42,7 +42,7 @@ if ($mode !== 'all') {
 $PAGE->set_url($url);
 require_login($course, false, $cm);
 
-require_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
+require_capability('mod/assignment:grade', context_module::instance($cm->id));
 
 $PAGE->requires->js('/mod/assignment/assignment.js');
 
index b746dac..4b0ab8c 100644 (file)
@@ -27,7 +27,7 @@ $PAGE->set_url('/mod/assignment/type/online/all.php', array('id'=>$id));
 require_course_login($course);
 
 // check for view capability at course level
-$context = get_context_instance(CONTEXT_COURSE,$course->id);
+$context = context_course::instance($course->id);
 require_capability('mod/assignment:view',$context);
 
 // various strings
@@ -60,7 +60,7 @@ foreach( $assignments as $assignment ) {
     }
 
     // check we are allowed to view this
-    $context = get_context_instance(CONTEXT_MODULE, $assignment->coursemodule);
+    $context = context_module::instance($assignment->coursemodule);
     if (!has_capability('mod/assignment:view',$context)) {
         continue;
     }
index 0ef8de8..4ada753 100644 (file)
@@ -23,7 +23,7 @@ class assignment_online extends assignment_base {
         $edit  = optional_param('edit', 0, PARAM_BOOL);
         $saved = optional_param('saved', 0, PARAM_BOOL);
 
-        $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+        $context = context_module::instance($this->cm->id);
         require_capability('mod/assignment:view', $context);
 
         $submission = $this->get_submission($USER->id, false);
index f5346ec..a7cfbf5 100644 (file)
@@ -27,7 +27,7 @@ if (! $user = $DB->get_record("user", array("id"=>$userid))) {
 
 require_login($course, false, $cm);
 
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
 if (($USER->id != $user->id) && !has_capability('mod/assignment:grade', $context)) {
     print_error('cannotviewassignment', 'assignment');
 }
index 83afeb4..c9b9dfd 100644 (file)
@@ -405,7 +405,7 @@ class assignment_upload extends assignment_base {
         global $DB;
 
         // Grab the context assocated with our course module
-        $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+        $context = context_module::instance($this->cm->id);
 
         // Get ids of users enrolled in the given course.
         list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $groupid);
@@ -1081,7 +1081,7 @@ class assignment_upload extends assignment_base {
         $mform->addHelpButton('var4', 'trackdrafts', 'assignment');
         $mform->setDefault('var4', 1);
 
-        $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+        $course_context = context_course::instance($COURSE->id);
         plagiarism_get_form_elements_module($mform, $course_context);
     }
 
index cd54918..318fdeb 100644 (file)
@@ -36,7 +36,7 @@ if (! $user = $DB->get_record('user', array('id'=>$userid))) {
 
 require_login($course, false, $cm);
 
-if (!has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+if (!has_capability('mod/assignment:grade', context_module::instance($cm->id))) {
     print_error('cannotviewassignment', 'assignment');
 }
 
index e0f79f4..743c2e1 100644 (file)
@@ -50,7 +50,7 @@ if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
     print_error('invalidid', 'assignment');
 }
 
-$fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+$fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
 
 $PAGE->set_url($url);
 $PAGE->set_context($context);
index 080d201..6c532fe 100644 (file)
@@ -62,7 +62,7 @@ class assignment_uploadsingle extends assignment_base {
 
         global $USER, $OUTPUT;
 
-        $context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
+        $context = context_module::instance($this->cm->id);
         require_capability('mod/assignment:view', $context);
 
         add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
@@ -114,7 +114,7 @@ class assignment_uploadsingle extends assignment_base {
         global $DB;
 
         // Grab the context assocated with our course module
-        $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+        $context = context_module::instance($this->cm->id);
 
         // Get ids of users enrolled in the given course.
         list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $groupid);
@@ -293,7 +293,7 @@ class assignment_uploadsingle extends assignment_base {
         $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
         $mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
 
-        $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+        $course_context = context_course::instance($COURSE->id);
         plagiarism_get_form_elements_module($mform, $course_context);
     }
 
index cab3e89..40d6f76 100644 (file)
@@ -51,7 +51,7 @@ if (isguestuser()) {
 }
 $instance = new assignment_uploadsingle($cm->id, $assignment, $cm, $course);
 
-$fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+$fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
 
 $PAGE->set_url($url);
 $PAGE->set_context($context);