Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal: Fix forum visibility and add alert for base course forums in LP - refs BT#21692 #5594

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions public/main/forum/forumfunction.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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).", <br />\n\r";
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions public/main/forum/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion public/main/forum/viewforum.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ function setFocus() {
}
}
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId."&action=notify&content=thread&id={$threadId}".'">'.
$iconsEdit .= '<a href="'.$viewForumUrl.'&forum='.$forumId."&action=notify&content=thread&id={$threadId}".'">'.
Display::getMdiIcon('email-alert', ($disable ? 'ch-tool-icon-disabled' : 'ch-tool-icon'), '', ICON_SIZE_SMALL, get_lang('Notify me')).'</a>';
}

Expand Down
23 changes: 16 additions & 7 deletions public/main/lp/learnpath.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6794,7 +6794,10 @@ function toggle_forum(forum_id) {
}
</script>';
$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(
Expand All @@ -6813,8 +6816,14 @@ class="list-group-item lp_resource_element"
$return .= ' </a>';
$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,
[
Expand All @@ -6826,12 +6835,12 @@ class="list-group-item lp_resource_element"
]
);
$return .= '<a onclick="javascript:toggle_forum('.$forumId.');" style="cursor:hand; vertical-align:middle">
<img
src="'.Display::returnIconPath('add.png').'"
id="forum_'.$forumId.'_opener" align="absbottom"
/>
</a>
'.$moveLink;
<img
src="'.Display::returnIconPath('add.png').'"
id="forum_'.$forumId.'_opener" align="absbottom"
/>
</a>
'.$moveLink. ' '.$alertIcon;
$return .= '</li>';

$return .= '<div style="display:none" id="forum_'.$forumId.'_content">';
Expand Down
Loading