-
Notifications
You must be signed in to change notification settings - Fork 502
[Grenoble] Améliorer le lien de création de groupe à partir d'une classe, refs #5774 #1709 #1710 #6295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[Grenoble] Améliorer le lien de création de groupe à partir d'une classe, refs #5774 #1709 #1710 #6295
Changes from all commits
3bbeba3
bc0b76f
d573589
27fa710
54babdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,18 @@ | |
|
||
break; | ||
case 'create_class_groups': | ||
GroupManager::create_class_groups($_POST['group_category']); | ||
$classIds = []; | ||
foreach (array_keys($_POST) as $key) { | ||
if (strpos($key, 'checkbox_class_id_') !== false) { | ||
$classId = str_replace('checkbox_class_id_', '', $key); | ||
$classIds[] = (int)$classId; | ||
} | ||
} | ||
if (isset($_POST['is_consistent_link'])) { | ||
GroupManager::create_usergroup_consistent_groups($_POST['group_category'], $classIds); | ||
} else { | ||
GroupManager::create_class_groups($_POST['group_category'], $classIds); | ||
} | ||
Display::addFlash(Display::return_message(get_lang('group(s) has (have) been added'))); | ||
header('Location: '.$currentUrl); | ||
exit; | ||
|
@@ -181,13 +192,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', | ||
|
@@ -203,13 +218,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', $_GET['category_id']); | ||
$defaults['group_'.$group_number.'_category'] = $_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); | ||
|
||
|
@@ -247,7 +278,7 @@ 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='.$_GET['category_id'] : '')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using $_GET[something], always filter it before using it as part of a URL. Here, because we know it's an integer (because it ends with |
||
$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'); | ||
|
@@ -306,16 +337,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', | ||
|
@@ -325,14 +347,42 @@ 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', $_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('Info message about deactivation of consistent link')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An info message should not start with "Info message about". It should be directly the message to the user 😄 |
||
); | ||
$classForm->addHtml('<p class="alert alert-info">'.get_lang('Info message about deactivation of consistent link').'</p>'); | ||
|
||
$classForm->addButtonSave(get_lang('Validate')); | ||
$defaults['group_category'] = GroupManager::DEFAULT_GROUP_CATEGORY; | ||
$defaults['action'] = 'create_class_groups'; | ||
$classForm->setDefaults($defaults); | ||
$classForm->display(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -14,7 +17,7 @@ | |
$groupEntity = api_get_group_entity($group_id); | ||
|
||
$nameTools = get_lang('Edit this group'); | ||
$interbreadcrumb[] = ['url' => 'group.php', 'name' => get_lang('Groups')]; | ||
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')]; | ||
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $groupEntity->getTitle()]; | ||
|
||
$is_group_member = GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity); | ||
|
@@ -227,6 +230,25 @@ function check_group_members($value) | |
|
||
$form->setDefaults($defaults); | ||
echo GroupManager::getSettingBar('member'); | ||
$form->display(); | ||
|
||
// check if group has a CGroupRelUsergroup | ||
$courseInfo = api_get_course_info_by_id(api_get_course_int_id()); | ||
|
||
if (GroupManager::is_group_linked_to_usergroup($groupEntity)) { | ||
|
||
echo '<div class="alert alert-info">Ce groupe est lié à la classe ' .$courseInfo['title'].'. La liste de ses membres dépend des membres de la classe et ne peut-être modifiée. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in French. Has to be translated to English, and because it includes a variable ( |
||
Allez dans les paramètres du groupe pour rompre ce lien si vous souhaitez ajouter ou ôter des membres de la classe. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. French |
||
</div>'; | ||
|
||
echo '<h3>Membres du groupe</h3>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. French |
||
$memberInfos = GroupManager::get_subscribed_users($groupEntity); | ||
echo '<ul>'; | ||
foreach ($memberInfos as $memberInfo) { | ||
echo '<li>'.$memberInfo['firstname'].' '.$memberInfo['lastname'].' ('.$memberInfo['username'].')'.'</li>'; | ||
} | ||
echo '</ul>'; | ||
} else { | ||
$form->display(); | ||
} | ||
|
||
Display::display_footer(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,13 @@ | |
$groupRepo = Container::getGroupRepository(); | ||
/** @var CGroup $groupEntity */ | ||
$groupEntity = $groupRepo->find($group_id); | ||
$linkedCategory = GroupManager::get_category_from_group($group_id); | ||
|
||
if (isset($_GET['remove_consistent_link'])) { | ||
GroupManager::remove_group_consistent_link($groupEntity); | ||
Display::addFlash(Display::return_message(get_lang('Group is no longer linked to the course'), 'normal')); | ||
header('Location: group.php?'.api_get_cidreq(true, false)); | ||
} | ||
|
||
if (null === $groupEntity) { | ||
api_not_allowed(true); | ||
|
@@ -35,9 +42,7 @@ | |
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $groupEntity->getTitle()]; | ||
$groupMember = GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity); | ||
|
||
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()); | ||
|
@@ -55,6 +60,17 @@ | |
// Group name | ||
$form->addElement('text', 'name', get_lang('Group name')); | ||
|
||
if (!$groupMember && !api_is_allowed_to_edit(false, true)) { | ||
api_not_allowed(true); | ||
} | ||
|
||
// Message for group rel usergroup | ||
if (GroupManager::is_group_linked_to_usergroup($groupEntity)) { | ||
$form->addHtml('<div class="alert alert-info">'.get_lang('Warning message to warn that the user cannot modify members of linked group').'<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A warning message should be the message to the final user, not start with "Warning message to warn...". |
||
<a href="settings.php?'.api_get_cidreq().'&remove_consistent_link=true" class="btn p-button-sm p-button p-mr-2 mt-2 pointer">'.get_lang('Remove the group link with the class'). | ||
'</a></div>'); | ||
} | ||
|
||
if ('true' === api_get_setting('allow_group_categories')) { | ||
$groupCategories = GroupManager::get_categories(); | ||
$categoryList = []; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$_GET['category_id']
should be filtered (because we know it's an integer) with(int) $_GET['category_id']
When a
$categoryId
comes from an integer field in the database, you know it's an integer so you don't have to filter it, but anything from $_GET, $_POST, $_REQUEST, even $_SESSION and other superglobals has to be filtered before inserting into the database or an URL or anything on a web page.