Skip to content

Commit

Permalink
Group: fix new group category creation
Browse files Browse the repository at this point in the history
  • Loading branch information
eristich committed Jan 28, 2025
1 parent 3cd6116 commit 84a647e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
21 changes: 12 additions & 9 deletions public/main/group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -264,13 +265,15 @@
// Edit
$actions .= '<a
href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
Display::getMdiIcon('edit', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).'</a>';
Display::getMdiIcon('pencil', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).'</a>';

// 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;',
]
);
Expand Down
8 changes: 6 additions & 2 deletions public/main/group/group_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -436,7 +440,7 @@ function check_groups_per_user($value)
// Else display the form
Display::display_header($nameTools, 'Group');

$actions = '<a href="group.php">'.
$actions = '<a href="group.php?'.api_get_cidreq().'">'.
Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back to Groups list')).'</a>';
echo Display::toolbarAction('toolbar', [$actions]);

Expand Down
14 changes: 7 additions & 7 deletions public/main/inc/lib/groupmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 84a647e

Please sign in to comment.