MDL-61290 mod_feedback: adding groups to csv download
authorAmaia Anabitarte <amaia@moodle.com>
Wed, 25 Jul 2018 16:39:45 +0000 (17:39 +0100)
committerAmaia Anabitarte <amaia@moodle.com>
Tue, 31 Jul 2018 14:32:43 +0000 (15:32 +0100)
Thanks Christine LEGEMBLE for your proposal

mod/feedback/classes/responses_table.php

index 50b7d9e..4327cc0 100644 (file)
@@ -113,8 +113,12 @@ class mod_feedback_responses_table extends table_sql {
      */
     protected function init($group = 0) {
 
-        $tablecolumns = array('userpic', 'fullname');
-        $tableheaders = array(get_string('userpic'), get_string('fullnameuser'));
+        $tablecolumns = array('userpic', 'fullname', 'groups');
+        $tableheaders = array(
+            get_string('userpic'),
+            get_string('fullnameuser'),
+            get_string('groups')
+        );
 
         $extrafields = get_extra_user_fields($this->get_context());
         $ufields = user_picture::fields('u', $extrafields, $this->useridfield);
@@ -258,6 +262,21 @@ class mod_feedback_responses_table extends table_sql {
         return $name;
     }
 
+    /**
+     * Prepares column groups for display
+     * @param array $row
+     * @return string
+     */
+    public function col_groups($row) {
+        $groups = '';
+        if ($usergrps = groups_get_all_groups($this->feedbackstructure->get_cm()->course, $row->userid, 0, 'name')) {
+            foreach ($usergrps as $group) {
+                $groups .= format_string($group->name). ' ';
+            }
+        }
+        return trim($groups);
+    }
+
     /**
      * Adds common values to the table that do not change the number or order of entries and
      * are only needed when outputting or downloading data.