Internal - Fix queries, fix behat tests

pull/3464/head
Julio Montoya 4 years ago
parent 225a8fb0f7
commit 50b9c091e4
  1. 54
      public/main/forum/forumfunction.inc.php
  2. 3
      public/main/forum/viewthread.php
  3. 49
      public/main/group/group_creation.php
  4. 4
      public/main/group/settings.php
  5. 10
      public/main/template/default/forum/list.html.twig
  6. 3
      tests/behat/features/sessionManagement.feature
  7. 2
      tests/behat/features/toolGroup.feature

@ -270,7 +270,7 @@ function show_add_forumcategory_form($lp_id)
); );
$extraField = new ExtraField('forum_category'); $extraField = new ExtraField('forum_category');
$returnParams = $extraField->addElements( $extraField->addElements(
$form, $form,
null, null,
[], //exclude [], //exclude
@ -571,8 +571,11 @@ function delete_forum_image($forum_id)
function editForumCategoryForm(CForumCategory $category) function editForumCategoryForm(CForumCategory $category)
{ {
$categoryId = $category->getIid(); $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. // Setting the form elements.
$form->addElement('header', '', get_lang('Edit forumCategory')); $form->addElement('header', '', get_lang('Edit forumCategory'));
@ -652,7 +655,6 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$clean_cat_title = $values['forum_category_title']; $clean_cat_title = $values['forum_category_title'];
$last_id = null; $last_id = null;
$repo = Container::getForumCategoryRepository(); $repo = Container::getForumCategoryRepository();
if (isset($values['forum_category_id'])) { if (isset($values['forum_category_id'])) {
@ -665,15 +667,7 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
$repo->getEntityManager()->persist($category); $repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush(); $repo->getEntityManager()->flush();
$message = get_lang('The forum category has been modified');
/*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');
$logInfo = [ $logInfo = [
'tool' => TOOL_FORUM, 'tool' => TOOL_FORUM,
@ -702,31 +696,14 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
$repo->getEntityManager()->flush(); $repo->getEntityManager()->flush();
$last_id = $category->getIid(); $last_id = $category->getIid();
if ($last_id > 0) { if ($last_id > 0) {
$sql = "UPDATE $table_categories SET cat_id = $last_id WHERE iid = $last_id"; $sql = "UPDATE $table_categories SET cat_id = $last_id WHERE iid = $last_id";
Database::query($sql); Database::query($sql);
$message = get_lang('The forum category has been added');
/*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
);*/
} }
$return_message = get_lang('The forum category has been added');
$logInfo = [ $logInfo = [
'tool' => TOOL_FORUM, 'tool' => TOOL_FORUM,
'tool_id' => 0,
'tool_id_detail' => 0,
'action' => 'new-forumcategory', 'action' => 'new-forumcategory',
'action_details' => 'forumcategory', 'action_details' => 'forumcategory',
'info' => $clean_cat_title, 'info' => $clean_cat_title,
@ -740,7 +717,7 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
$extraFieldValue->saveFieldValues($values); $extraFieldValue->saveFieldValues($values);
if ($showMessage) { if ($showMessage) {
Display::addFlash(Display::return_message($return_message, 'confirmation')); Display::addFlash(Display::return_message($message, 'confirmation'));
} }
return $last_id; 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); $table_posts = Database::get_course_table(TABLE_FORUM_POST);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT * FROM $table_posts $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'; ORDER BY post_date DESC';
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
@ -1139,7 +1116,7 @@ function return_visible_invisible_icon(
$content, $content,
$id, $id,
$current_visibility_status, $current_visibility_status,
$additional_url_parameters $additional_url_parameters = []
) { ) {
$html = ''; $html = '';
$id = (int) $id; $id = (int) $id;
@ -3861,7 +3838,7 @@ function store_edit_post(CForumForum $forum, $values)
'thread_title' => $values['post_title'], 'thread_title' => $values['post_title'],
'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : 0, '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); Database::update($threadTable, $params, $where);
} }
@ -3928,9 +3905,12 @@ function store_edit_post(CForumForum $forum, $values)
$message = get_lang('The post has been modified').'<br />'; $message = get_lang('The post has been modified').'<br />';
$message .= get_lang('You can now return to the'). $message .= get_lang('You can now return to the').
' <a href="viewforum.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&">'.get_lang('Forum').'</a><br />'; ' <a href="viewforum.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&">'.
get_lang('Forum').'</a><br />';
$message .= get_lang('You can now return to the'). $message .= get_lang('You can now return to the').
' <a href="viewthread.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&thread='.$values['thread_id'].'&post='.Security::remove_XSS($_GET['post']).'">'.get_lang('Message').'</a>'; ' <a
href="viewthread.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&thread='.$values['thread_id'].'&post='.Security::remove_XSS($_GET['post']).'">'.
get_lang('Message').'</a>';
Session::erase('formelements'); Session::erase('formelements');
Session::erase('origin'); Session::erase('origin');

@ -716,7 +716,8 @@ if ($showForm) {
$forumEntity, $forumEntity,
$threadEntity, $threadEntity,
null, null,
false null,
null
); );
$formToString = $form->returnForm(); $formToString = $form->returnForm();
} }

