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. 64
      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['strftimeshortdate'] = '%d.%m.%Y';
$string['studentid'] = 'Student ID'; $string['studentid'] = 'Student ID';
$string['takeattendance'] = 'Take attendance'; $string['takeattendance'] = 'Take attendance';
$string['takensessions'] = 'Taken sessions';
$string['tempaddform'] = 'Add temporary user'; $string['tempaddform'] = 'Add temporary user';
$string['tempexists'] = 'There is already a temporary user with this email address'; $string['tempexists'] = 'There is already a temporary user with this email address';
$string['tempusers'] = 'Temporary users'; $string['tempusers'] = 'Temporary users';

27
locallib.php

@ -256,6 +256,22 @@ function attendance_get_max_statusset($attendanceid) {
return 0; 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 * 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); 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. // Includes disablrd/deleted statuses.
public $allstatuses; public $allstatuses;
public $gradable;
public $decimalpoints;
public $usersgroups = array(); public $usersgroups = array();
public $sessionslog = array(); public $sessionslog = array();
public $usersstats = array(); public $summary = array();
public $grades = array();
public $maxgrades = array();
public $att; public $att;
public function __construct(mod_attendance_structure $att) { public function __construct(mod_attendance_structure $att) {
global $CFG;
$currenttime = time(); $currenttime = time();
if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) { if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) {
$att->pageparams->enddate = $currenttime; $att->pageparams->enddate = $currenttime;
@ -492,32 +482,16 @@ class attendance_report_data implements renderable {
$this->statuses = $att->get_statuses(true, true); $this->statuses = $att->get_statuses(true, true);
$this->allstatuses = $att->get_statuses(false, true); $this->allstatuses = $att->get_statuses(false, true);
$this->gradable = $att->grade > 0; $this->summary = new mod_attendance_summary($att->id, array_keys($this->users), $att->pageparams->startdate, $att->pageparams->enddate);
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);
foreach ($this->users as $key => $user) { foreach ($this->users as $key => $user) {
$grade = 0; $usersummary = $this->summary->get_taken_sessions_summary_for($user->id);
if ($this->gradable) { if ($att->pageparams->view != ATT_VIEW_NOTPRESENT ||
$grade = $att->get_user_grade($user->id, array('enddate' => $currenttime)); $usersummary->takensessionspoints < $usersummary->takensessionsmaxpoints ||
$totalgrade = $att->get_user_grade($user->id); $usersummary->takensessionsmaxpoints == 0) {
}
if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || $grade < $maxgrade) {
$this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id); $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->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 { } else {
unset($this->users[$key]); unset($this->users[$key]);
} }

64
renderer.php

@ -882,18 +882,17 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->size[] = '1px'; $table->size[] = '1px';
} }
foreach ($reportdata->statuses as $status) { $table->head[] = get_string('takensessions', 'attendance');
$table->head[] = $status->acronym; $table->align[] = 'center';
$table->align[] = 'center'; $table->size[] = '1px';
$table->size[] = '1px';
$sessionstats[$status->id] = 0;
}
if ($reportdata->gradable) { $table->head[] = get_string('points', 'attendance');
$table->head[] = get_string('grade'); $table->align[] = 'center';
$table->align[] = 'center'; $table->size[] = '1px';
$table->size[] = '1px';
} $table->head[] = get_string('percentage', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
if ($bulkmessagecapability) { // Display the table header for bulk messaging. 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. // 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); $cellsgenerator = new user_sessions_cells_html_generator($reportdata, $user);
$row->cells = array_merge($row->cells, $cellsgenerator->get_cells(true)); $row->cells = array_merge($row->cells, $cellsgenerator->get_cells(true));
foreach ($reportdata->statuses as $status) { $usersummary = $reportdata->summary->get_taken_sessions_summary_for($user->id);
if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) { $row->cells[] = $usersummary->numtakensessions;
$row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt; $row->cells[] = attendance_format_float($usersummary->takensessionspoints) . ' / ' .
} else { attendance_format_float($usersummary->takensessionsmaxpoints);
// No attendance data for this $status => no statistic for this status. $row->cells[] = attendance_format_float($usersummary->takensessionspercentage * 100, false) . '%';
$row->cells[] = 0;
}
}
if ($reportdata->gradable) {
$row->cells[] = format_float($reportdata->grades[$user->id]).' / '.format_float($reportdata->maxgrades[$user->id]);
}
if ($bulkmessagecapability) { // Create the checkbox for bulk messaging. if ($bulkmessagecapability) { // Create the checkbox for bulk messaging.
$row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false, '', $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[] = '';
$statrow->cells[] = get_string('summary'); $statrow->cells[] = get_string('summary');
foreach ($reportdata->sessions as $sess) { foreach ($reportdata->sessions as $sess) {
$sessionstats = array();
foreach ($reportdata->statuses as $status) {
if ($status->setnumber == $sess->statusset) {
$status->count = 0;
$sessionstats[$status->id] = $status;
}
}
foreach ($reportdata->users as $user) { foreach ($reportdata->users as $user) {
foreach ($reportdata->statuses as $status) { if (!empty($reportdata->sessionslog[$user->id][$sess->id])) {
if (!empty($reportdata->sessionslog[$user->id][$sess->id])) { $statusid = $reportdata->sessionslog[$user->id][$sess->id]->statusid;
if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) { if (isset($sessionstats[$statusid]->count)) {
$sessionstats[$status->id]++; $sessionstats[$statusid]->count++;
}
} }
} }
} }
$statsoutput = '<br/>'; $statsoutput = '<br/>';
foreach ($reportdata->statuses as $status) { foreach ($sessionstats as $status) {
$statsoutput .= "$status->description:".$sessionstats[$status->id]." <br/>"; $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; $table->data[] = $statrow;

Loading…
Cancel
Save