From 50b9c091e4c2a6a004c8a3699ccffbab450b43ad Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 24 Sep 2020 15:39:03 +0200 Subject: [PATCH] Internal - Fix queries, fix behat tests --- public/main/forum/forumfunction.inc.php | 54 ++++++------------- public/main/forum/viewthread.php | 3 +- public/main/group/group_creation.php | 49 +++++++++-------- public/main/group/settings.php | 4 +- .../template/default/forum/list.html.twig | 10 ++-- .../behat/features/sessionManagement.feature | 3 +- tests/behat/features/toolGroup.feature | 2 +- 7 files changed, 52 insertions(+), 73 deletions(-) diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php index 18fcdf9fe6..c200a7501a 100644 --- a/public/main/forum/forumfunction.inc.php +++ b/public/main/forum/forumfunction.inc.php @@ -270,7 +270,7 @@ function show_add_forumcategory_form($lp_id) ); $extraField = new ExtraField('forum_category'); - $returnParams = $extraField->addElements( + $extraField->addElements( $form, null, [], //exclude @@ -571,8 +571,11 @@ function delete_forum_image($forum_id) function editForumCategoryForm(CForumCategory $category) { $categoryId = $category->getIid(); - $form = new FormValidator('forumcategory', 'post', 'index.php?action=edit_category&'.api_get_cidreq().'&id='.$categoryId); - + $form = new FormValidator( + 'forumcategory', + 'post', + 'index.php?action=edit_category&'.api_get_cidreq().'&id='.$categoryId + ); // Setting the form elements. $form->addElement('header', '', get_lang('Edit forumCategory')); @@ -652,7 +655,6 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) $session_id = api_get_session_id(); $clean_cat_title = $values['forum_category_title']; $last_id = null; - $repo = Container::getForumCategoryRepository(); if (isset($values['forum_category_id'])) { @@ -665,15 +667,7 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) $repo->getEntityManager()->persist($category); $repo->getEntityManager()->flush(); - - /*api_item_property_update( - $courseInfo, - TOOL_FORUM_CATEGORY, - $values['forum_category_id'], - 'ForumCategoryUpdated', - api_get_user_id() - );*/ - $return_message = get_lang('The forum category has been modified'); + $message = get_lang('The forum category has been modified'); $logInfo = [ 'tool' => TOOL_FORUM, @@ -702,31 +696,14 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) $repo->getEntityManager()->flush(); $last_id = $category->getIid(); - if ($last_id > 0) { $sql = "UPDATE $table_categories SET cat_id = $last_id WHERE iid = $last_id"; Database::query($sql); - - /*api_item_property_update( - $courseInfo, - TOOL_FORUM_CATEGORY, - $last_id, - 'ForumCategoryAdded', - api_get_user_id() - ); - api_set_default_visibility( - $last_id, - TOOL_FORUM_CATEGORY, - 0, - $courseInfo - );*/ + $message = get_lang('The forum category has been added'); } - $return_message = get_lang('The forum category has been added'); $logInfo = [ 'tool' => TOOL_FORUM, - 'tool_id' => 0, - 'tool_id_detail' => 0, 'action' => 'new-forumcategory', 'action_details' => 'forumcategory', 'info' => $clean_cat_title, @@ -740,7 +717,7 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) $extraFieldValue->saveFieldValues($values); if ($showMessage) { - Display::addFlash(Display::return_message($return_message, 'confirmation')); + Display::addFlash(Display::return_message($message, 'confirmation')); } return $last_id; @@ -1117,7 +1094,7 @@ function check_if_last_post_of_thread($thread_id) $table_posts = Database::get_course_table(TABLE_FORUM_POST); $course_id = api_get_course_int_id(); $sql = "SELECT * FROM $table_posts - WHERE c_id = $course_id AND thread_id = ".(int) $thread_id.' + WHERE thread_id = ".(int) $thread_id.' ORDER BY post_date DESC'; $result = Database::query($sql); if (Database::num_rows($result) > 0) { @@ -1139,7 +1116,7 @@ function return_visible_invisible_icon( $content, $id, $current_visibility_status, - $additional_url_parameters + $additional_url_parameters = [] ) { $html = ''; $id = (int) $id; @@ -3861,7 +3838,7 @@ function store_edit_post(CForumForum $forum, $values) 'thread_title' => $values['post_title'], 'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : 0, ]; - $where = ['c_id = ? AND thread_id = ?' => [$course_id, $values['thread_id']]]; + $where = ['iid = ?' => [$values['thread_id']]]; Database::update($threadTable, $params, $where); } @@ -3928,9 +3905,12 @@ function store_edit_post(CForumForum $forum, $values) $message = get_lang('The post has been modified').'
'; $message .= get_lang('You can now return to the'). - ' '.get_lang('Forum').'
'; + ' '. + get_lang('Forum').'
'; $message .= get_lang('You can now return to the'). - ' '.get_lang('Message').''; + ' '. + get_lang('Message').''; Session::erase('formelements'); Session::erase('origin'); diff --git a/public/main/forum/viewthread.php b/public/main/forum/viewthread.php index 4c5dc2b474..96235eb615 100644 --- a/public/main/forum/viewthread.php +++ b/public/main/forum/viewthread.php @@ -716,7 +716,8 @@ if ($showForm) { $forumEntity, $threadEntity, null, - false + null, + null ); $formToString = $form->returnForm(); } diff --git a/public/main/group/group_creation.php b/public/main/group/group_creation.php index 5879462209..0e6672e226 100644 --- a/public/main/group/group_creation.php +++ b/public/main/group/group_creation.php @@ -11,6 +11,16 @@ if (!api_is_allowed_to_edit(false, true)) { } $currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(); +$allowGroupCategories = 'true' === api_get_setting('allow_group_categories'); + +$categories = []; +$numberOfGroups = GroupManager::get_number_of_groups() + 1; +if ($allowGroupCategories) { + $groupCategories = GroupManager::get_categories(); + foreach ($groupCategories as $category) { + $categories[$category['iid']] = $category['title']; + } +} /* Create the groups */ if (isset($_POST['action'])) { @@ -131,12 +141,6 @@ if (isset($_POST['number_of_groups'])) { $category) { - $cat_options[$category['iid']] = $category['title']; - } $form = new FormValidator('create_groups_step2', 'POST', api_get_self().'?'.api_get_cidreq()); // Modify the default templates @@ -165,7 +169,7 @@ EOT; $group_el = []; $group_el[] = $form->createElement('static', null, null, ''.get_lang('Group name').''); - if ('true' === api_get_setting('allow_group_categories')) { + if ($allowGroupCategories) { $group_el[] = $form->createElement('static', null, null, ''.get_lang('Group category').''); } $group_el[] = $form->createElement('static', null, null, ''.get_lang('seats (optional)').''); @@ -174,7 +178,7 @@ EOT; if ($_POST['number_of_groups'] > 1) { $group_el = []; $group_el[] = $form->createElement('static', null, null, ' '); - if ('true' === api_get_setting('allow_group_categories')) { + if ($allowGroupCategories) { $group_el[] = $form->createElement( 'checkbox', 'same_category', @@ -196,17 +200,18 @@ EOT; for ($group_number = 0; $group_number < $_POST['number_of_groups']; $group_number++) { $group_el = []; $group_el[] = $form->createElement('text', 'group_'.$group_number.'_name'); - if ('true' === api_get_setting('allow_group_categories')) { + if ($allowGroupCategories) { $group_el[] = $form->createElement( 'select', 'group_'.$group_number.'_category', null, - $cat_options, + $categories, ['id' => 'category_'.$group_number] ); } else { $group_el[] = $form->createElement('hidden', 'group_'.$group_number.'_category', 0); - $defaults['group_'.$group_number.'_category'] = array_keys($cat_options)[0]; + + $defaults['group_'.$group_number.'_category'] = null; } $group_el[] = $form->createElement( 'text', @@ -216,18 +221,18 @@ EOT; ); if ($_POST['number_of_groups'] < 10000) { - if ($group_id < 10) { + if ($numberOfGroups < 10) { $prev = '000'; - } elseif ($group_id < 100) { + } elseif ($numberOfGroups < 100) { $prev = '00'; - } elseif ($group_id < 1000) { + } elseif ($numberOfGroups < 1000) { $prev = '0'; } else { $prev = ''; } } - $defaults['group_'.$group_number.'_name'] = get_lang('Group').' '.$prev.$group_id++; + $defaults['group_'.$group_number.'_name'] = get_lang('Group').' '.$prev.$numberOfGroups++; $form->addGroup($group_el, 'group_'.$group_number, null, '', false); } $defaults['action'] = 'create_groups'; @@ -252,7 +257,7 @@ EOT; /* * Show form to generate subgroups */ - if ('true' === api_get_setting('allow_group_categories')) { + if ($allowGroupCategories) { $groups = GroupManager::get_group_list(); if (!empty($groups)) { $base_group_options = []; @@ -260,8 +265,7 @@ EOT; $groupId = $group['iid']; $number_of_students = GroupManager::number_of_students($groupId); if ($number_of_students > 0) { - $base_group_options[$groupId] = - $group['name'].' ('.$number_of_students.' '.get_lang('Users').')'; + $base_group_options[$groupId] = $group['name'].' ('.$number_of_students.' '.get_lang('Users').')'; } } /*if (count($base_group_options) > 0) { @@ -320,13 +324,8 @@ EOT; $classForm->addHtml($description); $classForm->addElement('hidden', 'action'); - if ('true' === api_get_setting('allow_group_categories')) { - $group_categories = GroupManager :: get_categories(); - $cat_options = []; - foreach ($group_categories as $index => $category) { - $cat_options[$category['id']] = $category['title']; - } - $classForm->addElement('select', 'group_category', null, $cat_options); + if ($allowGroupCategories) { + $classForm->addElement('select', 'group_category', null, $categories); } else { $classForm->addElement('hidden', 'group_category'); } diff --git a/public/main/group/settings.php b/public/main/group/settings.php index 4ff79865ba..c09994def6 100644 --- a/public/main/group/settings.php +++ b/public/main/group/settings.php @@ -44,9 +44,8 @@ $form->addElement('text', 'name', get_lang('Group name')); if ('true' == api_get_setting('allow_group_categories')) { $groupCategories = GroupManager::get_categories(); $categoryList = []; - //$categoryList[] = null; foreach ($groupCategories as $category) { - $categoryList[$category['id']] = $category['title']; + $categoryList[$category['iid']] = $category['title']; } $form->addElement('select', 'category_id', get_lang('Category'), $categoryList); } else { @@ -56,7 +55,6 @@ $form->addElement('html', ''); $form->addElement('html', '
'); $form->addElement('textarea', 'description', get_lang('Description')); - $form->addElement('html', '
'); $form->addElement('html', '
'); diff --git a/public/main/template/default/forum/list.html.twig b/public/main/template/default/forum/list.html.twig index d8c0c5d28a..3fd4819b43 100644 --- a/public/main/template/default/forum/list.html.twig +++ b/public/main/template/default/forum/list.html.twig @@ -111,11 +111,11 @@

{{ 'forum_yellow.png'|img(32) }} {{ subitem.title }} - {% if subitem.forum_of_group != 0 %} - - {{ "forum.png"|img(22) }} {{ "Go to"|trans }} {{ subitem.forum_group_title }} - - {% endif %} +{# {% if subitem.forum_of_group != 0 %}#} +{# #} +{# {{ "forum.png"|img(22) }} {{ "Go to"|trans }} {{ subitem.forum_group_title }}#} +{# #} +{# {% endif %}#} {{ subitem.icon_session }}

{% if subitem.last_poster_id is not empty %} diff --git a/tests/behat/features/sessionManagement.feature b/tests/behat/features/sessionManagement.feature index cf7d75d8a0..4b1b43d270 100644 --- a/tests/behat/features/sessionManagement.feature +++ b/tests/behat/features/sessionManagement.feature @@ -61,7 +61,8 @@ Feature: Session management tool And I check "Show description" And I press "submit" Then wait very long for the page to be loaded - Then I should see "Update successful" + Then I should not see an error + #Then I should see "Update successful" Scenario: Check session description with platform setting off Given I am on "/admin/settings/search_settings?keyword=show_session_description" diff --git a/tests/behat/features/toolGroup.feature b/tests/behat/features/toolGroup.feature index 538ea925de..205321df49 100644 --- a/tests/behat/features/toolGroup.feature +++ b/tests/behat/features/toolGroup.feature @@ -11,7 +11,7 @@ Feature: Group tool Then I should see "Default groups" Then I follow "Delete" Then I confirm the popup - And wait the page to be loaded when ready + And wait very long for the page to be loaded Then I should see "The category has been deleted" Scenario: Create a group directory