Merge pull request #1613 from jloguercio/cies-12221

Added Course Session Users CSV export - BT#12221
remotes/angel/1.11.x
José Loguercio 8 years ago committed by GitHub
commit 922b6fd4b4
  1. 32
      main/admin/user_export.php
  2. 20
      main/inc/lib/sessionmanager.lib.php

@ -15,12 +15,19 @@ api_protect_admin_script();
$course_table = Database:: get_main_table(TABLE_MAIN_COURSE);
$user_table = Database:: get_main_table(TABLE_MAIN_USER);
$course_user_table = Database:: get_main_table(TABLE_MAIN_COURSE_USER);
$session_course_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tool_name = get_lang('ExportUserListXMLCSV');
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
set_time_limit(0);
$coursesSessions = [];
$coursesSessions[''] = '--';
$allCoursesFromSessions = SessionManager::getAllCoursesFromAllSessions();
$coursesSessions = array_merge($coursesSessions, $allCoursesFromSessions);
$courses = array ();
$courses[''] = '--';
@ -52,6 +59,7 @@ $form->addElement('radio', 'file_type', null, 'XLS', 'xls');
$form->addElement('checkbox', 'addcsvheader', get_lang('AddCSVHeader'), get_lang('YesAddCSVHeader'),'1');
$form->addElement('select', 'course_code', get_lang('OnlyUsersFromCourse'), $courses);
$form->addElement('select', 'course_session', get_lang('OnlyUsersFromCourseSession'), $coursesSessions);
$form->addButtonExport(get_lang('Export'));
$form->setDefaults(array('file_type' => 'csv'));
@ -62,6 +70,20 @@ if ($form->validate()) {
$courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id'];
$courseSessionValue = explode(':', $export['course_session']);
$courseSessionCode = '';
$sessionId = 0;
$courseSessionId = 0;
$sessionInfo = [];
if (is_array($courseSessionValue) && isset($courseSessionValue[1])) {
$courseSessionCode = $courseSessionValue[0];
$sessionId = $courseSessionValue[1];
$courseSessionInfo= api_get_course_info($courseSessionCode);
$courseSessionId = $courseSessionInfo['real_id'];
$sessionInfo = api_get_session_info($sessionId);
}
$sql = "SELECT
u.user_id AS UserId,
u.lastname AS LastName,
@ -81,7 +103,15 @@ if ($form->validate()) {
cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
ORDER BY lastname,firstname";
$filename = 'export_users_'.$course_code.'_'.api_get_local_time();
} else {
} else if (strlen($courseSessionCode) > 0) {
$sql .= " FROM $user_table u, $session_course_user_table scu
WHERE
u.user_id = scu.user_id AND
scu.c_id = $courseSessionId AND
scu.session_id = $sessionId
ORDER BY lastname,firstname";
$filename = 'export_users_'.$courseSessionCode.'_'.$sessionInfo['name'].'_'.api_get_local_time();
} else {
if (api_is_multiple_url_enabled()) {
$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$access_url_id = api_get_current_access_url_id();

@ -5134,6 +5134,26 @@ class SessionManager
return $coursesFromSession;
}
/**
* getAllCoursesFromAllSessions
*
* @return array
*/
public static function getAllCoursesFromAllSessions()
{
$sessions = SessionManager::get_sessions_list();
$coursesFromSession = array();
if (!empty($sessions)) {
foreach ($sessions as $session) {
$courseList = SessionManager::get_course_list_by_session_id($session['id']);
foreach ($courseList as $course) {
$coursesFromSession[$course['code'].':'.$session['id']] = $course['visual_code'] . ' - ' . $course['title'] . ' (' . $session['name'] . ')';
}
}
}
return $coursesFromSession;
}
/**
* @param string $status
* @param int $userId

Loading…
Cancel
Save