Fix forum thread move

pull/3124/head
Julio 5 years ago
parent 50fb21b2a4
commit 98ca544acc
  1. 217
      public/main/forum/forumfunction.inc.php
  2. 2
      public/main/forum/index.php
  3. 41
      public/main/forum/viewforum.php
  4. 45
      public/main/forum/viewforumcategory.php
  5. 58
      public/main/inc/lib/tracking.lib.php
  6. 3
      public/main/lp/learnpath.class.php
  7. 2
      public/main/template/default/forum/list.html.twig
  8. 2
      public/main/template/default/survey/pending.html.twig
  9. 5
      src/CourseBundle/Entity/CForumForum.php

@ -176,10 +176,15 @@ function handleForum($url)
exit; exit;
break; break;
case 'move': case 'move':
move_up_down($content, $_REQUEST['direction'], $id); move_up_down($content, $_REQUEST['direction'] ?? '', $id);
header('Location: '. $url); header('Location: '. $url);
exit; exit;
break; break;
case 'move_thread':
$message = move_thread_form();
return $message;
break;
case 'visible': case 'visible':
case 'invisible': case 'invisible':
if ('visible' === $action) { if ('visible' === $action) {
@ -753,11 +758,6 @@ function store_forum($values, $courseInfo = [], $returnId = false)
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo; $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$courseId = $courseInfo['real_id']; $courseId = $courseInfo['real_id'];
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$group_id = api_get_group_id();
if (isset($values['group_id']) && !empty($values['group_id'])) {
$group_id = $values['group_id'];
}
$table_forums = Database::get_course_table(TABLE_FORUM); $table_forums = Database::get_course_table(TABLE_FORUM);
// Find the max forum_order for the given category. The new forum is added at the end => max cat_order + & // Find the max forum_order for the given category. The new forum is added at the end => max cat_order + &
@ -851,7 +851,6 @@ function store_forum($values, $courseInfo = [], $returnId = false)
->setEndTime(!empty($values['end_time']) ? api_get_utc_datetime($values['end_time'], true, true) : null) ->setEndTime(!empty($values['end_time']) ? api_get_utc_datetime($values['end_time'], true, true) : null)
->setSessionId($session_id) ->setSessionId($session_id)
->setLpId($values['lp_id'] ?? 0) ->setLpId($values['lp_id'] ?? 0)
; ;
$user = api_get_user_entity(api_get_user_id()); $user = api_get_user_entity(api_get_user_id());
@ -1230,9 +1229,9 @@ function return_up_down_icon($content, $id, $list)
$forumCategory = isset($_GET['forumcategory']) ? Security::remove_XSS($_GET['forumcategory']) : null; $forumCategory = isset($_GET['forumcategory']) ? Security::remove_XSS($_GET['forumcategory']) : null;
if (is_array($list)) { if (is_array($list)) {
foreach ($list as $key => $listitem) { foreach ($list as $item) {
$internal_counter++; $internal_counter++;
if ($id == $key) { if ($id == $item->getIid()) {
$position = $internal_counter; $position = $internal_counter;
} }
} }
@ -1298,7 +1297,7 @@ function move_up_down($content, $direction, $id)
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$forum_category = $row['forum_category']; $forum_category = $row['forum_category'];
} else { } else {
return get_lang('Error'); return false;
} }
// Determine the need for sorting ascending or descending order. // Determine the need for sorting ascending or descending order.
@ -1307,7 +1306,7 @@ function move_up_down($content, $direction, $id)
} elseif ('up' == $direction) { } elseif ('up' == $direction) {
$sort_direction = 'DESC'; $sort_direction = 'DESC';
} else { } else {
return get_lang('Error'); return false;
} }
// The SQL statement // The SQL statement
@ -1315,7 +1314,7 @@ function move_up_down($content, $direction, $id)
$sql = "SELECT * $sql = "SELECT *
FROM $table_categories forum_categories FROM $table_categories forum_categories
WHERE WHERE
forum_categories.c_id = $course_id' forum_categories.c_id = $course_id
ORDER BY forum_categories.cat_order $sort_direction"; ORDER BY forum_categories.cat_order $sort_direction";
} }
if ('forum' == $content) { if ('forum' == $content) {
@ -1330,7 +1329,9 @@ function move_up_down($content, $direction, $id)
$result = Database::query($sql); $result = Database::query($sql);
$found = false; $found = false;
$next_sort = ''; $next_sort = '';
while ($row = Database::fetch_array($result)) { $this_sort = '';
while ($row = Database::fetch_array($result, 'ASSOC')) {
//var_dump($content, $row, $id_column, $sort_column);
if ($found) { if ($found) {
$next_id = $row[$id_column]; $next_id = $row[$id_column];
$next_sort = $row[$sort_column]; $next_sort = $row[$sort_column];
@ -1343,34 +1344,42 @@ function move_up_down($content, $direction, $id)
} }
} }
// Committing the switch. if ('forum' == $content && $next_sort) {
// We do an extra check if we do not have illegal values. If your remove this if statement you will $repo = Container::getForumRepository();
// be able to mess with the sorting by refreshing the page over and over again. /** @var CForumForum $forum */
if ('' != $this_sort && '' != $next_sort && '' != $next_id && '' != $this_id) { $forum = $repo->find($id);
$sql = "UPDATE $table SET $sort_column='".Database::escape_string($this_sort)."' $forum->setForumOrder($next_sort);
WHERE c_id = $course_id AND $id_column='".Database::escape_string($next_id)."'"; $repo->getEntityManager()->persist($forum);
Database::query($sql); $repo->getEntityManager()->flush();
$sql = "UPDATE $table SET $sort_column='".Database::escape_string($next_sort)."' Display::addFlash(Display::return_message(get_lang('Updated')));
WHERE c_id = $course_id AND $id_column='".Database::escape_string($this_id)."'"; } else {
Database::query($sql); if ($next_sort) {
} $repo = Container::getForumCategoryRepository();
/** @var CForumCategory $forum */
$category = $repo->find($id);
if ($category) {
$category->setCatOrder($next_sort);
$repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush();
return get_lang(ucfirst($content).'Moved'); Display::addFlash(Display::return_message(get_lang('Updated')));
}
}
}
} }
/** /**
* Retrieve all the information off the forum categories (or one specific) for the current course. * Retrieve all the information off the forum categories (or one specific) for the current course.
* The categories are sorted according to their sorting order (cat_order. * The categories are sorted according to their sorting order (cat_order.
* *
* @param int|string $id default ''. When an id is passed we only find the information
* about that specific forum category. If no id is passed we get all the forum categories.
* @param int $courseId Optional. The course ID * @param int $courseId Optional. The course ID
* @param int $sessionId Optional. The session ID * @param int $sessionId Optional. The session ID
* *
* @return CForumCategory[] * @return CForumCategory[]
*/ */
function get_forum_categories($id = 0, $courseId = 0, $sessionId = 0) function get_forum_categories($courseId = 0, $sessionId = 0)
{ {
$repo = Container::getForumCategoryRepository(); $repo = Container::getForumCategoryRepository();
@ -1380,84 +1389,12 @@ function get_forum_categories($id = 0, $courseId = 0, $sessionId = 0)
$qb = $repo->getResources(api_get_user_entity(api_get_user_id()), $course->getResourceNode(), $course, $session); $qb = $repo->getResources(api_get_user_entity(api_get_user_id()), $course->getResourceNode(), $course, $session);
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
$table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY);
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
// Condition for the session
$session_id = $sessionId ?: api_get_session_id();
$course_id = $courseId ?: api_get_course_int_id();
$condition_session = api_get_session_condition(
$session_id,
true,
true,
'forum_categories.session_id'
);
$condition_session .= " AND forum_categories.c_id = $course_id AND item_properties.c_id = $course_id";
if (empty($id)) {
$sql = "SELECT *
FROM $table_item_property item_properties
INNER JOIN $table_categories forum_categories
ON (
forum_categories.cat_id = item_properties.ref AND
item_properties.c_id = forum_categories.c_id
)
WHERE
item_properties.visibility = 1 AND
item_properties.tool = '".TOOL_FORUM_CATEGORY."'
$condition_session
ORDER BY forum_categories.cat_order ASC";
if (api_is_allowed_to_edit()) {
$sql = "SELECT *
FROM $table_item_property item_properties
INNER JOIN $table_categories forum_categories
ON (
forum_categories.cat_id = item_properties.ref AND
item_properties.c_id = forum_categories.c_id
)
WHERE
item_properties.visibility<>2 AND
item_properties.tool='".TOOL_FORUM_CATEGORY."'
$condition_session
ORDER BY forum_categories.cat_order ASC";
}
} else {
$sql = "SELECT *
FROM $table_item_property item_properties
INNER JOIN $table_categories forum_categories
ON (
forum_categories.cat_id = item_properties.ref AND
item_properties.c_id = forum_categories.c_id
)
WHERE
item_properties.tool='".TOOL_FORUM_CATEGORY."' AND
forum_categories.cat_id = ".(int) $id."
$condition_session
ORDER BY forum_categories.cat_order ASC";
}
$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 {
$forum_categories_list = $row;
}
}
return $forum_categories_list;
} }
/** /**
* This function retrieves all the fora in a given forum category. * This function retrieves all the fora in a given forum category.
* *
* @param int $cat_id the id of the forum category * @param int $categoryId the id of the forum category
* @param int $courseId Optional. The course ID * @param int $courseId Optional. The course ID
* *
* @return CForumForum[] containing all the information about the forums (regardless of their category) * @return CForumForum[] containing all the information about the forums (regardless of their category)
@ -1466,52 +1403,19 @@ function get_forum_categories($id = 0, $courseId = 0, $sessionId = 0)
* *
* @version february 2006, dokeos 1.8 * @version february 2006, dokeos 1.8
*/ */
function get_forums_in_category($cat_id, $courseId = 0) function get_forums_in_category($categoryId, $courseId = 0)
{ {
$repo = Container::getForumRepository(); $repo = Container::getForumRepository();
$course = api_get_course_entity($courseId); $course = api_get_course_entity($courseId);
$qb = $repo->getResourcesByCourse($course, null); $qb = $repo->getResourcesByCourse($course, null);
$qb->andWhere('resource.forumCategory = :catId') $qb
->setParameter('catId', $cat_id); ->andWhere('resource.forumCategory = :catId')
->setParameter('catId', $categoryId)
->orderBy('resource.forumOrder')
;
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
$table_forums = Database::get_course_table(TABLE_FORUM);
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$forum_list = [];
$course_id = $courseId ?: api_get_course_int_id();
$cat_id = (int) $cat_id;
$sql = "SELECT * FROM $table_forums forum
INNER JOIN $table_item_property item_properties
ON (forum.forum_id = item_properties.ref AND item_properties.c_id = forum.c_id)
WHERE
forum.forum_category = '".$cat_id."' AND
item_properties.visibility = 1 AND
forum.c_id = $course_id AND
item_properties.c_id = $course_id AND
item_properties.tool = '".TOOL_FORUM."'
ORDER BY forum.forum_order ASC";
if (api_is_allowed_to_edit()) {
$sql = "SELECT * FROM $table_forums forum
INNER JOIN $table_item_property item_properties
ON (forum.forum_id = item_properties.ref AND item_properties.c_id = forum.c_id)
WHERE
forum.forum_category = '".$cat_id."' AND
item_properties.visibility <> 2 AND
item_properties.tool = '".TOOL_FORUM."' AND
item_properties.c_id = $course_id AND
forum.c_id = $course_id
ORDER BY forum_order ASC";
}
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
$forum_list[$row['forum_id']] = $row;
}
return $forum_list;
} }
/** /**
@ -1527,7 +1431,6 @@ function get_forums_in_category($cat_id, $courseId = 0)
* @return CForumForum[] * @return CForumForum[]
*/ */
function get_forums( function get_forums(
$id = 0,
$courseId = '', $courseId = '',
$includeGroupsForum = true, $includeGroupsForum = true,
$sessionId = 0 $sessionId = 0
@ -4580,13 +4483,10 @@ function move_thread_form()
'post', 'post',
api_get_self().'?forum='.(int) ($_GET['forum']).'&thread='.(int) ($_GET['thread']).'&action='.Security::remove_XSS($_GET['action']).'&'.api_get_cidreq() api_get_self().'?forum='.(int) ($_GET['forum']).'&thread='.(int) ($_GET['thread']).'&action='.Security::remove_XSS($_GET['action']).'&'.api_get_cidreq()
); );
// The header for the form $form->addHeader(get_lang('Move Thread'));
$form->addElement('header', get_lang('Move Thread'));
// Invisible form: the thread_id // Invisible form: the thread_id
$form->addElement('hidden', 'thread_id', (int) ($_GET['thread'])); $form->addHidden('thread_id', (int) ($_GET['thread']));
// the fora
$forum_categories = get_forum_categories(); $forum_categories = get_forum_categories();
$forums = get_forums();
$htmlcontent = '<div class="row"> $htmlcontent = '<div class="row">
<div class="label"> <div class="label">
@ -4594,14 +4494,11 @@ function move_thread_form()
</div> </div>
<div class="formw">'; <div class="formw">';
$htmlcontent .= '<select name="forum">'; $htmlcontent .= '<select name="forum">';
foreach ($forum_categories as $key => $category) { foreach ($forum_categories as $category) {
$htmlcontent .= '<optgroup label="'.$category['cat_title'].'">'; $htmlcontent .= '<optgroup label="'.$category->getCatTitle().'">';
foreach ($forums as $key => $forum) { $forums = $category->getForums();
if (isset($forum['forum_category'])) { foreach ($forums as $forum) {
if ($forum['forum_category'] == $category['cat_id']) { $htmlcontent .= '<option value="'.$forum->getIid().'">'.$forum->getForumTitle().'</option>';
$htmlcontent .= '<option value="'.$forum['forum_id'].'">'.$forum['forum_title'].'</option>';
}
}
} }
$htmlcontent .= '</optgroup>'; $htmlcontent .= '</optgroup>';
} }
@ -4619,9 +4516,10 @@ function move_thread_form()
$values = $form->exportValues(); $values = $form->exportValues();
if (isset($_POST['forum'])) { if (isset($_POST['forum'])) {
store_move_thread($values); store_move_thread($values);
Display::addFlash(Display::return_message(get_lang('Moved')));
} }
} else { } else {
$form->display(); return $form->returnForm();
} }
} }
@ -4846,7 +4744,7 @@ function store_move_thread($values)
$forumId = (int) ($_POST['forum']); $forumId = (int) ($_POST['forum']);
$threadId = (int) ($_POST['thread_id']); $threadId = (int) ($_POST['thread_id']);
$forumInfo = get_forums($forumId); //$forumInfo = get_forums($forumId);
// Change the thread table: Setting the forum_id to the new forum. // Change the thread table: Setting the forum_id to the new forum.
$sql = "UPDATE $table_threads SET forum_id = $forumId $sql = "UPDATE $table_threads SET forum_id = $forumId
@ -4857,9 +4755,10 @@ function store_move_thread($values)
$sql = "UPDATE $table_posts SET forum_id = $forumId $sql = "UPDATE $table_posts SET forum_id = $forumId
WHERE c_id = $courseId AND thread_id= $threadId"; WHERE c_id = $courseId AND thread_id= $threadId";
Database::query($sql); Database::query($sql);
// Fix group id, if forum is moved to a different group // Fix group id, if forum is moved to a different group
if (!empty($forumInfo['to_group_id'])) { if (!empty($forumInfo['to_group_id'])) {
$groupId = $forumInfo['to_group_id']; /*$groupId = $forumInfo['to_group_id'];
$item = api_get_item_property_info( $item = api_get_item_property_info(
$courseId, $courseId,
TABLE_FORUM_THREAD, TABLE_FORUM_THREAD,
@ -4892,7 +4791,7 @@ function store_move_thread($values)
$sessionCondition $sessionCondition
"; ";
Database::query($sql); Database::query($sql);
} }*/
} }
return get_lang('Thread moved'); return get_lang('Thread moved');
@ -6621,7 +6520,7 @@ function getCountPostsWithStatus($status, $forum, $threadId = null)
; ;
if (!empty($threadId)) { if (!empty($threadId)) {
$criteria->andWhere(Criteria::expr()->eq('threadId', $threadId)); $criteria->andWhere(Criteria::expr()->eq('thread', $threadId));
} }
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p'); $qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p');

