Adds students/tutors export/import see BT#9340

1.9.x
Julio Montoya 10 years ago
parent f7b569e961
commit cef6d391f8
  1. 2
      main/admin/example_class.csv
  2. 6
      main/group/example.csv
  3. 7
      main/group/group.php
  4. 27
      main/group/group_overview.php
  5. 4
      main/group/import.php
  6. 94
      main/inc/lib/groupmanager.lib.php

@ -1,3 +1,3 @@
name;description
name;description;
Class A4;20 students in general courses
Class B5;20 students from technical background

1 name name;description; description
2 Class A4 Class A4;20 students in general courses 20 students in general courses
3 Class B5 Class B5;20 students from technical background 20 students from technical background

@ -1,5 +1,5 @@
"category";"group";"description";"announcements_state";"calendar_state";"chat_state";"doc_state";"forum_state";"work_state";"wiki_state";"max_student";"self_reg_allowed";"self_unreg_allowed";"groups_per_user";
"category";"group";"description";"announcements_state";"calendar_state";"chat_state";"doc_state";"forum_state";"work_state";"wiki_state";"max_student";"self_reg_allowed";"self_unreg_allowed";"groups_per_user";"students";"tutors"
"Category 1";"";"This is a category";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"0";
"";"Group 1";"This is a group with no category";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0"
"Category 1";"Group 2";"This is a group in a category 1";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0"
"";"Group 1";"This is a group with no category";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"";"username1,username2";"username3,username4"
"Category 1";"Group 2";"This is a group in a category 1";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"";"username1,username2";"username3,username4"

Can't render this file because it has a wrong number of fields in line 3.

