]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10888: groupings - mod/lesson - updated to support groupings
authormattc-catalyst <mattc-catalyst>
Mon, 27 Aug 2007 23:05:42 +0000 (23:05 +0000)
committermattc-catalyst <mattc-catalyst>
Mon, 27 Aug 2007 23:05:42 +0000 (23:05 +0000)
mod/lesson/essay.php
mod/lesson/mod_form.php
mod/lesson/report.php

index 2d0dbbc56b543bc634f9529ae4e84796e8b3869b..bdccd0653fc219a1ec699ceb638d18c62d807692 100644 (file)
                 // Get only the attempts that are in response to essay questions
                 if ($essayattempts = get_records_select('lesson_attempts', 'pageid IN('.implode(',', array_keys($pages)).')')) {
                     // Get all the users who have taken this lesson, order by their last name
-                    if (!$users = get_records_sql("SELECT u.*
-                                             FROM {$CFG->prefix}user u,
-                                                  {$CFG->prefix}lesson_attempts a
-                                             WHERE a.lessonid = '$lesson->id' and
-                                                   u.id = a.userid
-                                             ORDER BY u.lastname")) {
-                        error('Error: could not find users');
+                    if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
+                        $sql = "SELECT DISTINCT u.*
+                                FROM {$CFG->prefix}lesson_attempts a 
+                                    INNER JOIN {$CFG->prefix}user u ON u.id = a.userid
+                                    INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id
+                                    INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid}
+                                WHERE a.lessonid = '$lesson->id'
+                                ORDER BY u.lastname";
+                    } else {
+                        $sql = "SELECT u.*
+                                FROM {$CFG->prefix}user u,
+                                     {$CFG->prefix}lesson_attempts a
+                                WHERE a.lessonid = '$lesson->id' and
+                                      u.id = a.userid
+                                ORDER BY u.lastname";
+                    }
+                    if (!$users = get_records_sql($sql)) {
+                        $mode = 'none'; // not displaying anything
+                        lesson_set_message(get_string('noonehasanswered', 'lesson'));
                     }
                 } else {
                     $mode = 'none'; // not displaying anything
index 68c3506da19e986a908518b276c09ab98d3e044a..43e790693b6ac212d97269e5a725923666486a40 100644 (file)
@@ -278,7 +278,11 @@ class mod_lesson_mod_form extends moodleform_mod {
         $mform->setDefault('lessondefault', 0);
 
 //-------------------------------------------------------------------------------
-        $this->standard_coursemodule_elements(array('groups'=>false));
+        $features = new stdClass;
+        $features->groups = false;
+        $features->groupings = true;
+        $features->groupmembersonly = true;
+        $this->standard_coursemodule_elements($features);
 //-------------------------------------------------------------------------------
 // buttons
         $this->add_action_buttons();
index ac4132b06f1c3762620f3a2122c1f042e9e62a55..bc6b6f915608ec646fc9bce624b45ce7320855ab 100644 (file)
     $nothingtodisplay = false;
 
     list($cm, $course, $lesson) = lesson_get_basics($id);
-
-    if (! $students = get_records_sql("SELECT u.*
-                                 FROM {$CFG->prefix}user u,
-                                      {$CFG->prefix}lesson_attempts a
-                                 WHERE a.lessonid = '$lesson->id' and
-                                       u.id = a.userid
-                                 ORDER BY u.lastname")) {
+    
+    if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
+        $sql = "SELECT DISTINCT u.*
+                FROM {$CFG->prefix}lesson_attempts a 
+                    INNER JOIN {$CFG->prefix}user u ON u.id = a.userid
+                    INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id
+                    INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid}
+                WHERE a.lessonid = '$lesson->id'
+                ORDER BY u.lastname";
+    } else {
+        $sql = "SELECT u.*
+                FROM {$CFG->prefix}user u,
+                     {$CFG->prefix}lesson_attempts a
+                WHERE a.lessonid = '$lesson->id' and
+                      u.id = a.userid
+                ORDER BY u.lastname";
+    }
+    
+    if (! $students = get_records_sql($sql)) {
         $nothingtodisplay = true;
     }