Skip to content

[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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

eristich
Copy link
Contributor

No description provided.

* @return array
* @throws \Doctrine\DBAL\DBALException
*/
public static function create_usergroup_consistent_groups(int $category_id = 0, array $classIds = []): array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method create_usergroup_consistent_groups has 63 lines of code (exceeds 25 allowed). Consider refactoring.

* @return array
* @throws \Doctrine\DBAL\DBALException
*/
public static function create_usergroup_consistent_groups(int $category_id = 0, array $classIds = []): array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_usergroup_consistent_groups has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

*
* @return array
*/
public static function create_class_groups($categoryId)
public static function create_class_groups(int $categoryId, array $classIds = []): array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_class_groups has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

Copy link

codeclimate bot commented May 15, 2025

Code Climate has analyzed commit 54babdc and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

Copy link
Member

@ywarnier ywarnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several (small) things to fix before this can be merged.

@@ -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'] : ''));
Copy link
Member

Choose a reason for hiding this comment

The 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 _id), you can immediately and very cheaply filter it with (int) $_GET['category_id'] directly inside the concatenation.

]
);
$group_el[] = $form->createElement('hidden', 'group_'.$group_number.'_category', $_GET['category_id']);
$defaults['group_'.$group_number.'_category'] = $_GET['category_id'];
Copy link
Member

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.


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.
Copy link
Member

Choose a reason for hiding this comment

The 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 ($courseInfo['title']), it should be a string with a %s` in it, and the get_lang() call should be called inside a sprintf() call. Look for sprintf in the code, I'm sure you'll find many examples.

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.
Allez dans les paramètres du groupe pour rompre ce lien si vous souhaitez ajouter ou ôter des membres de la classe.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

French

Allez dans les paramètres du groupe pour rompre ce lien si vous souhaitez ajouter ou ôter des membres de la classe.
</div>';

echo '<h3>Membres du groupe</h3>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

French


// 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>
Copy link
Member

Choose a reason for hiding this comment

The 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...".

@@ -2317,6 +2502,9 @@ class = "btn btn--plain"
$table->set_header($column++, get_lang('Groups'));
$table->set_header($column++, get_lang('Group tutor'));
$table->set_header($column++, get_lang('Registered'), false);
if (api_get_setting('allow_group_categories') === 'true') {
$table->set_header($column++, get_lang('Classe liée'), false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text in French. Should be "Linked class".


msgid "Group is no longer linked to the course"
msgstr "Group is no longer linked to the course"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the wrong text msgid for those messages like "Info message about ..." and "Warning message to warn..." (should be updated together with the code).
It is also missing the various strings that are currently in French in the code.

Also, try to always add your new strings at the end of the file. No matter the group of strings or any alphabetical order.


msgid "Group is no longer linked to the course"
msgstr "Le groupe n'esp plus lié au cours"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same notes as for the English file


msgid "Group is no longer linked to the course"
msgstr ""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same notes as for the English file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants