diff --git a/export.php b/export.php index ca5d445..6e46d3f 100644 --- a/export.php +++ b/export.php @@ -35,9 +35,11 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUS $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); -require_capability('mod/attendance:export', $PAGE->context); -$att = new attendance($att, $cm, $course, $PAGE->context); +$context = context_module::instance($cm->id); +require_capability('mod/attendance:export', $context); + +$att = new attendance($att, $cm, $course, $context); $PAGE->set_url($att->url_export()); $PAGE->set_title($course->shortname. ": ".$att->name); @@ -46,7 +48,7 @@ $PAGE->set_cacheable(true); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance')); $PAGE->navbar->add(get_string('export', 'attendance')); -$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context); +$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context); $mform = new mod_attendance_export_form($att->url_export(), $formparams); if ($formdata = $mform->get_data()) { diff --git a/manage.php b/manage.php index 27709d6..5d13a52 100644 --- a/manage.php +++ b/manage.php @@ -39,17 +39,18 @@ $att = $DB->get_record('attendance', array('id' => $cm->instance), '* require_login($course, true, $cm); +$context = context_module::instance($cm->id); $capabilities = array( 'mod/attendance:manageattendances', 'mod/attendance:takeattendances', 'mod/attendance:changeattendances' ); -if (!has_any_capability($capabilities, $PAGE->context)) { +if (!has_any_capability($capabilities, $context)) { redirect($att->url_view()); } $pageparams->init($cm); -$att = new attendance($att, $cm, $course, $PAGE->context, $pageparams); +$att = new attendance($att, $cm, $course, $context, $pageparams); // If teacher is coming from block, then check for a session exists for today. if ($from === 'block') { @@ -57,8 +58,8 @@ if ($from === 'block') { $size = count($sessions); if ($size == 1) { $sess = reset($sessions); - $nottaken = !$sess->lasttaken && has_capability('mod/attendance:takeattendances', $PAGE->context); - $canchange = $sess->lasttaken && has_capability('mod/attendance:changeattendances', $PAGE->context); + $nottaken = !$sess->lasttaken && has_capability('mod/attendance:takeattendances', $context); + $canchange = $sess->lasttaken && has_capability('mod/attendance:changeattendances', $context); if ($nottaken || $canchange) { redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid))); } diff --git a/preferences.php b/preferences.php index 1c4c0dd..795bc77 100644 --- a/preferences.php +++ b/preferences.php @@ -37,7 +37,9 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUS $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); -require_capability('mod/attendance:changepreferences', $PAGE->context); + +$context = context_module::instance($cm->id); +require_capability('mod/attendance:changepreferences', $context); // Make sure the statusset is valid. $maxstatusset = attendance_get_max_statusset($att->id); @@ -45,7 +47,7 @@ if ($pageparams->statusset > $maxstatusset + 1) { $pageparams->statusset = $maxstatusset + 1; } -$att = new attendance($att, $cm, $course, $PAGE->context, $pageparams); +$att = new attendance($att, $cm, $course, $context, $pageparams); $PAGE->set_url($att->url_preferences()); $PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('settings', 'attendance')); diff --git a/renderables.php b/renderables.php index d6fef01..4ce0d91 100644 --- a/renderables.php +++ b/renderables.php @@ -78,8 +78,7 @@ class attendance_tabs implements renderable { $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), get_string('add', 'attendance')); } - - if ($this->att->perm->can_view_reports()) { + if (has_capability('mod/attendance:viewreports', $this->att->context)) { $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), get_string('report', 'attendance')); } diff --git a/report.php b/report.php index 8ecabe2..81510b2 100644 --- a/report.php +++ b/report.php @@ -41,10 +41,12 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUS $attrecord = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); -require_capability('mod/attendance:viewreports', $PAGE->context); + +$context = context_module::instance($cm->id); +require_capability('mod/attendance:viewreports', $context); $pageparams->init($cm); -$att = new attendance($attrecord, $cm, $course, $PAGE->context, $pageparams); +$att = new attendance($attrecord, $cm, $course, $context, $pageparams); $PAGE->set_url($att->url_report()); $PAGE->set_pagelayout('report'); diff --git a/sessions.php b/sessions.php index e4350d0..3aa8e8c 100644 --- a/sessions.php +++ b/sessions.php @@ -45,9 +45,11 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUS $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); -require_capability('mod/attendance:manageattendances', $PAGE->context); -$att = new attendance($att, $cm, $course, $PAGE->context, $pageparams); +$context = context_module::instance($cm->id); +require_capability('mod/attendance:manageattendances', $context); + +$att = new attendance($att, $cm, $course, $context, $pageparams); $PAGE->set_url($att->url_sessions(array('action'=>$pageparams->action))); $PAGE->set_title($course->shortname. ": ".$att->name); @@ -56,7 +58,7 @@ $PAGE->set_cacheable(true); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance')); $PAGE->navbar->add($att->name); -$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'att' => $att); +$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'att' => $att); switch ($att->pageparams->action) { case att_sessions_page_params::ACTION_ADD: $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); diff --git a/tempedit.php b/tempedit.php index 0422e0c..2a66026 100644 --- a/tempedit.php +++ b/tempedit.php @@ -46,7 +46,8 @@ if ($action) { $PAGE->set_url($att->url_tempedit($params)); require_login($course, true, $cm); -require_capability('mod/attendance:managetemporaryusers', $PAGE->context); +$context = context_module::instance($cm->id); +require_capability('mod/attendance:managetemporaryusers', $context); $PAGE->set_title($course->shortname.": ".$att->name.' - '.get_string('tempusersedit', 'attendance')); $PAGE->set_heading($course->fullname); diff --git a/tempusers.php b/tempusers.php index e3dbe49..38c56ba 100644 --- a/tempusers.php +++ b/tempusers.php @@ -37,7 +37,8 @@ $att = new attendance($att, $cm, $course); $PAGE->set_url($att->url_managetemp()); require_login($course, true, $cm); -require_capability('mod/attendance:managetemporaryusers', $PAGE->context); +$context = context_module::instance($cm->id); +require_capability('mod/attendance:managetemporaryusers', $context); $PAGE->set_title($course->shortname.": ".$att->name.' - '.get_string('tempusers', 'attendance')); $PAGE->set_heading($course->fullname); diff --git a/view.php b/view.php index c163555..a7af7a6 100644 --- a/view.php +++ b/view.php @@ -39,17 +39,23 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUS $attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); -require_capability('mod/attendance:view', $PAGE->context); +$context = context_module::instance($cm->id); +require_capability('mod/attendance:view', $context); $pageparams->init($cm); -$att = new attendance($attendance, $cm, $course, $PAGE->context, $pageparams); +$att = new attendance($attendance, $cm, $course, $context, $pageparams); // Not specified studentid for displaying attendance? // Redirect to appropriate page if can. if (!$pageparams->studentid) { - if ($att->perm->can_manage() || $att->perm->can_take() || $att->perm->can_change()) { + $capabilities = array( + 'mod/attendance:manageattendances', + 'mod/attendance:takeattendances', + 'mod/attendance:changeattendances' + ); + if (has_any_capability($capabilities, $context)) { redirect($att->url_manage()); - } else if ($att->perm->can_view_reports()) { + } else if (has_capability('mod/attendance:viewreports', $context)) { redirect($att->url_report()); } } @@ -64,7 +70,7 @@ $output = $PAGE->get_renderer('mod_attendance'); if (isset($pageparams->studentid) && $USER->id != $pageparams->studentid) { // Only users with proper permissions should be able to see any user's individual report. - require_capability('mod/attendance:viewreports', $PAGE->context); + require_capability('mod/attendance:viewreports', $context); $userid = $pageparams->studentid; } else { // A valid request to see another users report has not been sent, show the user's own.