Remove user of DEFAULT_GROUP_CATEGORY and VIRTUAL_COURSE_CATEGORY

If group doesn't have a category then category_id = 0

See BT#7682
1.10.x
Julio Montoya 10 years ago
parent fa4db6debe
commit f0abad1340
  1. 42
      main/group/group.php
  2. 2
      main/group/group_category.php
  3. 67
      main/group/group_creation.php
  4. 4
      main/inc/lib/groupmanager.lib.php
  5. 3
      src/Chamilo/CoreBundle/Migrations/Schema/V110/Version20150522112023.php

@ -38,19 +38,6 @@ $(document).ready( function() {
$nameTools = get_lang('GroupManagement');
$course_id = api_get_course_int_id();
// Create default category if it doesn't exist when group categories aren't allowed
if (api_get_setting('allow_group_categories') == 'false') {
$cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
$sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".GroupManager::DEFAULT_GROUP_CATEGORY."'";
$res = Database::query($sql);
$num = Database::num_rows($res);
if ($num == 0) {
$sql = "INSERT INTO $cat_table (c_id, id , title , description , forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)
VALUES ($course_id, '2', '".Database::escape_string(get_lang('DefaultGroupCategory'))."', '', '1', '1', '8', '0', '0', '0', '0');";
Database::query($sql);
}
}
/* Header */
Display::display_header(get_lang('Groups'));
@ -196,28 +183,41 @@ echo UserManager::getUserSubscriptionTab(4);
/* List all categories */
if (api_get_setting('allow_group_categories') == 'true') {
$defaultCategory = [
'id' => 0,
'description' => '',
'title' => get_lang('DefaultGroupCategory')
];
$group_cats = array_merge($group_cats, [$defaultCategory]);
foreach ($group_cats as $index => $category) {
$group_list = GroupManager::get_group_list($category['id']);
$categoryId = $category['id'];
$group_list = GroupManager::get_group_list($categoryId);
$groupToShow = GroupManager::process_groups($group_list, $categoryId);
if (empty($groupToShow)) {
continue;
}
$label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info');
$actions = null;
if (api_is_allowed_to_edit(false, true)) {
$actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.
if (api_is_allowed_to_edit(false, true) && !empty($categoryId)) {
$actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
$actions .=
Display::url(
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL),
'group.php?'.api_get_cidreq().'&action=delete_category&id='.$category['id'],
'group.php?'.api_get_cidreq().'&action=delete_category&id='.$categoryId,
array(
'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;'
)
);
if ($index != 0) {
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$category['id'].'&id2='.$group_cats[$index -1]['id'].'">'.
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index -1]['id'].'">'.
Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
}
if ($index != count($group_cats) - 1) {
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$category['id'].'&id2='.$group_cats[$index +1]['id'].'">'.
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index +1]['id'].'">'.
Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
}
}
@ -230,11 +230,11 @@ if (api_get_setting('allow_group_categories') == 'true') {
);
echo $category['description'];
GroupManager::process_groups($group_list, $category['id']);
echo $groupToShow;
}
} else {
$group_list = GroupManager::get_group_list();
GroupManager::process_groups($group_list);
echo GroupManager::process_groups($group_list);
}
if (!isset($_GET['origin']) || $_GET['origin'] != 'learnpath') {

@ -49,7 +49,7 @@ function check_groups_per_user($value)
}
if (api_get_setting('allow_group_categories') == 'true') {
if (isset ($_GET['id'])) {
if (isset($_GET['id'])) {
$category = GroupManager::get_category($_GET['id']);
$nameTools = get_lang('EditGroupCategory').': '.$category['title'];
} else {

@ -34,7 +34,7 @@ if (isset($_POST['action'])) {
$group['places'] = $_POST['group_0_places'];
}
if (api_get_setting('allow_group_categories') == 'false') {
$group['category'] = GroupManager::DEFAULT_GROUP_CATEGORY;
$group['category'] = 0;
} elseif (isset($_POST['same_category']) && $_POST['same_category']) {
$group['category'] = $_POST['group_0_category'];
}
@ -51,7 +51,10 @@ if (isset($_POST['action'])) {
exit;
break;
case 'create_subgroups':
GroupManager::create_subgroups($_POST['base_group'], $_POST['number_of_groups']);
GroupManager::create_subgroups(
$_POST['base_group'],
$_POST['number_of_groups']
);
$msg = urlencode($_POST['number_of_groups'].' '.get_lang('GroupsAdded'));
header('Location: group.php?action=show_msg&msg='.$msg);
exit;
@ -73,13 +76,13 @@ if (!api_is_allowed_to_edit(false, true)) {
api_not_allowed();
}
/* MAIN TOOL CODE */
/* Show group-settings-form */
elseif (isset($_POST['number_of_groups'])) {
if (isset($_POST['number_of_groups'])) {
if (!is_numeric($_POST['number_of_groups']) || intval($_POST['number_of_groups']) < 1) {
Display :: display_error_message(get_lang('PleaseEnterValidNumber').'<br /><br /><a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>', false);
Display :: display_error_message(
get_lang('PleaseEnterValidNumber').'<br /><br />
<a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>',
false
);
} else {
$number_of_groups = intval($_POST['number_of_groups']);
if ($number_of_groups > 1) {
@ -121,10 +124,7 @@ elseif (isset($_POST['number_of_groups'])) {
$group_categories = GroupManager::get_categories();
$group_id = GroupManager :: get_number_of_groups() + 1;
foreach ($group_categories as $index => $category) {
// Don't allow new groups in the virtual course category!
if ($category['id'] != GroupManager::VIRTUAL_COURSE_CATEGORY) {
$cat_options[$category['id']] = $category['title'];
}
$cat_options[$category['id']] = $category['title'];
}
$form = new FormValidator('create_groups_step2', 'POST', api_get_self().'?'.api_get_cidreq());
@ -149,16 +149,16 @@ EOT;
$form->addElement('header', $nameTools);
$form->addElement('hidden', 'action');
$form->addElement('hidden', 'number_of_groups');
$defaults = array ();
$defaults = array();
// Table heading
$group_el = array ();
$group_el = array();
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupName').'</b>');
if (api_get_setting('allow_group_categories') == 'true') {
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupCategory').'</b>');
}
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupPlacesThis').'</b>');
$form->addGroup($group_el, 'groups', null, "\n</td>\n<td>\n", false);
$form->addGroup($group_el, 'groups', null, "</td><td>", false);
// Checkboxes
if ($_POST['number_of_groups'] > 1) {
$group_el = array ();
@ -171,7 +171,7 @@ EOT;
}
// Properties for all groups
for ($group_number = 0; $group_number < $_POST['number_of_groups']; $group_number ++) {
$group_el = array ();
$group_el = array();
$group_el[] = $form->createElement('text', 'group_'.$group_number.'_name');
if (api_get_setting('allow_group_categories') == 'true') {
$group_el[] = $form->createElement('select', 'group_'.$group_number.'_category', null, $cat_options, array('id' => 'category_'.$group_number));
@ -203,21 +203,17 @@ EOT;
/*
* Show form to generate new groups
*/
$categories = GroupManager :: get_categories();
if (count($categories) > 1 || isset ($categories[0]) && $categories[0]['id'] != GroupManager::VIRTUAL_COURSE_CATEGORY) {
$create_groups_form = new FormValidator('create_groups', 'post', api_get_self().'?'.api_get_cidreq());
$create_groups_form->addElement('header', $nameTools);
$group_el = array ();
$group_el[] = $create_groups_form->createElement('text', 'number_of_groups', array(get_lang('Create'), '1'));
$group_el[] = $create_groups_form->addButtonCreate(get_lang('ProceedToCreateGroup'), 'submit', true);
$create_groups_form->addGroup($group_el, 'create_groups', get_lang('NumberOfGroupsToCreate'), ' ', false);
$defaults = array();
$defaults['number_of_groups'] = 1;
$create_groups_form->setDefaults($defaults);
$create_groups_form->display();
} else {
echo get_lang('NoCategoriesDefined');
}
$create_groups_form = new FormValidator('create_groups', 'post', api_get_self().'?'.api_get_cidreq());
$create_groups_form->addElement('header', $nameTools);
$group_el = array ();
$group_el[] = $create_groups_form->createElement('text', 'number_of_groups', array(get_lang('Create'), '1'));
$group_el[] = $create_groups_form->addButtonCreate(get_lang('ProceedToCreateGroup'), 'submit', true);
$create_groups_form->addGroup($group_el, 'create_groups', get_lang('NumberOfGroupsToCreate'), ' ', false);
$defaults = array();
$defaults['number_of_groups'] = 1;
$create_groups_form->setDefaults($defaults);
$create_groups_form->display();
/*
* Show form to generate subgroups
@ -232,7 +228,7 @@ EOT;
}
}
if (count($base_group_options) > 0) {
$create_subgroups_form = new FormValidator('create_subgroups');
$create_subgroups_form = new FormValidator('create_subgroups', 'post', api_get_self().'?'.api_get_cidreq());
$create_subgroups_form->addElement('header', get_lang('CreateSubgroups'));
$create_subgroups_form->addElement('html', get_lang('CreateSubgroupsInfo'));
$create_subgroups_form->addElement('hidden', 'action');
@ -270,16 +266,13 @@ EOT;
}
echo '</ul>';
$create_class_groups_form = new FormValidator('create_class_groups_form');
$create_class_groups_form = new FormValidator('create_class_groups_form', 'post', api_get_self().'?'.api_get_cidreq());
$create_class_groups_form->addElement('hidden', 'action');
if (api_get_setting('allow_group_categories') == 'true') {
$group_categories = GroupManager :: get_categories();
$cat_options = array ();
foreach ($group_categories as $index => $category) {
// Don't allow new groups in the virtual course category!
if ($category['id'] != GroupManager::VIRTUAL_COURSE_CATEGORY) {
$cat_options[$category['id']] = $category['title'];
}
$cat_options[$category['id']] = $category['title'];
}
$create_class_groups_form->addElement('select', 'group_category', null, $cat_options);
} else {

@ -804,12 +804,12 @@ class GroupManager
$categoryId = Database::insert_id();
// @todo check if this code do something ... virtual course category?
if ($categoryId == self::VIRTUAL_COURSE_CATEGORY) {
/*if ($categoryId == self::VIRTUAL_COURSE_CATEGORY) {
$sql = "UPDATE ".$table_group_category." SET id = ". ($categoryId +1)."
WHERE c_id = $course_id AND id = $categoryId";
Database::query($sql);
$categoryId = $categoryId +1;
}
}*/
$sql = "UPDATE $table_group_category SET id = iid WHERE iid = $categoryId";
Database::query($sql);

@ -16,6 +16,9 @@ class Version20150522112023 extends AbstractMigrationChamilo
*/
public function up(Schema $schema)
{
// Set 0 if there's no group category.
$this->addSql('UPDATE c_group_info SET category_id = 0 WHERE category_id = 2');
$this->addSql('ALTER TABLE usergroup ADD group_type INT NOT NULL, ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL');
$this->addSql('ALTER TABLE usergroup ADD picture VARCHAR(255) DEFAULT NULL, ADD url VARCHAR(255) DEFAULT NULL, ADD visibility VARCHAR(255) NOT NULL, ADD allow_members_leave_group INT NOT NULL, CHANGE description description LONGTEXT DEFAULT NULL');
$this->addSql('CREATE TABLE usergroup_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, group_id INT NOT NULL, subgroup_id INT NOT NULL, relation_type INT NOT NULL, PRIMARY KEY(id));');

Loading…
Cancel
Save