make correct check for group mode
authorDan Marsden <dan@danmarsden.com>
Wed, 18 Dec 2013 20:37:33 +0000 (09:37 +1300)
committerDan Marsden <dan@danmarsden.com>
Wed, 18 Dec 2013 20:37:33 +0000 (09:37 +1300)
export.php
export_form.php
locallib.php

index 19f9619..a0a690a 100644 (file)
@@ -90,7 +90,8 @@ if ($mform->is_submitted()) {
         }
         $data->tabhead[] = get_string('lastname');
         $data->tabhead[] = get_string('firstname');
-        if (!empty($cm->groupmode)) {
+        $groupmode = groups_get_activity_groupmode($cm, $course);
+        if (!empty($groupmode)) {
             $data->tabhead[] = get_string('groups');
         }
 
@@ -123,7 +124,7 @@ if ($mform->is_submitted()) {
             }
             $data->table[$i][] = $user->lastname;
             $data->table[$i][] = $user->firstname;
-            if (!empty($cm->groupmode)) {
+            if (!empty($groupmode)) {
                 $grouptext = '';
                 $groupsraw = groups_get_all_groups($course->id, $user->id, 0, 'g.name');
                 $groups = array();
index 17a932c..994c5e1 100644 (file)
@@ -48,7 +48,7 @@ class mod_attendance_export_form extends moodleform {
 
         $mform->addElement('header', 'general', get_string('export', 'quiz'));
 
-        $groupmode=groups_get_activity_groupmode($cm);
+        $groupmode=groups_get_activity_groupmode($cm, $course);
         $groups = groups_get_activity_allowed_groups($cm, $USER->id);
         if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
             $grouplist[0] = get_string('allparticipants');
index 40c7a85..bba91a9 100644 (file)
@@ -599,7 +599,7 @@ class attendance {
 
     public function get_group_mode() {
         if (is_null($this->groupmode)) {
-            $this->groupmode = groups_get_activity_groupmode($this->cm);
+            $this->groupmode = groups_get_activity_groupmode($this->cm, $this->course);
         }
         return $this->groupmode;
     }
@@ -1070,7 +1070,7 @@ class attendance {
         global $DB;
 
         if (!array_key_exists($userid, $this->userstatusesstat)) {
-            if (!empty($this->cm->groupmode)) {
+            if (!empty($this->groupmode)) {
                 $qry = "SELECT al.statusid, count(al.statusid) AS stcnt
                       FROM {attendance_log} al
                       JOIN {attendance_sessions} ats ON al.sessionid = ats.id
@@ -1142,7 +1142,7 @@ class attendance {
         } else {
             $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate";
         }
-        if (!empty($this->cm->groupmode)) {
+        if (!empty($this->groupmode)) {
             $sql = "SELECT ats.id, ats.sessdate, ats.groupid, al.statusid, al.remarks
                   FROM {attendance_sessions} ats
                   JOIN {attendance_log} al ON ats.id = al.sessionid AND al.studentid = :uid
@@ -1192,7 +1192,7 @@ class attendance {
         // 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.
         $id = $DB->sql_concat(':value', 'ats.id');
-        if (!empty($this->cm->groupmode)) {
+        if (!empty($this->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
@@ -1348,8 +1348,9 @@ function att_get_statuses($attid, $onlyvisible=true) {
 }
 
 function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule) {
-    global $DB;
-    if (!empty($coursemodule->groupmode)) {
+    global $DB, $COURSE;
+    $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE);
+    if (!empty($groupmode)) {
         $qry = "SELECT count(*) as cnt
               FROM {attendance_log} al
               JOIN {attendance_sessions} ats ON al.sessionid = ats.id
@@ -1375,8 +1376,8 @@ function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $c
 }
 
 function att_get_user_statuses_stat($attid, $coursestartdate, $userid, $coursemodule) {
-    global $DB;
-
+    global $DB, $COURSE;
+    $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE);
     if (!empty($coursemodule->groupmode)) {
         $qry = "SELECT al.statusid, count(al.statusid) AS stcnt
               FROM {attendance_log} al