diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php index f0f55f862df..8b3fa4bda2c 100644 --- a/public/main/forum/forumfunction.inc.php +++ b/public/main/forum/forumfunction.inc.php @@ -1105,12 +1105,13 @@ function get_forum_categories(int $courseId = 0, int $sessionId = 0): Array * * @version february 2006, dokeos 1.8 */ -function get_forums_in_category(int $categoryId, int $courseId = 0) +function get_forums_in_category(int $categoryId, int $courseId = 0, int $sessionId = 0) { $repo = Container::getForumRepository(); $course = api_get_course_entity($courseId); + $session = api_get_session_entity($sessionId); - $qb = $repo->getResourcesByCourse($course, null, null, null, true, true); + $qb = $repo->getResourcesByCourse($course, $session, null, null, true, true); $qb ->andWhere('resource.forumCategory = :catId') ->setParameter('catId', $categoryId) @@ -3357,7 +3358,7 @@ function send_mail($userInfo, CForum $forum, CForumThread $thread, CForumPost $p $threadId = $thread->getIid(); $thread_link = api_get_path(WEB_CODE_PATH). - 'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId; + 'forum/viewthread.php?'.api_get_cidreq(true, true, false).'&forum='.$forumId.'&thread='.$threadId; $email_body = get_lang('Dear').' '. api_get_person_name($userInfo['firstname'], $userInfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).",
\n\r"; @@ -5357,7 +5358,7 @@ function reportPost(CForumPost $post, CForum $forumInfo, CForumThread $threadInf $users = getReportRecipients(); if (!empty($users)) { $url = api_get_path(WEB_CODE_PATH). - 'forum/viewthread.php?forum='.$forumInfo->getIid().'&thread='.$threadInfo->getIid().'&'.api_get_cidreq().'&post_id='.$postId.'#post_id_'.$postId; + 'forum/viewthread.php?forum='.$forumInfo->getIid().'&thread='.$threadInfo->getIid().'&'.api_get_cidreq(true, true, false).'&post_id='.$postId.'#post_id_'.$postId; $postLink = Display::url( $post->getTitle(), $url @@ -5376,3 +5377,51 @@ function reportPost(CForumPost $post, CForum $forumInfo, CForumThread $threadInf return true; } + +function getVisibleForums($courseId, $sessionId): array +{ + $forums = get_forums($courseId, $sessionId); + $visibleForums = []; + + foreach ($forums as $forum) { + $forumSession = $forum->getFirstResourceLink()->getSession(); + if ($sessionId > 0) { + if (null === $forumSession) { + $threads = get_threads($forum->getIid(), $courseId, $sessionId, true); + if (!empty($threads)) { + $visibleForums[] = $forum; + } + } else { + $visibleForums[] = $forum; + } + } else { + $visibleForums[] = $forum; + } + } + + return $visibleForums; +} + +function getVisibleForumsInCategory($categoryId, $courseId, $sessionId): array +{ + $forumsInCategory = get_forums_in_category($categoryId, $courseId, $sessionId); + $visibleForums = []; + + foreach ($forumsInCategory as $forum) { + $forumSession = $forum->getFirstResourceLink()->getSession(); + if ($sessionId > 0) { + if (null === $forumSession) { + $threads = get_threads($forum->getIid(), $courseId, $sessionId, true); + if (!empty($threads)) { + $visibleForums[] = $forum; + } + } else { + $visibleForums[] = $forum; + } + } else { + $visibleForums[] = $forum; + } + } + + return $visibleForums; +} diff --git a/public/main/forum/index.php b/public/main/forum/index.php index dd630718451..819b18b94c8 100644 --- a/public/main/forum/index.php +++ b/public/main/forum/index.php @@ -179,7 +179,7 @@ function hidecontent(content){ // Step 2: We find all the forums (only the visible ones if it is a student). // display group forum in general forum tool depending to configuration option $setting = api_get_setting('display_groups_forum_in_general_tool'); -$allCourseForums = get_forums(); +$allCourseForums = getVisibleForums($courseId, $sessionId); $user_id = api_get_user_id(); /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */ @@ -399,7 +399,7 @@ function hidecontent(content){ $forumCategoryInfo['forums'] = []; // The forums in this category. $forumInfo = []; - $forumsInCategory = get_forums_in_category($categoryId, $courseId); + $forumsInCategory = getVisibleForumsInCategory($categoryId, $courseId, $sessionId); if (!empty($forumsInCategory)) { $forumsDetailsList = []; diff --git a/public/main/forum/viewforum.php b/public/main/forum/viewforum.php index cbd1ae40ee9..5496de71d75 100644 --- a/public/main/forum/viewforum.php +++ b/public/main/forum/viewforum.php @@ -494,7 +494,7 @@ function setFocus() { } } if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) { - $iconsEdit .= ''. + $iconsEdit .= ''. Display::getMdiIcon('email-alert', ($disable ? 'ch-tool-icon-disabled' : 'ch-tool-icon'), '', ICON_SIZE_SMALL, get_lang('Notify me')).''; } diff --git a/public/main/lp/learnpath.class.php b/public/main/lp/learnpath.class.php index 5c94a4f126c..299ec48a8ca 100644 --- a/public/main/lp/learnpath.class.php +++ b/public/main/lp/learnpath.class.php @@ -6794,7 +6794,10 @@ function toggle_forum(forum_id) { } '; $moveIcon = Display::getMdiIcon('cursor-move', 'ch-tool-icon', '', 16, get_lang('Move')); + $userRights = api_is_allowed_to_edit(false, true); foreach ($a_forums as $forum) { + $forumSession = $forum->getFirstResourceLink()->getSession(); + $isForumSession = (null !== $forumSession); $forumId = $forum->getIid(); $title = Security::remove_XSS($forum->getTitle()); $link = Display::url( @@ -6813,8 +6816,14 @@ class="list-group-item lp_resource_element" $return .= ' '; $return .= Display::getMdiIcon('comment-quote', 'ch-tool-icon', null, 16, get_lang('Forum')); + $alertIcon = ''; + if (!$isForumSession && $userRights) { + $tooltip = get_lang('This Learningpath includes a forum in the base course, so once users in a session will participate in this forum, it will start to appear in the forum tool in the session, whereas by default forums from the base course do not appear in the session.'); + $alertIcon = Display::return_icon('warning.png', $tooltip, null, ICON_SIZE_SMALL); + } + $moveLink = Display::url( - $title.' '.$link, + $title, api_get_self().'?'. api_get_cidreq().'&action=add_item&type='.TOOL_FORUM.'&forum_id='.$forumId.'&lp_id='.$this->lp_id, [ @@ -6826,12 +6835,12 @@ class="list-group-item lp_resource_element" ] ); $return .= ' - - - '.$moveLink; + + + '.$moveLink. ' '.$alertIcon; $return .= ''; $return .= '