MDL-56753 mod_assign: fix groups and submitted counting on grading summary
authorSimey Lameze <simey@moodle.com>
Tue, 8 Nov 2016 01:40:18 +0000 (09:40 +0800)
committerSimey Lameze <simey@moodle.com>
Thu, 10 Nov 2016 02:58:29 +0000 (10:58 +0800)
This also fixes a coding error that was displayed when a group was not part of
assignment grouping.

mod/assign/locallib.php

index 8c4aace..4dae253 100644 (file)
@@ -1903,6 +1903,10 @@ class assign {
                         $count += 1;
                     }
                 }
+            } else if ($activitygroup != 0 && empty($groups)) {
+                // Set count to 1 if $groups returns empty.
+                // It means the group is not part of $this->get_instance()->teamsubmissiongroupingid.
+                $count = 1;
             }
         } else {
             // It is faster to loop around participants if no grouping was specified.
@@ -2074,6 +2078,12 @@ class assign {
                                                 array_keys($participants),
                                                 $this->get_instance()->teamsubmissiongroupingid,
                                                 'DISTINCT g.id, g.name');
+                if (empty($groups)) {
+                    // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
+                    // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
+                    // count towards groupid = 0. Setting to true as only '0' key matters.
+                    $groups = [true];
+                }
                 list($groupssql, $groupsparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED);
                 $groupsstr = 's.groupid ' . $groupssql . ' AND';
                 $params = $params + $groupsparams;