Forum: Fix forum movement and improve display layout

pull/5208/head
christianbeeznst 2 years ago
parent cd6df1d0ec
commit 9f9295136d
  1. 8
      assets/css/app.scss
  2. 73
      assets/css/scss/_forums.scss
  3. 180
      public/main/forum/forumfunction.inc.php
  4. 12
      public/main/forum/index.php
  5. 11
      public/main/template/default/forum/list.html.twig
  6. 8
      webpack.config.js

@ -37,6 +37,14 @@
.collapse { .collapse {
visibility: inherit !important; visibility: inherit !important;
} }
.border-gray-300 {
--tw-border-opacity: 1;
border-color: rgba(156, 163, 175, var(--tw-border-opacity));
}
.border-gray-100 {
--tw-border-opacity: 1;
border-color: rgba(247, 250, 252, var(--tw-border-opacity));
}
} }
@layer components { @layer components {

@ -4,4 +4,75 @@
.forum_display { .forum_display {
@apply flex flex-row w-full; @apply flex flex-row w-full;
} }
.category-forum {
@apply flex flex-row w-full;
}
.forum_display {
@apply flex flex-row w-full;
}
.custom-panel-heading {
@apply flex items-center justify-between;
}
.open {
@apply flex-shrink-0;
}
.custom-panel-heading h4 {
@apply m-0 flex-grow pl-2.5;
}
.actions {
@apply flex items-center gap-2.5;
}
.actions a,
.actions button {
@apply flex items-center;
}
.custom-panel-heading {
@apply bg-gray-25 border-b border-gray-300 py-2.5 px-4 flex items-center justify-between;
}
.custom-panel-title span {
@apply font-bold text-lg text-gray-90;
}
.custom-panel-heading a {
@apply text-gray-90 no-underline;
}
.custom-panel-heading a:hover,
.custom-panel-heading a:focus {
@apply underline;
}
.custom-panel-body {
@apply p-4;
}
.forum_display {
@apply border-t border-gray-300 py-2.5;
}
.forum_display:first-child {
@apply border-t-0;
}
.forum-description,
.description {
@apply text-gray-50 text-sm mt-1.5;
}
.custom-panel-heading .mdi-folder {
@apply text-gray-90;
}
.ch-tool-icon-disabled {
@apply text-gray-50;
}

@ -990,169 +990,73 @@ function returnLockUnlockIcon(
} }
/** /**
* This function takes care of the display of the up and down icon. * Generates HTML for up and down icons with links to move an item up or down in a list.
*
* @param string $content what is it that we want to make (in)visible: forum category, forum, thread, post
* @param int $id is the id of the item we want to display the icons for
* @param array $list is an array of all the items. All items in this list should have
* an up and down icon except for the first (no up icon) and the last (no down icon)
* The key of this $list array is the id of the item.
*
* @return string HTML
*/ */
function returnUpDownIcon(string $content, int $id, array $list): string function returnUpDownIcon(string $content, int $id, array $list): string {
{
$total_items = count($list);
$position = 0;
$internal_counter = 0;
$forumCategory = isset($_GET['forumcategory']) ? Security::remove_XSS($_GET['forumcategory']) : null; $forumCategory = isset($_GET['forumcategory']) ? Security::remove_XSS($_GET['forumcategory']) : null;
$totalItemsOfType = 0;
if (!empty($list)) { $position = 0;
foreach ($list as $item) { foreach ($list as $key => $item) {
$internal_counter++; if (($content === 'forumcategory' && $item instanceof CForumCategory) ||
($content === 'forum' && $item instanceof CForum)) {
$totalItemsOfType++;
if ($id == $item->getIid()) { if ($id == $item->getIid()) {
$position = $internal_counter; $position = $key + 1;
} }
} }
} }
if ($position > 1) { $upIcon = $position > 1
$return_value = '<a ? '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=up&content='.$content.'&id='.$id.'" title="'.get_lang('Move up').'">'.Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move up')).'</a>'
href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=up&content='.$content.'&forumcategory='.$forumCategory.'&id='.$id.'" : '<span class="ch-tool-icon-disabled">'.Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, '').'</span>';
title="'.get_lang('Move up').'">'.
Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move up')).'</a>'; $downIcon = $position < $totalItemsOfType
} else { ? '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=down&content='.$content.'&id='.$id.'" title="'.get_lang('Move down').'">'.Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move down')).'</a>'
$return_value = Display::url( : '<span class="ch-tool-icon-disabled">'.Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, '').'</span>';
Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, ''),
'javascript:void(0)'
);
}
if ($position < $total_items) {
$return_value .= '<a
href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=down&content='.$content.'&forumcategory='.$forumCategory.'&id='.$id.'"
title="'.get_lang('Move down').'" >'.
Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move down')).'</a>';
} else {
$return_value = Display::url(
Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, ''),
'javascript:void(0)'
);
}
return $return_value; return $upIcon . $downIcon;
} }
/** /**
* This function moves a forum or a forum category up or down. * Moves a forum or forum category up or down in the display order.
*
* @param string $content is it that we want to make (in)visible: forum category, forum, thread, post
* @param string $direction we want to move it up or down
* @param int $id id of the content we want to make invisible
*
* @return string language variable
*
* @todo consider removing the table_item_property calls here but this can
* prevent unwanted side effects when a forum does not have an entry in
* the item_property table but does have one in the forum table.
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version february 2006, dokeos 1.8
*/ */
function moveUpDown(string $content, string $direction, int $id): string function moveUpDown(string $content, string $direction, int $id): string
{ {
$table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY); $em = Database::getManager();
$table_forums = Database::get_course_table(TABLE_FORUM);
$course_id = api_get_course_int_id();
// Determine which field holds the sort order. $entity = null;
if ('forumcategory' === $content) { if ('forumcategory' === $content) {
$table = $table_categories; $entityRepo = $em->getRepository(CForumCategory::class);
$sort_column = 'cat_order';
$id_column = 'cat_id';
$sort_column = 'cat_order';
} elseif ('forum' === $content) { } elseif ('forum' === $content) {
$table = $table_forums; $entityRepo = $em->getRepository(CForum::class);
$sort_column = 'forum_order';
$id_column = 'forum_id';
$sort_column = 'forum_order';
// We also need the forum_category of this forum.
$sql = "SELECT forum_category FROM $table_forums
WHERE forum_id = ".$id;
$result = Database::query($sql);
$row = Database::fetch_array($result);
$forum_category = $row['forum_category'];
} else {
return '';
} }
// Determine the need for sorting ascending or descending order. if (null === $entityRepo) {
if ('down' === $direction) { return false;
$sort_direction = 'ASC';
} elseif ('up' === $direction) {
$sort_direction = 'DESC';
} else {
return '';
} }
// The SQL statement $entity = $entityRepo->find($id);
if ('forumcategory' === $content) { if (null === $entity) {
$sql = "SELECT * return false;
FROM $table_categories forum_categories
WHERE
forum_categories.c_id = $course_id
ORDER BY forum_categories.cat_order $sort_direction";
}
if ('forum' === $content) {
$sql = "SELECT *
FROM $table
WHERE
c_id = $course_id AND
forum_category = '".Database::escape_string($forum_category)."'
ORDER BY forum_order $sort_direction";
} }
// Finding the items that need to be switched.
$result = Database::query($sql); $resourceNode = $entity->getResourceNode();
$found = false; if (null === $resourceNode) {
$next_sort = ''; return false;
$this_sort = '';
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($found) {
$next_id = $row[$id_column];
$next_sort = $row[$sort_column];
$found = false;
}
if ($id == $row[$id_column]) {
$this_id = $id;
$this_sort = $row[$sort_column];
$found = true;
}
} }
if ('forum' === $content && $next_sort) { $currentDisplayOrder = $resourceNode->getDisplayOrder();
$repo = Container::getForumRepository();
/** @var CForum $forum */
$forum = $repo->find($id);
$forum->setForumOrder($next_sort);
$repo->update($forum);
Display::addFlash(Display::return_message(get_lang('Updated'))); $newPosition = $currentDisplayOrder + ($direction === 'down' ? 1 : -1);
} else { $newPosition = max(0, $newPosition);
if ($next_sort) {
$repo = Container::getForumCategoryRepository();
/** @var CForumCategory $forum */
$category = $repo->find($id);
if ($category) {
$category->setCatOrder($next_sort);
$repo->update($category);
Display::addFlash(Display::return_message(get_lang('Updated')));
}
}
}
return ''; $resourceNode->setDisplayOrder($newPosition);
$em->flush();
Display::addFlash(Display::return_message(get_lang('Updated')));
return true;
} }
/** /**
@ -1171,7 +1075,7 @@ function get_forum_categories(int $courseId = 0, int $sessionId = 0): Array
$course = api_get_course_entity($courseId); $course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId); $session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourse($course, $session, null, $course->getResourceNode()); $qb = $repo->getResourcesByCourse($course, $session, null, $course->getResourceNode(), true, true);
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }
@ -1197,7 +1101,7 @@ function get_forums_in_category(int $categoryId, int $courseId = 0)
$qb $qb
->andWhere('resource.forumCategory = :catId') ->andWhere('resource.forumCategory = :catId')
->setParameter('catId', $categoryId) ->setParameter('catId', $categoryId)
->orderBy('resource.forumOrder') ->orderBy('node.displayOrder')
; ;
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();

@ -254,7 +254,17 @@ if ($value && isset($value['value']) && !empty($value['value'])) {
$searchFilter = ''; $searchFilter = '';
$translate = 'true' === api_get_setting('editor.translate_html'); $translate = 'true' === api_get_setting('editor.translate_html');
if ($translate) { if ($translate) {
$form = new FormValidator('search_simple', 'get', api_get_self().'?'.api_get_cidreq(), null, null, 'inline'); $htmlHeadXtra[] = api_get_css_asset('select2/css/select2.min.css');
$htmlHeadXtra[] = api_get_asset('select2/js/select2.min.js');
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
$("#extra_language").select2({
placeholder: "'.get_lang('Select a language').'",
allowClear: true
});
});
</script>';
$form = new FormValidator('search_simple', 'get', api_get_self().'?'.api_get_cidreq(), null, null);
$form->addHidden('cid', api_get_course_int_id()); $form->addHidden('cid', api_get_course_int_id());
$form->addHidden('sid', api_get_session_id()); $form->addHidden('sid', api_get_session_id());

@ -27,6 +27,17 @@
}); });
}); });
}); });
$(document).ready(function() {
var selectedLanguage = localStorage.getItem('selectedLanguage');
if (selectedLanguage) {
$('#extra_language').val(selectedLanguage).trigger('change');
}
$('#extra_language').on('change', function() {
var selectedLanguage = $(this).val();
localStorage.setItem('selectedLanguage', selectedLanguage);
});
});
</script> </script>
{% endif %} {% endif %}

@ -129,6 +129,14 @@ Encore.copyFiles({
from: "node_modules/moment/locale", from: "node_modules/moment/locale",
to: "libs/locale/[path][name].[ext]", to: "libs/locale/[path][name].[ext]",
}) })
Encore.copyFiles({
from: "./node_modules/select2/dist/css",
to: "libs/select2/css/[name].[ext]",
})
Encore.copyFiles({
from: "./node_modules/select2/dist/js",
to: "libs/select2/js/[name].[ext]",
})
const themes = ["chamilo"] const themes = ["chamilo"]

Loading…
Cancel
Save