/** * Return array of rows where each row is an array of tab objects * taking into account permissions of current user */ public function get_tabs() { $toprow = array(); $context = $this->att->context; $capabilities = array('mod/attendance:manageattendances', 'mod/attendance:takeattendances', 'mod/attendance:changeattendances'); if (has_any_capability($capabilities, $context)) { $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(), get_string('sessions', 'attendance')); } if (has_capability('mod/attendance:manageattendances', $context)) { $toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), get_string('add', 'attendance')); } if (has_capability('mod/attendance:viewreports', $context)) { $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), get_string('report', 'attendance')); } if (has_capability('mod/attendance:export', $context)) { $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), get_string('export', 'attendance')); } if (has_capability('mod/attendance:changepreferences', $context)) { $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(), get_string('settings', 'attendance')); } if (has_capability('mod/attendance:managetemporaryusers', $context)) { $toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(), get_string('tempusers', 'attendance')); } return array($toprow); }
/** * Return array of rows where each row is an array of tab objects * taking into account permissions of current user */ public function get_tabs() { $toprow = array(); if ($this->att->perm->can_manage() or $this->att->perm->can_take() or $this->att->perm->can_change()) { $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(), get_string('sessions', 'local_attendance')); } if ($this->att->perm->can_manage()) { $toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => local_att_sessions_page_params::ACTION_ADD)), get_string('add', 'local_attendance')); } if ($this->att->perm->can_view_reports()) { $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), get_string('report', 'local_attendance')); } if ($this->att->perm->can_export()) { $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), get_string('export', 'local_attendance')); } if ($this->att->perm->can_change_preferences()) { $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(), get_string('settings', 'local_attendance')); } return array($toprow); }
/** * Gets the content for this block * * @return object $this->content */ public function get_content() { global $CFG, $USER, $COURSE; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->footer = ''; $this->content->text = ''; $attendances = get_all_instances_in_course('attendance', $COURSE, null, true); if (count($attendances) == 0) { $this->content->text = get_string('needactivity', 'block_attendance'); return $this->content; } require_once $CFG->dirroot . '/mod/attendance/locallib.php'; require_once $CFG->dirroot . '/mod/attendance/renderhelpers.php'; foreach ($attendances as $attinst) { $cmid = $attinst->coursemodule; $cm = get_coursemodule_from_id('attendance', $cmid, $COURSE->id, false, MUST_EXIST); $context = context_module::instance($cmid, MUST_EXIST); $divided = $this->divide_databasetable_and_coursemodule_data($attinst); $att = new attendance($divided->atttable, $divided->cm, $COURSE, $context); $this->content->text .= html_writer::link($att->url_view(), html_writer::tag('b', format_string($att->name))); $this->content->text .= html_writer::empty_tag('br'); // Link to attendance. if ($att->perm->can_take() or $att->perm->can_change()) { $this->content->text .= html_writer::link($att->url_manage(array('from' => 'block')), get_string('takeattendance', 'attendance')); $this->content->text .= html_writer::empty_tag('br'); } if ($att->perm->can_manage()) { $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); $this->content->text .= html_writer::link($url, get_string('add', 'attendance')); $this->content->text .= html_writer::empty_tag('br'); } if ($att->perm->can_view_reports()) { $this->content->text .= html_writer::link($att->url_report(), get_string('report', 'attendance')); $this->content->text .= html_writer::empty_tag('br'); } if ($att->perm->can_be_listed() && $att->perm->can_view()) { $this->content->text .= construct_full_user_stat_html_table($attinst, $COURSE, $USER, $cm); } $this->content->text .= "<br />"; } return $this->content; }
$id = required_param('id', PARAM_INT); $from = optional_param('from', null, PARAM_ACTION); $pageparams->view = optional_param('view', null, PARAM_INT); $pageparams->curdate = optional_param('curdate', null, PARAM_INT); $pageparams->group = optional_param('group', null, PARAM_INT); $pageparams->sort = optional_param('sort', null, PARAM_INT); $pageparams->page = optional_param('page', 1, PARAM_INT); $pageparams->perpage = get_config('attendance', 'resultsperpage'); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); $pageparams->init($cm); $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams); $att->perm->require_view_reports_capability(); $PAGE->set_url($att->url_report()); $PAGE->set_pagelayout('report'); $PAGE->set_title($course->shortname . ": " . $att->name . ' - ' . get_string('report', 'attendance')); $PAGE->set_heading($course->fullname); $PAGE->set_cacheable(true); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance')); $PAGE->navbar->add(get_string('report', 'attendance')); $output = $PAGE->get_renderer('mod_attendance'); $tabs = new attendance_tabs($att, attendance_tabs::TAB_REPORT); $filtercontrols = new attendance_filter_controls($att); $reportdata = new attendance_report_data($att); // Trigger a report viewed event. $event = \mod_attendance\event\report_viewed::create(array('objectid' => $att->id, 'context' => $PAGE->context, 'other' => array())); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('attendance', $att); $event->trigger();
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); $context = context_module::instance($cm->id); require_capability('mod/attendance:view', $context); $pageparams->init($cm); $att = new attendance($attendance, $cm, $course, $context, $pageparams); // Not specified studentid for displaying attendance? // Redirect to appropriate page if can. if (!$pageparams->studentid) { $capabilities = array('mod/attendance:manageattendances', 'mod/attendance:takeattendances', 'mod/attendance:changeattendances'); if (has_any_capability($capabilities, $context)) { redirect($att->url_manage()); } else { if (has_capability('mod/attendance:viewreports', $context)) { redirect($att->url_report()); } } } $PAGE->set_url($att->url_view()); $PAGE->set_title($course->shortname . ": " . $att->name); $PAGE->set_heading($course->fullname); $PAGE->set_cacheable(true); $PAGE->navbar->add(get_string('attendancereport', 'attendance')); $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', $context); $userid = $pageparams->studentid; } else { // A valid request to see another users report has not been sent, show the user's own.