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 A4;20 students in general courses
Class B5;20 students from technical background 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"; "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" "";"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" "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">'. echo '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>'; 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>'; 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>'; 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">'. echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>'; 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().'">'. echo '<a href="group_overview.php?'.api_get_cidreq().'">'.
Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Main page for the group module. * Main page for the group module.
* This script displays the general group settings, * 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 * @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
* @package chamilo.group * @package chamilo.group
*/ */
/**
* INIT SECTION
*/
// Name of the language file that needs to be included // Name of the language file that needs to be included
$language_file = array('group', 'admin'); $language_file = array('group', 'admin');
@ -39,7 +37,7 @@ $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
if (isset($_GET['action'])) { if (isset($_GET['action'])) {
switch ($_GET['action']) { switch ($_GET['action']) {
case 'export_all': case 'export_all':
$data = GroupManager::exportCategoriesAndGroupsToArray(); $data = GroupManager::exportCategoriesAndGroupsToArray(null, true);
Export::export_table_csv($data); Export::export_table_csv($data);
exit; exit;
break; break;
@ -54,26 +52,9 @@ if (isset($_GET['action'])) {
break; break;
case 'export': case 'export':
$groupId = isset($_GET['id']) ? intval($_GET['id']) : null; $groupId = isset($_GET['id']) ? intval($_GET['id']) : null;
$groups = GroupManager::get_group_list();
$data = array(); $data = GroupManager::exportCategoriesAndGroupsToArray($groupId, true);
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;
}
}
switch ($_GET['type']) { switch ($_GET['type']) {
case 'csv': case 'csv':
Export::export_table_csv($data); 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')); $form->addElement('button', 'submit', get_lang('Import'));
if ($form->validate()) { 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']); $groupData = Import::csv_reader($_FILES['file']['tmp_name']);
$deleteNotInArray = $form->getSubmitValue('delete_not_in_file') == 1 ? true : false; $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) 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); $course_info = api_get_course_info($course_code);
$session_id = api_get_session_id();
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER); $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$table_group = Database :: get_course_table(TABLE_GROUP); $table_group = Database :: get_course_table(TABLE_GROUP);
//condition for the session
$session_id = api_get_session_id();
$sql = "SELECT g.id, $sql = "SELECT g.id,
g.name, g.name,
g.description, 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 Christophe Gesche <christophe.gesche@claroline.net>
* @author Hugues Peeters <hugues.peeters@claroline.net> * @author Hugues Peeters <hugues.peeters@claroline.net>
* @author Bart Mollet * @author Bart Mollet
@ -413,6 +410,7 @@ class GroupManager
// Unsubscribe all users // Unsubscribe all users
self :: unsubscribe_all_users($group_ids); self :: unsubscribe_all_users($group_ids);
$sql = "SELECT id, secret_directory, session_id FROM $group_table $sql = "SELECT id, secret_directory, session_id FROM $group_table
WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")"; WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")";
$db_result = Database::query($sql); $db_result = Database::query($sql);
@ -1084,6 +1082,8 @@ class GroupManager
$sql = "SELECT user_id FROM $tutor_user_table $sql = "SELECT user_id FROM $tutor_user_table
WHERE c_id = $course_id AND group_id = $group_id"; WHERE c_id = $course_id AND group_id = $group_id";
$res = Database::query($sql); $res = Database::query($sql);
$users = array();
while ($obj = Database::fetch_object($res)) { while ($obj = Database::fetch_object($res)) {
$users[] = api_get_user_info($obj->user_id); $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 mixed $user_ids Can be an array with user-id's or a single user-id
* @param int $group_id * @param int $group_id
* @return bool TRUE if successfull * @return bool TRUE if successful
*/ */
public static function subscribe_users($user_ids, $group_id) public static function subscribe_users($user_ids, $group_id)
{ {
@ -1567,10 +1567,12 @@ class GroupManager
foreach ($user_ids as $user_id) { foreach ($user_ids as $user_id) {
$user_id = intval($user_id); $user_id = intval($user_id);
$group_id = intval($group_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) $sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id)
VALUES ('$course_id', '" . $user_id . "', '" . $group_id . "')"; VALUES ('$course_id', '" . $user_id . "', '" . $group_id . "')";
$result &= Database::query($sql); $result &= Database::query($sql);
} }
}
return $result; return $result;
} }
@ -2266,7 +2268,6 @@ class GroupManager
} }
/** /**
*
* @param array $groupData * @param array $groupData
* @param bool $deleteNotInArray * @param bool $deleteNotInArray
* @return array * @return array
@ -2404,6 +2405,27 @@ class GroupManager
$data['group_id'] = $groupId; $data['group_id'] = $groupId;
$result['updated']['group'][] = $data; $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; $elementsFound['groups'][] = $groupId;
} }
} }
@ -2434,9 +2456,11 @@ class GroupManager
/** /**
* Export all categories/group from a course to an array. * Export all categories/group from a course to an array.
* This function works only in a context of a course. * This function works only in a context of a course.
* @param int $groupId
* @param bool $loadUsers
* @return array * @return array
*/ */
public static function exportCategoriesAndGroupsToArray() public static function exportCategoriesAndGroupsToArray($groupId = null, $loadUsers = false)
{ {
$data = array(); $data = array();
$data[] = array( $data[] = array(
@ -2456,10 +2480,18 @@ class GroupManager
'groups_per_user' 'groups_per_user'
); );
$count = 1;
if ($loadUsers) {
$data[0][] = 'students';
$data[0][] = 'tutors';
}
if ($loadUsers == false) {
$categories = GroupManager::get_categories(); $categories = GroupManager::get_categories();
foreach ($categories as $categoryInfo) { foreach ($categories as $categoryInfo) {
$data[] = array( $data[$count] = array(
$categoryInfo['title'], $categoryInfo['title'],
null, null,
$categoryInfo['description'], $categoryInfo['description'],
@ -2475,6 +2507,8 @@ class GroupManager
$categoryInfo['self_unreg_allowed'], $categoryInfo['self_unreg_allowed'],
$categoryInfo['groups_per_user'] $categoryInfo['groups_per_user']
); );
$count++;
}
} }
$groups = GroupManager::get_group_list(); $groups = GroupManager::get_group_list();
@ -2487,7 +2521,31 @@ class GroupManager
$categoryTitle = $categoryInfo['title']; $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, $categoryTitle,
$groupSettings['name'], $groupSettings['name'],
$groupSettings['description'], $groupSettings['description'],
@ -2501,8 +2559,22 @@ class GroupManager
$groupSettings['maximum_number_of_students'], $groupSettings['maximum_number_of_students'],
$groupSettings['self_registration_allowed'], $groupSettings['self_registration_allowed'],
$groupSettings['self_unregistration_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; return $data;
} }

Loading…
Cancel
Save