Skip to content

Commit

Permalink
MDL-31607 use full course object for require_login() if already avail…
Browse files Browse the repository at this point in the history
…able

This eliminates 1 db query.
  • Loading branch information
skodak committed Apr 22, 2012
1 parent ead4f18 commit cdbea7e
Show file tree
Hide file tree
Showing 85 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion course/completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}
require_login($course->id);
require_login($course);
require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));

} else {
Expand Down
2 changes: 1 addition & 1 deletion course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
if (is_array($aroles) && isset($aroles[$switchrole])) {
role_switch($switchrole, $context);
// Double check that this role is allowed here
require_login($course->id);
require_login($course);
}
// reset course page state - this prevents some weird problems ;-)
$USER->activitycopy = false;
Expand Down
2 changes: 1 addition & 1 deletion file.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
}

if ($course->id != SITEID) {
require_login($course->id, true, null, false);
require_login($course, true, null, false);

} else if ($CFG->forcelogin) {
if (!empty($CFG->sitepolicy)
Expand Down
2 changes: 1 addition & 1 deletion grade/report/grader/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
print_error('nocourseid');
}

require_login($course->id);
require_login($course);

$context = get_context_instance(CONTEXT_COURSE, $course->id);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
Expand Down
2 changes: 1 addition & 1 deletion grade/report/outcomes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
print_error('nocourseid');
}

require_login($course->id);
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);

require_capability('gradereport/outcomes:view', $context);
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

$PAGE->set_url($url);
require_login($course->id, false, $cm);
require_login($course, false, $cm);

/// Load up the required assignment code
require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/submissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$url->param('mode', $mode);
}
$PAGE->set_url($url);
require_login($course->id, false, $cm);
require_login($course, false, $cm);

require_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id));

Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/type/online/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
print_error('usermisconf', 'assignment');
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (($USER->id != $user->id) && !has_capability('mod/assignment:grade', $context)) {
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/type/upload/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ function delete_file() {
$mode = optional_param('mode', '', PARAM_ALPHA);
$offset = optional_param('offset', 0, PARAM_INT);

require_login($this->course->id, false, $this->cm);
require_login($this->course, false, $this->cm);

if (empty($mode)) {
$urlreturn = 'view.php';
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/type/upload/notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
print_error("invaliduserid");
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

if (!has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
print_error('cannotviewassignment', 'assignment');
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

$PAGE->set_url($url);
require_login($course->id, false, $cm);
require_login($course, false, $cm);

/// Load up the required assignment code
require_once($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_ajax/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id, false, MUST_EXIST);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course->id, false, $cm);
require_login($course, false, $cm);
require_capability('mod/chat:chat', $context);

/// Check to see if groups are being used here
Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_basic/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course->id, false, $cm);
require_login($course, false, $cm);
require_capability('mod/chat:chat', $context);
$PAGE->set_pagelayout('base');

Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_header_js/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$context = get_context_instance(CONTEXT_MODULE, $cm->id);

require_login($course->id, false, $cm);
require_login($course, false, $cm);

require_capability('mod/chat:chat', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/chat/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$PAGE->set_context($context);

require_login($course->id, false, $cm);
require_login($course, false, $cm);

if (empty($chat->studentlogs) && !has_capability('mod/chat:readlog', $context)) {
notice(get_string('nopermissiontoseethechatlog', 'chat'));
Expand Down
2 changes: 1 addition & 1 deletion mod/choice/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
print_error("coursemisconf");
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);

Expand Down
2 changes: 1 addition & 1 deletion mod/data/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

if (isguestuser()) {
redirect('view.php?d='.$data->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/data/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
print_error('invalidcontext', '');
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);
require_capability(DATA_CAP_EXPORT, $context);

// get fields for this database
Expand Down
2 changes: 1 addition & 1 deletion mod/data/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
}
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:managetemplates', $context);
Expand Down
2 changes: 1 addition & 1 deletion mod/data/preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$cm = get_coursemodule_from_instance('data', $data->id, $course->id, null, MUST_EXIST);
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
require_login($course->id, false, $cm);
require_login($course, false, $cm);
require_capability('mod/data:managetemplates', $context);
$PAGE->set_url(new moodle_url('/mod/data/preset.php', array('d'=>$data->id)));
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
Expand Down
2 changes: 1 addition & 1 deletion mod/data/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:managetemplates', $context);
Expand Down
4 changes: 2 additions & 2 deletions mod/feedback/analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
}

if ($course->id == SITEID) {
require_login($course->id, true);
require_login($course, true);
} else {
require_login($course->id, true, $cm);
require_login($course, true, $cm);
}

//check whether the given courseid exists
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/analysis_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
print_error('error');
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/analysis_to_excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:viewreports', $context);

Expand Down
4 changes: 2 additions & 2 deletions mod/feedback/complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@

if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
if ($course->id == SITEID) {
require_login($course->id, true);
require_login($course, true);
} else {
require_login($course->id, true, $cm);
require_login($course, true, $cm);
}
} else {
if ($course->id == SITEID) {
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/delete_completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:deletesubmissions', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/delete_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:edititems', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/delete_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:deletetemplate', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:edititems', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/edit_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:edititems', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:edititems', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:edititems', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
print_error('badcontext');
}

require_login($course->id);
require_login($course);
$PAGE->set_pagelayout('incourse');

add_to_log($course->id, 'feedback', 'view all', $url->out(false), $course->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/mapcourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:mapcourse', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:view', $context);
$PAGE->set_pagelayout('embedded');
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/show_entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey');
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/show_entries_anonym.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:viewreports', $context);

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/show_nonrespondents.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey');
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/use_templ.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
print_error('badcontext');
}

require_login($course->id, true, $cm);
require_login($course, true, $cm);

require_capability('mod/feedback:edititems', $context);

Expand Down
4 changes: 2 additions & 2 deletions mod/feedback/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@

if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
if ($course->id == SITEID) {
require_login($course->id, true);
require_login($course, true);
} else {
require_login($course->id, true, $cm);
require_login($course, true, $cm);
}
} else {
if ($course->id == SITEID) {
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

if (is_null($mode) and !is_enrolled($context, $USER, '', true)) { // Guests and visitors can't subscribe - only enrolled
$PAGE->set_title($course->shortname);
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/subscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$cm->id = 0;
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/forum:viewsubscribers', $context)) {
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/deleteentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
print_error('invalidentry');
}

require_login($course->id, false, $cm);
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$manageentries = has_capability('mod/glossary:manageentries', $context);

Expand Down
Loading

0 comments on commit cdbea7e

Please sign in to comment.