Browse Source

Fix #188 and report part of #127, and implements #163 and #38

MOODLE_31_STABLE
Antonio Carlos Mariani 9 years ago
parent
commit
9cb02ba230
  1. 1
      lang/en/attendance.php
  2. 27
      locallib.php
  3. 38
      renderables.php
  4. 54
      renderer.php

1
lang/en/attendance.php

@ -256,6 +256,7 @@ $string['strftimehm'] = '%H:%M'; // Line added to allow display of time.
$string['strftimeshortdate'] = '%d.%m.%Y';
$string['studentid'] = 'Student ID';
$string['takeattendance'] = 'Take attendance';
$string['takensessions'] = 'Taken sessions';
$string['tempaddform'] = 'Add temporary user';
$string['tempexists'] = 'There is already a temporary user with this email address';
$string['tempusers'] = 'Temporary users';

27
locallib.php

@ -256,6 +256,22 @@ function attendance_get_max_statusset($attendanceid) {
return 0;
}
/**
* Returns the maxpoints for each statusset
*
* @param array statuses
* @return array
*/
function attendance_get_statusset_maxpoints($statuses) {
$statussetmaxpoints = array();
foreach ($statuses as $st) {
if (!isset($statussetmaxpoints[$st->setnumber])) {
$statussetmaxpoints[$st->setnumber] = $st->grade;
}
}
return $statussetmaxpoints;
}
/**
* Update user grades
*
@ -302,3 +318,14 @@ function attendance_update_users_grade($attendance, $userids=array()) {
return grade_update('mod/attendance', $course->id, 'mod', 'attendance', $attendance->id, 0, $grades);
}
/**
* Given a float, prints it nicely.
*
* @param float $float The float to print
* @param bool $stripzeros If true, removes final zeros after decimal point
* @return string locale float
*/
function attendance_format_float($float, $stripzeros=true) {
return format_float($float, 1, true, $stripzeros);
}

38
renderables.php

@ -449,25 +449,15 @@ class attendance_report_data implements renderable {
// Includes disablrd/deleted statuses.
public $allstatuses;
public $gradable;
public $decimalpoints;
public $usersgroups = array();
public $sessionslog = array();
public $usersstats = array();
public $grades = array();
public $maxgrades = array();
public $summary = array();
public $att;
public function __construct(mod_attendance_structure $att) {
global $CFG;
$currenttime = time();
if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) {
$att->pageparams->enddate = $currenttime;
@ -492,32 +482,16 @@ class attendance_report_data implements renderable {
$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 = attendance_get_user_max_grade(count($this->sessions), $this->statuses);
$this->summary = new mod_attendance_summary($att->id, array_keys($this->users), $att->pageparams->startdate, $att->pageparams->enddate);
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) {
$usersummary = $this->summary->get_taken_sessions_summary_for($user->id);
if ($att->pageparams->view != ATT_VIEW_NOTPRESENT ||
$usersummary->takensessionspoints < $usersummary->takensessionsmaxpoints ||
$usersummary->takensessionsmaxpoints == 0) {
$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]);
}

54
renderer.php

@ -882,18 +882,17 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->size[] = '1px';
}
foreach ($reportdata->statuses as $status) {
$table->head[] = $status->acronym;
$table->head[] = get_string('takensessions', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$sessionstats[$status->id] = 0;
}
if ($reportdata->gradable) {
$table->head[] = get_string('grade');
$table->head[] = get_string('points', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$table->head[] = get_string('percentage', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
}
if ($bulkmessagecapability) { // Display the table header for bulk messaging.
// The checkbox must have an id of cb_selector so that the JavaScript will pick it up.
@ -910,18 +909,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
$cellsgenerator = new user_sessions_cells_html_generator($reportdata, $user);
$row->cells = array_merge($row->cells, $cellsgenerator->get_cells(true));
foreach ($reportdata->statuses as $status) {
if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) {
$row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt;
} else {
// No attendance data for this $status => no statistic for this status.
$row->cells[] = 0;
}
}
if ($reportdata->gradable) {
$row->cells[] = format_float($reportdata->grades[$user->id]).' / '.format_float($reportdata->maxgrades[$user->id]);
}
$usersummary = $reportdata->summary->get_taken_sessions_summary_for($user->id);
$row->cells[] = $usersummary->numtakensessions;
$row->cells[] = attendance_format_float($usersummary->takensessionspoints) . ' / ' .
attendance_format_float($usersummary->takensessionsmaxpoints);
$row->cells[] = attendance_format_float($usersummary->takensessionspercentage * 100, false) . '%';
if ($bulkmessagecapability) { // Create the checkbox for bulk messaging.
$row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false, '',
@ -936,22 +928,30 @@ class mod_attendance_renderer extends plugin_renderer_base {
$statrow->cells[] = '';
$statrow->cells[] = get_string('summary');
foreach ($reportdata->sessions as $sess) {
foreach ($reportdata->users as $user) {
$sessionstats = array();
foreach ($reportdata->statuses as $status) {
if (!empty($reportdata->sessionslog[$user->id][$sess->id])) {
if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) {
$sessionstats[$status->id]++;
if ($status->setnumber == $sess->statusset) {
$status->count = 0;
$sessionstats[$status->id] = $status;
}
}
foreach ($reportdata->users as $user) {
if (!empty($reportdata->sessionslog[$user->id][$sess->id])) {
$statusid = $reportdata->sessionslog[$user->id][$sess->id]->statusid;
if (isset($sessionstats[$statusid]->count)) {
$sessionstats[$statusid]->count++;
}
}
}
$statsoutput = '<br/>';
foreach ($reportdata->statuses as $status) {
$statsoutput .= "$status->description:".$sessionstats[$status->id]." <br/>";
foreach ($sessionstats as $status) {
$statsoutput .= "$status->description: {$status->count}<br/>";
}
$statrow->cells[] = $statsoutput;
$cell = new html_table_cell($statsoutput);
$cell->style = 'white-space:nowrap;';
$statrow->cells[] = $cell;
}
$table->data[] = $statrow;

Loading…
Cancel
Save