From 77d187ed1ead401bd5eadd24a1c55131a6fa9d64 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Wed, 18 Jul 2012 08:37:23 +0800 Subject: [PATCH 01/73] MDL-28568 message: added a warning message when the user is about to message someone who cant reply --- lang/en/message.php | 3 ++- message/index.php | 15 +++++++++++++-- theme/standard/style/core.css | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lang/en/message.php b/lang/en/message.php index fd25102a8f4..10c83e83de2 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -82,6 +82,7 @@ $string['messagehistory'] = 'Message history'; $string['messagehistoryfull'] = 'All messages'; $string['messages'] = 'Messages'; $string['messaging'] = 'Messaging'; +$string['messagingblockednoncontact'] = '{$a} will not be able to reply as you have blocked non-contacts'; $string['messagingdisabled'] = 'Messaging is disabled on this site, emails will be sent instead'; $string['mycontacts'] = 'My contacts'; $string['newonlymsg'] = 'Show only new'; @@ -140,5 +141,5 @@ $string['unreadnewmessage'] = 'New message from {$a}'; $string['unreadnewnotification'] = 'New notification'; $string['unreadnewnotifications'] = 'New notifications ({$a})'; $string['userisblockingyou'] = 'This user has blocked you from sending messages to them'; -$string['userisblockingyounoncontact'] = 'This user is only accepting messages from people listed as contacts, and you are not currently on the list.'; +$string['userisblockingyounoncontact'] = '{$a} only accepts messages from their contacts.'; $string['userssearchresults'] = 'Users found: {$a}'; diff --git a/message/index.php b/message/index.php index a695b27fd0d..daaa5ff56ff 100644 --- a/message/index.php +++ b/message/index.php @@ -153,7 +153,7 @@ if ($currentuser && !empty($user2) && has_capability('moodle/site:sendmessage', if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts if (empty($contact)) { // We are not a contact! - $messageerror = get_string('userisblockingyounoncontact', 'message'); + $messageerror = get_string('userisblockingyounoncontact', 'message', fullname($user2)); } } @@ -287,8 +287,19 @@ echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align')); if ($currentuser && has_capability('moodle/site:sendmessage', $context)) { echo html_writer::start_tag('div', array('class' => 'mdl-align messagesend')); if (!empty($messageerror)) { - echo $OUTPUT->heading($messageerror, 3); + echo html_writer::tag('span', $messageerror, array('id' => 'messagewarning')); } else { + // Display a warning if the current user is blocking non-contacts and is about to message to a non-contact + // Otherwise they may wonder why they never get a reply + $blocknoncontacts = get_user_preferences('message_blocknoncontacts', '', $user1->id); + if (!empty($blocknoncontacts)) { + $contact = $DB->get_record('message_contacts', array('userid' => $user1->id, 'contactid' => $user2->id)); + if (empty($contact)) { + $msg = get_string('messagingblockednoncontact', 'message', fullname($user2)); + echo html_writer::tag('span', $msg, array('id' => 'messagewarning')); + } + } + $mform = new send_form(); $defaultmessage = new stdClass; $defaultmessage->id = $user2->id; diff --git a/theme/standard/style/core.css b/theme/standard/style/core.css index cb7311557f0..d3410e7b28a 100644 --- a/theme/standard/style/core.css +++ b/theme/standard/style/core.css @@ -453,3 +453,4 @@ table#tag-management-list {margin: 10px auto;width: 80%;} #page-message-edit table.generaltable th.c0 {text-align: left;} #page-message-edit table.generaltable td.c0 {text-align: right;} #page-message-edit table.generaltable td.disallowed {text-align: center;vertical-align:middle;} +#messagewarning {font-style:italic;} From 8fea05bfb432b19d198c240229b53f7e52f55498 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 20 Jul 2012 14:56:00 +0800 Subject: [PATCH 02/73] MDL-33537 gradingform_rubric Adding the definition when retrieving grading instances Credit to Sam Chaffee --- grade/grading/form/rubric/lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grade/grading/form/rubric/lib.php b/grade/grading/form/rubric/lib.php index 71b38ecad2b..ae97eeedb0b 100644 --- a/grade/grading/form/rubric/lib.php +++ b/grade/grading/form/rubric/lib.php @@ -556,7 +556,8 @@ class gradingform_rubric_controller extends gradingform_controller { return $this->get_instance($instance); } if ($itemid && $raterid) { - if ($rs = $DB->get_records('grading_instances', array('raterid' => $raterid, 'itemid' => $itemid), 'timemodified DESC', '*', 0, 1)) { + $params = array('definitionid' => $this->definition->id, 'raterid' => $raterid, 'itemid' => $itemid); + if ($rs = $DB->get_records('grading_instances', $params, 'timemodified DESC', '*', 0, 1)) { $record = reset($rs); $currentinstance = $this->get_current_instance($raterid, $itemid); if ($record->status == gradingform_rubric_instance::INSTANCE_STATUS_INCOMPLETE && From 67ba9007b778b5df41658be7fff31160f3c76581 Mon Sep 17 00:00:00 2001 From: Kanika Goyal Date: Tue, 24 Jul 2012 01:52:54 +0530 Subject: [PATCH 03/73] MDL-32227: Plagiarism API - add support for plagiarism api to workshop module --- mod/workshop/mod_form.php | 3 +++ mod/workshop/renderer.php | 18 ++++++++++++++++++ mod/workshop/submission.php | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/mod/workshop/mod_form.php b/mod/workshop/mod_form.php index 87ea8002806..2a1103aec0f 100644 --- a/mod/workshop/mod_form.php +++ b/mod/workshop/mod_form.php @@ -197,6 +197,9 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true)); $mform->setAdvanced('assessmentend'); + $coursecontext = context_course::instance($this->course->id); + plagiarism_get_form_elements_module($mform, $coursecontext); + // Common module settings, Restrict availability, Activity completion etc. ---- $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true, 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false); diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php index eeee5ad59a9..f6172da4b7d 100644 --- a/mod/workshop/renderer.php +++ b/mod/workshop/renderer.php @@ -82,6 +82,7 @@ class mod_workshop_renderer extends plugin_renderer_base { * @return string HTML */ protected function render_workshop_submission(workshop_submission $submission) { + global $CFG; $o = ''; // output HTML code $anonymous = $submission->is_anonymous(); @@ -134,6 +135,15 @@ class mod_workshop_renderer extends plugin_renderer_base { $content = format_text($submission->content, $submission->contentformat, array('overflowdiv'=>true)); $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id, 'mod_workshop', 'submission_content', $submission->id); + if (!empty($content)) { + if (!empty($CFG->enableplagiarism)) { + require_once($CFG->libdir.'/plagiarismlib.php'); + $content .= plagiarism_get_links(array('userid' => $submission->authorid, + 'content' => $submission->content, + 'cmid' => $this->page->cm->id, + 'course' => $this->page->course)); + } + } $o .= $this->output->container($content, 'content'); $o .= $this->helper_submission_attachments($submission->id, 'html'); @@ -767,6 +777,14 @@ class mod_workshop_renderer extends plugin_renderer_base { } else if ($format == 'text') { $outputfiles .= $linktxt . PHP_EOL; } + + if (!empty($CFG->enableplagiarism)) { + require_once($CFG->libdir.'/plagiarismlib.php'); + $outputfiles .= plagiarism_get_links(array('userid' => $file->get_userid(), + 'file' => $file, + 'cmid' => $this->page->cm->id, + 'course' => $this->page->course->id)); + } } if ($format == 'html') { diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index e17f13bf824..3d56078d02e 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -207,6 +207,22 @@ if ($edit) { } // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten) $DB->update_record('workshop_submissions', $formdata); + + // send submitted content for plagiarism detection + $fs = get_file_storage(); + $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id); + $eventdata = new stdClass(); + $eventdata->modulename = 'workshop'; + $eventdata->cmid = $cm->id; + $eventdata->itemid = $submission->id; + $eventdata->courseid = $course->id; + $eventdata->userid = $USER->id; + $eventdata->content = $formdata->content; + if ($files) { + $eventdata->pathnamehashes = array_keys($files); + } + events_trigger('assessable_content_uploaded', $eventdata); + redirect($workshop->submission_url($formdata->id)); } } @@ -265,6 +281,10 @@ if (trim($workshop->instructauthors)) { // if in edit mode, display the form to edit the submission if ($edit) { + if (!empty($CFG->enableplagiarism)) { + require_once($CFG->libdir.'/plagiarismlib.php'); + echo plagiarism_print_disclosure($cm->id); + } $mform->display(); echo $output->footer(); die(); From 10f2c0fb49b6ea402c76e7bf3e544331a2735284 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Mon, 23 Jul 2012 15:28:26 +0100 Subject: [PATCH 04/73] MDL-34433 Check for existence of e and e.target in set_form_changed This is required for cases when code directly calls set_form_changed as happens with the filepicker. --- lib/yui/formchangechecker/formchangechecker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/yui/formchangechecker/formchangechecker.js b/lib/yui/formchangechecker/formchangechecker.js index 5c46983f195..ea5164d2742 100644 --- a/lib/yui/formchangechecker/formchangechecker.js +++ b/lib/yui/formchangechecker/formchangechecker.js @@ -93,7 +93,7 @@ YUI.add('moodle-core-formchangechecker', * Set the form changed state to true */ M.core_formchangechecker.set_form_changed = function(e) { - if (e.target.hasClass('ignoredirty')) { + if (e && e.target && e.target.hasClass('ignoredirty')) { // Don't warn on elements with the ignoredirty class return; } From 9eba24266bbb88e4bf5d60757d1b54d6df8ffba3 Mon Sep 17 00:00:00 2001 From: Rex Lorenzo Date: Tue, 24 Jul 2012 12:01:11 -0700 Subject: [PATCH 05/73] MDL-34519 - Course reset not protected by proper capability --- course/reset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/course/reset.php b/course/reset.php index cd0a66b640d..088c2036bb4 100644 --- a/course/reset.php +++ b/course/reset.php @@ -39,7 +39,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) { $PAGE->set_url('/course/reset.php', array('id'=>$id)); require_login($course); -require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id)); +require_capability('moodle/course:reset', get_context_instance(CONTEXT_COURSE, $course->id)); $strreset = get_string('reset'); $strresetcourse = get_string('resetcourse'); From d2a27ab01bc3d9fd07c7ded2e32ea551a96cf4b0 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Sat, 7 Jul 2012 11:31:55 +0100 Subject: [PATCH 06/73] MDL-29007 Rename moodle-enrol-notification to moodle-core-notification --- .../ui/yui/confirmcancel/confirmcancel.js | 2 +- blocks/community/yui/comments/comments.js | 4 +- .../yui/imagegallery/imagegallery.js | 2 +- course/yui/dragdrop/dragdrop.js | 2 +- .../yui/quickenrolment/quickenrolment.js | 2 +- .../yui/quickenrolment/quickenrolment.js | 2 +- enrol/yui/notification/notification.js | 390 +----------------- .../otherusersmanager/otherusersmanager.js | 2 +- enrol/yui/rolemanager/rolemanager.js | 2 +- filter/glossary/yui/autolinker/autolinker.js | 2 +- lib/upgrade.txt | 3 + lib/yui/blocks/blocks.js | 2 +- lib/yui/chooserdialogue/chooserdialogue.js | 2 +- lib/yui/dragdrop/dragdrop.js | 2 +- .../assets/skins/sam/notification.css | 0 .../notification/assets/skins/sam/sprite.png | Bin lib/yui/notification/notification.js | 385 +++++++++++++++++ 17 files changed, 407 insertions(+), 397 deletions(-) rename {enrol => lib}/yui/notification/assets/skins/sam/notification.css (100%) rename {enrol => lib}/yui/notification/assets/skins/sam/sprite.png (100%) create mode 100644 lib/yui/notification/notification.js diff --git a/backup/util/ui/yui/confirmcancel/confirmcancel.js b/backup/util/ui/yui/confirmcancel/confirmcancel.js index 6d84615e543..77deaf1c466 100644 --- a/backup/util/ui/yui/confirmcancel/confirmcancel.js +++ b/backup/util/ui/yui/confirmcancel/confirmcancel.js @@ -27,4 +27,4 @@ M.core_backup.watch_cancel_buttons = function(config) { }); } -}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-enrol-notification']}); +}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-core-notification']}); diff --git a/blocks/community/yui/comments/comments.js b/blocks/community/yui/comments/comments.js index 155a823c570..817e3ac5d8a 100644 --- a/blocks/community/yui/comments/comments.js +++ b/blocks/community/yui/comments/comments.js @@ -85,5 +85,5 @@ YUI.add('moodle-block_community-comments', function(Y) { } }, '@VERSION@', { - requires:['base','overlay', 'moodle-enrol-notification'] -}); \ No newline at end of file + requires:['base','overlay', 'moodle-core-notification'] +}); diff --git a/blocks/community/yui/imagegallery/imagegallery.js b/blocks/community/yui/imagegallery/imagegallery.js index f91abb08e42..e7072aaee87 100644 --- a/blocks/community/yui/imagegallery/imagegallery.js +++ b/blocks/community/yui/imagegallery/imagegallery.js @@ -195,5 +195,5 @@ YUI.add('moodle-block_community-imagegallery', function(Y) { } }, '@VERSION@', { - requires:['base','node','overlay', 'moodle-enrol-notification'] + requires:['base','node','overlay', 'moodle-core-notification'] }); diff --git a/course/yui/dragdrop/dragdrop.js b/course/yui/dragdrop/dragdrop.js index 435b3559bc1..431408d1ae1 100644 --- a/course/yui/dragdrop/dragdrop.js +++ b/course/yui/dragdrop/dragdrop.js @@ -411,4 +411,4 @@ YUI.add('moodle-course-dragdrop', function(Y) { M.course.init_section_dragdrop = function(params) { new DRAGSECTION(params); } -}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-enrol-notification', 'moodle-course-coursebase']}); +}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-core-notification', 'moodle-course-coursebase']}); diff --git a/enrol/cohort/yui/quickenrolment/quickenrolment.js b/enrol/cohort/yui/quickenrolment/quickenrolment.js index 7f5437ec137..6c22963ef33 100644 --- a/enrol/cohort/yui/quickenrolment/quickenrolment.js +++ b/enrol/cohort/yui/quickenrolment/quickenrolment.js @@ -381,4 +381,4 @@ YUI.add('moodle-enrol_cohort-quickenrolment', function(Y) { } } -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']}); diff --git a/enrol/manual/yui/quickenrolment/quickenrolment.js b/enrol/manual/yui/quickenrolment/quickenrolment.js index 88c09ea4dab..08f8d702823 100644 --- a/enrol/manual/yui/quickenrolment/quickenrolment.js +++ b/enrol/manual/yui/quickenrolment/quickenrolment.js @@ -524,4 +524,4 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { } } -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']}); diff --git a/enrol/yui/notification/notification.js b/enrol/yui/notification/notification.js index 8b9144331a9..f2bf542a384 100644 --- a/enrol/yui/notification/notification.js +++ b/enrol/yui/notification/notification.js @@ -1,385 +1,7 @@ +/** + * This module provides backwards compatability and should be removed + * entirely in Moodle 2.5 + */ YUI.add('moodle-enrol-notification', function(Y) { - -var DIALOGUE_NAME = 'Moodle dialogue', - DIALOGUE_PREFIX = 'moodle-dialogue', - CONFIRM_NAME = 'Moodle confirmation dialogue', - EXCEPTION_NAME = 'Moodle exception', - AJAXEXCEPTION_NAME = 'Moodle AJAX exception', - ALERT_NAME = 'Moodle alert', - C = Y.Node.create, - BASE = 'notificationBase', - LIGHTBOX = 'lightbox', - NODELIGHTBOX = 'nodeLightbox', - COUNT = 0, - CONFIRMYES = 'yesLabel', - CONFIRMNO = 'noLabel', - TITLE = 'title', - QUESTION = 'question', - CSS = { - BASE : 'moodle-dialogue-base', - WRAP : 'moodle-dialogue-wrap', - HEADER : 'moodle-dialogue-hd', - BODY : 'moodle-dialogue-bd', - CONTENT : 'moodle-dialogue-content', - FOOTER : 'moodle-dialogue-fd', - HIDDEN : 'hidden', - LIGHTBOX : 'moodle-dialogue-lightbox' - }; - -var DIALOGUE = function(config) { - COUNT++; - var id = 'moodle-dialogue-'+COUNT; - config.notificationBase = - C('
') - .append(C('
')) - .append(C('
') - .append(C('
')) - .append(C('
')) - .append(C('
'))); - Y.one(document.body).append(config.notificationBase); - config.srcNode = '#'+id; - config.width = config.width || '400px'; - config.visible = config.visible || false; - config.center = config.centered || true; - config.centered = false; - DIALOGUE.superclass.constructor.apply(this, [config]); -}; -Y.extend(DIALOGUE, Y.Overlay, { - initializer : function(config) { - this.set(NODELIGHTBOX, this.get(BASE).one('.'+CSS.LIGHTBOX).setStyle('opacity', 0.5)); - this.after('visibleChange', this.visibilityChanged, this); - this.after('headerContentChange', function(e){ - var h = (this.get('closeButton'))?this.get(BASE).one('.'+CSS.HEADER):false; - if (h && !h.one('.closebutton')) { - var c = C('
'); - c.on('click', this.hide, this); - h.append(c); - } - }, this); - this.render(); - this.show(); - }, - visibilityChanged : function(e) { - switch (e.attrName) { - case 'visible': - if (this.get(LIGHTBOX)) { - var l = this.get(NODELIGHTBOX); - if (!e.prevVal && e.newVal) { - l.setStyle('height',l.get('docHeight')+'px').removeClass(CSS.HIDDEN); - } else if (e.prevVal && !e.newVal) { - l.addClass(CSS.HIDDEN); - } - } - if (this.get('center') && !e.prevVal && e.newVal) { - this.centerDialogue(); - } - if (this.get('draggable')) { - var titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; - this.plug(Y.Plugin.Drag, {handles : [titlebar]}); - this.dd.addInvalid('div.closebutton'); - Y.one(titlebar).setStyle('cursor', 'move'); - } - break; - } - }, - centerDialogue : function() { - var bb = this.get('boundingBox'), hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'); - if (hidden) { - bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); - } - var x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); - var y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); - - if (hidden) { - bb.addClass(DIALOGUE_PREFIX+'-hidden'); - } - bb.setStyle('left', x).setStyle('top', y); - } -}, { - NAME : DIALOGUE_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - notificationBase : { - - }, - nodeLightbox : { - value : null - }, - lightbox : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButton : { - validator : Y.Lang.isBoolean, - value : true - }, - center : { - validator : Y.Lang.isBoolean, - value : true - }, - draggable : { - validator : Y.Lang.isBoolean, - value : false - } - } -}); - -var ALERT = function(config) { - config.closeButton = false; - ALERT.superclass.constructor.apply(this, [config]); -}; -Y.extend(ALERT, DIALOGUE, { - _enterKeypress : null, - initializer : function(config) { - this.publish('complete'); - var yes = C(''), - content = C('
') - .append(C('
'+this.get('message')+'
')) - .append(C('
') - .append(yes)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, this.get(TITLE), Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); - }, - submit : function(e, outcome) { - this._enterKeypress.detach(); - this.fire('complete'); - this.hide(); - this.destroy(); - } -}, { - NAME : ALERT_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - title : { - validator : Y.Lang.isString, - value : 'Alert' - }, - message : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - yesLabel : { - validator : Y.Lang.isString, - setter : function(txt) { - if (!txt) { - txt = 'Ok'; - } - return txt; - }, - value : 'Ok' - } - } -}); - -var CONFIRM = function(config) { - CONFIRM.superclass.constructor.apply(this, [config]); -}; -Y.extend(CONFIRM, DIALOGUE, { - _enterKeypress : null, - _escKeypress : null, - initializer : function(config) { - this.publish('complete'); - this.publish('complete-yes'); - this.publish('complete-no'); - var yes = C(''), - no = C(''), - content = C('
') - .append(C('
'+this.get(QUESTION)+'
')) - .append(C('
') - .append(yes) - .append(no)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, this.get(TITLE), Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); - }, - submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); - this.fire('complete', outcome); - if (outcome) { - this.fire('complete-yes'); - } else { - this.fire('complete-no'); - } - this.hide(); - this.destroy(); - } -}, { - NAME : CONFIRM_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - yesLabel : { - validator : Y.Lang.isString, - value : 'Yes' - }, - noLabel : { - validator : Y.Lang.isString, - value : 'No' - }, - title : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - question : { - validator : Y.Lang.isString, - value : 'Are you sure?' - } - } -}); -Y.augment(CONFIRM, Y.EventTarget); - -var EXCEPTION = function(config) { - config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; - config.closeButton = true; - EXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(EXCEPTION, DIALOGUE, { - _hideTimeout : null, - _keypress : null, - initializer : function(config) { - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); - var content = C('
') - .append(C('
'+this.get('message')+'
')) - .append(C('')) - .append(C('')) - .append(C('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - var self = this; - var delay = this.get('hideTimeoutDelay'); - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName == 'visible' && e.prevVal && !e.newVal) { - if (this._keypress) this._keypress.detach(); - var self = this; - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : EXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - message : { - value : '' - }, - name : { - value : '' - }, - fileName : { - value : '' - }, - lineNumber : { - value : '' - }, - stack : { - setter : function(str) { - var lines = str.split("\n"); - var pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'); - for (var i in lines) { - lines[i] = lines[i].replace(pattern, "
ln: $4
$3
$1
"); - } - return lines.join(''); - }, - value : '' - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -var AJAXEXCEPTION = function(config) { - config.name = config.name || 'Error'; - config.closeButton = true; - AJAXEXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(AJAXEXCEPTION, DIALOGUE, { - _keypress : null, - initializer : function(config) { - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); - var content = C('
') - .append(C('
'+this.get('error')+'
')) - .append(C('')) - .append(C('')) - .append(C('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - var self = this; - var delay = this.get('hideTimeoutDelay'); - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName == 'visible' && e.prevVal && !e.newVal) { - var self = this; - this._keypress.detach(); - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : AJAXEXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - error : { - validator : Y.Lang.isString, - value : 'Unknown error' - }, - debuginfo : { - value : null - }, - stacktrace : { - value : null - }, - reproductionlink : { - setter : function(link) { - if (link !== null) { - link = ''+link.replace(M.cfg.wwwroot, '')+''; - } - return link; - }, - value : null - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -M.core = M.core || {}; -M.core.dialogue = DIALOGUE; -M.core.alert = ALERT; -M.core.confirm = CONFIRM; -M.core.exception = EXCEPTION; -M.core.ajaxException = AJAXEXCEPTION; - -}, '@VERSION@', {requires:['base','node','overlay','event-key', 'moodle-enrol-notification-skin', 'dd-plugin']}); + console.log("You are using a deprecated name. Please update your YUI module to use moodle-core-notification instead of moodle-enrol-notification"); +}, '@VERSION@', {requires:['base','node','overlay','event-key', 'moodle-core-notification']}); diff --git a/enrol/yui/otherusersmanager/otherusersmanager.js b/enrol/yui/otherusersmanager/otherusersmanager.js index 6685c1989fc..32b1ad87476 100644 --- a/enrol/yui/otherusersmanager/otherusersmanager.js +++ b/enrol/yui/otherusersmanager/otherusersmanager.js @@ -391,4 +391,4 @@ YUI.add('moodle-enrol-otherusersmanager', function(Y) { } } -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']}); \ No newline at end of file +}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']}); diff --git a/enrol/yui/rolemanager/rolemanager.js b/enrol/yui/rolemanager/rolemanager.js index a03bc3502f5..afa52c2beb4 100644 --- a/enrol/yui/rolemanager/rolemanager.js +++ b/enrol/yui/rolemanager/rolemanager.js @@ -416,4 +416,4 @@ YUI.add('moodle-enrol-rolemanager', function(Y) { } } -}, '@VERSION@', {requires:['base','node','io-base','json-parse','test','moodle-enrol-notification']}); \ No newline at end of file +}, '@VERSION@', {requires:['base','node','io-base','json-parse','test','moodle-core-notification']}); diff --git a/filter/glossary/yui/autolinker/autolinker.js b/filter/glossary/yui/autolinker/autolinker.js index 484c42ef21b..1a1586df4a2 100644 --- a/filter/glossary/yui/autolinker/autolinker.js +++ b/filter/glossary/yui/autolinker/autolinker.js @@ -130,4 +130,4 @@ YUI.add('moodle-filter_glossary-autolinker', function(Y) { return new AUTOLINKER(config); } -}, '@VERSION@', {requires:['base','node','io-base','json-parse','event-delegate','overlay','moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base','node','io-base','json-parse','event-delegate','overlay','moodle-core-notification']}); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 58682c5673f..d3bc9c16f35 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -6,6 +6,9 @@ information provided here is intended especially for developers. * Pagelib: Numerous deprecated functions were removed as classes page_base, page_course and page_generic_activity. +YUI changes: +* moodle-enrol-notification has been renamed to moodle-core-notification + === 2.3 === Database layer changes: diff --git a/lib/yui/blocks/blocks.js b/lib/yui/blocks/blocks.js index cec719f859b..f487b02fba1 100644 --- a/lib/yui/blocks/blocks.js +++ b/lib/yui/blocks/blocks.js @@ -268,5 +268,5 @@ YUI.add('moodle-core-blocks', function(Y) { M.core_blocks.init_dragdrop = function(params) { new DRAGBLOCK(params); } -}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-core-notification']}); diff --git a/lib/yui/chooserdialogue/chooserdialogue.js b/lib/yui/chooserdialogue/chooserdialogue.js index 9560b3e7880..874bb938c6c 100644 --- a/lib/yui/chooserdialogue/chooserdialogue.js +++ b/lib/yui/chooserdialogue/chooserdialogue.js @@ -303,6 +303,6 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { M.core.chooserdialogue = CHOOSERDIALOGUE; }, '@VERSION@', { - requires:['base', 'overlay', 'moodle-enrol-notification'] + requires:['base', 'overlay', 'moodle-core-notification'] } ); diff --git a/lib/yui/dragdrop/dragdrop.js b/lib/yui/dragdrop/dragdrop.js index 6669f37126a..db4c73aaad5 100644 --- a/lib/yui/dragdrop/dragdrop.js +++ b/lib/yui/dragdrop/dragdrop.js @@ -200,4 +200,4 @@ YUI.add('moodle-core-dragdrop', function(Y) { M.core = M.core || {}; M.core.dragdrop = DRAGDROP; -}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'moodle-core-notification']}); diff --git a/enrol/yui/notification/assets/skins/sam/notification.css b/lib/yui/notification/assets/skins/sam/notification.css similarity index 100% rename from enrol/yui/notification/assets/skins/sam/notification.css rename to lib/yui/notification/assets/skins/sam/notification.css diff --git a/enrol/yui/notification/assets/skins/sam/sprite.png b/lib/yui/notification/assets/skins/sam/sprite.png similarity index 100% rename from enrol/yui/notification/assets/skins/sam/sprite.png rename to lib/yui/notification/assets/skins/sam/sprite.png diff --git a/lib/yui/notification/notification.js b/lib/yui/notification/notification.js new file mode 100644 index 00000000000..3df1c5292d3 --- /dev/null +++ b/lib/yui/notification/notification.js @@ -0,0 +1,385 @@ +YUI.add('moodle-core-notification', function(Y) { + +var DIALOGUE_NAME = 'Moodle dialogue', + DIALOGUE_PREFIX = 'moodle-dialogue', + CONFIRM_NAME = 'Moodle confirmation dialogue', + EXCEPTION_NAME = 'Moodle exception', + AJAXEXCEPTION_NAME = 'Moodle AJAX exception', + ALERT_NAME = 'Moodle alert', + C = Y.Node.create, + BASE = 'notificationBase', + LIGHTBOX = 'lightbox', + NODELIGHTBOX = 'nodeLightbox', + COUNT = 0, + CONFIRMYES = 'yesLabel', + CONFIRMNO = 'noLabel', + TITLE = 'title', + QUESTION = 'question', + CSS = { + BASE : 'moodle-dialogue-base', + WRAP : 'moodle-dialogue-wrap', + HEADER : 'moodle-dialogue-hd', + BODY : 'moodle-dialogue-bd', + CONTENT : 'moodle-dialogue-content', + FOOTER : 'moodle-dialogue-fd', + HIDDEN : 'hidden', + LIGHTBOX : 'moodle-dialogue-lightbox' + }; + +var DIALOGUE = function(config) { + COUNT++; + var id = 'moodle-dialogue-'+COUNT; + config.notificationBase = + C('
') + .append(C('
')) + .append(C('
') + .append(C('
')) + .append(C('
')) + .append(C('
'))); + Y.one(document.body).append(config.notificationBase); + config.srcNode = '#'+id; + config.width = config.width || '400px'; + config.visible = config.visible || false; + config.center = config.centered || true; + config.centered = false; + DIALOGUE.superclass.constructor.apply(this, [config]); +}; +Y.extend(DIALOGUE, Y.Overlay, { + initializer : function(config) { + this.set(NODELIGHTBOX, this.get(BASE).one('.'+CSS.LIGHTBOX).setStyle('opacity', 0.5)); + this.after('visibleChange', this.visibilityChanged, this); + this.after('headerContentChange', function(e){ + var h = (this.get('closeButton'))?this.get(BASE).one('.'+CSS.HEADER):false; + if (h && !h.one('.closebutton')) { + var c = C('
'); + c.on('click', this.hide, this); + h.append(c); + } + }, this); + this.render(); + this.show(); + }, + visibilityChanged : function(e) { + switch (e.attrName) { + case 'visible': + if (this.get(LIGHTBOX)) { + var l = this.get(NODELIGHTBOX); + if (!e.prevVal && e.newVal) { + l.setStyle('height',l.get('docHeight')+'px').removeClass(CSS.HIDDEN); + } else if (e.prevVal && !e.newVal) { + l.addClass(CSS.HIDDEN); + } + } + if (this.get('center') && !e.prevVal && e.newVal) { + this.centerDialogue(); + } + if (this.get('draggable')) { + var titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; + this.plug(Y.Plugin.Drag, {handles : [titlebar]}); + this.dd.addInvalid('div.closebutton'); + Y.one(titlebar).setStyle('cursor', 'move'); + } + break; + } + }, + centerDialogue : function() { + var bb = this.get('boundingBox'), hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'); + if (hidden) { + bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); + } + var x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); + var y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); + + if (hidden) { + bb.addClass(DIALOGUE_PREFIX+'-hidden'); + } + bb.setStyle('left', x).setStyle('top', y); + } +}, { + NAME : DIALOGUE_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + notificationBase : { + + }, + nodeLightbox : { + value : null + }, + lightbox : { + validator : Y.Lang.isBoolean, + value : true + }, + closeButton : { + validator : Y.Lang.isBoolean, + value : true + }, + center : { + validator : Y.Lang.isBoolean, + value : true + }, + draggable : { + validator : Y.Lang.isBoolean, + value : false + } + } +}); + +var ALERT = function(config) { + config.closeButton = false; + ALERT.superclass.constructor.apply(this, [config]); +}; +Y.extend(ALERT, DIALOGUE, { + _enterKeypress : null, + initializer : function(config) { + this.publish('complete'); + var yes = C(''), + content = C('
') + .append(C('
'+this.get('message')+'
')) + .append(C('
') + .append(yes)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, this.get(TITLE), Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); + yes.on('click', this.submit, this); + }, + submit : function(e, outcome) { + this._enterKeypress.detach(); + this.fire('complete'); + this.hide(); + this.destroy(); + } +}, { + NAME : ALERT_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + title : { + validator : Y.Lang.isString, + value : 'Alert' + }, + message : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + yesLabel : { + validator : Y.Lang.isString, + setter : function(txt) { + if (!txt) { + txt = 'Ok'; + } + return txt; + }, + value : 'Ok' + } + } +}); + +var CONFIRM = function(config) { + CONFIRM.superclass.constructor.apply(this, [config]); +}; +Y.extend(CONFIRM, DIALOGUE, { + _enterKeypress : null, + _escKeypress : null, + initializer : function(config) { + this.publish('complete'); + this.publish('complete-yes'); + this.publish('complete-no'); + var yes = C(''), + no = C(''), + content = C('
') + .append(C('
'+this.get(QUESTION)+'
')) + .append(C('
') + .append(yes) + .append(no)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, this.get(TITLE), Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); + this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); + yes.on('click', this.submit, this, true); + no.on('click', this.submit, this, false); + }, + submit : function(e, outcome) { + this._enterKeypress.detach(); + this._escKeypress.detach(); + this.fire('complete', outcome); + if (outcome) { + this.fire('complete-yes'); + } else { + this.fire('complete-no'); + } + this.hide(); + this.destroy(); + } +}, { + NAME : CONFIRM_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + yesLabel : { + validator : Y.Lang.isString, + value : 'Yes' + }, + noLabel : { + validator : Y.Lang.isString, + value : 'No' + }, + title : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + question : { + validator : Y.Lang.isString, + value : 'Are you sure?' + } + } +}); +Y.augment(CONFIRM, Y.EventTarget); + +var EXCEPTION = function(config) { + config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; + config.closeButton = true; + EXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(EXCEPTION, DIALOGUE, { + _hideTimeout : null, + _keypress : null, + initializer : function(config) { + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); + var content = C('
') + .append(C('
'+this.get('message')+'
')) + .append(C('')) + .append(C('')) + .append(C('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + var self = this; + var delay = this.get('hideTimeoutDelay'); + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName == 'visible' && e.prevVal && !e.newVal) { + if (this._keypress) this._keypress.detach(); + var self = this; + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : EXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + message : { + value : '' + }, + name : { + value : '' + }, + fileName : { + value : '' + }, + lineNumber : { + value : '' + }, + stack : { + setter : function(str) { + var lines = str.split("\n"); + var pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'); + for (var i in lines) { + lines[i] = lines[i].replace(pattern, "
ln: $4
$3
$1
"); + } + return lines.join(''); + }, + value : '' + }, + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +var AJAXEXCEPTION = function(config) { + config.name = config.name || 'Error'; + config.closeButton = true; + AJAXEXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(AJAXEXCEPTION, DIALOGUE, { + _keypress : null, + initializer : function(config) { + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); + var content = C('
') + .append(C('
'+this.get('error')+'
')) + .append(C('')) + .append(C('')) + .append(C('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + var self = this; + var delay = this.get('hideTimeoutDelay'); + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName == 'visible' && e.prevVal && !e.newVal) { + var self = this; + this._keypress.detach(); + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : AJAXEXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + error : { + validator : Y.Lang.isString, + value : 'Unknown error' + }, + debuginfo : { + value : null + }, + stacktrace : { + value : null + }, + reproductionlink : { + setter : function(link) { + if (link !== null) { + link = ''+link.replace(M.cfg.wwwroot, '')+''; + } + return link; + }, + value : null + }, + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core = M.core || {}; +M.core.dialogue = DIALOGUE; +M.core.alert = ALERT; +M.core.confirm = CONFIRM; +M.core.exception = EXCEPTION; +M.core.ajaxException = AJAXEXCEPTION; + +}, '@VERSION@', {requires:['base','node','overlay','event-key', 'moodle-core-notification-skin', 'dd-plugin']}); From 4373103084527e9ca33cc98e388d5e7b2fba39a3 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 26 Jul 2012 11:38:02 +0800 Subject: [PATCH 07/73] MDL-34460 Librairies: Replaced deprecated get_context_instance() --- rss/file.php | 2 +- tag/coursetags_add.php | 2 +- tag/coursetags_edit.php | 4 ++-- tag/coursetags_more.php | 6 +++--- tag/coursetagslib.php | 2 +- tag/edit.php | 2 +- tag/edit_form.php | 2 +- tag/index.php | 2 +- tag/lib.php | 2 +- tag/locallib.php | 8 ++++---- tag/manage.php | 4 ++-- tag/search.php | 4 ++-- theme/mymobile/renderers.php | 10 +++++----- user/addnote.php | 2 +- user/edit.php | 10 +++++----- user/edit_form.php | 4 ++-- user/editadvanced.php | 12 ++++++------ user/editadvanced_form.php | 2 +- user/editlib.php | 2 +- user/emailupdate.php | 2 +- user/externallib.php | 10 +++++----- user/files.php | 2 +- user/filters/courserole.php | 2 +- user/filters/globalrole.php | 2 +- user/groupaddnote.php | 2 +- user/index.php | 14 +++++++------- user/lib.php | 12 ++++++------ user/managetoken.php | 2 +- user/messageselect.php | 6 +++--- user/pix.php | 2 +- user/policy.php | 2 +- user/portfolio.php | 2 +- user/portfoliologs.php | 2 +- user/profile.php | 10 +++++----- user/profile/field/checkbox/field.class.php | 2 +- user/profile/field/menu/field.class.php | 2 +- user/profile/lib.php | 12 ++++++------ user/profilesys.php | 2 +- user/renderer.php | 2 +- user/repository.php | 2 +- user/selector/lib.php | 6 +++--- user/selector/search.php | 2 +- user/view.php | 8 ++++---- userpix/index.php | 2 +- webservice/externallib.php | 2 +- webservice/lib.php | 12 ++++++------ webservice/upload.php | 2 +- webservice/wsdoc.php | 2 +- 48 files changed, 106 insertions(+), 106 deletions(-) diff --git a/rss/file.php b/rss/file.php index fdc4958e675..b9896db3781 100644 --- a/rss/file.php +++ b/rss/file.php @@ -85,7 +85,7 @@ if ($token==="$inttoken") { foreach ($modinfo->instances[$componentname] as $modinstanceid=>$cm) { if ($modinstanceid==$instanceid) { - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id, IGNORE_MISSING); break; } } diff --git a/tag/coursetags_add.php b/tag/coursetags_add.php index 969dda3e3ac..2ad17772202 100644 --- a/tag/coursetags_add.php +++ b/tag/coursetags_add.php @@ -28,7 +28,7 @@ require_once('../config.php'); require_login(); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); require_capability('moodle/tag:create', $systemcontext); if (empty($CFG->usetags)) { diff --git a/tag/coursetags_edit.php b/tag/coursetags_edit.php index 8dbc285dffa..53e6be65186 100644 --- a/tag/coursetags_edit.php +++ b/tag/coursetags_edit.php @@ -59,7 +59,7 @@ if ($courseid != SITEID) { } // Permissions -$sitecontext = get_context_instance(CONTEXT_SYSTEM); +$sitecontext = context_system::instance(); require_login($course); $canedit = has_capability('moodle/tag:create', $sitecontext); @@ -85,7 +85,7 @@ if ($data = data_submitted()) { // The title and breadcrumb $title = get_string('edittitle', $tagslang); $coursefullname = format_string($course->fullname); -$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->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($course->fullname); diff --git a/tag/coursetags_more.php b/tag/coursetags_more.php index 60b18207be1..61c3ccd3331 100644 --- a/tag/coursetags_more.php +++ b/tag/coursetags_more.php @@ -65,7 +65,7 @@ if ($courseid) { } if ($courseid) { - $PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid)); + $PAGE->set_context(context_course::instance($courseid)); } else { $PAGE->set_context(get_system_context()); } @@ -86,7 +86,7 @@ $welcome = get_string('morewelcome', $tagslang); // The title and breadcrumb if ($courseid) { - $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid))); + $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($courseid))); $PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid))); } $PAGE->navbar->add($title); @@ -183,7 +183,7 @@ if ($loggedin) { } } if ($courseid) { - $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))); if ($show == 'course') { $link1 .= ' | '.get_string('moreshowcoursetags', $tagslang, $fullname).''; } else { diff --git a/tag/coursetagslib.php b/tag/coursetagslib.php index 5b5557aa5e4..7d36b473642 100644 --- a/tag/coursetagslib.php +++ b/tag/coursetagslib.php @@ -232,7 +232,7 @@ function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_siz $step = ($max_size - $min_size)/($spread); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext); //prints the tag cloud diff --git a/tag/edit.php b/tag/edit.php index b71c72f2be0..3629ed0315c 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -36,7 +36,7 @@ if (empty($CFG->usetags)) { } //Editing a tag requires moodle/tag:edit capability -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); require_capability('moodle/tag:edit', $systemcontext); if ($tag_name) { diff --git a/tag/edit_form.php b/tag/edit_form.php index 972836755a7..9c62a4a6d05 100644 --- a/tag/edit_form.php +++ b/tag/edit_form.php @@ -51,7 +51,7 @@ class tag_edit_form extends moodleform { $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); if (has_capability('moodle/tag:manage', $systemcontext)) { $mform->addElement('text', 'rawname', get_string('name', 'tag'), diff --git a/tag/index.php b/tag/index.php index 7e957826964..dbf3009a9c1 100644 --- a/tag/index.php +++ b/tag/index.php @@ -41,7 +41,7 @@ $edit = optional_param('edit', -1, PARAM_BOOL); $userpage = optional_param('userpage', 0, PARAM_INT); // which page to show $perpage = optional_param('perpage', 24, PARAM_INT); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); if ($tagname) { $tag = tag_get('name', $tagname, '*'); diff --git a/tag/lib.php b/tag/lib.php index cdbe37fb904..d2a6f66500e 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -600,7 +600,7 @@ function tag_delete($tagids) { } $success = true; - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); foreach ($tagids as $tagid) { if (is_null($tagid)) { // can happen if tag doesn't exists continue; diff --git a/tag/locallib.php b/tag/locallib.php index fb7f9a9f730..81afc01928f 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -39,7 +39,7 @@ require_once($CFG->libdir.'/filelib.php'); function tag_print_cloud($nr_of_tags=150, $return=false) { global $CFG, $DB; - $can_manage_tags = has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM)); + $can_manage_tags = has_capability('moodle/tag:manage', context_system::instance()); if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid @@ -146,7 +146,7 @@ function tag_print_description_box($tag_object, $return=false) { $options = new stdClass(); $options->para = false; $options->overflowdiv = true; - $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', get_context_instance(CONTEXT_SYSTEM)->id, 'tag', 'description', $tag_object->id); + $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $tag_object->id); $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options); } @@ -190,7 +190,7 @@ function tag_print_management_box($tag_object, $return=false) { if (!isguestuser()) { $output .= $OUTPUT->box_start('box','tag-management-box'); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $links = array(); // Add a link for users to add/remove this from their interests @@ -356,7 +356,7 @@ function tag_print_tagged_users_table($tag_object, $limitfrom='', $limitnum='', function tag_print_user_box($user, $return=false) { global $CFG, $OUTPUT; - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); $profilelink = ''; if ($usercontext and (has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id))) { diff --git a/tag/manage.php b/tag/manage.php index e0edeb94bf5..2a886d3c7aa 100644 --- a/tag/manage.php +++ b/tag/manage.php @@ -41,7 +41,7 @@ if (empty($CFG->usetags)) { print_error('tagsaredisabled', 'tag'); } -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); require_capability('moodle/tag:manage', $systemcontext); $params = array(); @@ -151,7 +151,7 @@ switch($action) { // tag exists, change the type tag_type_set($new_otag_id, 'official'); } else { - require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/tag:create', context_system::instance()); tag_add($new_otag, 'official'); } $notice .= get_string('addedotag', 'tag', $new_otag) .' '; diff --git a/tag/search.php b/tag/search.php index 7ebcfbf3e99..422d4e1bc7c 100644 --- a/tag/search.php +++ b/tag/search.php @@ -47,10 +47,10 @@ if ($perpage !== 18) { $params['perpage'] = $perpage; } $PAGE->set_url(new moodle_url('/tag/search.php', $params)); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_pagelayout('standard'); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); $manage_link = ' '; $PAGE->set_title(get_string('tags', 'tag')); diff --git a/theme/mymobile/renderers.php b/theme/mymobile/renderers.php index 2b340d95212..b6b49cf273a 100644 --- a/theme/mymobile/renderers.php +++ b/theme/mymobile/renderers.php @@ -44,7 +44,7 @@ class theme_mymobile_renderer extends plugin_renderer_base { */ public function settings_tree(settings_navigation $navigation) { $content = $this->navigation_node($navigation, array('class' => 'settings')); - if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('moodle/site:config', context_system::instance())) { // TODO: Work out whether something is missing from here. } return $content; @@ -326,7 +326,7 @@ class theme_mymobile_core_renderer extends core_renderer { // $course->id is not defined during installation return ''; } else if (isloggedin()) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $fullname = fullname($USER, true); // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page) @@ -364,7 +364,7 @@ class theme_mymobile_core_renderer extends core_renderer { } else { $loggedinas .= get_string('failedloginattemptsall', '', $count); } - if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) { + if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) { $loggedinas .= ' ('.get_string('logs').')'; } $loggedinas .= '
'; @@ -405,7 +405,7 @@ class theme_mymobile_core_renderer extends core_renderer { // $course->id is not defined during installation return ''; } else if (isloggedin()) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $fullname = fullname($USER, true); // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page) @@ -447,7 +447,7 @@ class theme_mymobile_core_renderer extends core_renderer { } else { $loggedinas .= get_string('failedloginattemptsall', '', $count); } - if (has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('report/log:view', context_system::instance())) { $loggedinas .= ' ('.get_string('logs').')'; } $loggedinas .= '
'; diff --git a/user/addnote.php b/user/addnote.php index 1b899822686..e64957b4ecc 100644 --- a/user/addnote.php +++ b/user/addnote.php @@ -37,7 +37,7 @@ if (! $course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } -$context = get_context_instance(CONTEXT_COURSE, $id); +$context = context_course::instance($id); require_login($course); // to create notes the current user needs a capability diff --git a/user/edit.php b/user/edit.php index aa88131d5fa..207093c23dd 100644 --- a/user/edit.php +++ b/user/edit.php @@ -97,12 +97,12 @@ if ($editurl = $userauth->edit_profile_url()) { } if ($course->id == SITEID) { - $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + $coursecontext = context_system::instance(); // SYSTEM context } else { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + $coursecontext = context_course::instance($course->id); // Course context } -$systemcontext = get_context_instance(CONTEXT_SYSTEM); -$personalcontext = get_context_instance(CONTEXT_USER, $user->id); +$systemcontext = context_system::instance(); +$personalcontext = context_user::instance($user->id); // check access control if ($user->id == $USER->id) { @@ -244,7 +244,7 @@ if ($usernew = $userform->get_data()) { $a = new stdClass(); $a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id; - $a->site = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))); + $a->site = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID))); $a->fullname = fullname($user, true); $emailupdatemessage = get_string('emailupdatemessage', 'auth', $a); diff --git a/user/edit_form.php b/user/edit_form.php index b077a0c2143..cec4d5dfd68 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -83,7 +83,7 @@ class user_edit_form extends moodleform { // print picture if (!empty($CFG->gdversion)) { - $context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST); + $context = context_user::instance($user->id, MUST_EXIST); $fs = get_file_storage(); $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); if (!empty($user->picture) && $hasuploadedpicture) { @@ -147,7 +147,7 @@ class user_edit_form extends moodleform { $errors['email'] = get_string('toomanybounces'); } - if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', context_system::instance())) { $errorstr = email_is_not_allowed($usernew->email); if ($errorstr !== false) { $errors['email'] = $errorstr; diff --git a/user/editadvanced.php b/user/editadvanced.php index cdf03bd86e7..10c0faa0b48 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -49,11 +49,11 @@ if (!empty($USER->newadminuser)) { } if ($course->id == SITEID) { - $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + $coursecontext = context_system::instance(); // SYSTEM context } else { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + $coursecontext = context_course::instance($course->id); // Course context } -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); if ($id == -1) { // creating new user @@ -68,7 +68,7 @@ if ($id == -1) { // editing existing user require_capability('moodle/user:update', $systemcontext); $user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST); - $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); + $PAGE->set_context(context_user::instance($user->id)); if ($user->id == $USER->id) { if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) { $node->make_active(); @@ -112,7 +112,7 @@ if (!empty($CFG->usetags)) { } if ($user->id !== -1) { - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); $editoroptions = array( 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, @@ -203,7 +203,7 @@ if ($usernew = $userform->get_data()) { $usercreated = false; } - $usercontext = get_context_instance(CONTEXT_USER, $usernew->id); + $usercontext = context_user::instance($usernew->id); //update preferences useredit_update_user_preference($usernew); diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index dbe6d829cab..04a63d718e0 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -130,7 +130,7 @@ class user_editadvanced_form extends moodleform { // print picture if (!empty($CFG->gdversion) and empty($USER->newadminuser)) { if ($user) { - $context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST); + $context = context_user::instance($user->id, MUST_EXIST); $fs = get_file_storage(); $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); if (!empty($user->picture) && $hasuploadedpicture) { diff --git a/user/editlib.php b/user/editlib.php index 4c2a317fa34..d2250fbbfc3 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -46,7 +46,7 @@ function useredit_update_picture(stdClass $usernew, moodleform $userform, $filem global $CFG, $DB; require_once("$CFG->libdir/gdlib.php"); - $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST); + $context = context_user::instance($usernew->id, MUST_EXIST); $user = $DB->get_record('user', array('id'=>$usernew->id), 'id, picture', MUST_EXIST); $newpicture = $user->picture; diff --git a/user/emailupdate.php b/user/emailupdate.php index 602aa164017..0aee6c87584 100644 --- a/user/emailupdate.php +++ b/user/emailupdate.php @@ -31,7 +31,7 @@ $key = required_param('key', PARAM_ALPHANUM); $id = required_param('id', PARAM_INT); $PAGE->set_url('/user/emailupdate.php', array('id'=>$id, 'key'=>$key)); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); if (!$user = $DB->get_record('user', array('id' => $id))) { print_error('invaliduserid'); diff --git a/user/externallib.php b/user/externallib.php index 47b2663a663..49987cb938e 100644 --- a/user/externallib.php +++ b/user/externallib.php @@ -100,7 +100,7 @@ class core_user_external extends external_api { require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function // Ensure the current user is allowed to run this function - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); self::validate_context($context); require_capability('moodle/user:create', $context); @@ -226,7 +226,7 @@ class core_user_external extends external_api { require_once($CFG->dirroot."/user/lib.php"); // Ensure the current user is allowed to run this function - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); require_capability('moodle/user:delete', $context); self::validate_context($context); @@ -324,7 +324,7 @@ class core_user_external extends external_api { require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function // Ensure the current user is allowed to run this function - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); require_capability('moodle/user:update', $context); self::validate_context($context); @@ -413,7 +413,7 @@ class core_user_external extends external_api { continue; } context_instance_preload($user); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id, IGNORE_MISSING); self::validate_context($usercontext); $currentuser = ($user->id == $USER->id); @@ -576,7 +576,7 @@ class core_user_external extends external_api { } context_instance_preload($user); $course = $courses[$courseids[$user->id]]; - $context = get_context_instance(CONTEXT_COURSE, $courseids[$user->id]); + $context = context_course::instance($courseids[$user->id], IGNORE_MISSING); self::validate_context($context); if ($userarray = user_get_user_details($user, $course)) { $result[] = $userarray; diff --git a/user/files.php b/user/files.php index 54f7962c75a..973bbf5773c 100644 --- a/user/files.php +++ b/user/files.php @@ -38,7 +38,7 @@ if (empty($returnurl)) { $returnurl = new moodle_url('/user/files.php'); } -$context = get_context_instance(CONTEXT_USER, $USER->id); +$context = context_user::instance($USER->id); require_capability('moodle/user:manageownfiles', $context); $title = get_string('myfiles'); diff --git a/user/filters/courserole.php b/user/filters/courserole.php index a38fe415c6f..0247bcc4f99 100644 --- a/user/filters/courserole.php +++ b/user/filters/courserole.php @@ -21,7 +21,7 @@ class user_filter_courserole extends user_filter_type { * @return array of availble roles */ function get_roles() { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $roles = array(0=> get_string('anyrole','filters')) + get_default_enrol_roles($context); return $roles; } diff --git a/user/filters/globalrole.php b/user/filters/globalrole.php index 2721fdb9a0b..2e9635ecbe2 100644 --- a/user/filters/globalrole.php +++ b/user/filters/globalrole.php @@ -22,7 +22,7 @@ class user_filter_globalrole extends user_filter_type { * @return array of availble roles */ function get_roles() { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $roles = array(0=> get_string('anyrole','filters')) + get_assignable_roles($context); return $roles; } diff --git a/user/groupaddnote.php b/user/groupaddnote.php index 26649da10ba..67dc9b39c2c 100644 --- a/user/groupaddnote.php +++ b/user/groupaddnote.php @@ -44,7 +44,7 @@ if (! $course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } -$context = get_context_instance(CONTEXT_COURSE, $id); +$context = context_course::instance($id); require_login($course); // to create notes the current user needs a capability diff --git a/user/index.php b/user/index.php index c73e42b02a6..e850bdc9a90 100644 --- a/user/index.php +++ b/user/index.php @@ -41,7 +41,7 @@ $course = $DB->get_record('course', array('id'=>$context->instanceid), '*', MUST_EXIST); } else { $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); - $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); + $context = context_course::instance($course->id, MUST_EXIST); } // not needed anymore unset($contextid); @@ -49,10 +49,10 @@ require_login($course); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $isfrontpage = ($course->id == SITEID); - $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID); + $frontpagectx = context_course::instance(SITEID); if ($isfrontpage) { $PAGE->set_pagelayout('admin'); @@ -190,7 +190,7 @@ $courselist = array(); $popupurl = new moodle_url('/user/index.php?roleid='.$roleid.'&sifirst=&silast='); foreach ($mycourses as $mycourse) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + $coursecontext = context_course::instance($mycourse->id); $courselist[$mycourse->id] = format_string($mycourse->shortname, true, array('context' => $coursecontext)); } if (has_capability('moodle/site:viewparticipants', $systemcontext)) { @@ -579,8 +579,8 @@ context_instance_preload($user); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $context = context_course::instance($course->id); + $usercontext = context_user::instance($user->id); $countries = get_string_manager()->get_list_of_countries(); @@ -719,7 +719,7 @@ } } - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) { $profilelink = ''.fullname($user).''; diff --git a/user/lib.php b/user/lib.php index 9a497d2b9f2..8c84656a66a 100644 --- a/user/lib.php +++ b/user/lib.php @@ -70,7 +70,7 @@ function user_create_user($user) { $newuser = $DB->get_record('user', array('id' => $newuserid)); // create USER context for this user - get_context_instance(CONTEXT_USER, $newuserid); + context_user::instance($newuserid); // update user password if necessary if (isset($userpassword)) { @@ -225,11 +225,11 @@ function user_get_user_details($user, $course = null, array $userfields = array( } if (!empty($course)) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $context = context_course::instance($course->id); + $usercontext = context_user::instance($user->id); $canviewdetailscap = (has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext)); } else { - $context = get_context_instance(CONTEXT_USER, $user->id); + $context = context_user::instance($user->id); $usercontext = $context; $canviewdetailscap = has_capability('moodle/user:viewdetails', $usercontext); } @@ -448,10 +448,10 @@ function user_get_user_details($user, $course = null, array $userfields = array( if ($mycourses = enrol_get_users_courses($user->id, true)) { foreach ($mycourses as $mycourse) { if ($mycourse->category) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + $coursecontext = context_course::instance($mycourse->id); $enrolledcourse = array(); $enrolledcourse['id'] = $mycourse->id; - $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $mycourse->id))); + $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => context_course::instance($mycourse->id))); $enrolledcourse['shortname'] = format_string($mycourse->shortname, true, array('context' => $coursecontext)); $enrolledcourses[] = $enrolledcourse; } diff --git a/user/managetoken.php b/user/managetoken.php index c8f47b2af88..1342f129d48 100644 --- a/user/managetoken.php +++ b/user/managetoken.php @@ -29,7 +29,7 @@ require('../config.php'); require_login(); require_sesskey(); -$usercontext = get_context_instance(CONTEXT_USER, $USER->id); +$usercontext = context_user::instance($USER->id); $PAGE->set_context($usercontext); $PAGE->set_url('/user/managetoken.php'); diff --git a/user/messageselect.php b/user/messageselect.php index d54d26d4133..db354bf965d 100644 --- a/user/messageselect.php +++ b/user/messageselect.php @@ -58,7 +58,7 @@ if ($deluser !== 0) { $url->param('deluser', $deluser); } $PAGE->set_url($url); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); @@ -66,8 +66,8 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) { require_login(); -$coursecontext = get_context_instance(CONTEXT_COURSE, $id); // Course context -$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context +$coursecontext = context_course::instance($id); // Course context +$systemcontext = context_system::instance(); // SYSTEM context require_capability('moodle/course:bulkmessaging', $coursecontext); if (empty($SESSION->emailto)) { diff --git a/user/pix.php b/user/pix.php index b4b4cc1100b..1e354ed0c65 100644 --- a/user/pix.php +++ b/user/pix.php @@ -42,7 +42,7 @@ if (count($args) == 2) { } else { $image = 'f2'; } - if ($usercontext = get_context_instance(CONTEXT_USER, $userid)) { + if ($usercontext = context_user::instance($userid, IGNORE_MISSING)) { $url = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $image); redirect($url); } diff --git a/user/policy.php b/user/policy.php index 46a2f2bb20f..0f5168fe352 100644 --- a/user/policy.php +++ b/user/policy.php @@ -66,7 +66,7 @@ $strpolicyagree = get_string('policyagree'); $strpolicyagreement = get_string('policyagreement'); $strpolicyagreementclick = get_string('policyagreementclick'); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_title($strpolicyagreement); $PAGE->set_heading($SITE->fullname); $PAGE->navbar->add($strpolicyagreement); diff --git a/user/portfolio.php b/user/portfolio.php index c91e04e628d..653131e365d 100644 --- a/user/portfolio.php +++ b/user/portfolio.php @@ -58,7 +58,7 @@ $display = true; // set this to false in the conditions to stop processing require_login($course, false); $PAGE->set_url($url); -$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); +$PAGE->set_context(context_user::instance($user->id)); $PAGE->set_title("$course->fullname: $fullname: $strportfolios"); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); diff --git a/user/portfoliologs.php b/user/portfoliologs.php index 1690b1f6381..d9f60355ebd 100644 --- a/user/portfoliologs.php +++ b/user/portfoliologs.php @@ -60,7 +60,7 @@ if ($perpage !== 0) { $PAGE->set_url($url); $PAGE->set_title("$course->fullname: $fullname: $strportfolios"); $PAGE->set_heading($course->fullname); -$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); +$PAGE->set_context(context_user::instance($user->id)); $PAGE->set_pagelayout('standard'); echo $OUTPUT->header(); diff --git a/user/profile.php b/user/profile.php index 9dafdd9d35a..979319dcd88 100644 --- a/user/profile.php +++ b/user/profile.php @@ -59,7 +59,7 @@ $userid = $userid ? $userid : $USER->id; // Owner of the page $user = $DB->get_record('user', array('id' => $userid)); if ($user->deleted) { - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + $PAGE->set_context(context_system::instance()); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('userdeleted')); echo $OUTPUT->footer(); @@ -67,7 +67,7 @@ if ($user->deleted) { } $currentuser = ($user->id == $USER->id); -$context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST); +$context = $usercontext = context_user::instance($userid, MUST_EXIST); if (!$currentuser && !empty($CFG->forceloginforprofiles) && @@ -76,7 +76,7 @@ if (!$currentuser && // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) $struser = get_string('user'); - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + $PAGE->set_context(context_system::instance()); $PAGE->set_title("$SITE->shortname: $struser"); // Do not leak the name $PAGE->set_heading("$SITE->shortname: $struser"); $PAGE->set_url('/user/profile.php', array('id'=>$userid)); @@ -93,7 +93,7 @@ if (!$currentpage = my_get_page($userid, MY_PAGE_PUBLIC)) { } if (!$currentpage->userid) { - $context = get_context_instance(CONTEXT_SYSTEM); // A trick so that we even see non-sticky blocks + $context = context_system::instance(); // A trick so that we even see non-sticky blocks } $PAGE->set_context($context); @@ -306,7 +306,7 @@ if (!isset($hiddenfields['mycourses'])) { if ($mycourse->category) { $class = ''; if ($mycourse->visible == 0) { - $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + $ccontext = context_course::instance($mycourse->id); if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) { continue; } diff --git a/user/profile/field/checkbox/field.class.php b/user/profile/field/checkbox/field.class.php index 6602556d029..142ce254842 100644 --- a/user/profile/field/checkbox/field.class.php +++ b/user/profile/field/checkbox/field.class.php @@ -29,7 +29,7 @@ class profile_field_checkbox extends profile_field_base { $checkbox->setChecked(true); } $mform->setType($this->inputname, PARAM_BOOL); - if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) { $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client'); } } diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index 36b711acc8f..c0b8694134b 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -80,7 +80,7 @@ class profile_field_menu extends profile_field_base { if (!$mform->elementExists($this->inputname)) { return; } - if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->is_locked() and !has_capability('moodle/user:update', context_system::instance())) { $mform->hardFreeze($this->inputname); $mform->setConstant($this->inputname, $this->datakey); } diff --git a/user/profile/lib.php b/user/profile/lib.php index fd30d581180..4c193e4131d 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -67,7 +67,7 @@ class profile_field_base { function edit_field($mform) { if ($this->field->visible != PROFILE_VISIBLE_NONE - or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + or has_capability('moodle/user:update', context_system::instance())) { $this->edit_field_add($mform); $this->edit_field_set_default($mform); @@ -85,7 +85,7 @@ class profile_field_base { function edit_after_data($mform) { if ($this->field->visible != PROFILE_VISIBLE_NONE - or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + or has_capability('moodle/user:update', context_system::instance())) { $this->edit_field_set_locked($mform); return true; } @@ -183,7 +183,7 @@ class profile_field_base { if (!$mform->elementExists($this->inputname)) { return; } - if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->is_locked() and !has_capability('moodle/user:update', context_system::instance())) { $mform->hardFreeze($this->inputname); $mform->setConstant($this->inputname, $this->data); } @@ -283,11 +283,11 @@ class profile_field_base { return true; } else { return has_capability('moodle/user:viewalldetails', - get_context_instance(CONTEXT_USER, $this->userid)); + context_user::instance($this->userid)); } default: return has_capability('moodle/user:viewalldetails', - get_context_instance(CONTEXT_USER, $this->userid)); + context_user::instance($this->userid)); } } @@ -359,7 +359,7 @@ function profile_definition($mform, $userid = 0) { global $CFG, $DB; // if user is "admin" fields are displayed regardless - $update = has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + $update = has_capability('moodle/user:update', context_system::instance()); if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) { foreach ($categories as $category) { diff --git a/user/profilesys.php b/user/profilesys.php index 79740ef311e..fc3e467346e 100644 --- a/user/profilesys.php +++ b/user/profilesys.php @@ -37,7 +37,7 @@ $edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and of require_login(); -$context = get_context_instance(CONTEXT_SYSTEM); +$context = context_system::instance(); require_capability('moodle/my:configsyspages', $context); $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); $header = "$SITE->shortname: ".get_string('publicprofile')." (".get_string('myprofile', 'admin').")"; diff --git a/user/renderer.php b/user/renderer.php index 09f30d73895..70319c630b7 100644 --- a/user/renderer.php +++ b/user/renderer.php @@ -84,7 +84,7 @@ class user_files_tree implements renderable { public $dir; public function __construct() { global $USER; - $this->context = get_context_instance(CONTEXT_USER, $USER->id); + $this->context = context_user::instance($USER->id); $fs = get_file_storage(); $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0); } diff --git a/user/repository.php b/user/repository.php index 23ed84f160b..daa6de058f4 100644 --- a/user/repository.php +++ b/user/repository.php @@ -46,7 +46,7 @@ $configstr = get_string('manageuserrepository', 'repository'); $pluginstr = get_string('plugin', 'repository'); require_login($course, false); -$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$coursecontext = context_course::instance($course->id, MUST_EXIST); $link = new moodle_url('/user/view.php', array('id'=>$user->id)); $PAGE->navbar->add($fullname, $link); diff --git a/user/selector/lib.php b/user/selector/lib.php index 35f40658d77..9aa40edf03f 100644 --- a/user/selector/lib.php +++ b/user/selector/lib.php @@ -98,7 +98,7 @@ abstract class user_selector_base { if (isset($options['accesscontext'])) { $this->accesscontext = $options['accesscontext']; } else { - $this->accesscontext = get_context_instance(CONTEXT_SYSTEM); + $this->accesscontext = context_system::instance(); } if (isset($options['extrafields'])) { @@ -676,7 +676,7 @@ abstract class groups_user_selector_base extends user_selector_base { */ public function __construct($name, $options) { global $CFG; - $options['accesscontext'] = get_context_instance(CONTEXT_COURSE, $options['courseid']); + $options['accesscontext'] = context_course::instance($options['courseid']); parent::__construct($name, $options); $this->groupid = $options['groupid']; $this->courseid = $options['courseid']; @@ -809,7 +809,7 @@ class group_non_members_selector extends groups_user_selector_base { global $DB; // Get list of allowed roles. - $context = get_context_instance(CONTEXT_COURSE, $this->courseid); + $context = context_course::instance($this->courseid); if ($validroleids = groups_get_possible_roles($context)) { list($roleids, $roleparams) = $DB->get_in_or_equal($validroleids, SQL_PARAMS_NAMED, 'r'); } else { diff --git a/user/selector/search.php b/user/selector/search.php index fcaf74ec3bb..341ebf5b226 100644 --- a/user/selector/search.php +++ b/user/selector/search.php @@ -26,7 +26,7 @@ require_once(dirname(__FILE__) . '/../../config.php'); require_once($CFG->dirroot . '/user/selector/lib.php'); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_url('/user/selector/search.php'); // In developer debug mode, when there is a debug=1 in the URL send as plain text diff --git a/user/view.php b/user/view.php index 68d36ac33cf..4c4c8da2b99 100644 --- a/user/view.php +++ b/user/view.php @@ -46,9 +46,9 @@ $user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); $currentuser = ($user->id == $USER->id); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); -$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); -$usercontext = get_context_instance(CONTEXT_USER, $user->id, IGNORE_MISSING); +$systemcontext = context_system::instance(); +$coursecontext = context_course::instance($course->id); +$usercontext = context_user::instance($user->id, IGNORE_MISSING); // Require login first if (isguestuser($user)) { @@ -288,7 +288,7 @@ if (!isset($hiddenfields['mycourses'])) { $courselisting = ''; foreach ($mycourses as $mycourse) { if ($mycourse->category) { - $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);; + $ccontext = context_course::instance($mycourse->id);; $cfullname = format_string($mycourse->fullname, true, array('context' => $ccontext)); if ($mycourse->id != $course->id){ $class = ''; diff --git a/userpix/index.php b/userpix/index.php index 652df70401f..515957116ad 100644 --- a/userpix/index.php +++ b/userpix/index.php @@ -13,7 +13,7 @@ $PAGE->set_url('/userpix/index.php'); require_login(); /// Remove the following three lines if you want everyone to access it -$syscontext = get_context_instance(CONTEXT_SYSTEM); +$syscontext = context_system::instance(); require_capability('moodle/site:config', $syscontext); $title = get_string("users"); diff --git a/webservice/externallib.php b/webservice/externallib.php index 7b006d6e1b1..4effcde1d49 100644 --- a/webservice/externallib.php +++ b/webservice/externallib.php @@ -71,7 +71,7 @@ class core_webservice_external extends external_api { array('serviceshortnames'=>$serviceshortnames)); $profileimageurl = moodle_url::make_pluginfile_url( - get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f1'); + context_user::instance($USER->id)->id, 'user', 'icon', NULL, '/', 'f1'); //site information $siteinfo = array( diff --git a/webservice/lib.php b/webservice/lib.php index 4fac2e9722a..111ae75ec6f 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -102,7 +102,7 @@ class webservice { } //Non admin can not authenticate if maintenance mode - $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $user); + $hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user); if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) { //this is usually temporary, client want to implement code logic => moodle_exception throw new moodle_exception('sitemaintenance', 'admin'); @@ -116,7 +116,7 @@ class webservice { } //check if there is any required system capability - if ($service->requiredcapability and !has_capability($service->requiredcapability, get_context_instance(CONTEXT_SYSTEM), $user)) { + if ($service->requiredcapability and !has_capability($service->requiredcapability, context_system::instance(), $user)) { throw new webservice_access_exception('The capability ' . $service->requiredcapability . ' is required.'); } @@ -262,7 +262,7 @@ class webservice { global $CFG, $DB; // generate a token for non admin if web service are enable and the user has the capability to create a token - if (!is_siteadmin() && has_capability('moodle/webservice:createtoken', get_context_instance(CONTEXT_SYSTEM), $userid) && !empty($CFG->enablewebservices)) { + if (!is_siteadmin() && has_capability('moodle/webservice:createtoken', context_system::instance(), $userid) && !empty($CFG->enablewebservices)) { // for every service than the user is authorised on, create a token (if it doesn't already exist) // get all services which are set to all user (no restricted to specific users) @@ -298,7 +298,7 @@ class webservice { $newtoken->userid = $userid; $newtoken->externalserviceid = $serviceid; // TODO MDL-31190 find a way to get the context - UPDATE FOLLOWING LINE - $newtoken->contextid = get_context_instance(CONTEXT_SYSTEM)->id; + $newtoken->contextid = context_system::instance()->id; $newtoken->creatorid = $userid; $newtoken->timecreated = time(); @@ -835,7 +835,7 @@ abstract class webservice_server implements webservice_server_interface { throw new webservice_access_exception('The web service authentication plugin is missing.'); } - $this->restricted_context = get_context_instance(CONTEXT_SYSTEM); + $this->restricted_context = context_system::instance(); if (!$this->username) { throw new moodle_exception('missingusername', 'webservice'); @@ -860,7 +860,7 @@ abstract class webservice_server implements webservice_server_interface { } //Non admin can not authenticate if maintenance mode - $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $user); + $hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user); if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) { throw new moodle_exception('sitemaintenance', 'admin'); } diff --git a/webservice/upload.php b/webservice/upload.php index 5e2f6cc0f2f..9c01869e004 100644 --- a/webservice/upload.php +++ b/webservice/upload.php @@ -51,7 +51,7 @@ $webservicelib = new webservice(); $authenticationinfo = $webservicelib->authenticate_user($token); // check the user can manage his own files (can upload) -$context = get_context_instance(CONTEXT_USER, $USER->id); +$context = context_user::instance($USER->id); require_capability('moodle/user:manageownfiles', $context); $fs = get_file_storage(); diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index a0206c2dbae..01b71c034c9 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -29,7 +29,7 @@ require($CFG->dirroot . '/webservice/lib.php'); require_login(); require_sesskey(); -$usercontext = get_context_instance(CONTEXT_USER, $USER->id); +$usercontext = context_user::instance($USER->id); $tokenid = required_param('id', PARAM_INT); // PAGE settings From 4370d73d484a25b689e44ab88487566d3bc5142b Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Thu, 26 Jul 2012 14:22:22 +0800 Subject: [PATCH 08/73] MDL-34255 group calendar events: fixed adding group calendar event for students --- calendar/event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calendar/event.php b/calendar/event.php index 130e682351f..dbc0c32b370 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -123,10 +123,10 @@ if ($eventid !== 0) { $event = new stdClass(); $event->action = $action; $event->course = $courseid; + $event->courseid = $courseid; $event->timeduration = 0; if ($formoptions->eventtypes->courses) { if (!$issite) { - $event->courseid = $courseid; $event->eventtype = 'course'; } else { unset($formoptions->eventtypes->courses); From 6200f70c5ecc4d5b88f94c674507ef5acac9788c Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 26 Jul 2012 18:47:57 +0100 Subject: [PATCH 09/73] MDL-34589 quiz report graphs: PHP5.4 issue with unset($array[$float]). Thanks to Matthew Davidson for diagnosing the problem. --- mod/quiz/report/overview/overviewgraph.php | 4 +++- mod/quiz/report/reportlib.php | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mod/quiz/report/overview/overviewgraph.php b/mod/quiz/report/overview/overviewgraph.php index c450615d001..6583ef95708 100644 --- a/mod/quiz/report/overview/overviewgraph.php +++ b/mod/quiz/report/overview/overviewgraph.php @@ -89,7 +89,9 @@ while ($bands > 20 || $bands <= 10) { } } -$bands = ceil($bands); +// See MDL-34589. Using doubles as array keys causes problems in PHP 5.4, +// hence the explicit cast to int. +$bands = (int) ceil($bands); $bandwidth = $quiz->grade / $bands; $bandlabels = array(); for ($i = 1; $i <= $bands; $i++) { diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index d3e4e998d14..344513e5afe 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -191,6 +191,11 @@ function quiz_report_qm_filter_select($quiz, $quizattemptsalias = 'quiza') { */ function quiz_report_grade_bands($bandwidth, $bands, $quizid, $userids = array()) { global $DB; + if (!is_int($bands)) { + debugging('$bands passed to quiz_report_grade_bands must be an integer. (' . + gettype($bands) . ' passed.)', DEBUG_DEVELOPER); + $bands = (int) $bands; + } if ($userids) { list($usql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'u'); @@ -220,7 +225,7 @@ ORDER BY $data = $DB->get_records_sql_menu($sql, $params); // We need to create array elements with values 0 at indexes where there is no element. - $data = $data + array_fill(0, $bands+1, 0); + $data = $data + array_fill(0, $bands + 1, 0); ksort($data); // Place the maximum (prefect grade) into the last band i.e. make last From 2562c138ecf65b8fdee86e2e7f77aa0113e92aec Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Mon, 23 Jul 2012 11:28:01 +0100 Subject: [PATCH 10/73] MDL-34483 qformat_examview: changes required to make it basically work. --- question/format/examview/format.php | 52 +++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/question/format/examview/format.php b/question/format/examview/format.php index dc0481a20cd..3bd05392e68 100644 --- a/question/format/examview/format.php +++ b/question/format/examview/format.php @@ -58,6 +58,10 @@ class qformat_examview extends qformat_default { return true; } + public function mime_type() { + return 'application/xml'; + } + /** * unxmlise reconstructs part of the xml data structure in order * to identify the actual data therein @@ -84,6 +88,26 @@ class qformat_examview extends qformat_default { $text = strip_tags($text); return $text; } + protected function text_field($text) { + return array( + 'text' => htmlspecialchars(trim($text), ENT_NOQUOTES), + 'format' => FORMAT_HTML, + 'files' => array(), + ); + } + + protected function add_blank_combined_feedback($question) { + $question->correctfeedback['text'] = ''; + $question->correctfeedback['format'] = $question->questiontextformat; + $question->correctfeedback['files'] = array(); + $question->partiallycorrectfeedback['text'] = ''; + $question->partiallycorrectfeedback['format'] = $question->questiontextformat; + $question->partiallycorrectfeedback['files'] = array(); + $question->incorrectfeedback['text'] = ''; + $question->incorrectfeedback['format'] = $question->questiontextformat; + $question->incorrectfeedback['files'] = array(); + return $question; + } function parse_matching_groups($matching_groups) { @@ -115,7 +139,7 @@ class qformat_examview extends qformat_default { $phrase = trim($this->unxmlise($qrec['text']['0']['#'])); $answer = trim($this->unxmlise($qrec['answer']['0']['#'])); $answer = strip_tags( $answer ); - $match_group->subquestions[] = $phrase; + $match_group->subquestions[] = $this->text_field($phrase); $match_group->subanswers[] = $match_group->subchoices[$answer]; $this->matching_questions[$groupname] = $match_group; return NULL; @@ -130,8 +154,11 @@ class qformat_examview extends qformat_default { $question = $this->defaultquestion(); $htmltext = s($match_group->questiontext); $question->questiontext = $htmltext; - $question->name = $question->questiontext; + $question->questiontextformat = FORMAT_HTML; + $question->questiontextfiles = array(); + $question->name = shorten_text( $question->questiontext, 250 ); $question->qtype = MATCH; + $question = $this->add_blank_combined_feedback($question); $question->subquestions = array(); $question->subanswers = array(); foreach($match_group->subquestions as $key => $value) { @@ -192,6 +219,8 @@ class qformat_examview extends qformat_default { // Only one answer is allowed $htmltext = $this->unxmlise($qrec['#']['text'][0]['#']); $question->questiontext = $htmltext; + $question->questiontextformat = FORMAT_HTML; + $question->questiontextfiles = array(); $question->name = shorten_text( $question->questiontext, 250 ); switch ($question->qtype) { @@ -232,30 +261,31 @@ class qformat_examview extends qformat_default { $question->answer = $choices[$answer]; $question->correctanswer = $question->answer; if ($question->answer == 1) { - $question->feedbacktrue = 'Correct'; - $question->feedbackfalse = 'Incorrect'; + $question->feedbacktrue = $this->text_field('Correct'); + $question->feedbackfalse = $this->text_field('Incorrect'); } else { - $question->feedbacktrue = 'Incorrect'; - $question->feedbackfalse = 'Correct'; + $question->feedbacktrue = $this->text_field('Incorrect'); + $question->feedbackfalse = $this->text_field('Correct'); } return $question; } function parse_mc($qrec, $question) { + $question = $this->add_blank_combined_feedback($question); $answer = 'choice-'.strtolower(trim($qrec['answer'][0]['#'])); $choices = $qrec['choices'][0]['#']; foreach($choices as $key => $value) { if (strpos(trim($key),'choice-') !== FALSE) { - $question->answer[$key] = s($this->unxmlise($value[0]['#'])); + $question->answer[$key] = $this->text_field(s($this->unxmlise($value[0]['#']))); if (strcmp($key, $answer) == 0) { $question->fraction[$key] = 1; - $question->feedback[$key] = 'Correct'; + $question->feedback[$key] = $this->text_field('Correct'); } else { $question->fraction[$key] = 0; - $question->feedback[$key] = 'Incorrect'; + $question->feedback[$key] = $this->text_field('Incorrect'); } } } @@ -274,7 +304,7 @@ class qformat_examview extends qformat_default { if (strlen($value) > 0) { $question->answer[$key] = $value; $question->fraction[$key] = 1; - $question->feedback[$key] = "Correct"; + $question->feedback[$key] = $this->text_field("Correct"); } } return $question; @@ -299,7 +329,7 @@ class qformat_examview extends qformat_default { $errormargin = 0; $question->answer[$key] = $value; $question->fraction[$key] = 1; - $question->feedback[$key] = "Correct"; + $question->feedback[$key] = $this->text_field("Correct"); $question->min[$key] = $question->answer[$key] - $errormargin; $question->max[$key] = $question->answer[$key] + $errormargin; } From 9c3afc5bb6d88ff31a19c24d750470837264d92e Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Mon, 23 Jul 2012 11:31:32 +0100 Subject: [PATCH 11/73] MDL-34483 qformat_examview: clean the code to make codechecker happy --- question/format/examview/format.php | 139 +++++++++++++--------------- 1 file changed, 63 insertions(+), 76 deletions(-) diff --git a/question/format/examview/format.php b/question/format/examview/format.php index 3bd05392e68..f9e19752e84 100644 --- a/question/format/examview/format.php +++ b/question/format/examview/format.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once ($CFG->libdir . '/xmlize.php'); +require_once($CFG->libdir . '/xmlize.php'); /** @@ -54,7 +54,7 @@ class qformat_examview extends qformat_default { public $matching_questions = array(); - function provide_import() { + public function provide_import() { return true; } @@ -68,23 +68,22 @@ class qformat_examview extends qformat_default { * @param array $xml section of the xml data structure * @return string data with evrything else removed */ - function unxmlise( $xml ) { - // if it's not an array then it's probably just data + protected function unxmlise( $xml ) { + // If it's not an array then it's probably just data. if (!is_array($xml)) { $text = s($xml); - } - else { - // otherwise parse the array + } else { + // Otherwise parse the array. $text = ''; - foreach ($xml as $tag=>$data) { - // if tag is '@' then it's attributes and we don't care + foreach ($xml as $tag => $data) { + // If tag is '@' then it's attributes and we don't care. if ($tag!=='@') { $text = $text . $this->unxmlise( $data ); } } } - // currently we throw the tags we found + // Currently we throw the tags we found. $text = strip_tags($text); return $text; } @@ -109,13 +108,12 @@ class qformat_examview extends qformat_default { return $question; } - function parse_matching_groups($matching_groups) - { + protected function parse_matching_groups($matching_groups) { if (empty($matching_groups)) { return; } - foreach($matching_groups as $match_group) { - $newgroup = NULL; + foreach ($matching_groups as $match_group) { + $newgroup = null; $groupname = trim($match_group['@']['name']); $questiontext = $this->unxmlise($match_group['#']['text'][0]['#']); $newgroup->questiontext = trim($questiontext); @@ -123,8 +121,8 @@ class qformat_examview extends qformat_default { $newgroup->subquestions = array(); $newgroup->subanswers = array(); $choices = $match_group['#']['choices']['0']['#']; - foreach($choices as $key => $value) { - if (strpos(trim($key),'choice-') !== FALSE) { + foreach ($choices as $key => $value) { + if (strpos(trim($key), 'choice-') !== false) { $key = strtoupper(trim(str_replace('choice-', '', $key))); $newgroup->subchoices[$key] = trim($value['0']['#']); } @@ -133,8 +131,7 @@ class qformat_examview extends qformat_default { } } - function parse_ma($qrec, $groupname) - { + protected function parse_ma($qrec, $groupname) { $match_group = $this->matching_questions[$groupname]; $phrase = trim($this->unxmlise($qrec['text']['0']['#'])); $answer = trim($this->unxmlise($qrec['answer']['0']['#'])); @@ -142,15 +139,14 @@ class qformat_examview extends qformat_default { $match_group->subquestions[] = $this->text_field($phrase); $match_group->subanswers[] = $match_group->subchoices[$answer]; $this->matching_questions[$groupname] = $match_group; - return NULL; + return null; } - function process_matches(&$questions) - { + protected function process_matches(&$questions) { if (empty($this->matching_questions)) { return; } - foreach($this->matching_questions as $match_group) { + foreach ($this->matching_questions as $match_group) { $question = $this->defaultquestion(); $htmltext = s($match_group->questiontext); $question->questiontext = $htmltext; @@ -161,7 +157,7 @@ class qformat_examview extends qformat_default { $question = $this->add_blank_combined_feedback($question); $question->subquestions = array(); $question->subanswers = array(); - foreach($match_group->subquestions as $key => $value) { + foreach ($match_group->subquestions as $key => $value) { $htmltext = s($value); $question->subquestions[] = $htmltext; @@ -172,28 +168,28 @@ class qformat_examview extends qformat_default { } } - function cleanUnicode($text) { + protected function cleanunicode($text) { return str_replace('’', "'", $text); } protected function readquestions($lines) { - /// Parses an array of lines into an array of questions, - /// where each item is a question object as defined by - /// readquestion(). + // Parses an array of lines into an array of questions, + // where each item is a question object as defined by + // readquestion(). $questions = array(); $currentquestion = array(); $text = implode($lines, ' '); - $text = $this->cleanUnicode($text); + $text = $this->cleanunicode($text); $xml = xmlize($text, 0); if (!empty($xml['examview']['#']['matching-group'])) { $this->parse_matching_groups($xml['examview']['#']['matching-group']); } - $questionNode = $xml['examview']['#']['question']; - foreach($questionNode as $currentquestion) { + $questionnode = $xml['examview']['#']['question']; + foreach ($questionnode as $currentquestion) { if ($question = $this->readquestion($currentquestion)) { $questions[] = $question; } @@ -202,21 +198,18 @@ class qformat_examview extends qformat_default { $this->process_matches($questions); return $questions; } - // end readquestions - function readquestion($qrec) - { + public function readquestion($qrec) { $type = trim($qrec['@']['type']); $question = $this->defaultquestion(); if (array_key_exists($type, $this->qtypes)) { $question->qtype = $this->qtypes[$type]; - } - else { + } else { $question->qtype = null; } $question->single = 1; - // Only one answer is allowed + // Only one answer is allowed. $htmltext = $this->unxmlise($qrec['#']['text'][0]['#']); $question->questiontext = $htmltext; $question->questiontextformat = FORMAT_HTML; @@ -224,38 +217,35 @@ class qformat_examview extends qformat_default { $question->name = shorten_text( $question->questiontext, 250 ); switch ($question->qtype) { - case MULTICHOICE: - $question = $this->parse_mc($qrec['#'], $question); - break; - case MATCH: - $groupname = trim($qrec['@']['group']); - $question = $this->parse_ma($qrec['#'], $groupname); - break; - case TRUEFALSE: - $question = $this->parse_tf_yn($qrec['#'], $question); - break; - case SHORTANSWER: - $question = $this->parse_co($qrec['#'], $question); - break; - case ESSAY: - $question = $this->parse_sa($qrec['#'], $question); - break; - case NUMERICAL: - $question = $this->parse_nr($qrec['#'], $question); - break; - break; + case MULTICHOICE: + $question = $this->parse_mc($qrec['#'], $question); + break; + case MATCH: + $groupname = trim($qrec['@']['group']); + $question = $this->parse_ma($qrec['#'], $groupname); + break; + case TRUEFALSE: + $question = $this->parse_tf_yn($qrec['#'], $question); + break; + case SHORTANSWER: + $question = $this->parse_co($qrec['#'], $question); + break; + case ESSAY: + $question = $this->parse_sa($qrec['#'], $question); + break; + case NUMERICAL: + $question = $this->parse_nr($qrec['#'], $question); + break; + break; default: - print("

Question type ".$type." import not supported for ".$question->questiontext."

"); - $question = NULL; + print("

Question type ".$type." import not supported for ".$question->questiontext."

"); + $question = null; } - // end switch ($question->qtype) return $question; } - // end readquestion - function parse_tf_yn($qrec, $question) - { + protected function parse_tf_yn($qrec, $question) { $choices = array('T' => 1, 'Y' => 1, 'F' => 0, 'N' => 0 ); $answer = trim($qrec['answer'][0]['#']); $question->answer = $choices[$answer]; @@ -270,14 +260,13 @@ class qformat_examview extends qformat_default { return $question; } - function parse_mc($qrec, $question) - { + protected function parse_mc($qrec, $question) { $question = $this->add_blank_combined_feedback($question); $answer = 'choice-'.strtolower(trim($qrec['answer'][0]['#'])); $choices = $qrec['choices'][0]['#']; - foreach($choices as $key => $value) { - if (strpos(trim($key),'choice-') !== FALSE) { + foreach ($choices as $key => $value) { + if (strpos(trim($key), 'choice-') !== false) { $question->answer[$key] = $this->text_field(s($this->unxmlise($value[0]['#']))); if (strcmp($key, $answer) == 0) { @@ -292,14 +281,13 @@ class qformat_examview extends qformat_default { return $question; } - function parse_co($qrec, $question) - { + protected function parse_co($qrec, $question) { $question->usecase = 0; $answer = trim($this->unxmlise($qrec['answer'][0]['#'])); $answer = strip_tags( $answer ); - $answers = explode("\n",$answer); + $answers = explode("\n", $answer); - foreach($answers as $key => $value) { + foreach ($answers as $key => $value) { $value = trim($value); if (strlen($value) > 0) { $question->answer[$key] = $value; @@ -310,20 +298,19 @@ class qformat_examview extends qformat_default { return $question; } - function parse_sa($qrec, $question) { + protected function parse_sa($qrec, $question) { $feedback = trim($this->unxmlise($qrec['answer'][0]['#'])); $question->feedback = $feedback; $question->fraction = 0; return $question; } - function parse_nr($qrec, $question) - { + protected function parse_nr($qrec, $question) { $answer = trim($this->unxmlise($qrec['answer'][0]['#'])); $answer = strip_tags( $answer ); - $answers = explode("\n",$answer); + $answers = explode("\n", $answer); - foreach($answers as $key => $value) { + foreach ($answers as $key => $value) { $value = trim($value); if (is_numeric($value)) { $errormargin = 0; @@ -338,6 +325,6 @@ class qformat_examview extends qformat_default { } } -// end class +// End class. From 28d638729df68d5558509854443ed8218647ce23 Mon Sep 17 00:00:00 2001 From: Tom Lanyon Date: Wed, 9 May 2012 16:56:53 +0930 Subject: [PATCH 12/73] MDL-32931 mod_forum Change forum overview to avoid use of (potentially large and slow ) log table. --- mod/forum/lib.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 7c504e57c60..7c6ed42af4a 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1311,21 +1311,24 @@ function forum_print_overview($courses,&$htmlarray) { } - // get all forum logs in ONE query (much better!) + // look for new posts since lastaccess + $course_tuples = join( + ' OR ', + array_fill(0, count($visited_courses), '(f.course = ? AND p.created > ?)') + ); + + $sql = "SELECT f.id, COUNT(*) " + .'FROM {forum_posts} p, {forum_discussions} d, {forum} f ' + .'WHERE p.discussion = d.id AND d.forum = f.id ' + ."AND ($course_tuples) " + ."AND p.userid != ? " + ."GROUP BY f.id"; + $params = array(); - $sql = "SELECT instance,cmid,l.course,COUNT(l.id) as count FROM {log} l " - ." JOIN {course_modules} cm ON cm.id = cmid " - ." WHERE ("; foreach ($courses as $course) { - $sql .= '(l.course = ? AND l.time > ?) OR '; $params[] = $course->id; $params[] = $course->lastaccess; } - $sql = substr($sql,0,-3); // take off the last OR - - $sql .= ") AND l.module = 'forum' AND action = 'add post' " - ." AND userid != ? GROUP BY cmid,l.course,instance"; - $params[] = $USER->id; if (!$new = $DB->get_records_sql($sql, $params)) { From ba4ee840db5e22055c31e96bdb13046f49582ede Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 9 Jul 2012 15:29:42 +0800 Subject: [PATCH 13/73] MDL-32931 mod_forum Polishing patch and taking into account courses without previous accesses --- mod/forum/lib.php | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 7c6ed42af4a..8ee61aed0ab 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1310,26 +1310,33 @@ function forum_print_overview($courses,&$htmlarray) { return; } - - // look for new posts since lastaccess - $course_tuples = join( - ' OR ', - array_fill(0, count($visited_courses), '(f.course = ? AND p.created > ?)') - ); - - $sql = "SELECT f.id, COUNT(*) " - .'FROM {forum_posts} p, {forum_discussions} d, {forum} f ' - .'WHERE p.discussion = d.id AND d.forum = f.id ' - ."AND ($course_tuples) " - ."AND p.userid != ? " - ."GROUP BY f.id"; - + // Courses to search for new posts + $coursessqls = array(); $params = array(); foreach ($courses as $course) { - $params[] = $course->id; - $params[] = $course->lastaccess; + + // If the user has never entered into the course all posts are pending + if ($course->lastaccess == 0) { + $coursessqls[] = '(f.course = ?)'; + $params[] = $course->id; + + // Only posts created after the course last access + } else { + $coursessqls[] = '(f.course = ? AND p.created > ?)'; + $params[] = $course->id; + $params[] = $course->lastaccess; + } } $params[] = $USER->id; + $coursessql = implode(' OR ', $coursessqls); + + $sql = "SELECT f.id, COUNT(*) as count " + .'FROM {forum} f ' + .'JOIN {forum_discussions} d ON d.forum = f.id ' + .'JOIN {forum_posts} p ON p.discussion = d.id ' + ."WHERE ($coursessql) " + .'AND p.userid != ? ' + .'GROUP BY f.id'; if (!$new = $DB->get_records_sql($sql, $params)) { $new = array(); // avoid warnings From b4b6fc915563ff16939598fdc89961a63d1981a4 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 20 Jul 2012 11:55:45 +0800 Subject: [PATCH 14/73] MDL-32499 gradingform_rubric Avoid backup/restore of rubric fillings without an existing criteria --- .../moodle2/backup_gradingform_rubric_plugin.class.php | 9 +++++++-- .../moodle2/restore_gradingform_rubric_plugin.class.php | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php b/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php index 78741ec2a57..387406d93e4 100644 --- a/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php +++ b/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php @@ -106,8 +106,13 @@ class backup_gradingform_rubric_plugin extends backup_gradingform_plugin { // Set sources to populate the data - $filling->set_source_table('gradingform_rubric_fillings', - array('instanceid' => backup::VAR_PARENTID)); + // Binding criterionid to ensure it's existence + $filling->set_source_sql('SELECT rf.* + FROM {gradingform_rubric_fillings} rf + JOIN {grading_instances} gi ON gi.id = rf.instanceid + JOIN {gradingform_rubric_criteria} rc ON rc.id = rf.criterionid AND gi.definitionid = rc.definitionid + WHERE rf.instanceid = :instanceid', + array('instanceid' => backup::VAR_PARENTID)); // no need to annotate ids or files yet (one day when remark field supports // embedded fileds, they must be annotated here) diff --git a/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php b/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php index 62b5c96d9da..adb95978aa9 100644 --- a/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php +++ b/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php @@ -109,6 +109,9 @@ class restore_gradingform_rubric_plugin extends restore_gradingform_plugin { $data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid); $data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid); - $DB->insert_record('gradingform_rubric_fillings', $data); + if (!empty($data->criterionid)) { + $DB->insert_record('gradingform_rubric_fillings', $data); + } + } } From 0b3b8c30e2eaa66dda52bb59e312fa6bd80f25bd Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 26 Jul 2012 13:57:56 +0800 Subject: [PATCH 15/73] MDL-34464 mod_data Replace all instances of get_context_instance() with respective context_XXXX class in mod/data --- mod/data/edit.php | 4 ++-- mod/data/export.php | 5 +--- mod/data/field.php | 2 +- mod/data/field/file/field.class.php | 4 ++-- mod/data/field/latlong/kml.php | 2 +- mod/data/field/picture/field.class.php | 4 ++-- mod/data/import.php | 2 +- mod/data/index.php | 2 +- mod/data/lib.php | 32 +++++++++++++------------- mod/data/locallib.php | 13 +++++------ mod/data/rsslib.php | 4 ++-- mod/data/tabs.php | 2 +- mod/data/templates.php | 2 +- mod/data/view.php | 4 ++-- 14 files changed, 39 insertions(+), 43 deletions(-) diff --git a/mod/data/edit.php b/mod/data/edit.php index e90727d68ef..41780364874 100644 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -74,7 +74,7 @@ if (isguestuser()) { 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 @@ if ($cancel) { /// 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) { diff --git a/mod/data/export.php b/mod/data/export.php index 40fc89430bb..fd71e98600b 100644 --- a/mod/data/export.php +++ b/mod/data/export.php @@ -49,9 +49,7 @@ $data->course = $cm->course; $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 @@ require_capability(DATA_CAP_EXPORT, $context); $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 { diff --git a/mod/data/field.php b/mod/data/field.php index db5eb05a56b..57d3c7fd212 100644 --- a/mod/data/field.php +++ b/mod/data/field.php @@ -88,7 +88,7 @@ if ($id) { 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); /************************************ diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index aede3f0a493..5491117f6e0 100644 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -43,7 +43,7 @@ class data_field_file extends data_field_base { 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 @@ class data_field_file extends data_field_base { // 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) { diff --git a/mod/data/field/latlong/kml.php b/mod/data/field/latlong/kml.php index 4a5cf402a5b..6e36814a7f8 100644 --- a/mod/data/field/latlong/kml.php +++ b/mod/data/field/latlong/kml.php @@ -76,7 +76,7 @@ if ($rid) { 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")); diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index fe2053d0c14..25ec5832e87 100644 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -42,7 +42,7 @@ class data_field_picture extends data_field_base { 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 @@ class data_field_picture extends data_field_base { 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 diff --git a/mod/data/import.php b/mod/data/import.php index a9528bdbe84..c1c5979bae1 100644 --- a/mod/data/import.php +++ b/mod/data/import.php @@ -62,7 +62,7 @@ if ($id) { 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')); diff --git a/mod/data/index.php b/mod/data/index.php index ba0c1791f0f..f443b7e37fb 100644 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -37,7 +37,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) { 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", ""); diff --git a/mod/data/lib.php b/mod/data/lib.php index 3b3b2a7f5b5..6f1e245704d 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -114,7 +114,7 @@ class data_field_base { // Base class for Database Field Types (see field/*/ $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 '

'; echo '
'; echo '
'; @@ -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 @@ class data_preset_existing_importer extends data_preset_importer { 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)) { diff --git a/mod/data/locallib.php b/mod/data/locallib.php index e06430af81e..0662614d35a 100644 --- a/mod/data/locallib.php +++ b/mod/data/locallib.php @@ -101,7 +101,7 @@ class data_portfolio_caller extends portfolio_module_caller_base { $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 @@ class data_portfolio_caller extends portfolio_module_caller_base { 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 @@ class data_portfolio_caller extends portfolio_module_caller_base { // 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 @@ class data_portfolio_caller extends portfolio_module_caller_base { 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) { diff --git a/mod/data/rsslib.php b/mod/data/rsslib.php index 3db1c44495a..1c3b3e6d180 100644 --- a/mod/data/rsslib.php +++ b/mod/data/rsslib.php @@ -44,7 +44,7 @@ $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 @@ 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. diff --git a/mod/data/tabs.php b/mod/data/tabs.php index 214aca6f824..4ff8288ce1f 100644 --- a/mod/data/tabs.php +++ b/mod/data/tabs.php @@ -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; diff --git a/mod/data/templates.php b/mod/data/templates.php index 404f28d2553..4751732f8ec 100644 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -66,7 +66,7 @@ if ($id) { 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! diff --git a/mod/data/view.php b/mod/data/view.php index 3e9146e35e1..abedca48d55 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -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 = ''; From 2c979976e164214f8ba0752eb3e4838cc4c9c9fb Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 26 Jul 2012 13:59:09 +0800 Subject: [PATCH 16/73] MDL-34464 mod_feedback Replace all instances of get_context_instance() with respective context_XXXX class in mod/feedback --- mod/feedback/analysis.php | 4 +-- mod/feedback/analysis_course.php | 6 ++-- mod/feedback/analysis_to_excel.php | 6 ++-- mod/feedback/complete.php | 4 +-- mod/feedback/complete_guest.php | 4 +-- mod/feedback/delete_completed.php | 4 +-- mod/feedback/delete_item.php | 4 +-- mod/feedback/delete_template.php | 4 +-- mod/feedback/edit.php | 4 +-- mod/feedback/edit_item.php | 4 +-- mod/feedback/export.php | 4 +-- mod/feedback/import.php | 4 +-- mod/feedback/index.php | 4 +-- mod/feedback/item/info/lib.php | 8 ++--- mod/feedback/item/label/label_form.php | 2 -- mod/feedback/item/label/lib.php | 8 ++--- mod/feedback/lib.php | 42 +++++++++++--------------- mod/feedback/mapcourse.php | 8 ++--- mod/feedback/print.php | 4 +-- mod/feedback/show_entries.php | 4 +-- mod/feedback/show_entries_anonym.php | 4 +-- mod/feedback/show_nonrespondents.php | 10 ++---- mod/feedback/tabs.php | 5 +-- mod/feedback/unmapcourse.php | 4 +-- mod/feedback/use_templ.php | 4 +-- mod/feedback/view.php | 4 +-- 26 files changed, 53 insertions(+), 110 deletions(-) diff --git a/mod/feedback/analysis.php b/mod/feedback/analysis.php index 76a590174ed..02a8d39f3da 100644 --- a/mod/feedback/analysis.php +++ b/mod/feedback/analysis.php @@ -48,9 +48,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/analysis_course.php b/mod/feedback/analysis_course.php index b0ab0dc57e2..df87b2bb54d 100644 --- a/mod/feedback/analysis_course.php +++ b/mod/feedback/analysis_course.php @@ -68,9 +68,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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 @@ if ($courseitemfilter > 0) { $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 ''; diff --git a/mod/feedback/analysis_to_excel.php b/mod/feedback/analysis_to_excel.php index d6320efc0f6..0096c48875d 100644 --- a/mod/feedback/analysis_to_excel.php +++ b/mod/feedback/analysis_to_excel.php @@ -51,9 +51,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); } diff --git a/mod/feedback/complete.php b/mod/feedback/complete.php index e4c202c50d9..d4dc00b0014 100644 --- a/mod/feedback/complete.php +++ b/mod/feedback/complete.php @@ -87,9 +87,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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; diff --git a/mod/feedback/complete_guest.php b/mod/feedback/complete_guest.php index b472c09e023..695cf413330 100644 --- a/mod/feedback/complete_guest.php +++ b/mod/feedback/complete_guest.php @@ -108,9 +108,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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; diff --git a/mod/feedback/delete_completed.php b/mod/feedback/delete_completed.php index b2362b04287..d5eacb43a7f 100644 --- a/mod/feedback/delete_completed.php +++ b/mod/feedback/delete_completed.php @@ -50,9 +50,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/delete_item.php b/mod/feedback/delete_item.php index 31cc3c0faa9..d0840fb17b4 100644 --- a/mod/feedback/delete_item.php +++ b/mod/feedback/delete_item.php @@ -43,9 +43,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/delete_template.php b/mod/feedback/delete_template.php index d710b2b064a..289f2084324 100644 --- a/mod/feedback/delete_template.php +++ b/mod/feedback/delete_template.php @@ -67,9 +67,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/edit.php b/mod/feedback/edit.php index ce0e245a4af..b928c11e084 100644 --- a/mod/feedback/edit.php +++ b/mod/feedback/edit.php @@ -57,9 +57,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/edit_item.php b/mod/feedback/edit_item.php index 5879d61073b..8a7a3048e84 100644 --- a/mod/feedback/edit_item.php +++ b/mod/feedback/edit_item.php @@ -67,9 +67,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/export.php b/mod/feedback/export.php index 3b78120aa66..b4c3a9747c4 100644 --- a/mod/feedback/export.php +++ b/mod/feedback/export.php @@ -47,9 +47,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/import.php b/mod/feedback/import.php index 212e6cce1a2..7733292a4a5 100644 --- a/mod/feedback/import.php +++ b/mod/feedback/import.php @@ -52,9 +52,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/index.php b/mod/feedback/index.php index d48325784a4..327264f642c 100644 --- a/mod/feedback/index.php +++ b/mod/feedback/index.php @@ -35,9 +35,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) { 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'); diff --git a/mod/feedback/item/info/lib.php b/mod/feedback/item/info/lib.php index fbdf2d994c2..46a9e4c3d16 100644 --- a/mod/feedback/item/info/lib.php +++ b/mod/feedback/item/info/lib.php @@ -216,7 +216,7 @@ class feedback_item_info extends feedback_item_base { $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 @@ class feedback_item_info extends feedback_item_base { 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 @@ class feedback_item_info extends feedback_item_base { $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 @@ class feedback_item_info extends feedback_item_base { 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)); diff --git a/mod/feedback/item/label/label_form.php b/mod/feedback/item/label/label_form.php index 7a44530c5ee..dd04e53ccc1 100644 --- a/mod/feedback/item/label/label_form.php +++ b/mod/feedback/item/label/label_form.php @@ -29,8 +29,6 @@ class feedback_label_form extends feedback_item_form { $positionlist = $this->_customdata['positionlist']; $position = $this->_customdata['position']; - $context = get_context_instance(CONTEXT_MODULE, $common['cmid']); - $mform =& $this->_form; $mform->addElement('hidden', 'required', 0); diff --git a/mod/feedback/item/label/lib.php b/mod/feedback/item/label/lib.php index 06db9908851..350bbcec112 100644 --- a/mod/feedback/item/label/lib.php +++ b/mod/feedback/item/label/lib.php @@ -59,7 +59,7 @@ class feedback_item_label extends feedback_item_base { '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 @@ class feedback_item_label extends feedback_item_base { 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 @@ class feedback_item_label extends feedback_item_base { 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, diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 8705bbc8d8c..d11ce100530 100644 --- a/mod/feedback/lib.php +++ b/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'); } diff --git a/mod/feedback/mapcourse.php b/mod/feedback/mapcourse.php index 8014ca7d7db..3331357b193 100644 --- a/mod/feedback/mapcourse.php +++ b/mod/feedback/mapcourse.php @@ -61,9 +61,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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 @@ if ($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) { $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 = ''; diff --git a/mod/feedback/print.php b/mod/feedback/print.php index 7f63d9ca735..ac2ed30b388 100644 --- a/mod/feedback/print.php +++ b/mod/feedback/print.php @@ -41,9 +41,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/show_entries.php b/mod/feedback/show_entries.php index 1ee4b80b8c5..dceb7fb52c6 100644 --- a/mod/feedback/show_entries.php +++ b/mod/feedback/show_entries.php @@ -61,9 +61,7 @@ $url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do $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); diff --git a/mod/feedback/show_entries_anonym.php b/mod/feedback/show_entries_anonym.php index 1a76475b59b..7061b72a336 100644 --- a/mod/feedback/show_entries_anonym.php +++ b/mod/feedback/show_entries_anonym.php @@ -52,9 +52,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/show_nonrespondents.php b/mod/feedback/show_nonrespondents.php index de5d0c70281..d3a245cd1e1 100644 --- a/mod/feedback/show_nonrespondents.php +++ b/mod/feedback/show_nonrespondents.php @@ -65,14 +65,10 @@ $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm-> $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 @@ require_capability('mod/feedback:viewreports', $context); 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 = ""; diff --git a/mod/feedback/tabs.php b/mod/feedback/tabs.php index 2a1203a272e..c6a68c69f45 100644 --- a/mod/feedback/tabs.php +++ b/mod/feedback/tabs.php @@ -35,10 +35,7 @@ if (isset($cmid) AND intval($cmid) AND $cmid > 0) { $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; diff --git a/mod/feedback/unmapcourse.php b/mod/feedback/unmapcourse.php index 34b78490e08..145258b3d6c 100644 --- a/mod/feedback/unmapcourse.php +++ b/mod/feedback/unmapcourse.php @@ -46,9 +46,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/use_templ.php b/mod/feedback/use_templ.php index ed5bc812d49..12f62cea3ac 100644 --- a/mod/feedback/use_templ.php +++ b/mod/feedback/use_templ.php @@ -52,9 +52,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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); diff --git a/mod/feedback/view.php b/mod/feedback/view.php index aa01dd9b5d3..81a4ee02218 100644 --- a/mod/feedback/view.php +++ b/mod/feedback/view.php @@ -41,9 +41,7 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 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; From bb9ea890f6969e301982f841e0a8fab0558a2f76 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 25 Jul 2012 15:29:47 +0800 Subject: [PATCH 17/73] MDL-34507 Repository: Better support for 'any' accepted filetypes --- repository/lib.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/repository/lib.php b/repository/lib.php index dd00d82e353..2093c7d1e4c 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -899,6 +899,9 @@ abstract class repository { $repositories = array(); if (isset($args['accepted_types'])) { $accepted_types = $args['accepted_types']; + if (is_array($accepted_types) && in_array('*', $accepted_types)) { + $accepted_types = '*'; + } } else { $accepted_types = '*'; } From 3713514b086017a87859539dad4064138afc4bb7 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 17 Jul 2012 14:22:18 +0800 Subject: [PATCH 18/73] MDL-32827 calendar: Fixining calender entries with no eventtype --- lib/db/upgrade.php | 22 +++++++++++++++++++++- version.php | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 24d6120482f..f837f06b055 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -85,7 +85,7 @@ defined('MOODLE_INTERNAL') || die(); * @return bool always true */ function xmldb_main_upgrade($oldversion) { - global $CFG, $USER, $DB, $OUTPUT; + global $CFG, $USER, $DB, $OUTPUT, $SITE; require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions @@ -1069,5 +1069,25 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012072401.00); } + if ($oldversion < 2012072600.01) { + $rs = $DB->get_recordset('event', array( 'eventtype' => ''), '', 'id, courseid, groupid, userid, modulename'); + foreach ($rs as $event) { + if ($event->courseid == $SITE->id) { // Site event + $DB->set_field('event', 'eventtype', 'site', array('id' => $event->id)); + } else if ($event->courseid != 0 && $event->groupid == 0 && ($event->modulename == 'assignment' || $event->modulename == 'assign')) { + // Course assingment event + $DB->set_field('event', 'eventtype', 'due', array('id' => $event->id)); + } else if ($event->courseid != 0 && $event->groupid == 0) { // Course event + $DB->set_field('event', 'eventtype', 'course', array('id' => $event->id)); + } else if ($event->groupid) { // Group event + $DB->set_field('event', 'eventtype', 'group', array('id' => $event->id)); + } else if ($event->userid) { // User event + $DB->set_field('event', 'eventtype', 'user', array('id' => $event->id)); + } + } + $rs->close(); + // Main savepoint reached + upgrade_main_savepoint(true, 2012072600.01); + } return true; } diff --git a/version.php b/version.php index 4d207bc7e59..0b22e59c500 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012072600.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012072600.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes From 686ca2f5d18732271e2c77bb952dd8ada30bd243 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Wed, 25 Jul 2012 13:27:28 +0800 Subject: [PATCH 19/73] MDL-32827 calendar: Added logic to handle calendar events with empty eventtypes during restore --- backup/moodle2/restore_stepslib.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 1bd5a48b973..5ac98443fc3 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1769,6 +1769,23 @@ class restore_calendarevents_structure_step extends restore_structure_step { return; } } + // Handle events with empty eventtype //MDL-32827 + if(empty($data->eventtype)) { + if ($data->courseid == $SITE->id) { // Site event + $data->eventtype = "site"; + } else if ($data->courseid != 0 && $data->groupid == 0 && ($data->modulename == 'assignment' || $data->modulename == 'assign')) { + // Course assingment event + $data->eventtype = "due"; + } else if ($data->courseid != 0 && $data->groupid == 0) { // Course event + $data->eventtype = "course"; + } else if ($data->groupid) { // Group event + $data->eventtype = "group"; + } else if ($data->userid) { // User event + $data->eventtype = "user"; + } else { + return; + } + } $params = array( 'name' => $data->name, From b0c6dc1cac89c36c5d7ef3b267b5928b81516fd2 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Wed, 25 Jul 2012 16:25:55 +0800 Subject: [PATCH 20/73] MDL-34465 - lib - Replacing get_context_instance with context_XXXX::instance (group 8) --- lib/adminlib.php | 8 +-- lib/ajax/getnavbranch.php | 2 +- lib/blocklib.php | 8 +-- lib/datalib.php | 26 +++++----- lib/deprecatedlib.php | 10 ++-- lib/editor/tinymce/lib.php | 2 +- lib/enrollib.php | 12 ++--- lib/externallib.php | 2 +- lib/filebrowser/file_browser.php | 2 +- lib/filebrowser/file_info_context_course.php | 2 +- .../file_info_context_coursecat.php | 6 +-- lib/filebrowser/file_info_context_system.php | 4 +- lib/filelib.php | 20 +++---- lib/filterlib.php | 12 ++--- lib/form/editor.php | 2 +- lib/form/filemanager.php | 2 +- lib/form/filepicker.php | 6 +-- lib/form/tags.php | 2 +- lib/form/url.php | 4 +- lib/formslib.php | 12 ++--- lib/grade/grade_outcome.php | 4 +- lib/grade/grade_scale.php | 4 +- lib/gradelib.php | 8 +-- lib/grouplib.php | 12 ++--- lib/messagelib.php | 2 +- lib/modinfolib.php | 4 +- lib/moodlelib.php | 14 ++--- lib/navigationlib.php | 52 +++++++++---------- lib/outputcomponents.php | 2 +- lib/outputrenderers.php | 8 +-- lib/pagelib.php | 10 ++-- lib/portfoliolib.php | 2 +- lib/questionlib.php | 8 +-- lib/resourcelib.php | 4 +- lib/statslib.php | 8 +-- lib/tests/accesslib_test.php | 8 +-- lib/tests/blocklib_test.php | 20 +++---- lib/tests/filter_test.php | 2 +- lib/tests/other/pdflibtestpage.php | 2 +- lib/tests/other/todochecker.php | 2 +- lib/tests/pagelib_test.php | 16 +++--- .../filtersettingsperformancetester.php | 2 +- lib/uploadlib.php | 2 +- lib/weblib.php | 14 ++--- lib/xhprof/xhprof_html/callgraph.php | 2 +- lib/xhprof/xhprof_html/index.php | 2 +- lib/xhprof/xhprof_html/typeahead.php | 2 +- 47 files changed, 180 insertions(+), 180 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index ece35ca87c3..1d9fb8e9857 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -526,7 +526,7 @@ function set_cron_lock($name, $until, $ignorecurrent=false) { function admin_critical_warnings_present() { global $SESSION; - if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if (!has_capability('moodle/site:config', context_system::instance())) { return 0; } @@ -1164,7 +1164,7 @@ class admin_externalpage implements part_of_admin_tree { */ public function check_access() { global $CFG; - $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context; + $context = empty($this->context) ? context_system::instance() : $this->context; foreach($this->req_capability as $cap) { if (has_capability($cap, $context)) { return true; @@ -1340,7 +1340,7 @@ class admin_settingpage implements part_of_admin_tree { */ public function check_access() { global $CFG; - $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context; + $context = empty($this->context) ? context_system::instance() : $this->context; foreach($this->req_capability as $cap) { if (has_capability($cap, $context)) { return true; @@ -2854,7 +2854,7 @@ class admin_setting_users_with_capability extends admin_setting_configmultiselec if (is_array($this->choices)) { return true; } - $users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), + $users = get_users_by_capability(context_system::instance(), $this->capability, 'u.id,u.username,u.firstname,u.lastname', 'u.lastname,u.firstname'); $this->choices = array( '$@NONE@$' => get_string('nobody'), diff --git a/lib/ajax/getnavbranch.php b/lib/ajax/getnavbranch.php index 6891a3025c0..f4edede1f33 100644 --- a/lib/ajax/getnavbranch.php +++ b/lib/ajax/getnavbranch.php @@ -42,7 +42,7 @@ try { // This identifies the block instance requesting AJAX extension $instanceid = optional_param('instance', null, PARAM_INT); - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + $PAGE->set_context(context_system::instance()); // Create a global nav object $navigation = new global_navigation_for_ajax($PAGE, $branchtype, $branchid); diff --git a/lib/blocklib.php b/lib/blocklib.php index 3aabe710a76..b74272f1276 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -657,7 +657,7 @@ class block_manager { $blockinstance->id = $DB->insert_record('block_instances', $blockinstance); // Ensure the block context is created. - get_context_instance(CONTEXT_BLOCK, $blockinstance->id); + context_block::instance($blockinstance->id); // If the new instance was created, allow it to do additional setup if ($block = block_instance($blockname, $blockinstance)) { @@ -1230,8 +1230,8 @@ class block_manager { $bi->subpagepattern = $data->bui_subpagepattern; } - $systemcontext = get_context_instance(CONTEXT_SYSTEM); - $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); + $systemcontext = context_system::instance(); + $frontpagecontext = context_course::instance(SITEID); $parentcontext = get_context_instance_by_id($data->bui_parentcontextid); // Updating stickiness and contexts. See MDL-21375 for details. @@ -2102,7 +2102,7 @@ function blocks_add_default_system_blocks() { global $DB; $page = new moodle_page(); - $page->set_context(get_context_instance(CONTEXT_SYSTEM)); + $page->set_context(context_system::instance()); $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('navigation', 'settings')), '*', null, true); $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2); diff --git a/lib/datalib.php b/lib/datalib.php index dea5c4b6f16..97e90b78cbb 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -158,7 +158,7 @@ function search_users($courseid, $groupid, $searchtext, $sort='', array $excepti return $DB->get_records_sql($sql, $params); } else { - $context = get_context_instance(CONTEXT_COURSE, $courseid); + $context = context_course::instance($courseid); $contextlists = get_related_contexts_string($context); $sql = "SELECT u.id, u.firstname, u.lastname, u.email @@ -412,7 +412,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*") context_instance_preload($course); if (isset($course->visible) && $course->visible <= 0) { // for hidden courses, require visibility check - if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { + if (has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { $visiblecourses [$course->id] = $course; } } else { @@ -479,7 +479,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c context_instance_preload($course); if ($course->visible <= 0) { // for hidden courses, require visibility check - if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { + if (has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { $totalcount++; if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) { $visiblecourses [$course->id] = $course; @@ -596,7 +596,7 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a // managers efficiently later... foreach ($courses as $k => $course) { context_instance_preload($course); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $courses[$k] = $course; $courses[$k]->managers = array(); if ($allcats === false) { @@ -694,7 +694,7 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a } } else { foreach ($courses as $k => $course) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); // Note that strpos() returns 0 as "matched at pos 0" if (strpos($coursecontext->path, $ra->path.'/') === 0) { // Only add it to subpaths @@ -806,7 +806,7 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record $rs = $DB->get_recordset_sql($sql, $params); foreach($rs as $course) { context_instance_preload($course); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursecontext)) { // Don't exit this loop till the end // we need to count all the visible courses @@ -885,7 +885,7 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) { $rs = $DB->get_recordset_sql($sql, $params); foreach($rs as $cat) { context_instance_preload($cat); - $catcontext = get_context_instance(CONTEXT_COURSECAT, $cat->id); + $catcontext = context_coursecat::instance($cat->id); if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) { $categories[$cat->id] = $cat; } @@ -949,7 +949,7 @@ function get_course_category($catid=0) { $cat->timemodified = time(); $catid = $DB->insert_record('course_categories', $cat); // make sure category context exists - get_context_instance(CONTEXT_COURSECAT, $catid); + context_coursecat::instance($catid); mark_context_dirty('/'.SYSCONTEXTID); fix_course_sortorder(); // Required to build course_categories.depth and .path. $category = $DB->get_record('course_categories', array('id'=>$catid)); @@ -1032,7 +1032,7 @@ function fix_course_sortorder() { $defaultcat = reset($topcats); foreach ($frontcourses as $course) { $DB->set_field('course', 'category', $defaultcat->id, array('id'=>$course->id)); - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $fixcontexts[$context->id] = $context; } unset($frontcourses); @@ -1178,7 +1178,7 @@ function _fix_course_cats($children, &$sortorder, $parent, $depth, $path, &$fixc $update = true; // make sure context caches are rebuild and dirty contexts marked - $context = get_context_instance(CONTEXT_COURSECAT, $cat->id); + $context = context_coursecat::instance($cat->id); $fixcontexts[$context->id] = $context; } if ($cat->sortorder != $sortorder) { @@ -1620,7 +1620,7 @@ function coursemodule_visible_for_user($cm, $userid=0) { if (empty($userid)) { $userid = $USER->id; } - if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) { + if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id), $userid)) { return false; } if ($CFG->enableavailability) { @@ -1628,7 +1628,7 @@ function coursemodule_visible_for_user($cm, $userid=0) { $ci=new condition_info($cm,CONDITION_MISSING_EXTRATABLE); if(!$ci->is_available($cm->availableinfo,false,$userid) and !has_capability('moodle/course:viewhiddenactivities', - get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) { + context_module::instance($cm->id), $userid)) { return false; } } @@ -2010,7 +2010,7 @@ function user_can_create_courses() { global $DB; $catsrs = $DB->get_recordset('course_categories'); foreach ($catsrs as $cat) { - if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $cat->id))) { + if (has_capability('moodle/course:create', context_coursecat::instance($cat->id))) { $catsrs->close(); return true; } diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 5349be5ec60..4c5a392db53 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -75,7 +75,7 @@ function filter_text($text, $courseid = NULL) { $courseid = $COURSE->id; } - if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) { + if (!$context = context_course::instance($courseid, IGNORE_MISSING)) { return $text; } @@ -312,7 +312,7 @@ function get_teacher() { * @return array of user */ function get_course_participants($courseid) { - return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid)); + return get_enrolled_users(context_course::instance($courseid)); } /** @@ -324,7 +324,7 @@ function get_course_participants($courseid) { * @return boolean */ function is_course_participant($userid, $courseid) { - return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid); + return is_enrolled(context_course::instance($courseid), $userid); } /** @@ -341,7 +341,7 @@ function is_course_participant($userid, $courseid) { function get_recent_enrolments($courseid, $timestart) { global $DB; - $context = get_context_instance(CONTEXT_COURSE, $courseid); + $context = context_course::instance($courseid); $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time) FROM {user} u, {role_assignments} ra, {log} l @@ -2601,7 +2601,7 @@ function update_module_button($cmid, $ignored, $string) { //NOTE: DO NOT call new output method because it needs the module name we do not have here! - if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) { + if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) { $string = get_string('updatethis', '', $string); $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey())); diff --git a/lib/editor/tinymce/lib.php b/lib/editor/tinymce/lib.php index a7404834068..a16f0e3c096 100644 --- a/lib/editor/tinymce/lib.php +++ b/lib/editor/tinymce/lib.php @@ -92,7 +92,7 @@ class tinymce_texteditor extends texteditor { $lang = current_language(); $contentcss = $PAGE->theme->editor_css_url()->out(false); - $context = empty($options['context']) ? get_context_instance(CONTEXT_SYSTEM) : $options['context']; + $context = empty($options['context']) ? context_system::instance() : $options['context']; $config = get_config('editor_tinymce'); diff --git a/lib/enrollib.php b/lib/enrollib.php index b6736c4ece1..b437a48f1b1 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -389,7 +389,7 @@ function enrol_course_updated($inserted, $course, $data) { function enrol_add_course_navigation(navigation_node $coursenode, $course) { global $CFG; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $instances = enrol_get_instances($course->id, true); $plugins = enrol_get_plugins(true); @@ -604,7 +604,7 @@ function enrol_get_my_courses($fields = NULL, $sort = 'visible DESC,sortorder AS foreach ($courses as $id=>$course) { context_instance_preload($course); if (!$course->visible) { - if (!$context = get_context_instance(CONTEXT_COURSE, $id)) { + if (!$context = context_course::instance($id, IGNORE_MISSING)) { unset($courses[$id]); continue; } @@ -1018,7 +1018,7 @@ abstract class enrol_plugin { $enrol = $this->get_name(); return get_string('pluginname', 'enrol_'.$enrol); } else { - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); return format_string($instance->name, true, array('context'=>$context)); } } @@ -1215,7 +1215,7 @@ abstract class enrol_plugin { if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST); + $context = context_course::instance($instance->courseid, MUST_EXIST); $inserted = false; $updated = false; @@ -1352,7 +1352,7 @@ abstract class enrol_plugin { if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST); + $context = context_course::instance($instance->courseid, MUST_EXIST); if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) { // weird, user not enrolled @@ -1484,7 +1484,7 @@ abstract class enrol_plugin { return NULL; } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST); + $context = context_course::instance($instance->courseid, MUST_EXIST); if (!has_capability("enrol/$name:unenrolself", $context)) { return NULL; diff --git a/lib/externallib.php b/lib/externallib.php index da21ace392e..f547850e0f6 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -328,7 +328,7 @@ class external_api { throw new invalid_parameter_exception('Context does not exist'); } if (empty(self::$contextrestriction)) { - self::$contextrestriction = get_context_instance(CONTEXT_SYSTEM); + self::$contextrestriction = context_system::instance(); } $rcontext = self::$contextrestriction; diff --git a/lib/filebrowser/file_browser.php b/lib/filebrowser/file_browser.php index f2105cb8d11..4b86c66f4e6 100644 --- a/lib/filebrowser/file_browser.php +++ b/lib/filebrowser/file_browser.php @@ -73,7 +73,7 @@ class file_browser { */ public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) { if (!$context) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); } switch ($context->contextlevel) { case CONTEXT_SYSTEM: diff --git a/lib/filebrowser/file_info_context_course.php b/lib/filebrowser/file_info_context_course.php index 50876b36856..05b34890290 100644 --- a/lib/filebrowser/file_info_context_course.php +++ b/lib/filebrowser/file_info_context_course.php @@ -383,7 +383,7 @@ class file_info_context_course extends file_info { if (empty($cminfo->uservisible)) { continue; } - $modcontext = get_context_instance(CONTEXT_MODULE, $cminfo->id); + $modcontext = context_module::instance($cminfo->id, IGNORE_MISSING); if ($child = $this->browser->get_file_info($modcontext)) { $children[] = $child; } diff --git a/lib/filebrowser/file_info_context_coursecat.php b/lib/filebrowser/file_info_context_coursecat.php index 99b6d1fc240..1cded8310f1 100644 --- a/lib/filebrowser/file_info_context_coursecat.php +++ b/lib/filebrowser/file_info_context_coursecat.php @@ -65,7 +65,7 @@ class file_info_context_coursecat extends file_info { if (empty($component)) { // we can not list the category contents, so try parent, or top system if ($this->category->parent and $pc = $DB->get_record('course_categories', array('id'=>$this->category->parent))) { - $parent = get_context_instance(CONTEXT_COURSECAT, $pc->id); + $parent = context_coursecat::instance($pc->id, IGNORE_MISSING); return $this->browser->get_file_info($parent); } else { return $this->browser->get_file_info(); @@ -165,7 +165,7 @@ class file_info_context_coursecat extends file_info { $course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder', 'id,visible'); foreach ($course_cats as $category) { - $context = get_context_instance(CONTEXT_COURSECAT, $category->id); + $context = context_coursecat::instance($category->id); if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) { continue; } @@ -176,7 +176,7 @@ class file_info_context_coursecat extends file_info { $courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder', 'id,visible'); foreach ($courses as $course) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { continue; } diff --git a/lib/filebrowser/file_info_context_system.php b/lib/filebrowser/file_info_context_system.php index 375fd9872f0..a37f43ea8a1 100644 --- a/lib/filebrowser/file_info_context_system.php +++ b/lib/filebrowser/file_info_context_system.php @@ -101,7 +101,7 @@ class file_info_context_system extends file_info { $course_cats = $DB->get_records('course_categories', array('parent'=>0), 'sortorder', 'id,visible'); foreach ($course_cats as $category) { - $context = get_context_instance(CONTEXT_COURSECAT, $category->id); + $context = context_coursecat::instance($category->id); if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) { continue; } @@ -115,7 +115,7 @@ class file_info_context_system extends file_info { if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { continue; } - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); if ($child = $this->browser->get_file_info($context)) { $children[] = $child; } diff --git a/lib/filelib.php b/lib/filelib.php index 3b2d4531fc8..32df4bceee7 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -318,7 +318,7 @@ function file_get_unused_draft_itemid() { print_error('noguest'); } - $contextid = get_context_instance(CONTEXT_USER, $USER->id)->id; + $contextid = context_user::instance($USER->id)->id; $fs = get_file_storage(); $draftitemid = rand(1, 999999999); @@ -357,7 +357,7 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare $options['forcehttps'] = false; } - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); if (empty($draftitemid)) { @@ -465,7 +465,7 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil function file_get_draft_area_info($draftitemid) { global $CFG, $USER; - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); $results = array(); @@ -490,7 +490,7 @@ function file_get_draft_area_info($draftitemid) { function file_get_user_used_space() { global $DB, $USER; - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); $sql = "SELECT SUM(files1.filesize) AS totalbytes FROM {files} files1 JOIN (SELECT contenthash, filename, MAX(id) AS id FROM {files} @@ -526,7 +526,7 @@ function file_correct_filepath($str) { //TODO: what is this? (skodak) function file_get_drafarea_folders($draftitemid, $filepath, &$data) { global $USER, $OUTPUT, $CFG; $data->children = array(); - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); $fs = get_file_storage(); if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) { foreach ($files as $file) { @@ -558,7 +558,7 @@ function file_get_drafarea_folders($draftitemid, $filepath, &$data) { function file_get_drafarea_files($draftitemid, $filepath = '/') { global $USER, $OUTPUT, $CFG; - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); $fs = get_file_storage(); $data = new stdClass(); @@ -711,7 +711,7 @@ function file_restore_source_field_from_draft_file($storedfile) { function file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) { global $USER; - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); $options = (array)$options; @@ -905,7 +905,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea function file_rewrite_urls_to_pluginfile($text, $draftitemid, $forcehttps = false) { global $CFG, $USER; - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); $wwwroot = $CFG->wwwroot; if ($forcehttps) { @@ -3763,7 +3763,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { while (!$canview && count($courses) > 0) { $course = array_shift($courses); - if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_COURSE, $course->id))) { + if (has_capability('moodle/user:viewdetails', context_course::instance($course->id))) { $canview = true; } } @@ -3780,7 +3780,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { } else if ($filearea === 'profile' and $context->contextlevel == CONTEXT_COURSE) { $userid = (int)array_shift($args); - $usercontext = get_context_instance(CONTEXT_USER, $userid); + $usercontext = context_user::instance($userid); if ($CFG->forcelogin) { require_login(); diff --git a/lib/filterlib.php b/lib/filterlib.php index ca75b0d1cb6..de808355b51 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -605,7 +605,7 @@ function filter_set_global_state($filter, $state, $sortorder = false) { } // See if there is an existing record. - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); $rec = $DB->get_record('filter_active', array('filter' => $filter, 'contextid' => $syscontext->id)); if (empty($rec)) { $insert = true; @@ -747,7 +747,7 @@ function filter_set_local_state($filter, $contextid, $state) { "Must be one of TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_INHERIT."); } - if ($contextid == get_context_instance(CONTEXT_SYSTEM)->id) { + if ($contextid == context_system::instance()->id) { throw new coding_exception('You cannot use filter_set_local_state ' . 'with $contextid equal to the system context id.'); } @@ -847,7 +847,7 @@ function filter_get_local_config($filter, $contextid) { */ function filter_get_all_local_settings($contextid) { global $DB; - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); return array( $DB->get_records('filter_active', array('contextid' => $contextid), 'filter', 'filter,active'), $DB->get_records('filter_config', array('contextid' => $contextid), 'filter,name', 'filter,name,value'), @@ -940,13 +940,13 @@ function filter_preload_activities(course_modinfo $modinfo) { $cmcontexts = array(); $cmcontextids = array(); foreach ($modinfo->get_cms() as $cm) { - $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id); + $modulecontext = context_module::instance($cm->id); $cmcontextids[] = $modulecontext->id; $cmcontexts[] = $modulecontext; } // Get course context and all other parents... - $coursecontext = get_context_instance(CONTEXT_COURSE, $modinfo->get_course_id()); + $coursecontext = context_course::instance($modinfo->get_course_id()); $parentcontextids = explode('/', substr($coursecontext->path, 1)); $allcontextids = array_merge($cmcontextids, $parentcontextids); @@ -1094,7 +1094,7 @@ function filter_get_available_in_context($context) { */ function filter_get_global_states() { global $DB; - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); return $DB->get_records('filter_active', array('contextid' => $context->id), 'sortorder', 'filter,active,sortorder'); } diff --git a/lib/form/editor.php b/lib/form/editor.php index 5a919fb3715..3d6db559fc8 100644 --- a/lib/form/editor.php +++ b/lib/form/editor.php @@ -80,7 +80,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element { $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); } if (!$this->_options['context']) { - $this->_options['context'] = get_context_instance(CONTEXT_SYSTEM); + $this->_options['context'] = context_system::instance(); } $this->_options['trusted'] = trusttext_trusted($this->_options['context']); parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 82f9090131b..c5daa9ec0c7 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -321,7 +321,7 @@ class form_filemanager implements renderable { $this->options = file_get_drafarea_files($options->itemid, '/'); // calculate file count - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false); $filecount = count($files); $this->options->filecount = $filecount; diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index fb5e0f36036..da5aff8a3e1 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -126,9 +126,9 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { } if ($COURSE->id == SITEID) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); } else { - $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); + $context = context_course::instance($COURSE->id); } $client_id = uniqid(); @@ -191,7 +191,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { // make sure max one file is present and it is not too big if (!is_null($draftitemid)) { $fs = get_file_storage(); - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) { $file = array_shift($files); if ($this->_options['maxbytes'] diff --git a/lib/form/tags.php b/lib/form/tags.php index bdaa1337cdd..2c60979bfc8 100644 --- a/lib/form/tags.php +++ b/lib/form/tags.php @@ -130,7 +130,7 @@ class MoodleQuickForm_tags extends MoodleQuickForm_group { // If the user can manage official tags, give them a link to manage them. $label = get_string('otags', 'tag'); - if (has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('moodle/tag:manage', context_system::instance())) { $url = $CFG->wwwroot .'/tag/manage.php'; $label .= ' (' . $OUTPUT->action_link( $url, diff --git a/lib/form/url.php b/lib/form/url.php index 18c74650ea3..aa7100e35d1 100644 --- a/lib/form/url.php +++ b/lib/form/url.php @@ -97,9 +97,9 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{ $strsaved = get_string('filesaved', 'repository'); $straddlink = get_string('choosealink', 'repository'); if ($COURSE->id == SITEID) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); } else { - $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); + $context = context_course::instance($COURSE->id); } $client_id = uniqid(); diff --git a/lib/formslib.php b/lib/formslib.php index 38afe826588..e9da89e2f6e 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -395,7 +395,7 @@ abstract class moodleform { if ($rule['type'] == 'required') { $draftid = (int)$mform->getSubmitValue($elementname); $fs = get_file_storage(); - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { $errors[$elementname] = $rule['message']; } @@ -673,7 +673,7 @@ abstract class moodleform { } $draftid = $values[$elname]; $fs = get_file_storage(); - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } @@ -721,7 +721,7 @@ abstract class moodleform { } $draftid = $values[$elname]; $fs = get_file_storage(); - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } @@ -784,7 +784,7 @@ abstract class moodleform { } $draftid = $values[$elname]; $fs = get_file_storage(); - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return null; } @@ -828,7 +828,7 @@ abstract class moodleform { return false; } $draftid = $values[$elname]; - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) { return false; } @@ -890,7 +890,7 @@ abstract class moodleform { } $draftid = $values[$elname]; $fs = get_file_storage(); - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php index 02e765f3300..ffb47de5dd6 100644 --- a/lib/grade/grade_outcome.php +++ b/lib/grade/grade_outcome.php @@ -106,7 +106,7 @@ class grade_outcome extends grade_object { $DB->delete_records('grade_outcomes_courses', array('outcomeid' => $this->id, 'courseid' => $this->courseid)); } if (parent::delete($source)) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'grade', 'outcome', $this->id); foreach ($files as $file) { @@ -299,7 +299,7 @@ class grade_outcome extends grade_object { $options = new stdClass; $options->noclean = true; - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'outcome', $this->id); return format_text($description, $this->descriptionformat, $options); } diff --git a/lib/grade/grade_scale.php b/lib/grade/grade_scale.php index d26f10a0ce0..46167a9ce2e 100644 --- a/lib/grade/grade_scale.php +++ b/lib/grade/grade_scale.php @@ -142,7 +142,7 @@ class grade_scale extends grade_object { public function delete($source=null) { global $DB; if (parent::delete($source)) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'grade', 'scale', $this->id); foreach ($files as $file) { @@ -337,7 +337,7 @@ class grade_scale extends grade_object { global $CFG; require_once($CFG->libdir . '/filelib.php'); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $options = new stdClass; $options->noclean = true; $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $this->id); diff --git a/lib/gradelib.php b/lib/gradelib.php index 8de67cf103d..f83cffd5a52 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -758,7 +758,7 @@ function grade_format_gradevalue_percentage($value, $grade_item, $decimals, $loc * @return string */ function grade_format_gradevalue_letter($value, $grade_item) { - $context = get_context_instance(CONTEXT_COURSE, $grade_item->courseid); + $context = context_course::instance($grade_item->courseid, IGNORE_MISSING); if (!$letters = grade_get_letters($context)) { return ''; // no letters?? } @@ -939,7 +939,7 @@ function grade_recover_history_grades($userid, $courseid) { //Check the user is enrolled in this course //Dont bother checking if they have a gradeable role. They may get one later so recover //whatever grades they have now just in case. - $course_context = get_context_instance(CONTEXT_COURSE, $courseid); + $course_context = context_course::instance($courseid); if (!is_enrolled($course_context, $userid)) { debugging('Attempting to recover the grades of a user who is deleted or not enrolled. Skipping recover.'); return false; @@ -1228,7 +1228,7 @@ function remove_course_grades($courseid, $showfeedback) { $course_category = grade_category::fetch_course_category($courseid); $course_category->delete('coursedelete'); - $fs->delete_area_files(get_context_instance(CONTEXT_COURSE, $courseid)->id, 'grade', 'feedback'); + $fs->delete_area_files(context_course::instance($courseid)->id, 'grade', 'feedback'); if ($showfeedback) { echo $OUTPUT->notification($strdeleted.' - '.get_string('grades', 'grades').', '.get_string('items', 'grades').', '.get_string('categories', 'grades'), 'notifysuccess'); } @@ -1269,7 +1269,7 @@ function remove_course_grades($courseid, $showfeedback) { function grade_course_category_delete($categoryid, $newparentid, $showfeedback) { global $DB; - $context = get_context_instance(CONTEXT_COURSECAT, $categoryid); + $context = context_coursecat::instance($categoryid); $DB->delete_records('grade_letters', array('contextid'=>$context->id)); } diff --git a/lib/grouplib.php b/lib/grouplib.php index cecba9cb05c..f80064c848f 100644 --- a/lib/grouplib.php +++ b/lib/grouplib.php @@ -455,7 +455,7 @@ function groups_print_course_menu($course, $urlroot, $return=false) { } } - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $aag = has_capability('moodle/site:accessallgroups', $context); if ($groupmode == VISIBLEGROUPS or $aag) { @@ -548,7 +548,7 @@ function groups_print_activity_menu($cm, $urlroot, $return=false, $hideallpartic } } - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); $aag = has_capability('moodle/site:accessallgroups', $context); if ($groupmode == VISIBLEGROUPS or $aag) { @@ -617,7 +617,7 @@ function groups_get_course_group($course, $update=false, $allowedgroups=null) { return false; } - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); if (has_capability('moodle/site:accessallgroups', $context)) { $groupmode = 'aag'; } @@ -669,7 +669,7 @@ function groups_get_activity_group($cm, $update=false, $allowedgroups=null) { return false; } - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); if (has_capability('moodle/site:accessallgroups', $context)) { $groupmode = 'aag'; } @@ -725,7 +725,7 @@ function groups_get_activity_allowed_groups($cm,$userid=0) { // If visible groups mode, or user has the accessallgroups capability, // then they can access all groups for the activity... - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) { return groups_get_all_groups($cm->course, 0, $cm->groupingid); } else { @@ -756,7 +756,7 @@ function groups_course_module_visible($cm, $userid=null) { if (empty($cm->groupmembersonly)) { return true; } - if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid) or groups_has_membership($cm, $userid)) { + if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id), $userid) or groups_has_membership($cm, $userid)) { return true; } return false; diff --git a/lib/messagelib.php b/lib/messagelib.php index ba05880a4c8..b184f0dafa0 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -388,7 +388,7 @@ function message_get_my_providers() { function message_get_providers_for_user($userid) { global $DB, $CFG; - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $providers = get_message_providers(); diff --git a/lib/modinfolib.php b/lib/modinfolib.php index 613aba0e92d..fc24b9b5837 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -973,7 +973,7 @@ class cm_info extends stdClass { $this->icon = isset($mod->icon) ? $mod->icon : ''; $this->iconcomponent = isset($mod->iconcomponent) ? $mod->iconcomponent : ''; $this->customdata = isset($mod->customdata) ? $mod->customdata : ''; - $this->context = get_context_instance(CONTEXT_MODULE, $mod->cm); + $this->context = context_module::instance($mod->cm); $this->showdescription = isset($mod->showdescription) ? $mod->showdescription : 0; $this->state = self::STATE_BASIC; @@ -1091,7 +1091,7 @@ class cm_info extends stdClass { */ private function update_user_visible() { global $CFG; - $modcontext = get_context_instance(CONTEXT_MODULE, $this->id); + $modcontext = context_module::instance($this->id); $userid = $this->modinfo->get_user_id(); $this->uservisible = true; // Check visibility/availability conditions. diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 29f4362eb23..0d959114d94 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1443,7 +1443,7 @@ function get_users_from_config($value, $capability, $includeadmins = true) { // we have to make sure that users still have the necessary capability, // it should be faster to fetch them all first and then test if they are present // instead of validating them one-by-one - $users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), $capability); + $users = get_users_by_capability(context_system::instance(), $capability); if ($includeadmins) { $admins = get_admins(); foreach ($admins as $admin) { @@ -2864,10 +2864,10 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ } // Fetch the system context, the course context, and prefetch its child contexts - $sysctx = get_context_instance(CONTEXT_SYSTEM); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); + $sysctx = context_system::instance(); + $coursecontext = context_course::instance($course->id, MUST_EXIST); if ($cm) { - $cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST); + $cmcontext = context_module::instance($cm->id, MUST_EXIST); } else { $cmcontext = null; } @@ -4452,7 +4452,7 @@ function delete_course($courseorid, $showfeedback = true) { return false; } } - $context = get_context_instance(CONTEXT_COURSE, $courseid); + $context = context_course::instance($courseid); // frontpage course can not be deleted!! if ($courseid == SITEID) { @@ -4788,7 +4788,7 @@ function reset_course_userdata($data) { require_once($CFG->dirroot.'/group/lib.php'); $data->courseid = $data->id; - $context = get_context_instance(CONTEXT_COURSE, $data->courseid); + $context = context_course::instance($data->courseid); // calculate the time shift of dates if (!empty($data->reset_start_date)) { @@ -5618,7 +5618,7 @@ function send_password_change_info($user) { $site = get_site(); $supportuser = generate_email_supportuser(); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $data = new stdClass(); $data->firstname = $user->firstname; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index e6049b824ed..0317445fd87 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1131,7 +1131,7 @@ class global_navigation extends navigation_node { $addedcategories[$category->id] = $categoryparent->add($category->name, $url, self::TYPE_CATEGORY, $category->name, $category->id); if (!$category->visible) { - if (!has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_COURSECAT, $category->parent))) { + if (!has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->parent))) { $addedcategories[$category->id]->display = false; } else { $addedcategories[$category->id]->hidden = true; @@ -1230,7 +1230,7 @@ class global_navigation extends navigation_node { $isparent = false; if ($this->useridtouseforparentchecks) { if ($this->useridtouseforparentchecks != $USER->id) { - $usercontext = get_context_instance(CONTEXT_USER, $this->useridtouseforparentchecks, MUST_EXIST); + $usercontext = context_user::instance($this->useridtouseforparentchecks, MUST_EXIST); if ($DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id)) and has_capability('moodle/user:viewdetails', $usercontext)) { $isparent = true; @@ -1601,7 +1601,7 @@ class global_navigation extends navigation_node { continue; } context_instance_preload($course); - if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { + if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { continue; } $coursenodes[$course->id] = $this->add_course($course); @@ -1637,7 +1637,7 @@ class global_navigation extends navigation_node { break; } context_instance_preload($course); - if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { + if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { continue; } $coursenodes[$course->id] = $this->add_course($course); @@ -1661,7 +1661,7 @@ class global_navigation extends navigation_node { continue; } context_instance_preload($course); - if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { + if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { continue; } $coursenodes[$course->id] = $this->add_course($course); @@ -1843,7 +1843,7 @@ class global_navigation extends navigation_node { return; } $url = new moodle_url('/course/category.php', array('id' => $category->id)); - $context = get_context_instance(CONTEXT_COURSECAT, $category->id); + $context = context_coursecat::instance($category->id); $categoryname = format_string($category->name, true, array('context' => $context)); $categorynode = $parent->add($categoryname, $url, self::TYPE_CATEGORY, $categoryname, $category->id); if (empty($category->visible)) { @@ -2076,7 +2076,7 @@ class global_navigation extends navigation_node { } // Prepare the default name and url for the node - $activityname = format_string($activity->name, true, array('context' => get_context_instance(CONTEXT_MODULE, $activity->id))); + $activityname = format_string($activity->name, true, array('context' => context_module::instance($activity->id))); $action = new moodle_url($activity->url); // Check if the onclick property is set (puke!) @@ -2223,7 +2223,7 @@ class global_navigation extends navigation_node { $iscurrentuser = ($user->id == $USER->id); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); // Get the course set against the page, by default this will be the site $course = $this->page->course; @@ -2231,11 +2231,11 @@ class global_navigation extends navigation_node { if ($course->id != $SITE->id && (!$iscurrentuser || $forceforcontext)) { $coursenode = $this->load_course($course); $baseargs['course'] = $course->id; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $issitecourse = false; } else { // Load all categories and get the context for the system - $coursecontext = get_context_instance(CONTEXT_SYSTEM); + $coursecontext = context_system::instance(); $issitecourse = true; } @@ -2244,7 +2244,7 @@ class global_navigation extends navigation_node { // If it's the current user the information will go under the profile root node $usernode = $this->rootnodes['myprofile']; $course = get_site(); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $issitecourse = true; } else { if (!$issitecourse) { @@ -2327,7 +2327,7 @@ class global_navigation extends navigation_node { $usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages'); } - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); if ($iscurrentuser && has_capability('moodle/user:manageownfiles', $context)) { $url = new moodle_url('/user/files.php'); $usernode->add(get_string('myfiles'), $url, self::TYPE_SETTING); @@ -2399,7 +2399,7 @@ class global_navigation extends navigation_node { $userscoursesnode = $usernode->add(get_string('courses')); foreach ($userscourses as $usercourse) { - $usercoursecontext = get_context_instance(CONTEXT_COURSE, $usercourse->id); + $usercoursecontext = context_course::instance($usercourse->id); $usercourseshortname = format_string($usercourse->shortname, true, array('context' => $usercoursecontext)); $usercoursenode = $userscoursesnode->add($usercourseshortname, new moodle_url('/user/view.php', array('id'=>$user->id, 'course'=>$usercourse->id)), self::TYPE_CONTAINER); @@ -2497,7 +2497,7 @@ class global_navigation extends navigation_node { return $this->addedcourses[$course->id]; } - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); if ($course->id != $SITE->id && !$course->visible) { if (is_role_switched($course->id)) { @@ -2544,7 +2544,7 @@ class global_navigation extends navigation_node { $coursenode = $parent->add($shortname, $url, self::TYPE_COURSE, $shortname, $course->id); $coursenode->nodetype = self::NODETYPE_BRANCH; $coursenode->hidden = (!$course->visible); - $coursenode->title(format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)))); + $coursenode->title(format_string($course->fullname, true, array('context' => context_course::instance($course->id)))); if (!$forcegeneric) { $this->addedcourses[$course->id] = $coursenode; } @@ -2595,7 +2595,7 @@ class global_navigation extends navigation_node { } $filterselect = clean_param($filterselect, PARAM_INT); if (($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser()))) - and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) { + and has_capability('moodle/blog:view', context_system::instance())) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); $participants->add(get_string('blogscourse','blog'), $blogsurls->out()); } @@ -2660,7 +2660,7 @@ class global_navigation extends navigation_node { // Blogs if (!empty($CFG->bloglevel) and ($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser()))) - and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) { + and has_capability('moodle/blog:view', context_system::instance())) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); $coursenode->add(get_string('blogssite','blog'), $blogsurls->out()); } @@ -2856,7 +2856,7 @@ class global_navigation_for_ajax extends global_navigation { case self::TYPE_COURSE : $course = $DB->get_record('course', array('id' => $this->instanceid), '*', MUST_EXIST); require_course_login($course, true, null, false, true); - $this->page->set_context(get_context_instance(CONTEXT_COURSE, $course->id)); + $this->page->set_context(context_course::instance($course->id)); $coursenode = $this->add_course($course); $this->add_course_essentials($coursenode, $course); if ($this->format_display_course_content($course->format)) { @@ -2870,7 +2870,7 @@ class global_navigation_for_ajax extends global_navigation { WHERE cs.id = ?'; $course = $DB->get_record_sql($sql, array($this->instanceid), MUST_EXIST); require_course_login($course, true, null, false, true); - $this->page->set_context(get_context_instance(CONTEXT_COURSE, $course->id)); + $this->page->set_context(context_course::instance($course->id)); $coursenode = $this->add_course($course); $this->add_course_essentials($coursenode, $course); $sections = $this->load_course_sections($course, $coursenode); @@ -2887,7 +2887,7 @@ class global_navigation_for_ajax extends global_navigation { $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($this->instanceid); require_course_login($course, true, $cm, false, true); - $this->page->set_context(get_context_instance(CONTEXT_MODULE, $cm->id)); + $this->page->set_context(context_module::instance($cm->id)); $coursenode = $this->load_course($course); if ($course->id == $SITE->id) { $modulenode = $this->load_activity($cm, $course, $coursenode->find($cm->id, self::TYPE_ACTIVITY)); @@ -3540,7 +3540,7 @@ class settings_navigation extends navigation_node { global $CFG; $course = $this->page->course; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); // note: do not test if enrolled or viewing here because we need the enrol link in Course administration section @@ -4017,13 +4017,13 @@ class settings_navigation extends navigation_node { $course = $SITE; } - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + $coursecontext = context_course::instance($course->id); // Course context $systemcontext = get_system_context(); $currentuser = ($USER->id == $userid); if ($currentuser) { $user = $USER; - $usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context + $usercontext = context_user::instance($user->id); // User context } else { $select = context_helper::get_preload_record_columns_sql('ctx'); $sql = "SELECT u.*, $select @@ -4038,7 +4038,7 @@ class settings_navigation extends navigation_node { context_helper::preload_from_record($user); // Check that the user can view the profile - $usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context + $usercontext = context_user::instance($user->id); // User context $canviewuser = has_capability('moodle/user:viewdetails', $usercontext); if ($course->id == $SITE->id) { @@ -4199,7 +4199,7 @@ class settings_navigation extends navigation_node { if ($currentuser && !empty($CFG->bloglevel)) { $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs'); $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING); - if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM))) { + if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', context_system::instance())) { $blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING); $blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING); } @@ -4340,7 +4340,7 @@ class settings_navigation extends navigation_node { global $SITE, $CFG; $course = clone($SITE); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + $coursecontext = context_course::instance($course->id); // Course context $frontpage = $this->add(get_string('frontpagesettings'), null, self::TYPE_SETTING, null, 'frontpage'); if ($forceopen) { diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 35edf3b780e..1486d523c0d 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -92,7 +92,7 @@ class file_picker implements renderable { $options->currentfile = ''; if (!empty($options->itemid)) { $fs = get_file_storage(); - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $usercontext = context_user::instance($USER->id); if (empty($options->filename)) { if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id DESC', false)) { $file = reset($files); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index d099429c1d6..09a0fa578f1 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -457,7 +457,7 @@ class core_renderer extends renderer_base { if (!empty($CFG->debugpageinfo)) { $output .= '
This page is: ' . $this->page->debug_summary() . '
'; } - if (debugging(null, DEBUG_DEVELOPER) and has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { // Only in developer mode + if (debugging(null, DEBUG_DEVELOPER) and has_capability('moodle/site:config', context_system::instance())) { // Only in developer mode // Add link to profiling report if necessary if (function_exists('profiling_is_running') && profiling_is_running()) { $txt = get_string('profiledscript', 'admin'); @@ -535,7 +535,7 @@ class core_renderer extends renderer_base { // $course->id is not defined during installation return ''; } else if (isloggedin()) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $fullname = fullname($USER, true); // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page) @@ -579,7 +579,7 @@ class core_renderer extends renderer_base { } else { $loggedinas .= get_string('failedloginattemptsall', '', $count); } - if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) { + if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) { $loggedinas .= ' (
'.get_string('logs').')'; } @@ -2075,7 +2075,7 @@ EOD; */ public function update_module_button($cmid, $modulename) { global $CFG; - if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) { + if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) { $modulename = get_string('modulename', $modulename); $string = get_string('updatethis', '', $modulename); $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey())); diff --git a/lib/pagelib.php b/lib/pagelib.php index 277e6c55d7f..107911bb2eb 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -449,7 +449,7 @@ class moodle_page { .'to call require_login() or $PAGE->set_context(). The page may not display ' .'correctly as a result'); } - $this->_context = get_context_instance(CONTEXT_SYSTEM); + $this->_context = context_system::instance(); } return $this->_context; } @@ -862,7 +862,7 @@ class moodle_page { } if (!$this->_context) { - $this->set_context(get_context_instance(CONTEXT_COURSE, $this->_course->id)); + $this->set_context(context_course::instance($this->_course->id)); } } @@ -876,7 +876,7 @@ class moodle_page { // extremely ugly hack which sets context to some value in order to prevent warnings, // use only for core error handling!!!! if (!$this->_context) { - $this->_context = get_context_instance(CONTEXT_SYSTEM); + $this->_context = context_system::instance(); } return; } @@ -933,7 +933,7 @@ class moodle_page { // unfortunately the context setting is a mess, let's try to work around some common block problems and show some debug messages if (empty($this->_context) or $this->_context->contextlevel != CONTEXT_BLOCK) { - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); $this->set_context($context); } @@ -1096,7 +1096,7 @@ class moodle_page { $this->ensure_theme_not_set(); $this->set_course($SITE); $this->load_category($categoryid); - $this->set_context(get_context_instance(CONTEXT_COURSECAT, $categoryid)); + $this->set_context(context_coursecat::instance($categoryid)); } /** diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 45e9a78b497..6b01669dead 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -1096,7 +1096,7 @@ function portfolio_insane_notify_admins($insane, $instances=false) { $site = get_site(); $a = new StdClass; - $a->sitename = format_string($site->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))); + $a->sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID))); $a->fixurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageportfolios"; $a->htmllist = portfolio_report_insane($insane, $instances, true); $a->textlist = ''; diff --git a/lib/questionlib.php b/lib/questionlib.php index 1a24e8cf19f..36b6a3a707b 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -355,7 +355,7 @@ function question_delete_course($course, $feedback=true) { //Cache some strings $strcatdeleted = get_string('unusedcategorydeleted', 'quiz'); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $categoriescourse = $DB->get_records('question_categories', array('contextid' => $coursecontext->id), 'parent', 'id, parent, name, contextid'); @@ -407,7 +407,7 @@ function question_delete_course($course, $feedback=true) { function question_delete_course_category($category, $newcategory, $feedback=true) { global $DB, $OUTPUT; - $context = get_context_instance(CONTEXT_COURSECAT, $category->id); + $context = context_coursecat::instance($category->id); if (empty($newcategory)) { $feedbackdata = array(); // To store feedback to be showed at the end of the process $rescueqcategory = null; // See the code around the call to question_save_from_deletion. @@ -464,7 +464,7 @@ function question_delete_course_category($category, $newcategory, $feedback=true } else { // Move question categories ot the new context. - if (!$newcontext = get_context_instance(CONTEXT_COURSECAT, $newcategory->id)) { + if (!$newcontext = context_coursecat::instance($newcategory->id)) { return false; } $DB->set_field('question_categories', 'contextid', $newcontext->id, @@ -529,7 +529,7 @@ function question_delete_activity($cm, $feedback=true) { //Cache some strings $strcatdeleted = get_string('unusedcategorydeleted', 'quiz'); - $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); + $modcontext = context_module::instance($cm->id); if ($categoriesmods = $DB->get_records('question_categories', array('contextid' => $modcontext->id), 'parent', 'id, parent, name, contextid')) { //Sort categories following their tree (parent-child) relationships diff --git a/lib/resourcelib.php b/lib/resourcelib.php index c2d796f78d7..6cf51b49299 100644 --- a/lib/resourcelib.php +++ b/lib/resourcelib.php @@ -67,10 +67,10 @@ function resourcelib_try_file_migration($filepath, $cmid, $courseid, $component, return false; } - if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) { + if (!$context = context_module::instance($cmid)) { return false; } - if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid)) { + if (!$coursecontext = context_course::instance($courseid)) { return false; } diff --git a/lib/statslib.php b/lib/statslib.php index 4091dad30e2..6b2220fbe25 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -104,7 +104,7 @@ function stats_cron_daily($maxdays=1) { $now = time(); - $fpcontext = get_context_instance(CONTEXT_COURSE, SITEID, MUST_EXIST); + $fpcontext = context_course::instance(SITEID, MUST_EXIST); // read last execution date from db if (!$timestart = get_config(NULL, 'statslastdaily')) { @@ -1332,7 +1332,7 @@ function stats_get_report_options($courseid,$mode) { switch ($mode) { case STATS_MODE_GENERAL: $reportoptions[STATS_REPORT_ACTIVITY] = get_string('statsreport'.STATS_REPORT_ACTIVITY); - if ($courseid != SITEID && $context = get_context_instance(CONTEXT_COURSE, $courseid)) { + if ($courseid != SITEID && $context = context_course::instance($courseid)) { $sql = 'SELECT r.id, r.name FROM {role} r JOIN {stats_daily} s ON s.roleid = r.id WHERE s.courseid = :courseid GROUP BY r.id, r.name'; if ($roles = $DB->get_records_sql($sql, array('courseid' => $courseid))) { foreach ($roles as $role) { @@ -1350,13 +1350,13 @@ function stats_get_report_options($courseid,$mode) { case STATS_MODE_DETAILED: $reportoptions[STATS_REPORT_USER_ACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ACTIVITY); $reportoptions[STATS_REPORT_USER_ALLACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ALLACTIVITY); - if (has_capability('report/stats:view', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('report/stats:view', context_system::instance())) { $site = get_site(); $reportoptions[STATS_REPORT_USER_LOGINS] = get_string('statsreport'.STATS_REPORT_USER_LOGINS); } break; case STATS_MODE_RANKED: - if (has_capability('report/stats:view', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('report/stats:view', context_system::instance())) { $reportoptions[STATS_REPORT_ACTIVE_COURSES] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES); $reportoptions[STATS_REPORT_ACTIVE_COURSES_WEIGHTED] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES_WEIGHTED); $reportoptions[STATS_REPORT_PARTICIPATORY_COURSES] = get_string('statsreport'.STATS_REPORT_PARTICIPATORY_COURSES); diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 97712b1321d..52d700fea28 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2336,14 +2336,14 @@ class accesslib_testcase extends advanced_testcase { accesslib_clear_all_caches(false); $DB->delete_records('cache_flags', array()); $course = $DB->get_record('course', array('id'=>$testcourses[2])); - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $oldpath = $context->path; $miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}"); $categorycontext = context_coursecat::instance($miscid); $course->category = $miscid; $DB->update_record('course', $course); context_moved($context, $categorycontext); - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $this->assertEquals($context->get_parent_context(), $categorycontext); $this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2]))); @@ -2353,7 +2353,7 @@ class accesslib_testcase extends advanced_testcase { $name = get_contextlevel_name(CONTEXT_COURSE); $this->assertFalse(empty($name)); - $context = get_context_instance(CONTEXT_COURSE, $testcourses[2]); + $context = context_course::instance($testcourses[2]); $name = print_context_name($context); $this->assertFalse(empty($name)); @@ -2361,7 +2361,7 @@ class accesslib_testcase extends advanced_testcase { $this->assertFalse($url instanceof modole_url); $page = $DB->get_record('page', array('id'=>$testpages[7])); - $context = get_context_instance(CONTEXT_MODULE, $page->id); + $context = context_module::instance($page->id); $coursecontext = get_course_context($context); $this->assertEquals($coursecontext->contextlevel, CONTEXT_COURSE); $this->assertEquals(get_courseid_from_context($context), $page->course); diff --git a/lib/tests/blocklib_test.php b/lib/tests/blocklib_test.php index 704d3871fad..471e908cf05 100644 --- a/lib/tests/blocklib_test.php +++ b/lib/tests/blocklib_test.php @@ -56,7 +56,7 @@ class moodle_block_manager_testcase extends basic_testcase { protected function setUp() { parent::setUp(); $this->testpage = new moodle_page(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); + $this->testpage->set_context(context_system::instance()); $this->blockmanager = new testable_block_manager($this->testpage); } @@ -205,7 +205,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas // Set up fixture. list($page, $blockmanager) = $this->get_a_page_and_block_manager(array('a-region'), - get_context_instance(CONTEXT_SYSTEM), 'page-type'); + context_system::instance(), 'page-type'); // Exercise SUT. $blockmanager->load_blocks(); // Validate. @@ -219,7 +219,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas // Set up fixture. $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type'); @@ -238,7 +238,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas // Set up fixture. $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type'); @@ -257,7 +257,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas $this->purge_blocks(); // Set up fixture. - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); $cat = new stdClass(); $cat->name = 'testcategory'; $cat->parent = 0; @@ -286,7 +286,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas $this->purge_blocks(); // Set up fixture. - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); $childcontext = context_coursecat::instance(1); $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); @@ -307,7 +307,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas $this->purge_blocks(); // Set up fixture. - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); @@ -329,7 +329,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas // Set up fixture. $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'page-type', 'sub-page'); @@ -349,7 +349,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas // Set up fixture. $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'page-type', 'sub-page'); @@ -369,7 +369,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas // Set up fixture. $regionname = 'a-region'; $blockname = $this->get_a_known_block_type(); - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'page-type', 'sub-page'); diff --git a/lib/tests/filter_test.php b/lib/tests/filter_test.php index 1c8f0557895..b220781b47c 100644 --- a/lib/tests/filter_test.php +++ b/lib/tests/filter_test.php @@ -298,7 +298,7 @@ class filter_active_local_testcase extends advanced_testcase { */ public function test_throws_exception_when_setting_global() { // Exercise SUT. - filter_set_local_state('filter/name', get_context_instance(CONTEXT_SYSTEM)->id, TEXTFILTER_INHERIT); + filter_set_local_state('filter/name', context_system::instance()->id, TEXTFILTER_INHERIT); } public function test_local_inherit_deletes_existing() { diff --git a/lib/tests/other/pdflibtestpage.php b/lib/tests/other/pdflibtestpage.php index 985d175b9f8..7c53a2ec293 100644 --- a/lib/tests/other/pdflibtestpage.php +++ b/lib/tests/other/pdflibtestpage.php @@ -26,7 +26,7 @@ require(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->libdir . '/pdflib.php'); require_login(); -$context = get_context_instance(CONTEXT_SYSTEM); +$context = context_system::instance(); require_capability('moodle/site:config', $context); $getpdf = optional_param('getpdf', 0, PARAM_INT); diff --git a/lib/tests/other/todochecker.php b/lib/tests/other/todochecker.php index c22b30a94fb..9b40a2b742b 100644 --- a/lib/tests/other/todochecker.php +++ b/lib/tests/other/todochecker.php @@ -27,7 +27,7 @@ require(dirname(__FILE__) . '/../../../config.php'); require_login(); -$context = get_context_instance(CONTEXT_SYSTEM); +$context = context_system::instance(); require_capability('moodle/site:config', $context); $PAGE->set_url('/lib/tests/other/todochecker.php'); diff --git a/lib/tests/pagelib_test.php b/lib/tests/pagelib_test.php index 04814d0e506..243f2df8d50 100644 --- a/lib/tests/pagelib_test.php +++ b/lib/tests/pagelib_test.php @@ -65,7 +65,7 @@ class moodle_page_test extends advanced_testcase { public function test_setting_course_works() { // Setup fixture $course = $this->getDataGenerator()->create_course(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context. + $this->testpage->set_context(context_system::instance()); // Avoid trying to set the context. // Exercise SUT $this->testpage->set_course($course); // Validate @@ -76,7 +76,7 @@ class moodle_page_test extends advanced_testcase { global $COURSE, $PAGE; // Setup fixture $course = $this->getDataGenerator()->create_course(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context. + $this->testpage->set_context(context_system::instance()); // Avoid trying to set the context. $PAGE = $this->testpage; // Exercise SUT $this->testpage->set_course($course); @@ -89,7 +89,7 @@ class moodle_page_test extends advanced_testcase { $originalcourse = $COURSE; // Setup fixture $course = $this->getDataGenerator()->create_course(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context. + $this->testpage->set_context(context_system::instance()); // Avoid trying to set the context. // Exercise SUT $this->testpage->set_course($course); // Validate @@ -118,7 +118,7 @@ class moodle_page_test extends advanced_testcase { public function test_cannot_set_category_once_course_set() { // Setup fixture $course = $this->getDataGenerator()->create_course(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context. + $this->testpage->set_context(context_system::instance()); // Avoid trying to set the context. $this->testpage->set_course($course); // Set expectation. $this->setExpectedException('coding_exception'); @@ -129,7 +129,7 @@ class moodle_page_test extends advanced_testcase { public function test_categories_array_empty_for_front_page() { global $SITE; // Setup fixture - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context. + $this->testpage->set_context(context_system::instance()); // Avoid trying to set the context. $this->testpage->set_course($SITE); // Exercise SUT and validate. $this->assertEquals(array(), $this->testpage->categories); @@ -137,7 +137,7 @@ class moodle_page_test extends advanced_testcase { public function test_set_state_normal_path() { $course = $this->getDataGenerator()->create_course(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); + $this->testpage->set_context(context_system::instance()); $this->testpage->set_course($course); $this->assertEquals(moodle_page::STATE_BEFORE_HEADER, $this->testpage->state); @@ -166,7 +166,7 @@ class moodle_page_test extends advanced_testcase { public function test_header_printed_becomes_true() { $course = $this->getDataGenerator()->create_course(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); + $this->testpage->set_context(context_system::instance()); $this->testpage->set_course($course); // Exercise SUT @@ -564,7 +564,7 @@ class moodle_page_editing_test extends advanced_testcase { parent::setUp(); $this->setAdminUser(); $this->testpage = new testable_moodle_page(); - $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); + $this->testpage->set_context(context_system::instance()); $this->resetAfterTest(); } diff --git a/lib/tests/performance/filtersettingsperformancetester.php b/lib/tests/performance/filtersettingsperformancetester.php index bb387375286..6eec7b603bd 100644 --- a/lib/tests/performance/filtersettingsperformancetester.php +++ b/lib/tests/performance/filtersettingsperformancetester.php @@ -31,7 +31,7 @@ require(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->libdir . '/ddllib.php'); require_login(); -$syscontext = get_context_instance(CONTEXT_SYSTEM); +$syscontext = context_system::instance(); require_capability('moodle/site:config', $syscontext); $baseurl = new moodle_url('/lib/tests/performance/filtersettingsperformancetester.php'); diff --git a/lib/uploadlib.php b/lib/uploadlib.php index 960370d9ef0..7ee20cfeec8 100644 --- a/lib/uploadlib.php +++ b/lib/uploadlib.php @@ -650,7 +650,7 @@ function clam_scan_moodle_file(&$file, $course) { case 1: // bad wicked evil, we have a virus. $info = new stdClass(); if (!empty($course)) { - $info->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))); + $info->course = format_string($course->fullname, true, array('context' => context_course::instance($course->id))); } else { $info->course = 'No course'; diff --git a/lib/weblib.php b/lib/weblib.php index d70f33cdad2..8384f373871 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -713,7 +713,7 @@ class moodle_url { public static function make_draftfile_url($draftid, $pathname, $filename, $forcedownload = false) { global $CFG, $USER; $urlbase = "$CFG->httpswwwroot/draftfile.php"; - $context = get_context_instance(CONTEXT_USER, $USER->id); + $context = context_user::instance($USER->id); return self::make_file_url($urlbase, "/$context->id/user/draft/$draftid".$pathname.$filename, $forcedownload); } @@ -1076,7 +1076,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_ } } else if ($courseid_do_not_use) { // legacy courseid - $context = get_context_instance(CONTEXT_COURSE, $courseid_do_not_use); + $context = context_course::instance($courseid_do_not_use); } else { // fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-( $context = $PAGE->context; @@ -1272,7 +1272,7 @@ function format_string($string, $striplinks = true, $options = NULL) { if (is_numeric($options)) { // legacy courseid usage - $options = array('context'=>get_context_instance(CONTEXT_COURSE, $options)); + $options = array('context'=>context_course::instance($options)); } else { $options = (array)$options; // detach object, we can not modify it } @@ -1412,7 +1412,7 @@ function format_text_email($text, $format) { function format_module_intro($module, $activity, $cmid, $filter=true) { global $CFG; require_once("$CFG->libdir/filelib.php"); - $context = get_context_instance(CONTEXT_MODULE, $cmid); + $context = context_module::instance($cmid); $options = array('noclean'=>true, 'para'=>false, 'filter'=>$filter, 'context'=>$context, 'overflowdiv'=>true); $intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, 'mod_'.$module, 'intro', null); return trim(format_text($intro, $activity->introformat, $options, null)); @@ -2076,7 +2076,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li } } - $context = get_context_instance(CONTEXT_COURSE, $courseid); + $context = context_course::instance($courseid); // If there is no picture, do nothing if (!$group->picture) { @@ -2132,7 +2132,7 @@ function print_recent_activity_note($time, $user, $text, $link, $return=false, $ $output = ''; if (is_null($viewfullnames)) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $viewfullnames = has_capability('moodle/site:viewfullnames', $context); } @@ -2185,7 +2185,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid $menu = array(); $doneheading = false; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $menu[] = '
diff --git a/theme/canvas/layout/general.php b/theme/canvas/layout/general.php index cda6005acd4..09261f02e69 100644 --- a/theme/canvas/layout/general.php +++ b/theme/canvas/layout/general.php @@ -3,17 +3,27 @@ $hasheading = ($PAGE->heading); $hasnavbar = (empty($PAGE->layout_options['nonavbar']) && $PAGE->has_navbar()); $hasfooter = (empty($PAGE->layout_options['nofooter'])); -$hassidepre = $PAGE->blocks->region_has_content('side-pre', $OUTPUT); -$hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT); +$hassidepre = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('side-pre', $OUTPUT)); +$hassidepost = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('side-post', $OUTPUT)); +$haslogininfo = (empty($PAGE->layout_options['nologininfo'])); + +$showsidepre = ($hassidepre && !$PAGE->blocks->region_completely_docked('side-pre', $OUTPUT)); +$showsidepost = ($hassidepost && !$PAGE->blocks->region_completely_docked('side-post', $OUTPUT)); + +$custommenu = $OUTPUT->custom_menu(); +$hascustommenu = (empty($PAGE->layout_options['nocustommenu']) && !empty($custommenu)); $bodyclasses = array(); -if ($hassidepre && !$hassidepost) { +if ($showsidepre && !$showsidepost) { $bodyclasses[] = 'side-pre-only'; -} else if ($hassidepost && !$hassidepre) { +} else if ($showsidepost && !$showsidepre) { $bodyclasses[] = 'side-post-only'; -} else if (!$hassidepost && !$hassidepre) { +} else if (!$showsidepost && !$showsidepre) { $bodyclasses[] = 'content-only'; } +if ($hascustommenu) { + $bodyclasses[] = 'has_custom_menu'; +} echo $OUTPUT->doctype() ?> htmlattributes() ?>> @@ -49,6 +59,10 @@ echo $OUTPUT->doctype() ?>
+ +
+ + -
+
blocks_for_region('side-pre') ?>
@@ -84,7 +98,7 @@ echo $OUTPUT->doctype() ?> -
+
blocks_for_region('side-post') ?>
diff --git a/theme/canvas/layout/report.php b/theme/canvas/layout/report.php index fce6e89e427..9141174123d 100644 --- a/theme/canvas/layout/report.php +++ b/theme/canvas/layout/report.php @@ -3,17 +3,23 @@ $hasheading = ($PAGE->heading); $hasnavbar = (empty($PAGE->layout_options['nonavbar']) && $PAGE->has_navbar()); $hasfooter = (empty($PAGE->layout_options['nofooter'])); -$hassidepre = $PAGE->blocks->region_has_content('side-pre', $OUTPUT); -$hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT); +$hassidepre = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('side-pre', $OUTPUT)); +$haslogininfo = (empty($PAGE->layout_options['nologininfo'])); + +$showsidepre = ($hassidepre && !$PAGE->blocks->region_completely_docked('side-pre', $OUTPUT)); + +$custommenu = $OUTPUT->custom_menu(); +$hascustommenu = (empty($PAGE->layout_options['nocustommenu']) && !empty($custommenu)); $bodyclasses = array(); -if ($hassidepre && !$hassidepost) { +if ($showsidepre ) { $bodyclasses[] = 'side-pre-only'; -} else if ($hassidepost && !$hassidepre) { - $bodyclasses[] = 'side-post-only'; -} else if (!$hassidepost && !$hassidepre) { +} else { $bodyclasses[] = 'content-only'; } +if ($hascustommenu) { + $bodyclasses[] = 'has_custom_menu'; +} echo $OUTPUT->doctype() ?> htmlattributes() ?>> @@ -49,6 +55,10 @@ echo $OUTPUT->doctype() ?>
+ +
+ + '; From eac75f211dd11adee21ed13b4e0131ba0695234c Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Fri, 27 Jul 2012 18:12:47 +0800 Subject: [PATCH 65/73] MDL-34553 accessibility compliance for authentication: Add forform input text and select tag --- auth/cas/config.html | 28 ++++++++++++++-------------- auth/fc/config.html | 24 ++++++++++++------------ auth/imap/config.html | 14 +++++++------- auth/ldap/config.html | 2 +- auth/mnet/config.html | 6 +++--- auth/nntp/config.html | 12 ++++++------ auth/pop3/config.html | 18 +++++++++--------- auth/radius/config.html | 18 +++++++++--------- auth/shibboleth/config.html | 24 ++++++++++++------------ auth/shibboleth/index_form.html | 4 ++-- 10 files changed, 75 insertions(+), 75 deletions(-) diff --git a/auth/cas/config.html b/auth/cas/config.html index 4781cb90ffa..28557dda239 100644 --- a/auth/cas/config.html +++ b/auth/cas/config.html @@ -94,9 +94,9 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + - + error_text($err['hostname']); } ?> @@ -105,10 +105,10 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + - + error_text($err['baseuri']); } ?> @@ -117,10 +117,10 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + - + error_text($err['port']); } ?> @@ -129,7 +129,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + : - : + : language, false); ?> @@ -155,7 +155,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + : proxycas, false); ?> @@ -165,7 +165,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + : logoutcas, false); ?> @@ -174,7 +174,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + : multiauth, false); ?> @@ -183,7 +183,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + : certificate_check, false); ?> @@ -192,7 +192,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - : + error_text($err['certificate_path']); ?> @@ -219,7 +219,7 @@ $yesno = array( get_string('no'), get_string('yes') ); - + - : + - + error_text($err["host"]); ?> @@ -38,9 +38,9 @@ - : + - + error_text($err["host"]); ?> @@ -49,9 +49,9 @@ - : + - + error_text($err["userid"]); ?> @@ -59,9 +59,9 @@ - : + - + error_text($err["passwd"]); ?> @@ -70,9 +70,9 @@ - : + - + error_text($err["creators"]); ?> @@ -81,9 +81,9 @@ - : + - + changepasswordurl)) { - + - + - + - +
: - + changepasswordurl)) {
: : changepasswordurl)) {
: - + changepasswordurl)) {
: - +
- + mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode !== 'strict' - + +
: - + mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode !== 'strict' - : : changepasswordurl)) { - + - + - +
: - + changepasswordurl)) {
: - + changepasswordurl)) {
: - + changepasswordurl)) { - + - + - + - + - +
: - + changepasswordurl)) {
: : changepasswordurl)) {
: - + changepasswordurl)) {
: - + changepasswordurl)) {
: - + changepasswordurl)) { - + - + - + - + - + - + - + - + + + + '; diff --git a/course/scales.php b/course/scales.php index 37d64738c2e..d212489c8b6 100644 --- a/course/scales.php +++ b/course/scales.php @@ -70,7 +70,8 @@ if ($scaleid) { echo $OUTPUT->box_start(); echo $OUTPUT->heading($scale->name); echo "
"; - echo html_writer::select($scalemenu, 'unused'); + echo html_writer::label(get_string('scales'), 'scaleunused'. $scaleid, false, array('class' => 'accesshide')); + echo html_writer::select($scalemenu, 'unused', '', array('' => 'choosedots'), array('id' => 'scaleunused'.$scaleid)); echo "
"; echo text_to_html($scale->description); echo $OUTPUT->box_end(); @@ -101,7 +102,8 @@ if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name AS echo $OUTPUT->box_start(); echo $OUTPUT->heading($scale->name); echo "
"; - echo html_writer::select($scalemenu, 'unused'); + echo html_writer::label(get_string('scales'), 'courseunused' . $scale->id, false, array('class' => 'accesshide')); + echo html_writer::select($scalemenu, 'unused', '', array('' => 'choosedots'), array('id' => 'courseunused' . $scale->id)); echo "
"; echo text_to_html($scale->description); echo $OUTPUT->box_end(); @@ -127,7 +129,8 @@ if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) { echo $OUTPUT->box_start(); echo $OUTPUT->heading($scale->name); echo "
"; - echo html_writer::select($scalemenu, 'unused'); + echo html_writer::label(get_string('scales'), 'sitescale' . $scale->id, false, array('class' => 'accesshide')); + echo html_writer::select($scalemenu, 'unused', '', array('' => 'choosedots'), array('id' => 'sitescale' . $scale->id)); echo "
"; echo text_to_html($scale->description); echo $OUTPUT->box_end(); diff --git a/course/search.php b/course/search.php index 246577cd034..8c9f85cd156 100644 --- a/course/search.php +++ b/course/search.php @@ -377,6 +377,7 @@ if ($courses) { echo "\n"; echo "\n"; // Select box should only show categories in which user has min capability to move course. + echo html_writer::label(get_string('moveselectedcoursesto'), 'movetoid', false, array('class' => 'accesshide')); echo html_writer::select($usercatlist, 'moveto', '', array(''=>get_string('moveselectedcoursesto')), array('id'=>'movetoid')); $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false)); echo "\n\n"; From a8b8f472bd49f8ab9c0e12fbcca1142eae09ae79 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Wed, 1 Aug 2012 09:05:32 +0800 Subject: [PATCH 69/73] MDL-34599 mod_quiz: optional $thispage & $nextpage The previous change making the params required was a regression. --- mod/quiz/processattempt.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/quiz/processattempt.php b/mod/quiz/processattempt.php index 9f391f04ecf..aa4a171f35c 100644 --- a/mod/quiz/processattempt.php +++ b/mod/quiz/processattempt.php @@ -38,8 +38,8 @@ $timenow = time(); // Get submitted parameters. $attemptid = required_param('attempt', PARAM_INT); -$thispage = required_param('thispage', PARAM_INT); -$nextpage = required_param('nextpage', PARAM_INT); +$thispage = optional_param('thispage', 0, PARAM_INT); +$nextpage = optional_param('nextpage', 0, PARAM_INT); $next = optional_param('next', false, PARAM_BOOL); $finishattempt = optional_param('finishattempt', false, PARAM_BOOL); $timeup = optional_param('timeup', 0, PARAM_BOOL); // True if form was submitted by timer. From d3d1fec286e298f81bfe8368f74f7a90536b1a48 Mon Sep 17 00:00:00 2001 From: Aparup Banerjee Date: Wed, 1 Aug 2012 09:34:31 +0800 Subject: [PATCH 70/73] MDL-31288 assignment : shifted upgrade block to after 2.3 upgrade line. --- mod/assign/db/upgrade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/assign/db/upgrade.php b/mod/assign/db/upgrade.php index d85a572513c..e12e781d81f 100644 --- a/mod/assign/db/upgrade.php +++ b/mod/assign/db/upgrade.php @@ -46,6 +46,10 @@ function xmldb_assign_upgrade($oldversion) { // Assign savepoint reached. upgrade_mod_savepoint(true, 2012051700, 'assign'); } + + // Moodle v2.3.0 release upgrade line + // Put any upgrade step following this + if ($oldversion < 2012071800) { // Define field requiresubmissionstatement to be added to assign @@ -61,10 +65,6 @@ function xmldb_assign_upgrade($oldversion) { upgrade_mod_savepoint(true, 2012071800, 'assign'); } - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - return true; } From 4c7f536379840f2f4752d449d1aa36cf8add3a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Wed, 1 Aug 2012 08:30:28 +0200 Subject: [PATCH 71/73] MDL-34368 fix another validuntil condition --- webservice/lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webservice/lib.php b/webservice/lib.php index b383c74d42e..66ed91f8f8e 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -1612,7 +1612,7 @@ abstract class webservice_base_server extends webservice_server { FROM {external_services} s JOIN {external_services_functions} sf ON (sf.externalserviceid = s.id AND s.restrictedusers = 1 AND sf.functionname = :name2) JOIN {external_services_users} su ON (su.externalserviceid = s.id AND su.userid = :userid) - WHERE s.enabled = 1 AND su.validuntil IS NULL OR su.validuntil < :now $wscond2"; + WHERE s.enabled = 1 AND (su.validuntil IS NULL OR su.validuntil < :now) $wscond2"; $params = array_merge($params, array('userid'=>$USER->id, 'name1'=>$function->name, 'name2'=>$function->name, 'now'=>time())); $rs = $DB->get_recordset_sql($sql, $params); From d590ffdc68d763feca60e1b88c5f179442ca578e Mon Sep 17 00:00:00 2001 From: Aparup Banerjee Date: Wed, 1 Aug 2012 17:09:54 +0800 Subject: [PATCH 72/73] MDL-31288 Assignment : fixed requiresubmission setting states --- mod/assign/mod_form.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index aef0d91ae9b..afc94848644 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -92,9 +92,9 @@ class mod_assign_mod_form extends moodleform_mod { $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign'); $mform->setDefault('submissiondrafts', 0); // submission statement - if (!empty($config->requiresubmissionstatement)) { + if (empty($config->requiresubmissionstatement)) { $mform->addElement('selectyesno', 'requiresubmissionstatement', get_string('requiresubmissionstatement', 'assign')); - $mform->setDefault('requiresubmissionstatement', !empty($config->submissionstatement)); + $mform->setDefault('requiresubmissionstatement', 0); $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign'); } else { $mform->addElement('hidden', 'requiresubmissionstatement', 1); From 470d47f512b3a1e0e16021611c2bb3e3b5ab47e0 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 2 Aug 2012 14:38:14 +0800 Subject: [PATCH 73/73] weekly release 2.4dev --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 0b22e59c500..6f790c025fb 100644 --- a/version.php +++ b/version.php @@ -30,11 +30,11 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012072600.01; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012080200.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes -$release = '2.4dev (Build: 20120726)'; // Human-friendly version name +$release = '2.4dev (Build: 20120802)'; // Human-friendly version name $branch = '24'; // this version's branch $maturity = MATURITY_ALPHA; // this version's maturity level
: - + changepasswordurl)) {
: - + changepasswordurl)) {
: : changepasswordurl)) {
: - + changepasswordurl)) {
: - +
: - +
: - + convert_data and $config->convert_data != '' and !is_readable($config->convert_data)) { @@ -82,9 +82,9 @@ urn:mace:organization2:providerID, Example Organization 2, /Shibboleth.sso/WAYF/
: - - : - - : - - : - +
-

+

- Date: Fri, 27 Jul 2012 18:12:57 +0800 Subject: [PATCH 66/73] MDL-34554 accessibility compliance for blocks: Add forform input text and select tag --- blocks/section_links/config_instance.html | 4 ++-- blocks/tags/block_tags.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/blocks/section_links/config_instance.html b/blocks/section_links/config_instance.html index efc2fbc4238..a2765dafd25 100644 --- a/blocks/section_links/config_instance.html +++ b/blocks/section_links/config_instance.html @@ -66,7 +66,7 @@ for($i = 1; $i < 3; $i++){ ?>
- : + @@ -77,7 +77,7 @@ for($i = 1; $i < 3; $i++){
- : + diff --git a/blocks/tags/block_tags.php b/blocks/tags/block_tags.php index 70722b6a2cd..0e2e341cb89 100644 --- a/blocks/tags/block_tags.php +++ b/blocks/tags/block_tags.php @@ -224,7 +224,6 @@ class block_tags extends block_base { if ($officialtags) { $this->content->text .= $officialtagscontent; } if ($coursetags) { $this->content->text .= $coursetagscontent; } if ($commtags) { $this->content->text .= $commtagscontent; } - // add the input form section (allowing a user to tag the current course) and navigation, or loggin message if ($loggedin) { // only show the input form on course pages for those allowed (or not barred) @@ -249,7 +248,8 @@ class block_tags extends block_base {
- + +
Date: Fri, 27 Jul 2012 18:13:06 +0800 Subject: [PATCH 67/73] MDL-34555 accessibility compliance for calendar: Add forform input text and select tag --- calendar/lib.php | 1 + calendar/renderer.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/calendar/lib.php b/calendar/lib.php index dcb5e8a987a..8812c6310bc 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -1619,6 +1619,7 @@ function calendar_print_month_selector($name, $selected) { for ($i=1; $i<=12; $i++) { $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B'); } + echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide')); echo html_writer::select($months, $name, $selected, false); } diff --git a/calendar/renderer.php b/calendar/renderer.php index 60e3a743174..45a6404a242 100644 --- a/calendar/renderer.php +++ b/calendar/renderer.php @@ -710,7 +710,9 @@ class core_calendar_renderer extends plugin_renderer_base { $select = new single_select(new moodle_url(CALENDAR_URL.'set.php', array('return' => base64_encode($returnurl->out(false)), 'var' => 'setcourse', 'sesskey'=>sesskey())), 'id', $courseoptions, $selected, null); $select->class = 'cal_courses_flt'; if ($label !== null) { - $select->label = $label; + $select->set_label($label); + } else { + $select->set_label(get_string('listofcourses'), array('class' => 'accesshide')); } return $this->output->render($select); } From 70ad5136da4397a778c8e30f04d9b723197c2836 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Fri, 27 Jul 2012 18:13:16 +0800 Subject: [PATCH 68/73] MDL-34556 accessibility compliance for course: Add forform input text and select tag --- course/category.php | 1 + course/index.php | 1 + course/scales.php | 9 ++++++--- course/search.php | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/course/category.php b/course/category.php index 91efb2d199b..f88d867082b 100644 --- a/course/category.php +++ b/course/category.php @@ -422,6 +422,7 @@ if (!$courses) { make_categories_list($movetocategories, $notused, 'moodle/category:manage'); $movetocategories[$category->id] = get_string('moveselectedcoursesto'); echo '
'; + echo html_writer::label(get_string('moveselectedcoursesto'), 'movetoid', false, array('class' => 'accesshide')); echo html_writer::select($movetocategories, 'moveto', $category->id, null, array('id'=>'movetoid')); $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false)); echo ''; diff --git a/course/index.php b/course/index.php index 3a40df856c1..66435ef0cb4 100644 --- a/course/index.php +++ b/course/index.php @@ -369,6 +369,7 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $ } $popupurl = new moodle_url("index.php?move=$category->id&sesskey=".sesskey()); $select = new single_select($popupurl, 'moveto', $tempdisplaylist, $category->parent, null, "moveform$category->id"); + $select->set_label(get_string('frontpagecategorynames'), array('class' => 'accesshide')); echo $OUTPUT->render($select); } echo '