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('attforblock', $COURSE, NULL, true); if (count($attendances) == 0) { $this->content->text = get_string('needactivity', 'block_attendance'); return $this->content; } require_once $CFG->dirroot . '/mod/attforblock/locallib.php'; require_once $CFG->dirroot . '/mod/attforblock/renderhelpers.php'; foreach ($attendances as $attinst) { $cmid = $attinst->coursemodule; $context = get_context_instance(CONTEXT_MODULE, $cmid, MUST_EXIST); $divided = $this->divide_databasetable_and_coursemodule_data($attinst); $att = new attforblock($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', 'attforblock')); $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', 'attforblock')); $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', 'attforblock')); $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); } $this->content->text .= "<br />"; } return $this->content; }
$pageparams->studentid = optional_param('studentid', NULL, PARAM_INT); $pageparams->mode = optional_param('mode', att_view_page_params::MODE_THIS_COURSE, PARAM_INT); $pageparams->view = optional_param('view', NULL, PARAM_INT); $pageparams->curdate = optional_param('curdate', NULL, PARAM_INT); $cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $attforblock = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); $pageparams->init($cm); $att = new attforblock($attforblock, $cm, $course, $PAGE->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()) { redirect($att->url_manage()); } elseif ($att->perm->can_view_reports()) { redirect($att->url_report()); } } $att->perm->require_view_capability(); $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', 'attforblock')); $output = $PAGE->get_renderer('mod_attforblock'); $userid = isset($pageparams->studentid) ? $pageparams->studentid : $USER->id; $userdata = new attforblock_user_data($att, $userid); echo $output->header(); echo $output->render($userdata); echo $output->footer();
require_once dirname(__FILE__) . '/../../config.php'; require_once dirname(__FILE__) . '/locallib.php'; $pageparams = new att_manage_page_params(); $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->collapsetype = optional_param('collapsetype', NULL, PARAM_INT); $cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, true, $cm); $pageparams->init($cm); $att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change()) { redirect($att->url_view()); } // if teacher is coming from block, then check for a session exists for today if ($from === 'block') { $sessions = $att->get_today_sessions(); $size = count($sessions); if ($size == 1) { $sess = reset($sessions); $nottaken = !$sess->lasttaken && has_capability('mod/attforblock:takeattendances', $PAGE->context); $canchange = $sess->lasttaken && has_capability('mod/attforblock:changeattendances', $PAGE->context); if ($nottaken || $canchange) { redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid))); } } elseif ($size > 1) { $att->curdate = $today; //temporally set $view for single access to page from block
public function __construct(attforblock $att, $userid) { global $CFG; $this->user = $att->get_user($userid); $this->pageparams = $att->pageparams; if (!($this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints'))) { $this->decimalpoints = $CFG->grade_decimalpoints; } if ($this->pageparams->mode == att_view_page_params::MODE_THIS_COURSE) { $this->statuses = $att->get_statuses(); $this->stat = $att->get_user_stat($userid); $this->gradable = $att->grade > 0; if ($this->gradable) { $this->grade = $att->get_user_grade($userid); $this->maxgrade = $att->get_user_max_grade($userid); } $this->filtercontrols = new attforblock_filter_controls($att); $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid); } else { $this->coursesatts = att_get_user_courses_attendances($userid); $this->statuses = array(); $this->stat = array(); $this->gradable = array(); $this->grade = array(); $this->maxgrade = array(); foreach ($this->coursesatts as $ca) { $statuses = att_get_statuses($ca->attid); $user_taken_sessions_count = att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid); $user_statuses_stat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid); $this->statuses[$ca->attid] = $statuses; $this->stat[$ca->attid]['completed'] = $user_taken_sessions_count; $this->stat[$ca->attid]['statuses'] = $user_statuses_stat; $this->gradable[$ca->attid] = $ca->attgrade > 0; if ($this->gradable[$ca->attid]) { $this->grade[$ca->attid] = att_get_user_grade($user_statuses_stat, $statuses); // For getting sessions count implemented simplest method - taken sessions. // It can have error if users don't have attendance info for some sessions. // In the future we can implement another methods: // * all sessions between user start enrolment date and now; // * all sessions between user start and end enrolment date. $this->maxgrade[$ca->attid] = att_get_user_max_grade($user_taken_sessions_count, $statuses); } else { //for more comfortable and universal work with arrays $this->grade[$ca->attid] = NULL; $this->maxgrade[$ca->attid] = NULL; } } } $this->urlpath = $att->url_view()->out_omit_querystring(); $params = $att->pageparams->get_significant_params(); $params['id'] = $att->cm->id; $this->urlparams = $params; }