From 84a647e7b2250953452715108c884864442254a6 Mon Sep 17 00:00:00 2001 From: Esteban Ristich Date: Tue, 28 Jan 2025 16:07:51 +0100 Subject: [PATCH] Group: fix new group category creation --- public/main/group/group.php | 21 ++++++++++++--------- public/main/group/group_category.php | 8 ++++++-- public/main/inc/lib/groupmanager.lib.php | 14 +++++++------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/public/main/group/group.php b/public/main/group/group.php index ef16868feaf..85c306341fc 100644 --- a/public/main/group/group.php +++ b/public/main/group/group.php @@ -234,12 +234,13 @@ /* List all categories */ if ('true' === api_get_setting('allow_group_categories')) { - $defaultCategory = [ - 'iid' => null, - 'description' => '', - 'title' => get_lang('Default groups'), - ]; - $categories = array_merge([$defaultCategory], $categories); + if (empty($categories)) { + $defaultCategoryId = GroupManager::create_category( + get_lang('Default groups') + ); + $defaultCategory = GroupManager::get_category($defaultCategoryId); + $categories = [$defaultCategory]; + } $course = api_get_course_entity(); foreach ($categories as $index => $category) { $categoryId = $category['iid']; @@ -264,13 +265,15 @@ // Edit $actions .= ''. - Display::getMdiIcon('edit', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).''; + Display::getMdiIcon('pencil', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).''; // Delete $actions .= Display::url( - Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')), + Display::getMdiIcon(ActionIcon::DELETE, count($categories) == 1 ? 'ch-tool-icon-disabled' : 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')), 'group.php?'.api_get_cidreq().'&action=delete_category&category_id='.$categoryId, - [ + count($categories) == 1 ? [ + 'onclick' => 'javascript:alert('."'".addslashes(api_htmlentities(get_lang('You cannot delete the last category'), ENT_QUOTES))."'".'); return false;', + ] : [ 'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;', ] ); diff --git a/public/main/group/group_category.php b/public/main/group/group_category.php index 9fe24a037b2..9a2fe4d70b6 100644 --- a/public/main/group/group_category.php +++ b/public/main/group/group_category.php @@ -103,7 +103,11 @@ function check_groups_per_user($value) } else { // Create a new category $action = 'add_category'; - $form = new FormValidator('group_category'); + $form = new FormValidator( + 'group_category', + 'post', + api_get_self().'?'.api_get_cidreq() + ); } $form->addElement('header', $nameTools); @@ -436,7 +440,7 @@ function check_groups_per_user($value) // Else display the form Display::display_header($nameTools, 'Group'); -$actions = ''. +$actions = ''. Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back to Groups list')).''; echo Display::toolbarAction('toolbar', [$actions]); diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index dc3709cd11f..4c9f42c94f8 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -889,13 +889,13 @@ public static function delete_category($cat_id, $course_code = '') */ public static function create_category( $title, - $description, - $docState, - $workState, - $calendarState, - $anonuncementState, - $forumState, - $wikiState, + $description = '', + $docState = 1, + $workState = 1, + $calendarState = 1, + $anonuncementState = 1, + $forumState = 1, + $wikiState = 1, $chatState = 1, $selfRegistrationAllowed = 0, $selfUnRegistrationAllowed = 0,