@ -167,18 +167,15 @@ if (api_is_allowed_to_edit(false, true)) {
echo '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=csv">'.
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
Display::return_icon('export_excel.png', get_lang('ExportSettingsAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'">'.
Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Main page for the group module.
* This script displays the general group settings,
@ -12,9 +13,6 @@
* @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
* @package chamilo.group
*/
/**
* INIT SECTION
*/
// Name of the language file that needs to be included
$language_file = array('group', 'admin');
@ -39,7 +37,7 @@ $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'export_all':
$data = GroupManager::exportCategoriesAndGroupsToArray();
$data = GroupManager::exportCategoriesAndGroupsToArray(null, true);
Export::export_table_csv($data);
exit;
break;
@ -54,26 +52,9 @@ if (isset($_GET['action'])) {
break;
case 'export':
$groupId = isset($_GET['id']) ? intval($_GET['id']) : null;
$groups = GroupManager::get_group_list();
$data = array();
foreach ($groups as $index => $group) {
if (!empty($groupId)) {
if ($group['id'] != $groupId) {
continue;
}
}
$users = GroupManager::get_users($group['id']);
foreach ($users as $index => $user) {
$row = array();
$user = api_get_user_info($user);
$row[] = $group['name'];
$row[] = $user['official_code'];
$row[] = $user['lastName'];
$row[] = $user['firstName'];
$data[] = $row;
}
}
$data = GroupManager::exportCategoriesAndGroupsToArray($groupId, true);
switch ($_GET['type']) {
case 'csv':
Export::export_table_csv($data);

@ -35,7 +35,9 @@ $form->addElement('label', null, Display::url(get_lang('ExampleCSVFile'), api_ge
$form->addElement('button', 'submit', get_lang('Import'));
if ($form->validate()) {
if (isset($_FILES['file']['tmp_name']) && !empty($_FILES['file']['tmp_name'])) {
if (isset($_FILES['file']['tmp_name']) &&
!empty($_FILES['file']['tmp_name'])
) {
$groupData = Import::csv_reader($_FILES['file']['tmp_name']);
$deleteNotInArray = $form->getSubmitValue('delete_not_in_file') == 1 ? true : false;

@ -84,16 +84,13 @@ class GroupManager
*/
public static function get_group_list($category = null, $course_code = null)
{
$my_user_id = api_get_user_id();
$course_info = api_get_course_info($course_code);
$session_id = api_get_session_id();
$course_id = $course_info['real_id'];
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$table_group = Database :: get_course_table(TABLE_GROUP);
//condition for the session
$session_id = api_get_session_id();
$sql = "SELECT g.id,
g.name,
g.description,
@ -377,7 +374,7 @@ class GroupManager
}
/**
* deletes groups and their data.
* Deletes groups and their data.
* @author Christophe Gesche <christophe.gesche@claroline.net>
* @author Hugues Peeters <hugues.peeters@claroline.net>
* @author Bart Mollet
@ -413,6 +410,7 @@ class GroupManager
// Unsubscribe all users
self :: unsubscribe_all_users($group_ids);
$sql = "SELECT id, secret_directory, session_id FROM $group_table
WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")";
$db_result = Database::query($sql);
@ -1084,6 +1082,8 @@ class GroupManager
$sql = "SELECT user_id FROM $tutor_user_table
WHERE c_id = $course_id AND group_id = $group_id";
$res = Database::query($sql);
$users = array();
while ($obj = Database::fetch_object($res)) {
$users[] = api_get_user_info($obj->user_id);
}
@ -1524,10 +1524,10 @@ class GroupManager
}
/**
* Subscribe user(s) to a specified group in current course
* Subscribe user(s) to a specified group in current course (as a student)
* @param mixed $user_ids Can be an array with user-id's or a single user-id
* @param int $group_id
* @return bool TRUE if successfull
* @return bool TRUE if successful
*/
public static function subscribe_users($user_ids, $group_id)
{
@ -1567,10 +1567,12 @@ class GroupManager
foreach ($user_ids as $user_id) {
$user_id = intval($user_id);
$group_id = intval($group_id);
if (self::can_user_subscribe($user_id, $group_id)) {
$sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id)
VALUES ('$course_id', '" . $user_id . "', '" . $group_id . "')";
$result &= Database::query($sql);
}
}
return $result;
}
@ -2266,7 +2268,6 @@ class GroupManager
}
/**
*
* @param array $groupData
* @param bool $deleteNotInArray
* @return array
@ -2404,6 +2405,27 @@ class GroupManager
$data['group_id'] = $groupId;
$result['updated']['group'][] = $data;
}
$students = isset($data['students']) ? explode(',', $data['students']) : null;
if (!empty($students)) {
$studentUserIdList = array();
foreach ($students as $student) {
$userInfo = api_get_user_info_from_username($student);
$studentUserIdList[] = $userInfo['user_id'];
}
self::subscribe_users($studentUserIdList, $groupId);
}
$tutors = isset($data['tutors']) ? explode(',', $data['tutors']) : null;
if (!empty($tutors)) {
$tutorIdList = array();
foreach ($tutors as $tutor) {
$userInfo = api_get_user_info_from_username($tutor);
$tutorIdList[] = $userInfo['user_id'];
}
self::subscribe_tutors($tutorIdList, $groupId);
}
$elementsFound['groups'][] = $groupId;
}
}
@ -2434,9 +2456,11 @@ class GroupManager
/**
* Export all categories/group from a course to an array.
* This function works only in a context of a course.
* @param int $groupId
* @param bool $loadUsers
* @return array
*/
public static function exportCategoriesAndGroupsToArray()
public static function exportCategoriesAndGroupsToArray($groupId = null, $loadUsers = false)
{
$data = array();
$data[] = array(
@ -2456,10 +2480,18 @@ class GroupManager
'groups_per_user'
);
$count = 1;
if ($loadUsers) {
$data[0][] = 'students';
$data[0][] = 'tutors';
}
if ($loadUsers == false) {
$categories = GroupManager::get_categories();
foreach ($categories as $categoryInfo) {
$data[] = array(
$data[$count] = array(
$categoryInfo['title'],
null,
$categoryInfo['description'],
@ -2475,6 +2507,8 @@ class GroupManager
$categoryInfo['self_unreg_allowed'],
$categoryInfo['groups_per_user']
);
$count++;
}
}
$groups = GroupManager::get_group_list();
@ -2487,7 +2521,31 @@ class GroupManager
$categoryTitle = $categoryInfo['title'];
}
$data[] = array(
$users = GroupManager::getStudents($groupInfo['id']);
$userList = array();
foreach ($users as $user) {
$user = api_get_user_info($user['user_id']);
$userList[] = $user['username'];
}
$tutors = GroupManager::getTutors($groupInfo['id']);
$tutorList = array();
foreach ($tutors as $user) {
$user = api_get_user_info($user['user_id']);
$tutorList[] = $user['username'];
}
$userListToString = null;
if (!empty($userList)) {
$userListToString = implode(',', $userList);
}
$tutorListToString = null;
if (!empty($tutorList)) {
$tutorListToString = implode(',', $tutorList);
}
$data[$count] = array(
$categoryTitle,
$groupSettings['name'],
$groupSettings['description'],
@ -2501,8 +2559,22 @@ class GroupManager
$groupSettings['maximum_number_of_students'],
$groupSettings['self_registration_allowed'],
$groupSettings['self_unregistration_allowed'],
null
);
if ($loadUsers) {
$data[$count][] = $userListToString;
$data[$count][] = $tutorListToString;
}
if (!empty($groupId)) {
if ($groupId == $groupInfo['id']) {
break;
}
}
$count++;
}
return $data;
}

Loading…
Cancel
Save