Fixing group import when there are categories see BT#7682

1.9.x
Julio Montoya 12 years ago
parent 65119bc7f2
commit 11646b65e1
  1. 5
      main/group/example.csv
  2. 5
      main/group/import.php
  3. 8
      main/inc/lib/groupmanager.lib.php

@ -0,0 +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 1";"";"This is a category";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"0";
"";"This is a group with no category";"";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0"
"Category 1";"This is a group in a Category 1";"";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0"
Can't render this file because it has a wrong number of fields in line 3.

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */
// Name of the language file that needs to be included
$language_file = 'group';
$language_file = array('group', 'admin', 'registration');
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
@ -31,6 +31,7 @@ $form->addElement('header', get_lang('ImportGroups'));
$form->addElement('file', 'file', get_lang('File'));
$form->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('checkbox', 'delete_not_in_file', null, get_lang('DeleteItemsNotInFile'));
$form->addElement('label', null, Display::url(get_lang('ExampleCSVFile'), api_get_path(WEB_CODE_PATH).'group/example.csv'));
$form->addElement('button', 'submit', get_lang('Import'));
if ($form->validate()) {
@ -42,7 +43,6 @@ if ($form->validate()) {
if (!empty($result)) {
$html = null;
foreach ($result as $status => $data) {
if (empty($data['category']) && empty($data['group'])) {
continue;
}
@ -66,6 +66,7 @@ if ($form->validate()) {
}
}
}
$form->display();
Display::display_footer();

@ -2153,6 +2153,8 @@ class GroupManager
'groups' => array()
);
$groupCategories = GroupManager :: get_categories();
foreach ($groupData as $data) {
$isCategory = empty($data['group']) ? true : false;
@ -2209,9 +2211,15 @@ class GroupManager
if (empty($groupInfo)) {
$categoryInfo = self::getCategoryByTitle($data['category']);
$categoryId = null;
if (!empty($categoryInfo)) {
$categoryId = $categoryInfo['id'];
} else {
if (!empty($groupCategories) && isset($groupCategories[0])) {
$defaultGroupCategory = $groupCategories[0];
$categoryId = $defaultGroupCategory['id'];
}
}
// Add

Loading…
Cancel
Save