Skip to content

Commit

Permalink
Add courses, sessions in usergroup export see BT#18886
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 11, 2021
1 parent 6686dfe commit f24d0a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main/admin/usergroup_export.php
@@ -1,4 +1,5 @@
<?php

/* For licensing terms, see /license.txt */

$cidReset = true;
Expand All @@ -19,7 +20,7 @@
$form->addButtonExport(get_lang('Export'));

if ($form->validate()) {
$header = [['id', 'name', 'description', 'users']];
$header = [['id', 'name', 'description', 'users', 'courses', 'sessions']];
$data = $userGroup->getDataToExport();
$data = array_merge($header, $data);
$filename = 'export_classes_'.api_get_local_time();
Expand Down
21 changes: 20 additions & 1 deletion main/inc/lib/usergroup.lib.php
Expand Up @@ -1298,7 +1298,7 @@ public function getDataToExport($options = [])
if ($this->allowTeachers()) {
$options['where'] = [' author_id = ? ' => api_get_user_id()];
}
$classes = Database::select('a.id, name, description', $from, $options);
$classes = Database::select('u.id, name, description', $from, $options);
} else {
if ($this->allowTeachers()) {
$options['where'] = [' author_id = ? ' => api_get_user_id()];
Expand All @@ -1318,7 +1318,26 @@ public function getDataToExport($options = [])
}
$userToString = implode(',', $userNameList);
}

$courses = $this->get_courses_by_usergroup($data['id'], true);
$coursesToString = '';
if (!empty($courses)) {
$coursesToString = implode(', ', array_column($courses, 'code'));
}

$sessions = $this->get_sessions_by_usergroup($data['id']);
$sessionsToString = '';
if (!empty($sessions)) {
$sessionList = [];
foreach ($sessions as $sessionId) {
$sessionList[] = api_get_session_info($sessionId)['name'];
}
$sessionsToString = implode(', ', $sessionList);
}

$data['users'] = $userToString;
$data['courses'] = $coursesToString;
$data['sessions'] = $sessionsToString;
$result[] = $data;
}
}
Expand Down

0 comments on commit f24d0a5

Please sign in to comment.