From 5d42e28dd13a3ae28df79367e66af26e93e6e91f Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 6 Feb 2019 12:48:53 +0100 Subject: [PATCH] Add forum category extra field + add lang filter in forums see BT#15173 --- main/forum/forumfunction.inc.php | 42 ++++++++++++++++++- main/forum/index.php | 30 +++++++++++++- main/forum/viewforum.php | 43 +++++++++++--------- main/inc/lib/extra_field.lib.php | 5 +++ main/template/default/forum/global_list.tpl | 31 +++++++++++++- main/template/default/forum/list.tpl | 32 ++++++++++++++- src/Chamilo/CoreBundle/Entity/ExtraField.php | 1 + 7 files changed, 159 insertions(+), 25 deletions(-) diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index d0bed3f5b9..b27d4a7fae 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -211,6 +211,19 @@ function show_add_forumcategory_form($inputvalues = [], $lp_id) null, ['ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200'] ); + + $extraField = new ExtraField('forum_category'); + $returnParams = $extraField->addElements( + $form, + null, + [], //exclude + false, // filter + false, // tag as select + [], //show only fields + [], // order fields + [] // extra data + ); + $form->addButtonCreate(get_lang('CreateCategory'), 'SubmitForumCategory'); // Setting the rules. @@ -531,6 +544,18 @@ function show_edit_forumcategory_form($inputvalues = []) ['ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200'] ); + $extraField = new ExtraField('forum_category'); + $returnParams = $extraField->addElements( + $form, + $categoryId, + [], //exclude + false, // filter + false, // tag as select + [], //show only fields + [], // order fields + [] // extra data + ); + $form->addButtonUpdate(get_lang('ModifyCategory'), 'SubmitEditForumCategory'); // Setting the default values. @@ -625,6 +650,8 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) 'info' => $clean_cat_title, ]; Event::registerLog($logInfo); + + $values['item_id'] = $values['forum_category_id']; } else { $params = [ 'c_id' => $course_id, @@ -667,8 +694,13 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) 'info' => $clean_cat_title, ]; Event::registerLog($logInfo); + + $values['item_id'] = $last_id; } + $extraFieldValue = new ExtraFieldValue('forum_category'); + $extraFieldValue->saveFieldValues($values); + if ($showMessage) { Display::addFlash(Display::return_message($return_message, 'confirmation')); } @@ -1579,7 +1611,10 @@ function get_forum_categories($id = '', $courseId = 0, $sessionId = 0) $result = Database::query($sql); $forum_categories_list = []; + $extraFieldValue = new ExtraFieldValue('forum_category'); while ($row = Database::fetch_assoc($result)) { + $row['extra_fields'] = $extraFieldValue->getAllValuesByItem($row['cat_id']); + if (empty($id)) { $forum_categories_list[$row['cat_id']] = $row; } else { @@ -1828,6 +1863,7 @@ function get_forums( $forum_list[$key]['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname']; $forum_list[$key]['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname']; $forum_list[$key]['last_post_title'] = $last_post_info_of_forum['last_post_title']; + $forum_list[$key]['last_post_text'] = $last_post_info_of_forum['last_post_text']; } } } else { @@ -1847,6 +1883,7 @@ function get_forums( $forum_list['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname']; $forum_list['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname']; $forum_list['last_post_title'] = $last_post_info_of_forum['last_post_title']; + $forum_list['last_post_text'] = $last_post_info_of_forum['last_post_text']; } } @@ -1952,7 +1989,8 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ post.visible, thread_properties.visibility AS thread_visibility, forum_properties.visibility AS forum_visibility, - post.post_title + post.post_title, + post.post_text FROM $table_posts post, $table_users users, @@ -1981,6 +2019,7 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ $return_array['last_poster_lastname'] = $row['lastname']; $return_array['last_poster_firstname'] = $row['firstname']; $return_array['last_post_title'] = $row['post_title']; + $return_array['last_post_text'] = $row['post_text']; return $return_array; } else { @@ -1995,6 +2034,7 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ $return_array['last_poster_lastname'] = $row['lastname']; $return_array['last_poster_firstname'] = $row['firstname']; $return_array['last_post_title'] = $row['post_title']; + $return_array['last_post_text'] = $row['post_text']; return $return_array; } diff --git a/main/forum/index.php b/main/forum/index.php index 1f317331c8..18bfd0dd0e 100755 --- a/main/forum/index.php +++ b/main/forum/index.php @@ -211,6 +211,25 @@ if (!empty($allCourseForums)) { $actions = Display::toolbarAction('toolbar-forum', [$actionLeft]); + +// Create a search-box +$form = new FormValidator('search_simple', 'get', api_get_self().'?'.api_get_cidreq(), null, null, 'inline'); +$form->addHidden('cidReq', api_get_course_id()); +$form->addHidden('id_session', api_get_session_id()); + +$extraField = new ExtraField('forum_category'); +$returnParams = $extraField->addElements( + $form, + null, + [], //exclude + false, // filter + false, // tag as select + ['language'], //show only fields + [], // order fields + [] // extra data +); +$form->setDefaults(['extra_language' => ucfirst($_user['language'])]); + // Fixes error if there forums with no category. $forumsInNoCategory = get_forums_in_category(0); if (!empty($forumsInNoCategory)) { @@ -239,6 +258,7 @@ if (is_array($forumCategories)) { } else { $forumCategoryInfo['title'] = $forumCategory['cat_title']; } + $forumCategoryInfo['extra_fields'] = $forumCategory['extra_fields']; $forumCategoryInfo['icon_session'] = api_get_session_image($forumCategory['session_id'], $_user['status']); // Validation when belongs to a session @@ -461,7 +481,8 @@ if (is_array($forumCategories)) { if (!empty($forum['last_poster_id'])) { $forumInfo['last_poster_date'] = api_convert_and_format_date($forum['last_post_date']); $forumInfo['last_poster_user'] = display_user_link($poster_id, $name, null, $username); - $forumInfo['last_post_title'] = cut($forum['last_post_title'], 140); + $forumInfo['last_post_title'] = Security::remove_XSS(cut($forum['last_post_title'], 140)); + $forumInfo['last_post_text'] = Security::remove_XSS(cut($forum['last_post_text'], 140)); } if (api_is_allowed_to_edit(false, true) @@ -539,7 +560,14 @@ $tpl->assign('introduction', $introduction); $tpl->assign('actions', $actions); $tpl->assign('data', $listForumCategory); $tpl->assign('form_content', $formContent); +$tpl->assign('search_filter', $form->returnForm()); +$languages = api_get_languages(); +$languages = array_column($languages['all'], 'english_name', 'isocode'); + + +$tpl->assign('default_user_language', ucfirst($_user['language'])); +$tpl->assign('languages', array_flip($languages)); $extraFieldValue = new ExtraFieldValue('course'); $value = $extraFieldValue->get_values_by_handler_and_field_variable(api_get_course_int_id(), 'global_forum'); if ($value && isset($value['value']) && $value['value'] == 1) { diff --git a/main/forum/viewforum.php b/main/forum/viewforum.php index b182f86674..68c1d2caf8 100755 --- a/main/forum/viewforum.php +++ b/main/forum/viewforum.php @@ -484,6 +484,24 @@ if (is_array($threads)) { $iconStatus = null; $isAdmin = UserManager::is_admin($row['user_id']); + $last_post_info = get_last_post_by_thread( + $row['c_id'], + $row['thread_id'], + $row['forum_id'], + api_is_allowed_to_edit() + ); + $last_post = null; + if ($last_post_info) { + $poster_info = api_get_user_info($last_post_info['poster_id']); + $post_date = api_convert_and_format_date($last_post_info['post_date']); + $last_post = $post_date.'
'.get_lang('By').' '.display_user_link( + $last_post_info['poster_id'], + $poster_info['complete_name'], + '', + $poster_info['username'] + ); + } + if($_user['status']==5) { if($_user['has_certificates']){ $iconStatus = ''; @@ -509,6 +527,11 @@ if (is_array($threads)) { ] ); $html .= '

