From 566675d8833b5547ca7e96bdf5a1c1e3ef83835e Mon Sep 17 00:00:00 2001 From: NicoDucou Date: Wed, 23 Aug 2023 11:53:06 +0200 Subject: [PATCH] Group : add icon to export csv of student members of a group -refs BT#20952 --- main/group/group_overview.php | 7 +++++- main/inc/lib/groupmanager.lib.php | 36 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/main/group/group_overview.php b/main/group/group_overview.php index 8e81013bda..8fa8151b43 100755 --- a/main/group/group_overview.php +++ b/main/group/group_overview.php @@ -100,7 +100,12 @@ if (isset($_GET['action'])) { exit; } break; - } + } + break; + case 'export_users': + $data = GroupManager::exportStudentsToArray($groupId, true); + Export::arrayToCsv($data); + exit; break; } } diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index 89402db3f7..4fcdec3ee0 100755 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -2449,6 +2449,9 @@ class GroupManager $edit_actions .= ''. Display::return_icon('export_excel.png', get_lang('Export'), '', ICON_SIZE_SMALL).' '; + $edit_actions .= ''. + Display::return_icon('export_csv.png', get_lang('ExportUsers'), '', ICON_SIZE_SMALL).' '; + if ($surveyGroupExists) { $edit_actions .= Display::url( Display::return_icon('survey.png', get_lang('ExportSurveyResults'), '', ICON_SIZE_SMALL), @@ -2754,6 +2757,39 @@ class GroupManager return $result; } + + /** + * Export all students from a group to an array. + * This function works only in a context of a course. + * + * @param int $groupId + * + * @return array + */ + public static function exportStudentsToArray($groupId = null) + { + if (empty($groupId)) { + return false; + } + $data = []; + $data[] = [ + 'OfficialCode', + 'Lastname', + 'Firsname', + 'Email', + ]; + $users = self::getStudents($groupId); + $count = 1; + foreach ($users as $user) { + $user = api_get_user_info($user['user_id']); + $data[$count][] = $user['official_code']; + $data[$count][] = $user['lastname']; + $data[$count][] = $user['firstname']; + $data[$count][] = $user['email']; + $count++; + } + return $data; + } /** * Export all categories/group from a course to an array.