Permalink
Browse files

MDL-34467 glossary: Repalce all instances of get_context_instanc() wi…

…th respective context_XXX::instance()
  • Loading branch information...
1 parent 55a568f commit e0a91e119a35e3a362ffbe9f89649b01cd872309 @ankitagarwal ankitagarwal committed Jul 27, 2012
View
@@ -18,7 +18,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/glossary:approve', $context);
if (!$entry->approved and confirm_sesskey()) {
@@ -40,7 +40,7 @@
}
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
$manageentries = has_capability('mod/glossary:manageentries', $context);
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
@@ -67,7 +67,7 @@
if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) {
print_error('invalidcoursemodule');
}
- $newcontext = get_context_instance(CONTEXT_MODULE, $newcm->id);
+ $newcontext = context_module::instance($newcm->id);
$entry->glossaryid = $entry->sourceglossaryid;
$entry->sourceglossaryid = 0;
View
@@ -17,7 +17,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
print_error('invalidid', 'glossary');
@@ -18,7 +18,7 @@ function definition() {
$definitionoptions = $this->_customdata['definitionoptions'];
$attachmentoptions = $this->_customdata['attachmentoptions'];
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
// Prepare format_string/text options
$fmtoptions = array(
'context' => $context);
@@ -96,7 +96,7 @@ function validation($data, $files) {
$glossary = $this->_customdata['glossary'];
$cm = $this->_customdata['cm'];
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$id = (int)$data['id'];
$data['concept'] = trim($data['concept']);
@@ -63,7 +63,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/glossary:managecategories', $context);
$strglossaries = get_string("modulenameplural", "glossary");
View
@@ -33,7 +33,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/glossary:export', $context);
$strglossaries = get_string("modulenameplural", "glossary");
@@ -42,7 +42,7 @@
}
require_course_login($course->id, true, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/glossary:export', $context);
$returnurl = "view.php?id=$cm->id&mode=$prevmode&hook=".urlencode($hook);
@@ -56,8 +56,8 @@
print_error('invalidcoursemodule');
}
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-$maincontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+$context = context_module::instance($cm->id);
+$maincontext = context_module::instance($maincm->id);
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
View
@@ -33,7 +33,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/glossary:import', $context);
$strglossaries = get_string("modulenameplural", "glossary");
View
@@ -18,7 +18,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, "glossary", "view all", "index.php?id=$course->id", "");
View
@@ -60,7 +60,7 @@ function glossary_add_instance($glossary) {
$glossary->globalglossary = 0;
}
- if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
+ if (!has_capability('mod/glossary:manageentries', context_system::instance())) {
$glossary->globalglossary = 0;
}
@@ -97,7 +97,7 @@ function glossary_update_instance($glossary) {
$glossary->globalglossary = 0;
}
- if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
+ if (!has_capability('mod/glossary:manageentries', context_system::instance())) {
// keep previous
unset($glossary->globalglossary);
}
@@ -145,7 +145,7 @@ function glossary_delete_instance($id) {
return false;
}
- if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+ if (!$context = context_module::instance($cm->id)) {
return false;
}
@@ -163,7 +163,7 @@ function glossary_delete_instance($id) {
foreach ($exported as $entry) {
$entry->glossaryid = $entry->sourceglossaryid;
$entry->sourceglossaryid = 0;
- $newcontext = get_context_instance(CONTEXT_MODULE, $entry->sourcecmid);
+ $newcontext = context_module::instance($entry->sourcecmid);
if ($oldfiles = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id)) {
foreach ($oldfiles as $oldfile) {
$file_record = new stdClass();
@@ -504,7 +504,7 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
// generate list of approval capabilities for all glossaries in the course.
$approvals = array();
foreach ($ids as $glinstanceid => $glcmid) {
- $context = get_context_instance(CONTEXT_MODULE, $glcmid);
+ $context = context_module::instance($glcmid);
if (has_capability('mod/glossary:view', $context)) {
// get records glossary entries that are approved if user has no capability to approve entries.
if (has_capability('mod/glossary:approve', $context)) {
@@ -730,7 +730,7 @@ function glossary_rating_validate($params) {
}
$cm = get_coursemodule_from_instance('glossary', $info->glossaryid, $info->course, false, MUST_EXIST);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
+ $context = context_module::instance($cm->id, MUST_EXIST);
// if the supplied context doesnt match the item's context
if ($context->id != $params['context']->id) {
@@ -1001,13 +1001,13 @@ function glossary_get_entries_search($concept, $courseid) {
//Check if the user is an admin
$bypassadmin = 1; //This means NO (by default)
- if (has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('moodle/course:viewhiddenactivities', context_system::instance())) {
$bypassadmin = 0; //This means YES
}
//Check if the user is a teacher
$bypassteacher = 1; //This means NO (by default)
- if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_COURSE, $courseid))) {
+ if (has_capability('mod/glossary:manageentries', context_course::instance($courseid))) {
$bypassteacher = 0; //This means YES
}
@@ -1091,7 +1091,7 @@ function glossary_print_entry_default ($entry, $glossary, $cm) {
$definition = '<span class="nolink">' . strip_tags($definition) . '</span>';
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$definition = file_rewrite_pluginfile_urls($definition, 'pluginfile.php', $context->id, 'mod_glossary', 'entry', $entry->id);
$options = new stdClass();
@@ -1145,7 +1145,7 @@ function glossary_print_entry_definition($entry, $glossary, $cm) {
}
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$definition = file_rewrite_pluginfile_urls($definition, 'pluginfile.php', $context->id, 'mod_glossary', 'entry', $entry->id);
$options = new stdClass();
@@ -1221,7 +1221,7 @@ function glossary_print_entry_aliases($course, $cm, $glossary, $entry,$mode='',
function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$hook='', $type = 'print') {
global $USER, $CFG, $DB, $OUTPUT;
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$output = false; //To decide if we must really return text in "return". Activate when needed only!
$importedentry = ($entry->sourceglossaryid == $glossary->id);
@@ -1278,7 +1278,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
$filecontext = $context;
if ($entry->sourceglossaryid == $cm->instance) {
if ($maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
- $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ $filecontext = context_module::instance($maincm->id);
}
}
$fs = get_file_storage();
@@ -1426,7 +1426,7 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
$glos = $glossary->id;
}
- if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_COURSE, $glossary->course))) {
+ if (!has_capability('mod/glossary:manageentries', context_course::instance($glossary->course))) {
$glossarymodule = $DB->get_record("modules", array("name"=>"glossary"));
$onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
$onlyvisibletable = ", {course_modules} cm";
@@ -1530,15 +1530,15 @@ function glossary_search_entries($searchterms, $glossary, $extended) {
function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
global $CFG, $DB, $OUTPUT;
- if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+ if (!$context = context_module::instance($cm->id)) {
return '';
}
if ($entry->sourceglossaryid == $cm->instance) {
if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
return '';
}
- $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ $filecontext = context_module::instance($maincm->id);
} else {
$filecontext = $context;
@@ -1657,7 +1657,7 @@ function glossary_get_file_info($browser, $areas, $course, $cm, $context, $filea
if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
return null;
}
- $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ $filecontext = context_module::instance($maincm->id);
} else {
return null;
}
@@ -1729,7 +1729,7 @@ function glossary_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
return false;
}
- $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ $filecontext = context_module::instance($maincm->id);
} else {
return false;
@@ -1865,7 +1865,7 @@ function glossary_print_author_menu($cm, $glossary,$mode, $hook, $sortkey = '',
function glossary_print_categories_menu($cm, $glossary, $hook, $category) {
global $CFG, $DB, $OUTPUT;
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
// Prepare format_string/text options
$fmtoptions = array(
@@ -2735,7 +2735,7 @@ function glossary_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment');
//delete ratings
@@ -2768,7 +2768,7 @@ function glossary_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment');
//delete ratings
@@ -2798,7 +2798,7 @@ function glossary_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment');
//delete ratings
@@ -2824,7 +2824,7 @@ function glossary_reset_userdata($data) {
LEFT JOIN {user} u ON e.userid = u.id
WHERE g.course = ? AND e.userid > 0";
- $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
+ $course_context = context_course::instance($data->courseid);
$notenrolled = array();
$rs = $DB->get_recordset_sql($entriessql, $params);
if ($rs->valid()) {
@@ -2835,7 +2835,7 @@ function glossary_reset_userdata($data) {
$DB->delete_records('glossary_entries', array('id'=>$entry->id));
if ($cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
//delete ratings
@@ -2857,7 +2857,7 @@ function glossary_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
//delete ratings
$ratingdeloptions->contextid = $context->id;
@@ -3064,7 +3064,7 @@ function glossary_comment_validate($comment_param) {
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id, $course->id)) {
throw new comment_exception('invalidcoursemodule');
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if ($glossary->defaultapproval and !$record->approved and !has_capability('mod/glossary:approve', $context)) {
throw new comment_exception('notapproved', 'glossary');
View
@@ -72,7 +72,7 @@ public function load_data() {
$this->exportdata = array('entries' => $entries, 'aliases' => $aliases, 'categoryentries' => $categoryentries);
$fs = get_file_storage();
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ $context = context_module::instance($this->cm->id);
$this->multifiles = array();
foreach (array_keys($entries) as $entry) {
$this->keyedfiles[$entry] = array_merge(
@@ -186,7 +186,7 @@ public function prepare_package() {
* @return boolean
*/
public function check_permissions() {
- return has_capability('mod/glossary:export', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ return has_capability('mod/glossary:export', context_module::instance($this->cm->id));
}
/**
@@ -254,10 +254,10 @@ public function load_data() {
JOIN {glossary_categories} c
ON c.id = ec.categoryid
WHERE ec.entryid = ?', array($this->entryid));
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ $context = context_module::instance($this->cm->id);
if ($this->entry->sourceglossaryid == $this->cm->instance) {
if ($maincm = get_coursemodule_from_instance('glossary', $this->entry->glossaryid)) {
- $context = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ $context = context_module::instance($maincm->id);
}
}
$this->aliases = $DB->get_record('glossary_alias', array('entryid'=>$this->entryid));
@@ -283,7 +283,7 @@ public function expected_time() {
* @return boolean
*/
public function check_permissions() {
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ $context = context_module::instance($this->cm->id);
return has_capability('mod/glossary:exportentry', $context)
|| ($this->entry->userid == $this->user->id && has_capability('mod/glossary:exportownentry', $context));
}
@@ -389,7 +389,7 @@ public static function base_supported_formats() {
public static function entry_content($course, $cm, $glossary, $entry, $aliases, $format) {
global $OUTPUT, $DB;
$entry = clone $entry;
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$options = portfolio_format_text_options();
$options->trusted = $entry->definitiontrust;
$options->context = $context;
@@ -427,7 +427,7 @@ public static function entry_content($course, $cm, $glossary, $entry, $aliases,
if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
return '';
}
- $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ $filecontext = context_module::instance($maincm->id);
} else {
$filecontext = $context;
@@ -30,7 +30,7 @@ function definition() {
$mform->addRule('entbypage', null, 'required', null, 'client');
$mform->addRule('entbypage', null, 'numeric', null, 'client');
- if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('mod/glossary:manageentries', context_system::instance())) {
$mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
$mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
Oops, something went wrong.

0 comments on commit e0a91e1

Please sign in to comment.