'.get_lang('By').' '.$iconStatus.' '.$authorName.'

'; + + if ($last_post_info) { + $html .= '

'.Security::remove_XSS(cut($last_post_info['post_text'], 140)).'

'; + } + $html .= '

'.api_convert_and_format_date($row['insert_date']).'

'; if ($current_forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) { @@ -529,6 +552,7 @@ if (is_array($threads)) { $html .= ''; $html .= ''; + $html .= '
'; $html .= '
'; $html .= '
' @@ -542,25 +566,6 @@ if (is_array($threads)) { ).' '.$row['thread_views'].' '.get_lang('Views').'
'.$newPost; $html .= '
'; - $last_post_info = get_last_post_by_thread( - $row['c_id'], - $row['thread_id'], - $row['forum_id'], - api_is_allowed_to_edit() - ); - $last_post = null; - - if ($last_post_info) { - $poster_info = api_get_user_info($last_post_info['poster_id']); - $post_date = api_convert_and_format_date($last_post_info['post_date']); - $last_post = $post_date.'
'.get_lang('By').' '.display_user_link( - $last_post_info['poster_id'], - $poster_info['complete_name'], - '', - $poster_info['username'] - ); - } - $html .= '
' .Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY) .' '.$last_post; diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index fa14efa541..0d7623ab5f 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -146,6 +146,9 @@ class ExtraField extends Model case 'terms_and_condition': $this->extraFieldType = EntityExtraField::TERMS_AND_CONDITION_TYPE; break; + case 'forum_category': + $this->extraFieldType = EntityExtraField::FORUM_CATEGORY_TYPE; + break; } $this->pageUrl = 'extra_fields.php?type='.$this->type; @@ -180,6 +183,7 @@ class ExtraField extends Model 'user_certificate', 'survey', 'terms_and_condition', + 'forum_category', ]; if (api_get_configuration_value('allow_scheduled_announcements')) { @@ -510,6 +514,7 @@ class ExtraField extends Model $itemId = (int) $itemId; $form->addHidden('item_id', $itemId); + if (empty($extraData)) { if (!empty($itemId)) { $extraData = self::get_handler_extra_data($itemId); diff --git a/main/template/default/forum/global_list.tpl b/main/template/default/forum/global_list.tpl index 2fbdb5c50c..2cd2ef17a1 100644 --- a/main/template/default/forum/global_list.tpl +++ b/main/template/default/forum/global_list.tpl @@ -1,22 +1,45 @@ {% extends 'layout/layout_1_col.tpl'|get_template %} {% block content %} + + {{ form_content }} +{{ search_filter }} + {% if data is not empty %} {% for item in data %} -
+ {% set category_language = '' %} + {% for extra_field in item.extra_fields %} + {% if extra_field.variable == 'language' %} + {% set category_language = extra_field.value %} + {% endif %} + {% endfor %} + +
{{ item.tools }}

{{ 'forum_blue.png'|img(32) }} {{ item.title }}{{ item.icon_session }} +

{{ item.description }}
-
{% for subitem in item.forums %}
@@ -50,6 +73,9 @@
{{ subitem.description }}
+ + {{ subitem.last_post_text }} + {{ subitem.alert }} {% if subitem.moderation is not empty %} @@ -62,6 +88,7 @@
{% endfor %} +
{% endfor %} {% else %}
diff --git a/main/template/default/forum/list.tpl b/main/template/default/forum/list.tpl index a65e572e21..36a4924d74 100644 --- a/main/template/default/forum/list.tpl +++ b/main/template/default/forum/list.tpl @@ -3,20 +3,44 @@ {{ form_content }} + + +{{ search_filter }} + {% if data is not empty %} {% for item in data %} -