Skip to content
Browse files

MDL-34464 mod_feedback Replace all instances of get_context_instance(…

…) with respective context_XXXX class in mod/feedback
  • Loading branch information...
1 parent 0b3b8c3 commit 2c979976e164214f8ba0752eb3e4838cc4c9c9fb @dmonllao dmonllao committed Jul 26, 2012
View
4 mod/feedback/analysis.php
@@ -48,9 +48,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
if ($course->id == SITEID) {
require_login($course, true);
View
6 mod/feedback/analysis_course.php
@@ -68,9 +68,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
@@ -149,7 +147,7 @@
$sep_thous = get_string('separator_thousand', 'feedback');
foreach ($courses as $c) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $c->course_id);
+ $coursecontext = context_course::instance($c->course_id);
$shortname = format_string($c->shortname, true, array('context' => $coursecontext));
echo '<tr>';
View
6 mod/feedback/analysis_to_excel.php
@@ -51,9 +51,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
@@ -306,7 +304,7 @@ function feedback_excelprint_detailed_items(&$worksheet, $xls_formats,
$worksheet->write_number($row_offset, $col_offset, $courseid, $xls_formats->default);
$col_offset++;
if (isset($courseid) AND $course = $DB->get_record('course', array('id' => $courseid))) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+ $coursecontext = context_course::instance($courseid);
$shortname = format_string($course->shortname, true, array('context' => $coursecontext));
$worksheet->write_string($row_offset, $col_offset, $shortname, $xls_formats->default);
}
View
4 mod/feedback/complete.php
@@ -87,9 +87,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
$feedback_complete_cap = false;
View
4 mod/feedback/complete_guest.php
@@ -108,9 +108,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
$feedback_complete_cap = false;
View
4 mod/feedback/delete_completed.php
@@ -50,9 +50,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/delete_item.php
@@ -43,9 +43,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/delete_template.php
@@ -67,9 +67,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/edit.php
@@ -57,9 +57,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/edit_item.php
@@ -67,9 +67,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/export.php
@@ -47,9 +47,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/import.php
@@ -52,9 +52,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/index.php
@@ -35,9 +35,7 @@
print_error('invalidcourseid');
}
-if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
- print_error('badcontext');
-}
+$context = context_course::instance($course->id);
require_login($course);
$PAGE->set_pagelayout('incourse');
View
8 mod/feedback/item/info/lib.php
@@ -216,7 +216,7 @@ public function print_item_preview($item) {
$itemshowvalue = userdate($itemvalue);
break;
case 2:
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$itemvalue = format_string($course->shortname,
true,
array('context' => $coursecontext));
@@ -225,7 +225,7 @@ public function print_item_preview($item) {
break;
case 3:
if ($coursecategory) {
- $category_context = get_context_instance(CONTEXT_COURSECAT, $coursecategory->id);
+ $category_context = context_coursecat::instance($coursecategory->id);
$itemvalue = format_string($coursecategory->name,
true,
array('context' => $category_context));
@@ -293,7 +293,7 @@ public function print_item_complete($item, $value = '', $highlightrequire = fals
$itemshowvalue = userdate($itemvalue);
break;
case 2:
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$itemvalue = format_string($course->shortname,
true,
array('context' => $coursecontext));
@@ -302,7 +302,7 @@ public function print_item_complete($item, $value = '', $highlightrequire = fals
break;
case 3:
if ($coursecategory) {
- $category_context = get_context_instance(CONTEXT_COURSECAT, $coursecategory->id);
+ $category_context = context_coursecat::instance($coursecategory->id);
$itemvalue = format_string($coursecategory->name,
true,
array('context' => $category_context));
View
2 mod/feedback/item/label/label_form.php
@@ -29,8 +29,6 @@ public function definition() {
$positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position'];
- $context = get_context_instance(CONTEXT_MODULE, $common['cmid']);
-
$mform =& $this->_form;
$mform->addElement('hidden', 'required', 0);
View
8 mod/feedback/item/label/lib.php
@@ -59,7 +59,7 @@ public function build_editform($item, $feedback, $cm) {
'items'=>$feedbackitems,
'feedback'=>$feedback->id);
- $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $this->context = context_module::instance($cm->id);
//preparing the editor for new file-api
$item->presentationformat = FORMAT_HTML;
@@ -148,12 +148,12 @@ public function print_item($item) {
if ($template->ispublic) {
$context = get_system_context();
} else {
- $context = get_context_instance(CONTEXT_COURSE, $template->course);
+ $context = context_course::instance($template->course);
}
$filearea = 'template';
} else {
$cm = get_coursemodule_from_instance('feedback', $item->feedback);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$filearea = 'item';
}
@@ -232,7 +232,7 @@ public function get_presentation($data) {
public function postupdate($item) {
global $DB;
- $context = get_context_instance(CONTEXT_MODULE, $item->cmid);
+ $context = context_module::instance($item->cmid);
$item = file_postupdate_standard_editor($item,
'presentation',
$this->presentationoptions,
View
42 mod/feedback/lib.php
@@ -102,7 +102,7 @@ function feedback_add_instance($feedback) {
$cm = get_coursemodule_from_id('feedback', $feedback->id);
$feedback->coursemodule = $cm->id;
}
- $context = get_context_instance(CONTEXT_MODULE, $feedback->coursemodule);
+ $context = context_module::instance($feedback->coursemodule);
$editoroptions = feedback_get_editor_options();
@@ -150,7 +150,7 @@ function feedback_update_instance($feedback) {
//create or update the new events
feedback_set_events($feedback);
- $context = get_context_instance(CONTEXT_MODULE, $feedback->coursemodule);
+ $context = context_module::instance($feedback->coursemodule);
$editoroptions = feedback_get_editor_options();
@@ -416,7 +416,7 @@ function feedback_get_recent_mod_activity(&$activities, &$index,
return;
}
- $cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $cm_context = context_module::instance($cm->id);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
$groupmode = groups_get_activity_groupmode($cm, $course);
@@ -826,9 +826,7 @@ function feedback_get_context($cmid) {
return $context;
}
- if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
- print_error('badcontext');
- }
+ $context = context_module::instance($cmid);
return $context;
}
@@ -869,7 +867,7 @@ function feedback_get_incomplete_users($cm,
global $DB;
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
//first get all user who can complete this feedback
$cap = 'mod/feedback:complete';
@@ -975,9 +973,7 @@ function feedback_get_complete_users($cm,
global $DB;
- if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
- }
+ $context = context_module::instance($cm->id);
$params = (array)$params;
@@ -1023,9 +1019,7 @@ function feedback_get_complete_users($cm,
*/
function feedback_get_viewreports_users($cmid, $groups = false) {
- if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
- print_error('badcontext');
- }
+ $context = context_module::instance($cmid);
//description of the call below:
//get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='',
@@ -1051,9 +1045,7 @@ function feedback_get_viewreports_users($cmid, $groups = false) {
*/
function feedback_get_receivemail_users($cmid, $groups = false) {
- if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
- print_error('badcontext');
- }
+ $context = context_module::instance($cmid);
//description of the call below:
//get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='',
@@ -1126,10 +1118,10 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
if ($ispublic) {
$s_context = get_system_context();
} else {
- $s_context = get_context_instance(CONTEXT_COURSE, $newtempl->course);
+ $s_context = context_course::instance($newtempl->course);
}
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
- $f_context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $f_context = context_module::instance($cm->id);
//create items of this new template
//depend items we are storing temporary in an mapping list array(new id => dependitem)
@@ -1231,11 +1223,11 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
if ($template->ispublic) {
$s_context = get_system_context();
} else {
- $s_context = get_context_instance(CONTEXT_COURSE, $feedback->course);
+ $s_context = context_course::instance($feedback->course);
}
$course = $DB->get_record('course', array('id'=>$feedback->course));
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
- $f_context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $f_context = context_module::instance($cm->id);
//if deleteold then delete all old items before
//get all items
@@ -1534,7 +1526,7 @@ function feedback_delete_item($itemid, $renumber = true, $template = false) {
if ($template->ispublic) {
$context = get_system_context();
} else {
- $context = get_context_instance(CONTEXT_COURSE, $template->course);
+ $context = context_course::instance($template->course);
}
$templatefiles = $fs->get_area_files($context->id,
'mod_feedback',
@@ -1550,7 +1542,7 @@ function feedback_delete_item($itemid, $renumber = true, $template = false) {
if (!$cm = get_coursemodule_from_instance('feedback', $item->feedback)) {
return false;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$itemfiles = $fs->get_area_files($context->id,
'mod_feedback',
@@ -2985,7 +2977,7 @@ function feedback_send_email_anonym($cm, $feedback, $course) {
* @return string the text you want to post
*/
function feedback_send_email_text($info, $course) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
$posttext = $courseshortname.' -> '.get_string('modulenameplural', 'feedback').' -> '.
$info->feedback."\n";
@@ -3006,7 +2998,7 @@ function feedback_send_email_text($info, $course) {
*/
function feedback_send_email_html($info, $course, $cm) {
global $CFG;
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
$course_url = $CFG->wwwroot.'/course/view.php?id='.$course->id;
$feedback_all_url = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
@@ -3046,7 +3038,7 @@ function feedback_extend_settings_navigation(settings_navigation $settings,
global $PAGE, $DB;
- if (!$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id)) {
+ if (!$context = context_module::instance($PAGE->cm->id, IGNORE_MISSING)) {
print_error('badcontext');
}
View
8 mod/feedback/mapcourse.php
@@ -61,9 +61,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
@@ -132,9 +130,9 @@
$unmapurl = new moodle_url('/mod/feedback/unmapcourse.php');
foreach ($coursemap as $cmap) {
- $cmapcontext = get_context_instance(CONTEXT_COURSE, $cmap->id);
+ $cmapcontext = context_course::instance($cmap->id);
$cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext));
- $coursecontext = get_context_instance(CONTEXT_COURSE, $cmap->courseid);
+ $coursecontext = context_course::instance($cmap->courseid);
$cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
$unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id));
$anker = '<a href="'.$unmapurl->out().'">';
View
4 mod/feedback/print.php
@@ -41,9 +41,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/show_entries.php
@@ -61,9 +61,7 @@
$PAGE->set_url($url);
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/show_entries_anonym.php
@@ -52,9 +52,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id, IGNORE_MISSING);
require_login($course, true, $cm);
View
10 mod/feedback/show_nonrespondents.php
@@ -65,14 +65,10 @@
$PAGE->set_url($url);
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
//we need the coursecontext to allow sending of mass mails
-if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id)) {
- print_error('badcontext');
-}
+$coursecontext = context_course::instance($course->id);
require_login($course, true, $cm);
@@ -85,7 +81,7 @@
if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$shortname = format_string($course->shortname,
true,
- array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ array('context' => $coursecontext));
$strfeedbacks = get_string("modulenameplural", "feedback");
$htmlmessage = "<body id=\"email\">";
View
5 mod/feedback/tabs.php
@@ -35,10 +35,7 @@
$usedid = $id;
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $usedid)) {
- print_error('badcontext');
-}
-
+$context = context_module::instance($usedid);
$courseid = optional_param('courseid', false, PARAM_INT);
// $current_tab = $SESSION->feedback->current_tab;
View
4 mod/feedback/unmapcourse.php
@@ -46,9 +46,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_capability('mod/feedback:mapcourse', $context);
View
4 mod/feedback/use_templ.php
@@ -52,9 +52,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
require_login($course, true, $cm);
View
4 mod/feedback/view.php
@@ -41,9 +41,7 @@
print_error('invalidcoursemodule');
}
-if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
- print_error('badcontext');
-}
+$context = context_module::instance($cm->id);
$feedback_complete_cap = false;

0 comments on commit 2c97997

Please sign in to comment.
Something went wrong with that request. Please try again.