public function __construct(attendance $att)
 {
     global $CFG;
     $this->perm = $att->perm;
     $currenttime = time();
     if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) {
         $att->pageparams->enddate = $currenttime;
     }
     $this->pageparams = $att->pageparams;
     $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
     if (isset($att->pageparams->userids)) {
         foreach ($this->users as $key => $user) {
             if (!in_array($user->id, $att->pageparams->userids)) {
                 unset($this->users[$key]);
             }
         }
     }
     $this->groups = groups_get_all_groups($att->course->id);
     $this->sessions = $att->get_filtered_sessions();
     $this->statuses = $att->get_statuses(true, true);
     $this->allstatuses = $att->get_statuses(false, true);
     $this->gradable = $att->grade > 0;
     if (!($this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints'))) {
         $this->decimalpoints = $CFG->grade_decimalpoints;
     }
     $maxgrade = att_get_user_max_grade(count($this->sessions), $this->statuses);
     foreach ($this->users as $key => $user) {
         $grade = 0;
         if ($this->gradable) {
             $grade = $att->get_user_grade($user->id, array('enddate' => $currenttime));
             $totalgrade = $att->get_user_grade($user->id);
         }
         if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || $grade < $maxgrade) {
             $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id);
             $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id);
             $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id);
             if ($this->gradable) {
                 $this->grades[$user->id] = $totalgrade;
                 $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id);
             }
         } else {
             unset($this->users[$key]);
         }
     }
     $this->att = $att;
 }
 public function __construct(attendance $att)
 {
     global $CFG;
     $this->perm = $att->perm;
     $this->pageparams = $att->pageparams;
     $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
     $this->groups = groups_get_all_groups($att->course->id);
     $this->sessions = $att->get_filtered_sessions();
     $this->statuses = $att->get_statuses();
     $this->allstatuses = $att->get_statuses(false);
     $this->gradable = $att->grade > 0;
     if (!($this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints'))) {
         $this->decimalpoints = $CFG->grade_decimalpoints;
     }
     foreach ($this->users as $user) {
         $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id);
         $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id);
         $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id);
         if ($this->gradable) {
             $this->grades[$user->id] = $att->get_user_grade($user->id);
             $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id);
         }
     }
     $this->att = $att;
 }
示例#3
0
    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 = local_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 = local_att_get_statuses($ca->attid);
                $user_taken_sessions_count = local_att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid);
                $user_statuses_stat = local_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] = local_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] = local_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;
    }