Browse Source

More specific use of module context instead of global $PAGE use.

MOODLE_29_STABLE
Dan Marsden 10 years ago
parent
commit
4b9af8a95c
  1. 8
      export.php
  2. 9
      manage.php
  3. 6
      preferences.php
  4. 3
      renderables.php
  5. 6
      report.php
  6. 8
      sessions.php
  7. 3
      tempedit.php
  8. 3
      tempusers.php
  9. 16
      view.php

8
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()) {

9
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)));
}

6
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'));

3
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'));
}

6
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');

8
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));

3
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);

3
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);

16
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.

Loading…
Cancel
Save