Browse Source

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

MOODLE_35_STABLE
Dan Marsden 7 years ago
parent
commit
6826bb831e
  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();
break;
case ATT_VIEW_ALL:
case ATT_VIEW_NOTPRESENT:
$this->startdate = 0;
$this->enddate = 0;
break;

24
classes/structure.php

@ -96,6 +96,10 @@ class mod_attendance_structure {
/** @var array of sessionid. */
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
*
@ -1271,4 +1275,24 @@ class mod_attendance_structure {
}
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['iptimemissing'] = 'Invalid minutes to release';
$string['jumpto'] = 'Jump to';
$string['lowgrade'] = 'Low grade';
$string['below'] = 'Below {$a}%';
$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):
<ul>

10
renderables.php

@ -548,11 +548,6 @@ class attendance_report_data implements renderable {
* @param 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->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) {
$usersummary = $this->summary->get_taken_sessions_summary_for($user->id);
if ($att->pageparams->view != ATT_VIEW_NOTPRESENT ||
$usersummary->takensessionspoints < $usersummary->takensessionsmaxpoints ||
$usersummary->takensessionsmaxpoints == 0) {
attendance_calc_fraction($usersummary->takensessionspoints, $usersummary->takensessionsmaxpoints) <
$att->get_lowgrade_threshold()) {
$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);

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_DAYS] = get_string('days', 'attendance');
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) {
$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"
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"
And I am on "Course 1" course homepage
And I follow "Attendance"
@ -88,7 +88,7 @@ Feature: Teachers and Students can record session attendance
| id_sestime_endhour | 02 |
And I click on "id_submitbutton" "button"
And I follow "Report"
And I follow "Low grade"
And I follow "Below"
And I set the field "cb_selector" to "1"
And I click on "Send a message" "button"
And I should see "Message body"

Loading…
Cancel
Save