/**
  * 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;
 }
 public function __construct(attendance $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 attendance_filter_controls($att);
         $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
         $this->groups = groups_get_all_groups($att->course->id);
     } 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, $att->cm);
             $user_statuses_stat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid, $att->cm);
             $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;
 }
示例#3
0
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_ALPHANUMEXT);
$pageparams->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', null, 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);
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/attendance:takeattendances', $PAGE->context);
        $canchange = $sess->lasttaken && has_capability('mod/attendance:changeattendances', $PAGE->context);
        if ($nottaken || $canchange) {
            redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid)));
        }
    } else {
        if ($size > 1) {
            $att->curdate = $today;
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.
    $userid = $USER->id;
}
$userdata = new attendance_user_data($att, $userid);
echo $output->header();