Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions public/main/group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,18 @@
if ('true' === api_get_setting('allow_group_categories')) {
if (empty($categories)) {
$defaultCategoryId = GroupManager::create_category(
get_lang('Default groups')
get_lang('Default groups'),
'',
GroupManager::TOOL_NOT_AVAILABLE,
GroupManager::TOOL_NOT_AVAILABLE,
GroupManager::TOOL_NOT_AVAILABLE,
GroupManager::TOOL_NOT_AVAILABLE,
GroupManager::TOOL_NOT_AVAILABLE,
GroupManager::TOOL_NOT_AVAILABLE,
GroupManager::TOOL_NOT_AVAILABLE,
0,
0,
1
);
$defaultCategory = GroupManager::get_category($defaultCategoryId);
$categories = [$defaultCategory];
Expand Down Expand Up @@ -272,7 +283,10 @@
$actions .= '<a
href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
Display::getMdiIcon('pencil', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).'</a>';

// Add group
$actions .= ' <a
href="group_creation.php?'.api_get_cidreq().'&category_id='.$categoryId.'">'.
Display::getMdiIcon(ActionIcon::SUBSCRIBE_GROUP_USERS_TO_RESOURCE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Create new group(s)')).'</a>';
// Delete
$actions .= Display::url(
Display::getMdiIcon(ActionIcon::DELETE, count($categories) == 1 ? 'ch-tool-icon-disabled' : 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')),
Expand Down
3 changes: 3 additions & 0 deletions public/main/group/group_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ function check_groups_per_user($value)
$defaults['max_member_no_limit'] = 1;
$defaults['max_member'] = $defaults['max_student'];
}
if ('true' === api_get_setting('allow_group_categories') && isset($_GET['id'])) {
$defaults['id'] = (int) $_GET['id'];
}
$form->setDefaults($defaults);
$form->display();

Expand Down
111 changes: 82 additions & 29 deletions public/main/group/group_creation.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@

break;
case 'create_class_groups':
GroupManager::create_class_groups($_POST['group_category']);
$classIds = [];
foreach (array_keys($_POST) as $key) {
if (str_contains($key, 'checkbox_class_id_')) {
$classId = str_replace('checkbox_class_id_', '', $key);
$classIds[] = (int) $classId;
}
}
if (isset($_POST['is_consistent_link'])) {
GroupManager::create_usergroup_consistent_groups((int) $_POST['group_category'], $classIds);
} else {
GroupManager::create_class_groups((int) $_POST['group_category'], $classIds);
}
Display::addFlash(Display::return_message(get_lang('group(s) has (have) been added')));
header('Location: '.$currentUrl);
exit;
Expand All @@ -87,6 +98,11 @@
}

$nameTools = get_lang('New groups creation');

if ($allowGroupCategories && isset($_GET['category_id']) && isset($categories[(int)$_GET['category_id']])) {
$nameTools = sprintf(get_lang('New groups creation in category %s'), $categories[(int)$_GET['category_id']]);
}

$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
Expand Down Expand Up @@ -181,13 +197,17 @@ function copy_value(key) {
$group_el = [];
$group_el[] = $form->createElement('static', null, null, ' ');
if ($allowGroupCategories) {
$group_el[] = $form->createElement(
'checkbox',
'same_category',
null,
get_lang('same for all'),
['onclick' => "javascript: switch_state('category');"]
);
if (!isset($_GET['category_id'])) {
$group_el[] = $form->createElement(
'checkbox',
'same_category',
null,
get_lang('same for all'),
['onclick' => "javascript: switch_state('category');"]
);
} else {
$group_el[] = $form->createElement('static', null, null, ' ');
}
}
$group_el[] = $form->createElement(
'checkbox',
Expand All @@ -203,13 +223,29 @@ function copy_value(key) {
$group_el = [];
$group_el[] = $form->createElement('text', 'group_'.$group_number.'_name');
if ($allowGroupCategories) {
$group_el[] = $form->createElement(
'select',
'group_'.$group_number.'_category',
null,
$categories,
['id' => 'category_'.$group_number]
);
if (isset($_GET['category_id'])) {
$group_el[] = $form->createElement(
'select',
'group_' . $group_number . '_category',
null,
$categories,
[
'id' => 'category_' . $group_number,
'disabled' => 'true',
'style' => 'background-color: #f0f0f0;'
]
);
$group_el[] = $form->createElement('hidden', 'group_'.$group_number.'_category', (int)$_GET['category_id']);
$defaults['group_'.$group_number.'_category'] = (int)$_GET['category_id'];
} else {
$group_el[] = $form->createElement(
'select',
'group_' . $group_number . '_category',
null,
$categories,
['id' => 'category_' . $group_number]
);
}
} else {
$group_el[] = $form->createElement('hidden', 'group_'.$group_number.'_category', 0);

Expand Down Expand Up @@ -243,7 +279,11 @@ function copy_value(key) {
/*
* Show form to generate new groups
*/
$create_groups_form = new FormValidator('create_groups', 'post', api_get_self().'?'.api_get_cidreq());
$create_groups_form = new FormValidator(
'create_groups',
'post',
api_get_self().'?'.api_get_cidreq().(isset($_GET['category_id']) ? '&category_id='.(int)$_GET['category_id'] : '')
);
$create_groups_form->addElement('header', $nameTools);
$create_groups_form->addText('number_of_groups', get_lang('Number of groups to create'), null, ['value' => '1']);
$create_groups_form->addButton('submit', get_lang('Proceed to create group(s)'), 'plus', 'primary');
Expand Down Expand Up @@ -302,17 +342,7 @@ function copy_value(key) {
$obj = new UserGroupModel();
$classes = $obj->getUserGroupInCourse($options);
if (count($classes) > 0) {
$description = '<p>'.get_lang('Using this option, you can create groups based on the classes subscribed to your course.').'</p>';
$description .= '<ul>';
foreach ($classes as $index => $class) {
$number_of_users = count($obj->get_users_by_usergroup($class['id']));
$description .= '<li>';
$description .= $class['name'];
$description .= ' ('.$number_of_users.' '.get_lang('Users').')';
$description .= '</li>';
}
$description .= '</ul>';

$description = '<p>'.get_lang('Using this option, you can create groups based on the classes subscribed to your course.').'</p><br>';
$classForm = new FormValidator(
'create_class_groups_form',
'post',
Expand All @@ -321,14 +351,37 @@ function copy_value(key) {
$classForm->addHeader(get_lang('Groups from classes'));

$classForm->addHtml($description);
$classGroup = [];
foreach ($classes as $index => $class) {
$number_of_users = count($obj->get_users_by_usergroup($class['id']));
// $classForm->addCheckBox('checkbox_class_id_'.$class['id'], $class['title'] . ' ('.$number_of_users.' '.get_lang('Users').')');
$classGroup[] = $classForm->createElement('checkbox', 'checkbox_class_id_'.$class['id'], null, $class['title'] . ' ('.$number_of_users.' '.get_lang('Users').')');
}
$classForm->addGroup(
$classGroup,
'',
null,
null,
false
);
$classForm->addElement('hidden', 'action');
if ($allowGroupCategories) {
$classForm->addSelect('group_category', null, $categories);
if (isset($_GET['category_id'])) {
$classForm->addElement('hidden', 'group_category', (int)$_GET['category_id']);
} else {
$classForm->addSelect('group_category', null, $categories);
}
} else {
$classForm->addElement('hidden', 'group_category');
}

$classForm->addHtml('<div style="height: 1px; width: 100%; background-color: #e6e6e6; border-radius: 8px;" /><br>');

$classForm->addCheckBox('is_consistent_link', null, get_lang('Link classes to created groups ?'),
['title' => get_lang('Link classes to created groups ?')]);
$classForm->addHtml('<p class="alert alert-info">'.get_lang('If a class is linked to a group, users added to or removed from the class are automatically added to or removed from the group.').'</p>');

$classForm->addButtonSave(get_lang('Validate'));
$defaults['group_category'] = GroupManager::DEFAULT_GROUP_CATEGORY;
$defaults['action'] = 'create_class_groups';
$classForm->setDefaults($defaults);
$classForm->display();
Expand Down
6 changes: 6 additions & 0 deletions public/main/group/group_space.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class="inline-flex items-center gap-2 rounded-md border border-red-200 bg-white
}
}

// add edit tool
$actions_array[] = [
'url' => 'settings.php?'.api_get_cidreq(true, false).'&gid='.$group_id,
'content' => Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')),
];

if (GroupManager::TOOL_NOT_AVAILABLE != $groupEntity->getDocState()) {
$params = ['toolName' => 'document', 'cid' => $courseId];
$url = Container::getRouter()->generate('chamilo_core_course_redirect_tool', $params).'?'.api_get_cidreq();
Expand Down
22 changes: 21 additions & 1 deletion public/main/group/member_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/* For licensing terms, see /license.txt */

require_once __DIR__.'/../inc/global.inc.php';

use Chamilo\CoreBundle\Framework\Container;

$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;

Expand Down Expand Up @@ -237,6 +240,23 @@ function check_group_members($value)
}

$form->setDefaults($defaults);
$form->display();

// check if group has a CGroupRelUsergroup
$courseInfo = api_get_course_info_by_id(api_get_course_int_id());

if (GroupManager::isGroupLinkedToUsergroup($groupEntity)) {

echo '<div class="alert alert-info">'.sprintf(get_lang('This group is linked to class %s.<br>Group member list depends on class members and cannot be modified.<br>Go to the group settings to break this link if you wish to add or remove members for this group.'), $courseInfo['title']).'</div>';

echo '<h3>'.get_lang('Group members').'</h3>';
$memberInfos = GroupManager::get_subscribed_users($groupEntity);
echo '<ul>';
foreach ($memberInfos as $memberInfo) {
echo '<li>'.ucfirst($memberInfo['firstname']).' '.ucfirst($memberInfo['lastname']).' ('.$memberInfo['email'].')'.'</li>';
}
echo '</ul>';
} else {
$form->display();
}

Display::display_footer();
33 changes: 32 additions & 1 deletion public/main/group/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@
$groupRepo = Container::getGroupRepository();
/** @var CGroup $groupEntity */
$groupEntity = $groupRepo->find($group_id);

if (null === $groupEntity) {
api_not_allowed(true);
}

$linkedCategory = GroupManager::get_category_from_group($group_id);

if ('POST' === $_SERVER['REQUEST_METHOD']
&& isset($_POST['remove_consistent_link'])
&& api_is_allowed_to_edit(false, true)
&& Security::check_token('post')
) {
GroupManager::remove_group_consistent_link($groupEntity);
Security::clear_token();
Display::addFlash(Display::return_message(get_lang('The group is no longer linked to the class'), 'normal'));
header('Location: group.php?'.api_get_cidreq(true, false));
exit;
}

$nameTools = get_lang('Edit this group');
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $groupEntity->getTitle()];
Expand All @@ -30,6 +43,7 @@
if (!$groupMember && !api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}
$courseInfo = api_get_course_info_by_id(api_get_course_int_id());

// Build form
$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
Expand Down Expand Up @@ -60,6 +74,23 @@
]);
$form->addHtml('</div>');

// Message for group rel usergroup
if (GroupManager::isGroupLinkedToUsergroup($groupEntity)) {
$unlinkToken = Security::get_token();
$unlinkForm = '<form method="post" action="settings.php?'.api_get_cidreq().'" style="display:inline">'.
'<input type="hidden" name="remove_consistent_link" value="1">'.
'<input type="hidden" name="sec_token" value="'.$unlinkToken.'">'.
'<button type="submit" class="btn p-button-sm p-button p-mr-2 mt-2" onclick="return confirm(\''.addslashes(get_lang('Are you sure?')).'\')">'.
get_lang('Remove the group link with the class').
'</button></form>';
$form->addHtml(
'<div class="alert alert-info">'.
get_lang('Warning message to warn that the user cannot modify members of linked group').
'<br>'.$unlinkForm.
'</div>'
);
}

// Category
if ('true' === api_get_setting('allow_group_categories')) {
$groupCategories = GroupManager::get_categories();
Expand Down
1 change: 1 addition & 0 deletions public/main/inc/lib/database.constants.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
define('TABLE_GROUP_USER', 'group_rel_user');
define('TABLE_GROUP_TUTOR', 'group_rel_tutor');
define('TABLE_GROUP_CATEGORY', 'group_category');
define('TABLE_GROUP_CLASS', 'group_rel_usergroup');

// Course dropbox tables
define('TABLE_DROPBOX_CATEGORY', 'dropbox_category');
Expand Down
Loading
Loading