Browse Source

Attendance - only show groups in reports that user is a member of.

MOODLE_26_STABLE
Dan Marsden 11 years ago
parent
commit
350d6f076a
  1. 7
      lib.php
  2. 46
      locallib.php
  3. 2
      preferences.php
  4. 4
      renderables.php
  5. 8
      renderhelpers.php
  6. 4
      sessions.php

7
lib.php

@ -213,7 +213,6 @@ function attendance_reset_userdata($data) {
*/ */
function attendance_user_outline($course, $user, $mod, $attendance) { function attendance_user_outline($course, $user, $mod, $attendance) {
global $CFG; global $CFG;
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
@ -229,9 +228,9 @@ function attendance_user_outline($course, $user, $mod, $attendance) {
if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) {
$statuses = att_get_statuses($attendance->id); $statuses = att_get_statuses($attendance->id);
$grade = att_get_user_grade(att_get_user_statuses_stat($attendance->id, $course->startdate, $grade = att_get_user_grade(att_get_user_statuses_stat($attendance->id, $course->startdate,
$user->id), $statuses); $user->id, $mod), $statuses);
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate, $maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id), $statuses); $user->id, $mod), $statuses);
$result->info = $grade.' / '.$maxgrade; $result->info = $grade.' / '.$maxgrade;
} }
@ -250,7 +249,7 @@ function attendance_user_complete($course, $user, $mod, $attendance) {
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) {
echo construct_full_user_stat_html_table($attendance, $course, $user); echo construct_full_user_stat_html_table($attendance, $course, $user, $mod);
} }
} }
function attendance_print_recent_activity($course, $isteacher, $timestart) { function attendance_print_recent_activity($course, $isteacher, $timestart) {

46
locallib.php

@ -1061,7 +1061,7 @@ class attendance {
public function get_user_taken_sessions_count($userid) { public function get_user_taken_sessions_count($userid) {
if (!array_key_exists($userid, $this->usertakensesscount)) { if (!array_key_exists($userid, $this->usertakensesscount)) {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid); $this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, $this->cm);
} }
return $this->usertakensesscount[$userid]; return $this->usertakensesscount[$userid];
} }
@ -1179,7 +1179,6 @@ class attendance {
public function get_user_filtered_sessions_log_extended($userid) { public function get_user_filtered_sessions_log_extended($userid) {
global $DB; global $DB;
// All taked sessions (including previous groups). // All taked sessions (including previous groups).
if ($this->pageparams->startdate && $this->pageparams->enddate) { if ($this->pageparams->startdate && $this->pageparams->enddate) {
@ -1193,13 +1192,22 @@ class attendance {
// If the array's index is a number it will not merge entries. // If the array's index is a number it will not merge entries.
// It would be better as a UNION query butunfortunatly MS SQL does not seem to support doing a DISTINCT on a the description field. // It would be better as a UNION query butunfortunatly MS SQL does not seem to support doing a DISTINCT on a the description field.
$id = $DB->sql_concat(':value', 'ats.id'); $id = $DB->sql_concat(':value', 'ats.id');
if (!empty($this->cm->groupmode)) {
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
FROM {attendance_sessions} ats
RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid
JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid
WHERE $where
ORDER BY ats.sessdate ASC";
} else {
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
FROM {attendance_sessions} ats FROM {attendance_sessions} ats
RIGHT JOIN {attendance_log} al RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid ON ats.id = al.sessionid AND al.studentid = :uid
WHERE $where WHERE $where
ORDER BY ats.sessdate ASC"; ORDER BY ats.sessdate ASC";
}
$params = array( $params = array(
'uid' => $userid, 'uid' => $userid,
@ -1339,9 +1347,17 @@ function att_get_statuses($attid, $onlyvisible=true) {
return $statuses; return $statuses;
} }
function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid) { function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule) {
global $DB; global $DB;
if (!empty($coursemodule->groupmode)) {
$qry = "SELECT count(*) as cnt
FROM {attendance_log} al
JOIN {attendance_sessions} ats ON al.sessionid = ats.id
JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid
WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND
al.studentid = :uid";
} else {
$qry = "SELECT count(*) as cnt $qry = "SELECT count(*) as cnt
FROM {attendance_log} al FROM {attendance_log} al
JOIN {attendance_sessions} ats JOIN {attendance_sessions} ats
@ -1349,6 +1365,7 @@ function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid) {
WHERE ats.attendanceid = :aid AND WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND ats.sessdate >= :cstartdate AND
al.studentid = :uid"; al.studentid = :uid";
}
$params = array( $params = array(
'aid' => $attid, 'aid' => $attid,
'cstartdate' => $coursestartdate, 'cstartdate' => $coursestartdate,
@ -1357,9 +1374,19 @@ function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid) {
return $DB->count_records_sql($qry, $params); return $DB->count_records_sql($qry, $params);
} }
function att_get_user_statuses_stat($attid, $coursestartdate, $userid) { function att_get_user_statuses_stat($attid, $coursestartdate, $userid, $coursemodule) {
global $DB; global $DB;
if (!empty($coursemodule->groupmode)) {
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt
FROM {attendance_log} al
JOIN {attendance_sessions} ats ON al.sessionid = ats.id
JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid
WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND
al.studentid = :uid
GROUP BY al.statusid";
} else {
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt $qry = "SELECT al.statusid, count(al.statusid) AS stcnt
FROM {attendance_log} al FROM {attendance_log} al
JOIN {attendance_sessions} ats JOIN {attendance_sessions} ats
@ -1368,6 +1395,7 @@ function att_get_user_statuses_stat($attid, $coursestartdate, $userid) {
ats.sessdate >= :cstartdate AND ats.sessdate >= :cstartdate AND
al.studentid = :uid al.studentid = :uid
GROUP BY al.statusid"; GROUP BY al.statusid";
}
$params = array( $params = array(
'aid' => $attid, 'aid' => $attid,
'cstartdate' => $coursestartdate, 'cstartdate' => $coursestartdate,
@ -1424,7 +1452,7 @@ function att_get_gradebook_maxgrade($attid) {
return $DB->get_field('attendance', 'grade', array('id' => $attid)); return $DB->get_field('attendance', 'grade', array('id' => $attid));
} }
function att_update_all_users_grades($attid, $course, $context) { function att_update_all_users_grades($attid, $course, $context, $coursemodule) {
$grades = array(); $grades = array();
$userids = array_keys(get_enrolled_users($context, 'mod/attendance:canbelisted', 0, 'u.id')); $userids = array_keys(get_enrolled_users($context, 'mod/attendance:canbelisted', 0, 'u.id'));
@ -1434,8 +1462,8 @@ function att_update_all_users_grades($attid, $course, $context) {
foreach ($userids as $userid) { foreach ($userids as $userid) {
$grade = new stdClass; $grade = new stdClass;
$grade->userid = $userid; $grade->userid = $userid;
$userstatusesstat = att_get_user_statuses_stat($attid, $course->startdate, $userid); $userstatusesstat = att_get_user_statuses_stat($attid, $course->startdate, $userid, $coursemodule);
$usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid); $usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid, $coursemodule);
$usergrade = att_get_user_grade($userstatusesstat, $statuses); $usergrade = att_get_user_grade($userstatusesstat, $statuses);
$usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses); $usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses);
$grade->rawgrade = att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebook_maxgrade; $grade->rawgrade = att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebook_maxgrade;

2
preferences.php

@ -93,7 +93,7 @@ switch ($att->pageparams->action) {
foreach ($acronym as $id => $v) { foreach ($acronym as $id => $v) {
$att->update_status($id, $acronym[$id], $description[$id], $grade[$id], null); $att->update_status($id, $acronym[$id], $description[$id], $grade[$id], null);
} }
att_update_all_users_grades($att->id, $att->course, $att->context); att_update_all_users_grades($att->id, $att->course, $att->context, $cm);
break; break;
} }

4
renderables.php

@ -385,8 +385,8 @@ class attendance_user_data implements renderable {
$this->maxgrade = array(); $this->maxgrade = array();
foreach ($this->coursesatts as $ca) { foreach ($this->coursesatts as $ca) {
$statuses = att_get_statuses($ca->attid); $statuses = att_get_statuses($ca->attid);
$user_taken_sessions_count = att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid); $user_taken_sessions_count = att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid, $att->cm);
$user_statuses_stat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid); $user_statuses_stat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid, $att->cm);
$this->statuses[$ca->attid] = $statuses; $this->statuses[$ca->attid] = $statuses;

8
renderhelpers.php

@ -254,17 +254,17 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
return html_writer::table($stattable); return html_writer::table($stattable);
} }
function construct_full_user_stat_html_table($attendance, $course, $user) { function construct_full_user_stat_html_table($attendance, $course, $user, $coursemodule) {
global $CFG; global $CFG;
$gradeable = $attendance->grade > 0; $gradeable = $attendance->grade > 0;
$statuses = att_get_statuses($attendance->id); $statuses = att_get_statuses($attendance->id);
$userstatusesstat = att_get_user_statuses_stat($attendance->id, $course->startdate, $user->id); $userstatusesstat = att_get_user_statuses_stat($attendance->id, $course->startdate, $user->id, $coursemodule);
$stat['completed'] = att_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id); $stat['completed'] = att_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id, $coursemodule);
$stat['statuses'] = $userstatusesstat; $stat['statuses'] = $userstatusesstat;
if ($gradeable) { if ($gradeable) {
$grade = att_get_user_grade($userstatusesstat, $statuses); $grade = att_get_user_grade($userstatusesstat, $statuses);
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate, $maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id), $statuses); $user->id, $coursemodule), $statuses);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) { if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints; $decimalpoints = $CFG->grade_decimalpoints;
} }

4
sessions.php

@ -85,7 +85,7 @@ switch ($att->pageparams->action) {
if (isset($confirm) && confirm_sesskey()) { if (isset($confirm) && confirm_sesskey()) {
$att->delete_sessions(array($sessionid)); $att->delete_sessions(array($sessionid));
att_update_all_users_grades($att->id, $att->course, $att->context); att_update_all_users_grades($att->id, $att->course, $att->context, $cm);
redirect($att->url_manage(), get_string('sessiondeleted', 'attendance')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} }
@ -112,7 +112,7 @@ switch ($att->pageparams->action) {
$sessionsids = explode('_', $sessionsids); $sessionsids = explode('_', $sessionsids);
$att->delete_sessions($sessionsids); $att->delete_sessions($sessionsids);
att_update_all_users_grades($att->id, $att->course, $att->context); att_update_all_users_grades($att->id, $att->course, $att->context, $cm);
redirect($att->url_manage(), get_string('sessiondeleted', 'attendance')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} }
$sessid = required_param('sessid', PARAM_SEQUENCE); $sessid = required_param('sessid', PARAM_SEQUENCE);

Loading…
Cancel
Save