@ -228,39 +228,62 @@ function construct_session_full_date_time($datetime, $duration) {
return $sessinfo;
return $sessinfo;
}
}
function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade, $decimalpoints ) {
function construct_user_data_stat($usersummary, $view ) {
global $OUTPUT;
global $OUTPUT;
if (empty($usersummary)) {
return 'no data';
}
$stattable = new html_table();
$stattable = new html_table();
$stattable->attributes['class'] = 'attlist';
$stattable->attributes['class'] = 'attlist';
$row = new html_table_row();
$row = new html_table_row();
$row->cells[] = get_string('sessionscompleted', 'attendance').':';
$row->attributes['class'] = 'normal';
$row->cells[] = $stat['completed'];
$row->cells[] = get_string('sessionscompleted', 'attendance') . ':';
$row->cells[] = $usersummary->numtakensessions;
$stattable->data[] = $row;
$row = new html_table_row();
$row->attributes['class'] = 'normal';
$row->cells[] = get_string('pointssessionscompleted', 'attendance') . ':';
$row->cells[] = attendance_format_float($usersummary->takensessionspoints) . ' / ' . attendance_format_float($usersummary->takensessionsmaxpoints);
$stattable->data[] = $row;
$stattable->data[] = $row;
foreach ($statuses as $st) {
$row = new html_table_row();
$row->attributes['class'] = 'normal';
$row->cells[] = get_string('percentagesessionscompleted', 'attendance') . ':';
$row->cells[] = attendance_format_float($usersummary->takensessionspercentage * 100, false) . '%';
$stattable->data[] = $row;
if ($view == ATT_VIEW_ALL) {
$row = new html_table_row();
$row = new html_table_row();
$row->cells[] = $st->description . ':';
$row->attributes['class'] = 'highlight';
$row->cells[] = array_key_exists($st->id, $stat['statuses']) ? $stat['statuses'][$st->id]->stcnt : 0;
$row->cells[] = get_string('sessionstotal', 'attendance') . ':';
$row->cells[] = attendance_format_float($usersummary->numallsessions);
$stattable->data[] = $row;
$row = new html_table_row();
$row->attributes['class'] = 'highlight';
$row->cells[] = get_string('pointsallsessions', 'attendance') . ':';
$row->cells[] = attendance_format_float($usersummary->takensessionspoints) . ' / ' . attendance_format_float($usersummary->allsessionsmaxpoints);
$stattable->data[] = $row;
$stattable->data[] = $row;
}
if ($gradable) {
$row = new html_table_row();
$row = new html_table_row();
$row->cells[] = get_string('attendancegrade', 'attendance') .
$row->attributes['class'] = 'highlight';
$OUTPUT->help_icon('gradebookexplanation ', 'attendance') . ':';
$row->cells[] = get_string('percentageallsessions ', 'attendance') . ':';
$row->cells[] = format_float($grade) . ' / ' . format_float($maxgrade) ;
$row->cells[] = attendance_format_float($usersummary->allsessionspercentage * 100, false) . '%' ;
$stattable->data[] = $row;
$stattable->data[] = $row;
$row = new html_table_row();
$row = new html_table_row();
$row->cells[] = get_string('attendancepercent', 'attendance') . ':';
$row->attributes['class'] = 'normal';
if ($maxgrade == 0) {
$row->cells[] = get_string('maxpossiblepoints', 'attendance') . ':';
$percent = 0;
$row->cells[] = attendance_format_float($usersummary->maxpossiblepoints) . ' / ' . attendance_format_float($usersummary->allsessionsmaxpoints);
} else {
$stattable->data[] = $row;
$percent = $grade / $maxgrade * 100;
}
$row = new html_table_row();
$row->cells[] = format_float(sprintf("%0.{$decimalpoints}f", $percent));
$row->attributes['class'] = 'normal';
$row->cells[] = get_string('maxpossiblepercentage', 'attendance') . ':';
$row->cells[] = attendance_format_float($usersummary->maxpossiblepercentage * 100, false) . '%';
$stattable->data[] = $row;
$stattable->data[] = $row;
}
}
@ -268,25 +291,6 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
}
}
function construct_full_user_stat_html_table($attendance, $course, $user, $coursemodule) {
function construct_full_user_stat_html_table($attendance, $course, $user, $coursemodule) {
global $CFG;
$summary = new mod_attendance_summary($attendance->id, $user->id);
$gradeable = $attendance->grade > 0;
return construct_user_data_stat($summary->get_all_sessions_summary_for($user->id), ATT_VIEW_ALL);
$statuses = attendance_get_statuses($attendance->id);
$userstatusesstat = attendance_get_user_statuses_stat($attendance->id, $course->startdate, $user->id, $coursemodule);
$stat['completed'] = attendance_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id, $coursemodule);
$stat['statuses'] = $userstatusesstat;
if ($gradeable) {
$grade = attendance_get_user_grade($userstatusesstat, $statuses);
$maxgrade = attendance_get_user_max_grade(attendance_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id, $coursemodule), $statuses);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints;
}
} else {
$grade = 0;
$maxgrade = 0;
$decimalpoints = 0;
}
return construct_user_data_stat($stat, $statuses,
$gradeable, $grade, $maxgrade, $decimalpoints);
}
}