@ -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(); $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 */ /* Create the groups */
if (isset($_POST['action'])) { if (isset($_POST['action'])) {
@ -131,12 +141,6 @@ if (isset($_POST['number_of_groups'])) {
</script> </script>
<?php <?php
} }
$group_categories = GroupManager::get_categories();
$group_id = GroupManager::get_number_of_groups() + 1;
$cat_options = [];
foreach ($group_categories as $index => $category) {
$cat_options[$category['iid']] = $category['title'];
}
$form = new FormValidator('create_groups_step2', 'POST', api_get_self().'?'.api_get_cidreq()); $form = new FormValidator('create_groups_step2', 'POST', api_get_self().'?'.api_get_cidreq());
// Modify the default templates // Modify the default templates
@ -165,7 +169,7 @@ EOT;
$group_el = []; $group_el = [];
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('Group name').'</b>'); $group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('Group name').'</b>');
if ('true' === api_get_setting('allow_group_categories')) { if ($allowGroupCategories) {
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('Group category').'</b>'); $group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('Group category').'</b>');
} }
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('seats (optional)').'</b>'); $group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('seats (optional)').'</b>');
@ -174,7 +178,7 @@ EOT;
if ($_POST['number_of_groups'] > 1) { if ($_POST['number_of_groups'] > 1) {
$group_el = []; $group_el = [];
$group_el[] = $form->createElement('static', null, null, ' '); $group_el[] = $form->createElement('static', null, null, ' ');
if ('true' === api_get_setting('allow_group_categories')) { if ($allowGroupCategories) {
$group_el[] = $form->createElement( $group_el[] = $form->createElement(
'checkbox', 'checkbox',
'same_category', 'same_category',
@ -196,17 +200,18 @@ EOT;
for ($group_number = 0; $group_number < $_POST['number_of_groups']; $group_number++) { for ($group_number = 0; $group_number < $_POST['number_of_groups']; $group_number++) {
$group_el = []; $group_el = [];
$group_el[] = $form->createElement('text', 'group_'.$group_number.'_name'); $group_el[] = $form->createElement('text', 'group_'.$group_number.'_name');
if ('true' === api_get_setting('allow_group_categories')) { if ($allowGroupCategories) {
$group_el[] = $form->createElement( $group_el[] = $form->createElement(
'select', 'select',
'group_'.$group_number.'_category', 'group_'.$group_number.'_category',
null, null,
$cat_options, $categories,
['id' => 'category_'.$group_number] ['id' => 'category_'.$group_number]
); );
} else { } else {
$group_el[] = $form->createElement('hidden', 'group_'.$group_number.'_category', 0); $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( $group_el[] = $form->createElement(
'text', 'text',
@ -216,18 +221,18 @@ EOT;
); );
if ($_POST['number_of_groups'] < 10000) { if ($_POST['number_of_groups'] < 10000) {
if ($group_id < 10) { if ($numberOfGroups < 10) {
$prev = '000'; $prev = '000';
} elseif ($group_id < 100) { } elseif ($numberOfGroups < 100) {
$prev = '00'; $prev = '00';
} elseif ($group_id < 1000) { } elseif ($numberOfGroups < 1000) {
$prev = '0'; $prev = '0';
} else { } else {
$prev = ''; $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, '</td><td>', false); $form->addGroup($group_el, 'group_'.$group_number, null, '</td><td>', false);
} }
$defaults['action'] = 'create_groups'; $defaults['action'] = 'create_groups';
@ -252,7 +257,7 @@ EOT;
/* /*
* Show form to generate subgroups * Show form to generate subgroups
*/ */
if ('true' === api_get_setting('allow_group_categories')) { if ($allowGroupCategories) {
$groups = GroupManager::get_group_list(); $groups = GroupManager::get_group_list();
if (!empty($groups)) { if (!empty($groups)) {
$base_group_options = []; $base_group_options = [];
@ -260,8 +265,7 @@ EOT;
$groupId = $group['iid']; $groupId = $group['iid'];
$number_of_students = GroupManager::number_of_students($groupId); $number_of_students = GroupManager::number_of_students($groupId);
if ($number_of_students > 0) { if ($number_of_students > 0) {
$base_group_options[$groupId] = $base_group_options[$groupId] = $group['name'].' ('.$number_of_students.' '.get_lang('Users').')';
$group['name'].' ('.$number_of_students.' '.get_lang('Users').')';
} }
} }
/*if (count($base_group_options) > 0) { /*if (count($base_group_options) > 0) {
@ -320,13 +324,8 @@ EOT;
$classForm->addHtml($description); $classForm->addHtml($description);
$classForm->addElement('hidden', 'action'); $classForm->addElement('hidden', 'action');
if ('true' === api_get_setting('allow_group_categories')) { if ($allowGroupCategories) {
$group_categories = GroupManager :: get_categories(); $classForm->addElement('select', 'group_category', null, $categories);
$cat_options = [];
foreach ($group_categories as $index => $category) {
$cat_options[$category['id']] = $category['title'];
}
$classForm->addElement('select', 'group_category', null, $cat_options);
} else { } else {
$classForm->addElement('hidden', 'group_category'); $classForm->addElement('hidden', 'group_category');
} }

@ -44,9 +44,8 @@ $form->addElement('text', 'name', get_lang('Group name'));
if ('true' == api_get_setting('allow_group_categories')) { if ('true' == api_get_setting('allow_group_categories')) {
$groupCategories = GroupManager::get_categories(); $groupCategories = GroupManager::get_categories();
$categoryList = []; $categoryList = [];
//$categoryList[] = null;
foreach ($groupCategories as $category) { foreach ($groupCategories as $category) {
$categoryList[$category['id']] = $category['title']; $categoryList[$category['iid']] = $category['title'];
} }
$form->addElement('select', 'category_id', get_lang('Category'), $categoryList); $form->addElement('select', 'category_id', get_lang('Category'), $categoryList);
} else { } else {
@ -56,7 +55,6 @@ $form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">'); $form->addElement('html', '<div class="col-md-6">');
$form->addElement('textarea', 'description', get_lang('Description')); $form->addElement('textarea', 'description', get_lang('Description'));
$form->addElement('html', '</div>'); $form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">'); $form->addElement('html', '<div class="col-md-12">');

@ -111,11 +111,11 @@
<h3 class="title"> <h3 class="title">
{{ 'forum_yellow.png'|img(32) }} {{ 'forum_yellow.png'|img(32) }}
<a href="{{ subitem.url }}" title="{{ subitem.title }}" class="{{ subitem.visibility != '1' ? 'text-muted': '' }}">{{ subitem.title }}</a> <a href="{{ subitem.url }}" title="{{ subitem.title }}" class="{{ subitem.visibility != '1' ? 'text-muted': '' }}">{{ subitem.title }}</a>
{% if subitem.forum_of_group != 0 %} {# {% if subitem.forum_of_group != 0 %}#}
<a class="forum-goto" href="../group/group_space.php?cid={{ course.id }}&sid={{ session.id }}&gid={{ subitem.forum_of_group }}"> {# <a class="forum-goto" href="../group/group_space.php?cid={{ course.id }}&sid={{ session.id }}&gid={{ subitem.forum_of_group }}">#}
{{ "forum.png"|img(22) }} {{ "Go to"|trans }} {{ subitem.forum_group_title }} {# {{ "forum.png"|img(22) }} {{ "Go to"|trans }} {{ subitem.forum_group_title }}#}
</a> {# </a>#}
{% endif %} {# {% endif %}#}
{{ subitem.icon_session }} {{ subitem.icon_session }}
</h3> </h3>
{% if subitem.last_poster_id is not empty %} {% if subitem.last_poster_id is not empty %}

@ -61,7 +61,8 @@ Feature: Session management tool
And I check "Show description" And I check "Show description"
And I press "submit" And I press "submit"
Then wait very long for the page to be loaded 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 Scenario: Check session description with platform setting off
Given I am on "/admin/settings/search_settings?keyword=show_session_description" Given I am on "/admin/settings/search_settings?keyword=show_session_description"

@ -11,7 +11,7 @@ Feature: Group tool
Then I should see "Default groups" Then I should see "Default groups"
Then I follow "Delete" Then I follow "Delete"
Then I confirm the popup 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" Then I should see "The category has been deleted"
Scenario: Create a group directory Scenario: Create a group directory

Loading…
Cancel
Save