@ -375,7 +375,7 @@ if (is_array($forumCategories)) {
} else { } else {
$show_forum = GroupManager::user_has_access( $show_forum = GroupManager::user_has_access(
$user_id, $user_id,
$forum['forum_of_group'], $forum->getForumOfGroup(),
GroupManager::GROUP_TOOL_FORUM GroupManager::GROUP_TOOL_FORUM
); );
} }

@ -36,8 +36,8 @@ require_once 'forumfunction.inc.php';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0; $forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$url = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId; $viewForumUrl = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId;
handleForum($url); $message = handleForum($viewForumUrl);
$userId = api_get_user_id(); $userId = api_get_user_id();
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
@ -154,24 +154,8 @@ if ('learnpath' === $origin) {
Display::display_header(); Display::display_header();
} }
// Moving.
if ('move' == $my_action && isset($_GET['thread']) &&
$isAllowedToEdit
) {
$message = move_thread_form();
}
// Notification.
if ('notify' == $my_action &&
isset($_GET['content']) &&
isset($_GET['id']) &&
api_is_allowed_to_session_edit(false, true)
) {
$return_message = set_notification($_GET['content'], $_GET['id']);
echo Display::return_message($return_message, 'confirm', false);
}
// Student list // Student list
if ('liststd' == $my_action && if ('liststd' === $my_action &&
isset($_GET['content']) && isset($_GET['content']) &&
isset($_GET['id']) && isset($_GET['id']) &&
(api_is_allowed_to_edit(null, true) || $is_group_tutor) (api_is_allowed_to_edit(null, true) || $is_group_tutor)
@ -228,7 +212,7 @@ if ('liststd' == $my_action &&
$table_list .= '<tr >'; $table_list .= '<tr >';
$table_list .= '<th height="24">'.get_lang('First names and last names').'</th>'; $table_list .= '<th height="24">'.get_lang('First names and last names').'</th>';
if ('qualify' == $listType) { if ('qualify' === $listType) {
$table_list .= '<th>'.get_lang('Score').'</th>'; $table_list .= '<th>'.get_lang('Score').'</th>';
} }
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
@ -288,11 +272,6 @@ if ('learnpath' == $origin) {
echo '<div style="height:15px">&nbsp;</div>'; echo '<div style="height:15px">&nbsp;</div>';
} }
/* Display the action messages */
if (!empty($message)) {
echo Display::return_message($message, 'confirm');
}
/* Action links */ /* Action links */
echo '<div class="actions">'; echo '<div class="actions">';
if ('learnpath' != $origin) { if ('learnpath' != $origin) {
@ -329,6 +308,12 @@ if (api_is_allowed_to_edit(false, true) ||
} }
echo '</div>'; echo '</div>';
/* Display the action messages */
if (!empty($message)) {
echo $message;
}
$descriptionForum = $forumEntity->getForumComment(); $descriptionForum = $forumEntity->getForumComment();
$iconForum = Display::return_icon( $iconForum = Display::return_icon(
'forum_yellow.png', 'forum_yellow.png',
@ -462,7 +447,7 @@ if (is_array($threads)) {
$waitingCount = getCountPostsWithStatus( $waitingCount = getCountPostsWithStatus(
CForumPost::STATUS_WAITING_MODERATION, CForumPost::STATUS_WAITING_MODERATION,
$forumEntity, $forumEntity,
$thread['thread_id'] $thread->getIid()
); );
if (!empty($waitingCount)) { if (!empty($waitingCount)) {
$html .= Display::label( $html .= Display::label(
@ -562,7 +547,7 @@ if (is_array($threads)) {
'gid' => api_get_group_id(), 'gid' => api_get_group_id(),
] ]
); );
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId.'&action=move&thread='.$threadId.'">' $iconsEdit .= '<a href="'.$viewForumUrl.'&forum='.$forumId.'&action=move_thread&thread='.$threadId.'">'
.Display::return_icon('move.png', get_lang('Move Thread'), [], ICON_SIZE_SMALL) .Display::return_icon('move.png', get_lang('Move Thread'), [], ICON_SIZE_SMALL)
.'</a>'; .'</a>';
} }
@ -583,7 +568,7 @@ if (is_array($threads)) {
} }
if (api_is_allowed_to_edit(null, true) && 'learnpath' != $origin) { if (api_is_allowed_to_edit(null, true) && 'learnpath' != $origin) {
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId."&action=liststd&content=thread&id={$threadId}".'">'. $iconsEdit .= '<a href="'.$viewForumUrl.'&forum='.$forumId."&action=liststd&content=thread&id={$threadId}".'">'.
Display::return_icon($icon_liststd, get_lang('Learners list'), [], ICON_SIZE_SMALL) Display::return_icon($icon_liststd, get_lang('Learners list'), [], ICON_SIZE_SMALL)
.'</a>'; .'</a>';
} }

@ -151,10 +151,10 @@ if ('add' !== $action) {
// The groups of the user. // The groups of the user.
$groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']); $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']);
// All groups in the course (and sorting them as the id of the group = the key of the array. // All groups in the course (and sorting them as the id of the group = the key of the array.
$all_groups = GroupManager::get_group_list(); $groups = GroupManager::get_group_list();
if (is_array($all_groups)) { if (is_array($groups)) {
foreach ($all_groups as $group) { foreach ($groups as $group) {
$all_groups[$group['id']] = $group; $groups[$group['id']] = $group;
} }
} }
@ -250,7 +250,7 @@ if ('add' !== $action) {
} }
// The forums in this category. // The forums in this category.
$forums_in_category = get_forums_in_category($categoryId); $forum_list = get_forums_in_category($categoryId);
$forum_count = 0; $forum_count = 0;
foreach ($forum_list as $forum) { foreach ($forum_list as $forum) {
if (!empty($forum->getForumCategory())) { if (!empty($forum->getForumCategory())) {
@ -298,6 +298,8 @@ if ('add' !== $action) {
$html .= '<div class="panel-body">'; $html .= '<div class="panel-body">';
//$my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null; //$my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
$forumOfGroup = $forum->getForumOfGroup(); $forumOfGroup = $forum->getForumOfGroup();
$forum_title_group_addition = '';
if ('0' == $forumOfGroup) { if ('0' == $forumOfGroup) {
$forum_image = Display::return_icon( $forum_image = Display::return_icon(
'forum_group.png', 'forum_group.png',
@ -306,6 +308,12 @@ if ('add' !== $action) {
ICON_SIZE_LARGE ICON_SIZE_LARGE
); );
} else { } else {
$my_all_groups_forum_name = isset($groups[$forumOfGroup]['name']) ? $groups[$forumOfGroup]['name'] : null;
$my_all_groups_forum_id = isset($groups[$forumOfGroup]['id']) ? $groups[$forumOfGroup]['id'] : null;
$group_title = api_substr($my_all_groups_forum_name, 0, 30);
$forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq(true, false)
.'&gid='.$my_all_groups_forum_id.'" class="forum_group_link">'
.get_lang('Go to').' '.$group_title.'</a>)';
$forum_image = Display::return_icon( $forum_image = Display::return_icon(
'forum.png', 'forum.png',
get_lang('Forum'), get_lang('Forum'),
@ -314,30 +322,14 @@ if ('add' !== $action) {
); );
} }
if ('0' != $forumOfGroup) { $session_displayed = '';
$my_all_groups_forum_name = isset($all_groups[$forumOfGroup]['name'])
? $all_groups[$forumOfGroup]['name']
: null;
$my_all_groups_forum_id = isset($all_groups[$forumOfGroup]['id'])
? $all_groups[$forumOfGroup]['id']
: null;
$group_title = api_substr($my_all_groups_forum_name, 0, 30);
$forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq()
.'&gid='.$my_all_groups_forum_id.'" class="forum_group_link">'
.get_lang('Go to').' '.$group_title.'</a>)';
} else {
$forum_title_group_addition = '';
}
if (!empty($sessionId) && !empty($forum['session_name'])) { if (!empty($sessionId) && !empty($forum['session_name'])) {
$session_displayed = ' ('.$forum['session_name'].')'; $session_displayed = ' ('.$forum['session_name'].')';
} else {
$session_displayed = '';
} }
// the number of topics and posts // the number of topics and posts
$my_number_threads = $forum->getThreads() ? $forum->getThreads()->count() : 0; $my_number_threads = $forum->getThreads() ? $forum->getThreads()->count() : 0;
$my_number_posts = $forum->getForumPosts() ? $forum->getForumPosts()->count() : 0; $my_number_posts = $forum->getForumPosts();
$html .= '<div class="row">'; $html .= '<div class="row">';
$html .= '<div class="col-md-6">'; $html .= '<div class="col-md-6">';
@ -380,10 +372,7 @@ if ('add' !== $action) {
); );
if ($forum->isModerated() && api_is_allowed_to_edit(false, true)) { if ($forum->isModerated() && api_is_allowed_to_edit(false, true)) {
$waitingCount = getCountPostsWithStatus( $waitingCount = getCountPostsWithStatus(CForumPost::STATUS_WAITING_MODERATION, $forum);
CForumPost::STATUS_WAITING_MODERATION,
$forum
);
if (!empty($waitingCount)) { if (!empty($waitingCount)) {
$html .= Display::label( $html .= Display::label(
get_lang('Posts pending moderation').': '.$waitingCount, get_lang('Posts pending moderation').': '.$waitingCount,
@ -455,7 +444,7 @@ if ('add' !== $action) {
$html .= return_up_down_icon( $html .= return_up_down_icon(
'forum', 'forum',
$forumId, $forumId,
$forums_in_category $forum_list
); );
} }

@ -3933,64 +3933,8 @@ class Tracking
$qb = $repo->getResourcesByCourseLinkedToUser($user, $course, $session); $qb = $repo->getResourcesByCourseLinkedToUser($user, $course, $session);
$qb->select('count(resource)'); $qb->select('count(resource)');
$count = $qb->getQuery()->getSingleScalarResult();
return $count;
$tbl_forum_post = Database::get_course_table(TABLE_FORUM_POST);
$tbl_forum = Database::get_course_table(TABLE_FORUM);
$conditions = [];
if (is_array($student_id)) {
$studentList = array_map('intval', $student_id);
$conditions[] = " post.poster_id IN ('".implode("','", $studentList)."') ";
} else {
$student_id = (int) $student_id;
$conditions[] = " post.poster_id = '$student_id' ";
}
$conditionsToString = implode('AND ', $conditions);
if (empty($courseCode)) {
$sql = "SELECT count(poster_id) as count
FROM $tbl_forum_post post
INNER JOIN $tbl_forum forum
ON (forum.forum_id = post.forum_id AND forum.c_id = post.c_id)
WHERE $conditionsToString";
$rs = Database::query($sql); return $qb->getQuery()->getSingleScalarResult();
$row = Database::fetch_array($rs, 'ASSOC');
return $row['count'];
}
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
$courseInfo = api_get_course_info($courseCode);
$forums = [];
if (!empty($courseInfo)) {
$forums = get_forums('', $courseCode, true, $session_id);
$course_id = $courseInfo['real_id'];
$conditions[] = " post.c_id = $course_id ";
}
if (!empty($forums)) {
$idList = array_column($forums, 'forum_id');
$idListToString = implode("', '", $idList);
$conditions[] = " post.forum_id IN ('$idListToString')";
}
$conditionsToString = implode('AND ', $conditions);
$sql = "SELECT count(poster_id) as count
FROM $tbl_forum_post post
WHERE $conditionsToString";
$rs = Database::query($sql);
$row = Database::fetch_array($rs, 'ASSOC');
$count = $row['count'];
return $count;
} }
/** /**

@ -7094,7 +7094,7 @@ class learnpath
$works = $this->get_student_publications(); $works = $this->get_student_publications();
// Get all the forums. // Get all the forums.
$forums = $this->get_forums(null, $course_code); $forums = $this->get_forums();
// Get the final item form (see BT#11048) . // Get the final item form (see BT#11048) .
$finish = $this->getFinalItemForm(); $finish = $this->getFinalItemForm();
@ -8506,7 +8506,6 @@ class learnpath
); );
} }
$forumList = get_forums();
$a_forums = []; $a_forums = [];
$courseEntity = api_get_course_entity(api_get_course_int_id()); $courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id()); $sessionEntity = api_get_session_entity(api_get_session_id());

@ -109,7 +109,7 @@
{{ '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?{{ _p.web_cid_query }}&gidReq={{ 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 %}

@ -17,7 +17,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<div> <div>
<a href="{{ url('legacy_main', { 'name' : 'survey/fillsurvey.php', 'course': course_code, 'invitationcode': survey.invitation_code, 'cidReq': course_code, 'id_session': session_id}) |url_encode }}"> <a href="{{ url('legacy_main', { 'name' : 'survey/fillsurvey.php', 'course': course_code, 'invitationcode': survey.invitation_code, 'cid': survey.course.id, 'sid': session_id}) |url_encode }}">
{{ survey.title }} {{ survey.title }}
</a> </a>
</div> </div>

@ -8,6 +8,7 @@ use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface; use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/** /**
* CForumForum. * CForumForum.
@ -81,6 +82,8 @@ class CForumForum extends AbstractResource implements ResourceInterface
protected $forumLastPost; protected $forumLastPost;
/** /**
* @Gedmo\SortableGroup
*
* @var CForumCategory|null * @var CForumCategory|null
* *
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumCategory", inversedBy="forums") * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumCategory", inversedBy="forums")
@ -146,6 +149,7 @@ class CForumForum extends AbstractResource implements ResourceInterface
/** /**
* @var int * @var int
* @Gedmo\SortablePosition
* *
* @ORM\Column(name="forum_order", type="integer", nullable=true) * @ORM\Column(name="forum_order", type="integer", nullable=true)
*/ */
@ -223,6 +227,7 @@ class CForumForum extends AbstractResource implements ResourceInterface
$this->locked = 0; $this->locked = 0;
$this->forumImage = ''; $this->forumImage = '';
$this->forumOfGroup = 0; $this->forumOfGroup = 0;
$this->forumPosts = 0;
$this->forumGroupPublicPrivate = ''; $this->forumGroupPublicPrivate = '';
} }

Loading…
Cancel
Save