Permalink
Browse files

MDL-34467 lesson: Repalce all instances of get_context_instanc() with…

… respective context_XXX::instance()
  • Loading branch information...
1 parent b631c40 commit 5918e3715e7c1c40906d8875140c2ba3c205b67f @ankitagarwal ankitagarwal committed Jul 27, 2012
View
@@ -37,7 +37,7 @@
require_login($course, false, $cm);
require_sesskey();
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
$canmanage = has_capability('mod/lesson:manage', $context);
$lessonoutput = $PAGE->get_renderer('mod_lesson');
View
@@ -35,7 +35,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:manage', $context);
$mode = optional_param('mode', get_user_preferences('lesson_view', 'collapsed'), PARAM_ALPHA);
View
@@ -40,7 +40,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
$PAGE->set_url('/mod/lesson/editpage.php', array('pageid'=>$pageid, 'id'=>$id, 'qtype'=>$qtype));
View
@@ -37,7 +37,7 @@
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
$url = new moodle_url('/mod/lesson/essay.php', array('id'=>$id));
View
@@ -39,7 +39,7 @@
$PAGE->set_url('/mod/lesson/grade.php', array('id'=>$cm->id));
-if (has_capability('mod/lesson:edit', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+if (has_capability('mod/lesson:edit', context_module::instance($cm->id))) {
redirect('report.php?id='.$cm->id);
} else {
redirect('view.php?id='.$cm->id);
@@ -47,7 +47,7 @@
}
$PAGE->set_url($url);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
switch ($mode) {
case 'add':
View
@@ -40,7 +40,7 @@
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
$strimportquestions = get_string("importquestions", "lesson");
View
@@ -53,7 +53,7 @@
require_login($course, false, $cm);
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
$strimportppt = get_string("importppt", "lesson");
View
@@ -93,7 +93,7 @@
$link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
}
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if ($lesson->deadline == 0) {
$due = $strnodeadline;
View
@@ -45,7 +45,7 @@
$url = new moodle_url('/mod/lesson/lesson.php', array('id'=>$id,'action'=>$action));
$PAGE->set_url($url);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
require_sesskey();
View
@@ -50,7 +50,7 @@ function lesson_add_instance($data, $mform) {
$lessonid = $DB->insert_record("lesson", $data);
$data->id = $lessonid;
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
$lesson = $DB->get_record('lesson', array('id'=>$lessonid), '*', MUST_EXIST);
if ($filename = $mform->get_new_filename('mediafilepicker')) {
@@ -86,7 +86,7 @@ function lesson_update_instance($data, $mform) {
unset($data->mediafile);
$DB->update_record("lesson", $data);
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
if ($filename = $mform->get_new_filename('mediafilepicker')) {
if ($file = $mform->save_stored_file('mediafilepicker', $context->id, 'mod_lesson', 'mediafile', 0, '/', $filename, true)) {
$DB->set_field('lesson', 'mediafile', '/'.$file->get_filename(), array('id'=>$data->id));
@@ -295,7 +295,7 @@ function lesson_print_overview($courses, &$htmlarray) {
$str .= $OUTPUT->box(get_string('lessoncloseson', 'lesson', userdate($lesson->deadline)), 'info');
// Attempt information
- if (has_capability('mod/lesson:manage', get_context_instance(CONTEXT_MODULE, $lesson->coursemodule))) {
+ if (has_capability('mod/lesson:manage', context_module::instance($lesson->coursemodule))) {
// Number of user attempts
$attempts = $DB->count_records('lesson_attempts', array('lessonid'=>$lesson->id));
$str .= $OUTPUT->box(get_string('xattempts', 'lesson', $attempts), 'info');
View
@@ -484,7 +484,7 @@ function lesson_mediafile_block_contents($cmid, $lesson) {
**/
function lesson_clock_block_contents($cmid, $lesson, $timer, $page) {
// Display for timed lessons and for students only
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
if(!$lesson->timed || has_capability('mod/lesson:manage', $context)) {
return null;
}
@@ -2373,7 +2373,7 @@ public function get_contents() {
if (!isset($this->properties->contentsformat)) {
$this->properties->contentsformat = FORMAT_HTML;
}
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
+ $context = context_module::instance($PAGE->cm->id);
$contents = file_rewrite_pluginfile_urls($this->properties->contents, 'pluginfile.php', $context->id, 'mod_lesson', 'page_contents', $this->properties->id); // must do this BEFORE format_text()!!!!!!
return format_text($contents, $this->properties->contentsformat, array('context'=>$context, 'noclean'=>true)); // page edit is marked with XSS, we want all content here
} else {
View
@@ -39,7 +39,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
$canmanage = has_capability('mod/lesson:manage', $context);
$url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
@@ -176,7 +176,7 @@ public function check_answer() {
$DB->insert_record("lesson_branch", $branch);
// this is called when jumping to random from a branch table
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
+ $context = context_module::instance($PAGE->cm->id);
if($newpageid == LESSON_UNSEENBRANCHPAGE) {
if (has_capability('mod/lesson:manage', $context)) {
$newpageid = LESSON_NEXTPAGE;
@@ -107,7 +107,7 @@ public function update($properties, $context = null, $maxbytes = null) {
if (empty($properties->qoption)) {
$properties->qoption = '0';
}
- $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
+ $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
$DB->update_record("lesson_pages", $properties);
$answers = $this->get_answers();
@@ -76,7 +76,7 @@ public function update($properties, $context = null, $maxbytes = null) {
if (empty($properties->qoption)) {
$properties->qoption = '0';
}
- $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
+ $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
$DB->update_record("lesson_pages", $properties);
$answers = $this->get_answers();
@@ -131,7 +131,7 @@ public function update($properties, $context = null, $maxbytes = null) {
$answers = $this->get_answers();
$properties->id = $this->properties->id;
$properties->lessonid = $this->lesson->id;
- $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
+ $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
$DB->update_record("lesson_pages", $properties);
if (!array_key_exists(0, $this->answers)) {
@@ -298,7 +298,7 @@ public function update($properties, $context = null, $maxbytes = null) {
$answers = $this->get_answers();
$properties->id = $this->properties->id;
$properties->lessonid = $this->lesson->id;
- $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
+ $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
$DB->update_record("lesson_pages", $properties);
// need to add two to offset correct response and wrong response
@@ -158,7 +158,7 @@ public function update($properties, $context = null, $maxbytes = null) {
$answers = $this->get_answers();
$properties->id = $this->properties->id;
$properties->lessonid = $this->lesson->id;
- $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
+ $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
$DB->update_record("lesson_pages", $properties);
// need to reset offset for correct and wrong responses
View
@@ -43,7 +43,7 @@ public function header($lesson, $cm, $currenttab = '', $extraeditbuttons = false
$title = $this->page->course->shortname.": ".$activityname;
// Build the buttons
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
/// Header setup
$this->page->set_title($title);
@@ -215,7 +215,7 @@ public function display_edit_collapsed(lesson $lesson, $pageid) {
$table->width = '80%';
$table->data = array();
- $canedit = has_capability('mod/lesson:edit', get_context_instance(CONTEXT_MODULE, $this->page->cm->id));
+ $canedit = has_capability('mod/lesson:edit', context_module::instance($this->page->cm->id));
while ($pageid != 0) {
$page = $lesson->load_page($pageid);
@@ -250,7 +250,7 @@ public function display_edit_full(lesson $lesson, $pageid, $prevpageid, $single=
$manager = lesson_page_type_manager::get($lesson);
$qtypes = $manager->get_page_type_strings();
$npages = count($lesson->load_all_pages());
- $canedit = has_capability('mod/lesson:edit', get_context_instance(CONTEXT_MODULE, $this->page->cm->id));
+ $canedit = has_capability('mod/lesson:edit', context_module::instance($this->page->cm->id));
$content = '';
if ($canedit) {
@@ -452,7 +452,7 @@ public function page_action_links(lesson_page $page, $printmove, $printaddpage=f
public function ongoing_score(lesson $lesson) {
global $USER, $DB;
- $context = get_context_instance(CONTEXT_MODULE, $this->page->cm->id);
+ $context = context_module::instance($this->page->cm->id);
if (has_capability('mod/lesson:manage', $context)) {
return $this->output->box(get_string('teacherongoingwarning', 'lesson'), "ongoing center");
} else {
@@ -483,7 +483,7 @@ public function ongoing_score(lesson $lesson) {
public function progress_bar(lesson $lesson) {
global $CFG, $USER, $DB;
- $context = get_context_instance(CONTEXT_MODULE, $this->page->cm->id);
+ $context = context_module::instance($this->page->cm->id);
// lesson setting to turn progress bar on or off
if (!$lesson->progressbar) {
View
@@ -38,7 +38,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/lesson:manage', $context);
$ufields = user_picture::fields('u'); // These fields are enough
@@ -162,7 +162,7 @@
**************************************************************************/
echo $lessonoutput->header($lesson, $cm, $action);
- $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)) {
$seeallgradeslink = new moodle_url('/grade/report/grader/index.php', array('id'=>$course->id));
$seeallgradeslink = html_writer::link($seeallgradeslink, get_string('seeallcoursegrades', 'grades'));
@@ -377,7 +377,7 @@
**************************************************************************/
echo $lessonoutput->header($lesson, $cm, $action);
- $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)) {
$seeallgradeslink = new moodle_url('/grade/report/grader/index.php', array('id'=>$course->id));
$seeallgradeslink = html_writer::link($seeallgradeslink, get_string('seeallcoursegrades', 'grades'));
View
@@ -38,7 +38,7 @@
}
if (!isset($cm)) {
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
}
if (!isset($course)) {
$course = $DB->get_record('course', array('id' => $lesson->course));
View
@@ -55,7 +55,7 @@
}
$PAGE->set_url($url);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
$canmanage = has_capability('mod/lesson:manage', $context);
$lessonoutput = $PAGE->get_renderer('mod_lesson');

0 comments on commit 5918e37

Please sign in to comment.