Add forum category extra field + add lang filter in forums see BT#15173

pull/3063/head
Julio 7 years ago
parent 40a8375f14
commit 5d42e28dd1
  1. 42
      main/forum/forumfunction.inc.php
  2. 30
      main/forum/index.php
  3. 43
      main/forum/viewforum.php
  4. 5
      main/inc/lib/extra_field.lib.php
  5. 31
      main/template/default/forum/global_list.tpl
  6. 32
      main/template/default/forum/list.tpl
  7. 1
      src/Chamilo/CoreBundle/Entity/ExtraField.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;
}

@ -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) {

@ -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.'<br>'.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 = '<img src="'.$urlImg.'icons/svg/ofaj_graduated.svg" width="22px" height="22px">';
@ -509,6 +527,11 @@ if (is_array($threads)) {
]
);
$html .= '<p>'.get_lang('By').' '.$iconStatus.' '.$authorName.'</p>';
if ($last_post_info) {
$html .= '<p>'.Security::remove_XSS(cut($last_post_info['post_text'], 140)).'</p>';
}
$html .= '<p>'.api_convert_and_format_date($row['insert_date']).'</p>';
if ($current_forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) {
@ -529,6 +552,7 @@ if (is_array($threads)) {
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="col-md-6">';
$html .= '<div class="row">';
$html .= '<div class="col-md-4">'
@ -542,25 +566,6 @@ if (is_array($threads)) {
).' '.$row['thread_views'].' '.get_lang('Views').'<br>'.$newPost;
$html .= '</div>';
$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.'<br>'.get_lang('By').' '.display_user_link(
$last_post_info['poster_id'],
$poster_info['complete_name'],
'',
$poster_info['username']
);
}
$html .= '<div class="col-md-5">'
.Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY)
.' '.$last_post;

@ -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);

@ -1,22 +1,45 @@
{% extends 'layout/layout_1_col.tpl'|get_template %}
{% block content %}
<script>
$(document).ready(function () {
// default
$('.category-forum ').hide();
$('.{{ default_user_language }}').show();
$('#extra_language').on('change', function() {
var selectedLanguage = $(this).val();
$('.category-forum ').hide();
$('.'+ selectedLanguage).show();
});
});
</script>
{{ form_content }}
{{ search_filter }}
{% if data is not empty %}
{% for item in data %}
<div class="category-forum" id="category_{{ item.id }}">
{% set category_language = '' %}
{% for extra_field in item.extra_fields %}
{% if extra_field.variable == 'language' %}
{% set category_language = extra_field.value %}
{% endif %}
{% endfor %}
<div class="category-forum {{ category_language }}" id="category_{{ item.id }}">
<div class="pull-right">
{{ item.tools }}
</div>
<h3>
{{ 'forum_blue.png'|img(32) }}
<a href="{{ item.url }}" title="{{ item.title }}">{{ item.title }}{{ item.icon_session }}</a>
<span class="flag-icon flag-icon-{{ languages[category_language | lower] }}"></span>
</h3>
<div class="forum-description">
{{ item.description }}
</div>
</div>
{% for subitem in item.forums %}
<div class="forum_display">
<div class="panel panel-default forum">
@ -50,6 +73,9 @@
<div class="description">
{{ subitem.description }}
</div>
{{ subitem.last_post_text }}
{{ subitem.alert }}
{% if subitem.moderation is not empty %}
<span class="label label-warning">
@ -62,6 +88,7 @@
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% else %}
<div class="alert alert-warning">

@ -3,20 +3,44 @@
{{ form_content }}
<script>
$(document).ready(function () {
// default
$('.category-forum ').hide();
$('.{{ default_user_language }}').show();
$('#extra_language').on('change', function() {
var selectedLanguage = $(this).val();
$('.category-forum ').hide();
$('.'+ selectedLanguage).show();
});
});
</script>
{{ search_filter }}
{% if data is not empty %}
{% for item in data %}
<div class="category-forum" id="category_{{ item.id }}">
{% set category_language = '' %}
{% for extra_field in item.extra_fields %}
{% if extra_field.variable == 'language' %}
{% set category_language = extra_field.value %}
{% endif %}
{% endfor %}
<div class="category-forum {{ category_language }}" id="category_{{ item.id }}">
<div class="pull-right">
{{ item.tools }}
</div>
<h3>
{{ 'forum_blue.png'|img(32) }}
<a href="{{ item.url }}" title="{{ item.title }}">{{ item.title }}{{ item.icon_session }}</a>
<span class="flag-icon flag-icon-{{ languages[category_language | lower] }}"></span>
</h3>
<div class="forum-description">
{{ item.description }}
</div>
</div>
{% for subitem in item.forums %}
<div class="forum_display">
<div class="panel panel-default forum">
@ -25,6 +49,7 @@
<div class="col-md-3">
<div class="number-post">
<a href="{{ forum.url }}" title="{{forum.title}}">
{% if subitem.forum_image is not empty %}
<img src="{{ subitem.forum_image }}" width="48px">
{% else %}
@ -65,6 +90,8 @@
<div class="description">
{{ subitem.description }}
</div>
{{ subitem.last_post_text }}
{{ subitem.alert }}
{% if subitem.moderation is not empty %}
<span class="label label-warning">
@ -77,6 +104,7 @@
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% else %}
<div class="alert alert-warning">

@ -31,6 +31,7 @@ class ExtraField extends BaseAttribute
const SURVEY_FIELD_TYPE = 12;
const SCHEDULED_ANNOUNCEMENT = 13;
const TERMS_AND_CONDITION_TYPE = 14;
const FORUM_CATEGORY_TYPE = 15;
/**
* @var int

Loading…
Cancel
Save