Browse Source

Fix #196 Thanks to @antonio-c-mariani for this code.

MOODLE_36_STABLE
Dan Marsden 7 years ago
parent
commit
a1f36cea3c
  1. 1
      classes/page_with_filter_controls.php
  2. 24
      classes/structure.php
  3. 2
      lang/en/attendance.php
  4. 10
      renderables.php
  5. 3
      renderer.php
  6. 4
      tests/behat/attendance_mod.feature

1
classes/page_with_filter_controls.php

@ -154,6 +154,7 @@ class mod_attendance_page_with_filter_controls {
$this->enddate = time(); $this->enddate = time();
break; break;
case ATT_VIEW_ALL: case ATT_VIEW_ALL:
case ATT_VIEW_NOTPRESENT:
$this->startdate = 0; $this->startdate = 0;
$this->enddate = 0; $this->enddate = 0;
break; break;

24
classes/structure.php

@ -96,6 +96,10 @@ class mod_attendance_structure {
/** @var array of sessionid. */ /** @var array of sessionid. */
private $sessioninfo = array(); private $sessioninfo = array();
/** @var float number [0..1], the threshold for student to be shown at low grade report */
private $lowgradethreshold;
/** /**
* Initializes the attendance API instance using the data from DB * Initializes the attendance API instance using the data from DB
* *
@ -1271,4 +1275,24 @@ class mod_attendance_structure {
} }
return; return;
} }
/**
* Gets the lowgrade threshold to use.
*
*/
public function get_lowgrade_threshold() {
if (!isset($this->lowgradethreshold)) {
$this->lowgradethreshold = 1;
if ($this->grade > 0) {
$gradeitem = grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod',
'itemmodule' => 'attendance', 'iteminstance' => $this->id));
if ($gradeitem->gradepass > 0 && $gradeitem->grademax != $gradeitem->grademin) {
$this->lowgradethreshold = ($gradeitem->gradepass - $gradeitem->grademin) / ($gradeitem->grademax - $gradeitem->grademin);
}
}
}
return $this->lowgradethreshold;
}
} }

2
lang/en/attendance.php

@ -247,7 +247,7 @@ $string['invalidsessionendtime'] = 'The end time must be greater than start time
$string['invalidstatus'] = 'You have selected an invalid status, please try again'; $string['invalidstatus'] = 'You have selected an invalid status, please try again';
$string['iptimemissing'] = 'Invalid minutes to release'; $string['iptimemissing'] = 'Invalid minutes to release';
$string['jumpto'] = 'Jump to'; $string['jumpto'] = 'Jump to';
$string['lowgrade'] = 'Low grade'; $string['below'] = 'Below {$a}%';
$string['maxpossible'] = 'Maximum possible'; $string['maxpossible'] = 'Maximum possible';
$string['maxpossible_help'] = 'Shows the score each user can reach if they receive the maximum points in each session not yet taken (past and future): $string['maxpossible_help'] = 'Shows the score each user can reach if they receive the maximum points in each session not yet taken (past and future):
<ul> <ul>

10
renderables.php

@ -548,11 +548,6 @@ class attendance_report_data implements renderable {
* @param mod_attendance_structure $att * @param mod_attendance_structure $att
*/ */
public function __construct(mod_attendance_structure $att) { public function __construct(mod_attendance_structure $att) {
$currenttime = time();
if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) {
$att->pageparams->enddate = $currenttime;
}
$this->pageparams = $att->pageparams; $this->pageparams = $att->pageparams;
$this->users = $att->get_users($att->pageparams->group, $att->pageparams->page); $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
@ -582,8 +577,9 @@ class attendance_report_data implements renderable {
foreach ($this->users as $key => $user) { foreach ($this->users as $key => $user) {
$usersummary = $this->summary->get_taken_sessions_summary_for($user->id); $usersummary = $this->summary->get_taken_sessions_summary_for($user->id);
if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || if ($att->pageparams->view != ATT_VIEW_NOTPRESENT ||
$usersummary->takensessionspoints < $usersummary->takensessionsmaxpoints || attendance_calc_fraction($usersummary->takensessionspoints, $usersummary->takensessionsmaxpoints) <
$usersummary->takensessionsmaxpoints == 0) { $att->get_lowgrade_threshold()) {
$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);

3
renderer.php

@ -206,7 +206,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$views[ATT_VIEW_WEEKS] = get_string('weeks', 'attendance'); $views[ATT_VIEW_WEEKS] = get_string('weeks', 'attendance');
$views[ATT_VIEW_DAYS] = get_string('days', 'attendance'); $views[ATT_VIEW_DAYS] = get_string('days', 'attendance');
if ($fcontrols->reportcontrol && $fcontrols->att->grade > 0) { if ($fcontrols->reportcontrol && $fcontrols->att->grade > 0) {
$views[ATT_VIEW_NOTPRESENT] = get_string('lowgrade', 'attendance'); $a = $fcontrols->att->get_lowgrade_threshold() * 100;
$views[ATT_VIEW_NOTPRESENT] = get_string('below', 'attendance', $a);
} }
if ($fcontrols->reportcontrol) { if ($fcontrols->reportcontrol) {
$views[ATT_VIEW_SUMMARY] = get_string('summary', 'attendance'); $views[ATT_VIEW_SUMMARY] = get_string('summary', 'attendance');

4
tests/behat/attendance_mod.feature

@ -78,7 +78,7 @@ Feature: Teachers and Students can record session attendance
And I click on "Get these logs" "button" And I click on "Get these logs" "button"
Then "Attendance taken by student" "link" should exist Then "Attendance taken by student" "link" should exist
Scenario: Teachers can view low grade report and send a message Scenario: Teachers can view below % report and send a message
Given I log in as "teacher1" Given I log in as "teacher1"
And I am on "Course 1" course homepage And I am on "Course 1" course homepage
And I follow "Attendance" And I follow "Attendance"
@ -88,7 +88,7 @@ Feature: Teachers and Students can record session attendance
| id_sestime_endhour | 02 | | id_sestime_endhour | 02 |
And I click on "id_submitbutton" "button" And I click on "id_submitbutton" "button"
And I follow "Report" And I follow "Report"
And I follow "Low grade" And I follow "Below"
And I set the field "cb_selector" to "1" And I set the field "cb_selector" to "1"
And I click on "Send a message" "button" And I click on "Send a message" "button"
And I should see "Message body" And I should see "Message body"

Loading…
Cancel
Save