Remove item_property calls in forum/category

pull/3124/head
Julio 6 years ago
parent 4a16185889
commit b51a91de56
  1. 340
      public/main/forum/forumfunction.inc.php
  2. 49
      public/main/forum/index.php
  3. 2
      public/main/forum/newthread.php
  4. 107
      public/main/forum/viewforum.php
  5. 61
      public/main/forum/viewforumcategory.php

@ -87,101 +87,146 @@ $(function () {
});
</script>';
/**
* This function handles all the forum and forum categories actions. This is a wrapper for the
* forum and forum categories. All this code code could go into the section where this function is
* called but this make the code there cleaner.
*
* @param int $lp_id Learning path Id
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Juan Carlos Raña Trabado (return to lp_id)
*
* @version may 2011, Chamilo 1.8.8
*/
function handle_forum_and_forumcategories($lp_id = null)
function handleForum($url)
{
$action = isset($_GET['action']) ? $_GET['action'] : '';
$get_content = isset($_GET['content']) ? $_GET['content'] : '';
$post_submit_cat = isset($_POST['SubmitForumCategory']) ? true : false;
$post_submit_forum = isset($_POST['SubmitForum']) ? true : false;
$get_id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$forum_categories_list = get_forum_categories();
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
switch ($content) {
case 'forumcategory':
$repo = Container::getForumCategoryRepository();
break;
case 'forum':
$repo = Container::getForumRepository();
break;
case 'thread':
$repo = Container::getForumThreadRepository();
break;
}
if (api_is_allowed_to_edit(false, true)) {
//if is called from a learning path lp_id
$lp_id = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : null;
$content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$resource = $repo->find($get_id);
$repo = null;
switch ($action) {
case 'move':
$return_message = move_up_down($get_content, $_GET['direction'], $get_id);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
case 'lock':
case 'unlock':
if ('lock' === $action) {
$locked = 1;
$return_message = get_lang('Locked: students can no longer post new messages in this forum category, forum or thread but they can still read the messages that were already posted');
} else {
$locked = 0;
$return_message = get_lang('Unlocked: learners can post new messages in this forum category, forum or thread');
}
switch ($content) {
case 'forumcategory':
$repo = Container::getForumCategoryRepository();
break;
case 'forum':
$repo = Container::getForumRepository();
break;
case 'thread':
$repo = Container::getForumThreadRepository();
break;
}
$resource->setLocked($locked);
$repo->getEntityManager()->persist($resource);
$repo->getEntityManager()->flush();
if ($repo && $id) {
$resource = $repo->find($id);
}
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
case 'visible':
case 'invisible':
if ('visible' === $action) {
$repo->setVisibilityPublished($resource);
} else {
$repo->setVisibilityPending($resource);
}
switch ($action) {
case 'add_forum':
$formContent = forumForm(null, $lp_id);
if ('visible' === $action) {
handle_mail_cue($content, $get_id);
}
return $formContent;
break;
case 'edit_forum':
$repo = Container::getForumRepository();
$resource = $repo->find($id);
$formContent = forumForm($resource, $lp_id);
Display::addFlash(
Display::return_message(get_lang('Updated'), 'confirmation', false)
);
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
return $formContent;
break;
case 'add_category':
$formContent = show_add_forumcategory_form([], $lp_id);
case 'delete':
if ($resource) {
$repo->delete($resource);
}
return $formContent;
break;
case 'edit_category':
$repo = Container::getForumCategoryRepository();
$category = $repo->find($id);
$formContent = editForumCategoryForm($category);
Display::addFlash(Display::return_message(get_lang('Forum category deleted'), 'confirmation', false));
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
}
return $formContent;
break;
case 'notify':
if (0 != api_get_session_id() &&
false == api_is_allowed_to_session_edit(false, true)
) {
api_not_allowed();
}
$message = set_notification($content, $id);
Display::addFlash(Display::return_message($message, 'confirm', false));
header('Location: '. $url);
exit;
break;
case 'lock':
case 'unlock':
if ($resource) {
if ('lock' === $action) {
$locked = 1;
$message = get_lang('Locked: students can no longer post new messages in this forum category, forum or thread but they can still read the messages that were already posted');
} else {
$locked = 0;
$message = get_lang('Unlocked: learners can post new messages in this forum category, forum or thread');
}
$resource->setLocked($locked);
$repo->getEntityManager()->persist($resource);
$repo->getEntityManager()->flush();
Display::addFlash(
Display::return_message($message, 'confirmation', false)
);
}
header('Location: '. $url);
exit;
break;
case 'move':
move_up_down($content, $_REQUEST['direction'], $id);
header('Location: '. $url);
exit;
break;
case 'visible':
case 'invisible':
if ('visible' === $action) {
$repo->setVisibilityPublished($resource);
} else {
$repo->setVisibilityPending($resource);
}
if ('visible' === $action) {
handle_mail_cue($content, $id);
}
Display::addFlash(
Display::return_message(get_lang('Updated'), 'confirmation', false)
);
header('Location: '. $url);
exit;
break;
case 'delete':
$locked = api_resource_is_locked_by_gradebook($id, LINK_FORUM_THREAD);
if ($resource && false === $locked) {
$repo->delete($resource);
if ('thread' === $content) {
$return_message = get_lang('Thread deleted');
Skill::deleteSkillsFromItem($id, ITEM_TYPE_FORUM_THREAD);
}
$link_info = GradebookUtils::isResourceInCourseGradebook(
api_get_course_id(),
5,
$id,
api_get_session_id()
);
$link_id = $link_info['id'];
if (false !== $link_info) {
GradebookUtils::remove_resource_from_course_gradebook($link_id);
}
}
return $content;
Display::addFlash(Display::return_message(get_lang('Forum category deleted'), 'confirmation', false));
header('Location: '. $url);
exit;
break;
}
}
}
/**
@ -469,6 +514,9 @@ function forumForm(CForumForum $forum = null, $lp_id)
Display::addFlash(Display::return_message(get_lang('The forum has been added'), 'confirmation'));
}
}
$url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq();
header('Location: '.$url);
exit;
}
Security::clear_token();
} else {
@ -967,117 +1015,6 @@ function store_forum($values, $courseInfo = [], $returnId = false)
return $return_message;
}
/**
* This function deletes a forum or a forum category
* This function currently does not delete the forums inside the category,
* nor the threads and replies inside these forums.
* For the moment this is the easiest method and it has the advantage that it
* allows to recover fora that were acidently deleted
* when the forum category got deleted.
*
* @param $content = what we are deleting (a forum or a forum category)
* @param the $id id of the forum category that has to be deleted
*
* @todo write the code for the cascading deletion of the forums inside a
* forum category and also the threads and replies inside these forums
* @todo config setting for recovery or not
* (see also the documents tool: real delete or not).
*
* @return string
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version february 2006, dokeos 1.8
*/
function deleteForumCategoryThread($content, $id)
{
$_course = api_get_course_info();
$table_forums = Database::get_course_table(TABLE_FORUM);
$table_forums_post = Database::get_course_table(TABLE_FORUM_POST);
$table_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
$course_id = api_get_course_int_id();
$groupId = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($groupId);
$userId = api_get_user_id();
$id = (int) $id;
// Delete all attachment file about this tread id.
$sql = "SELECT post_id FROM $table_forums_post
WHERE c_id = $course_id AND thread_id = '".$id."' ";
$res = Database::query($sql);
while ($poster_id = Database::fetch_row($res)) {
delete_attachment($poster_id[0]);
}
$tool_constant = null;
$return_message = '';
if ('forumcategory' === $content) {
$tool_constant = TOOL_FORUM_CATEGORY;
$return_message = get_lang('Forum category deleted');
if (!empty($forum_list)) {
$sql = "SELECT forum_id FROM $table_forums
WHERE c_id = $course_id AND forum_category='".$id."'";
$result = Database::query($sql);
$row = Database::fetch_array($result);
foreach ($row as $arr_forum) {
$forum_id = $arr_forum['forum_id'];
api_item_property_update(
$_course,
'forum',
$forum_id,
'delete',
api_get_user_id()
);
}
}
}
if ('forum' === $content) {
$tool_constant = TOOL_FORUM;
$return_message = get_lang('Forum deleted');
if (!empty($number_threads)) {
$sql = "SELECT thread_id FROM $table_forum_thread
WHERE c_id = $course_id AND forum_id = $id ";
$result = Database::query($sql);
$row = Database::fetch_array($result);
foreach ($row as $arr_forum) {
$forum_id = $arr_forum['thread_id'];
api_item_property_update(
$_course,
'forum_thread',
$forum_id,
'delete',
api_get_user_id()
);
}
}
}
if ('thread' === $content) {
$tool_constant = TOOL_FORUM_THREAD;
$return_message = get_lang('Thread deleted');
Skill::deleteSkillsFromItem($id, ITEM_TYPE_FORUM_THREAD);
}
api_item_property_update(
$_course,
$tool_constant,
$id,
'delete',
$userId,
$groupInfo
);
// Check if this returns a true and if so => return $return_message, if not => return false;
if (!empty($return_message)) {
Display::addFlash(Display::return_message($return_message, 'confirmation', false));
}
return $return_message;
}
/**
* This function deletes a forum post. This separate function is needed because forum posts do not appear
* in the item_property table (yet)
@ -1340,7 +1277,6 @@ function move_up_down($content, $direction, $id)
{
$table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY);
$table_forums = Database::get_course_table(TABLE_FORUM);
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = api_get_course_int_id();
$id = (int) $id;
@ -1377,12 +1313,9 @@ function move_up_down($content, $direction, $id)
// The SQL statement
if ('forumcategory' == $content) {
$sql = "SELECT *
FROM $table_categories forum_categories, $table_item_property item_properties
FROM $table_categories forum_categories
WHERE
forum_categories.c_id = $course_id AND
item_properties.c_id = $course_id AND
forum_categories.cat_id=item_properties.ref AND
item_properties.tool='".TOOL_FORUM_CATEGORY."'
forum_categories.c_id = $course_id'
ORDER BY forum_categories.cat_order $sort_direction";
}
if ('forum' == $content) {
@ -1396,6 +1329,7 @@ function move_up_down($content, $direction, $id)
// Finding the items that need to be switched.
$result = Database::query($sql);
$found = false;
$next_sort = '';
while ($row = Database::fetch_array($result)) {
if ($found) {
$next_id = $row[$id_column];
@ -5429,7 +5363,9 @@ function delete_attachment($postId, $id_attach = 0)
$repoAttachment = Container::getForumAttachmentRepository();
$attachment = $repoAttachment->find($id_attach);
$post->removeAttachment($attachment);
if ($attachment) {
$post->removeAttachment($attachment);
}
$repo->getEntityManager()->persist($post);
$repo->getEntityManager()->flush();

@ -26,6 +26,7 @@ use ChamiloSession as Session;
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once 'forumfunction.inc.php';
api_protect_course_script(true);
$current_course_tool = TOOL_FORUM;
@ -52,8 +53,6 @@ $_user = api_get_user_info();
$hideNotifications = api_get_course_setting('hide_forum_notifications');
$hideNotifications = 1 == $hideNotifications;
require_once 'forumfunction.inc.php';
if (api_is_in_gradebook()) {
$interbreadcrumb[] = [
'url' => Category::getUrl(),
@ -62,9 +61,8 @@ if (api_is_in_gradebook()) {
}
$search_forum = isset($_GET['search']) ? Security::remove_XSS($_GET['search']) : '';
/* ACTIONS */
$action = isset($_GET['action']) ? $_GET['action'] : '';
$lp_id = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : null;
if ('add' === $action) {
switch ($_GET['content']) {
@ -103,50 +101,11 @@ if ('add' === $action) {
// Tool introduction
$introduction = Display::return_introduction_section(TOOL_FORUM);
$form_count = 0;
$formContent = '';
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
if (api_is_allowed_to_edit(false, true)) {
//if is called from a learning path lp_id
$lp_id = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : null;
switch ($action) {
case 'add_forum':
$formContent = forumForm([], $lp_id);
break;
case 'edit_forum':
$repo = Container::getForumRepository();
$resource = $repo->find($id);
$formContent = forumForm($resource, $lp_id);
break;
case 'add_category':
$formContent = show_add_forumcategory_form([], $lp_id);
break;
case 'edit_category':
$repo = Container::getForumCategoryRepository();
$category = $repo->find($id);
$formContent = editForumCategoryForm($category);
break;
}
//$formContent = handle_forum_and_forumcategories($lp_id);
}
// Notification
if ('notify' === $action && isset($_GET['content']) && isset($_GET['id'])) {
if (0 != api_get_session_id() &&
false == api_is_allowed_to_session_edit(false, true)
) {
api_not_allowed();
}
$return_message = set_notification($_GET['content'], $_GET['id']);
Display::addFlash(Display::return_message($return_message, 'confirm', false));
}
$url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq();
$formContent = handleForum($url);
get_whats_new();
$whatsnew_post_info = Session::read('whatsnew_post_info');
Event::event_access_tool(TOOL_FORUM);
$logInfo = [

@ -174,7 +174,7 @@ if ('learnpath' == $origin) {
} else {
Display::display_header();
}
handle_forum_and_forumcategories();
//handle_forum_and_forumcategories();
// Action links
echo '<div class="actions">';

@ -34,6 +34,11 @@ $origin = api_get_origin();
require_once 'forumfunction.inc.php';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$url = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId;
handleForum($url);
$userId = api_get_user_id();
$sessionId = api_get_session_id();
$groupId = api_get_group_id();
@ -43,12 +48,12 @@ $isTutor = GroupManager::is_tutor_of_group($userId, $groupInfo, $courseId);
$isAllowedToEdit = api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true);
$repo = Container::getForumRepository();
$my_forum = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($my_forum);
$forumEntity = $repo->find($forumId);
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
$isForumOpenByDateAccess = api_is_date_in_date_range($forumEntity->getStartTime(), $forumEntity->getEndTime());
$url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq();
if (!$isForumOpenByDateAccess && !$isAllowedToEdit) {
if ($origin) {
@ -96,7 +101,7 @@ $my_action = $_GET['action'] ?? '';
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => $my_forum,
'tool_id' => $forumId,
'tool_id_detail' => 0,
'action' => !empty($my_action) ? $my_action : 'list-threads',
'action_details' => $_GET['content'] ?? '',
@ -149,45 +154,6 @@ if ('learnpath' === $origin) {
Display::display_header();
}
/* Actions */
// Change visibility of a forum or a forum category.
if (('invisible' == $my_action || 'visible' == $my_action) &&
isset($_GET['content']) &&
isset($_GET['id']) &&
$isAllowedToEdit
) {
$message = change_visibility($_GET['content'], $_GET['id'], $_GET['action']);
}
// Locking and unlocking.
if (('lock' == $my_action || 'unlock' == $my_action) &&
isset($_GET['content']) && isset($_GET['id']) &&
$isAllowedToEdit
) {
$message = change_lock_status($_GET['content'], $_GET['id'], $my_action);
}
// Deleting.
if ('delete' == $my_action &&
isset($_GET['content']) &&
isset($_GET['id']) &&
$isAllowedToEdit
) {
$locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
if (false == $locked) {
$message = deleteForumCategoryThread($_GET['content'], $_GET['id']);
// Delete link
$link_info = GradebookUtils::isResourceInCourseGradebook(
api_get_course_id(),
5,
$_GET['id'],
api_get_session_id()
);
$link_id = $link_info['id'];
if (false !== $link_info) {
GradebookUtils::remove_resource_from_course_gradebook($link_id);
}
}
}
// Moving.
if ('move' == $my_action && isset($_GET['thread']) &&
$isAllowedToEdit
@ -237,7 +203,7 @@ if ('liststd' == $my_action &&
$table_list = Display::page_subheader(get_lang('Users list of the thread').': '.get_name_thread_by_id($_GET['id']));
if ($nrorow3 > 0 || -2 == $nrorow3) {
$url = api_get_cidreq().'&forum='.$my_forum.'&action='
$url = api_get_cidreq().'&forum='.$forumId.'&action='
.Security::remove_XSS($_GET['action']).'&content='
.Security::remove_XSS($_GET['content'], STUDENT).'&id='.(int) ($_GET['id']);
$tabs = [
@ -295,7 +261,7 @@ if ('liststd' == $my_action &&
);
$table_list .= '<td>
<a href="'.$forumUrl.'forumqualify.php?'.api_get_cidreq()
.'&forum='.(int) $my_forum.'&thread='
.'&forum='.(int) $forumId.'&thread='
.(int) ($_GET['id']).'&user='.$row_student_list['id']
.'&user_id='.$row_student_list['id'].'&idtextqualify='
.$current_qualify_thread.'">'
@ -352,18 +318,10 @@ if (api_is_allowed_to_edit(false, true) ||
) {
if (1 != $forumEntity->getLocked() && 1 != $forumEntity->getLocked()) {
if (!api_is_anonymous() && !api_is_invitee()) {
if ($my_forum == (string) ((int) $my_forum)) {
echo '<a href="'.$forumUrl.'newthread.php?'.api_get_cidreq().'&forum='
.Security::remove_XSS($my_forum).'">'
.Display::return_icon('new_thread.png', get_lang('Create thread'), '', ICON_SIZE_MEDIUM)
.'</a>';
} else {
$my_forum = (string) ((int) $my_forum);
echo '<a href="'.$forumUrl.'newthread.php?'.api_get_cidreq()
.'&forum='.$my_forum.'">'
.Display::return_icon('new_thread.png', get_lang('Create thread'), '', ICON_SIZE_MEDIUM)
.'</a>';
}
echo '<a href="'.$forumUrl.'newthread.php?'.api_get_cidreq().'&forum='
.$forumId.'">'
.Display::return_icon('new_thread.png', get_lang('Create thread'), '', ICON_SIZE_MEDIUM)
.'</a>';
}
} else {
echo get_lang('Forum blocked');
@ -404,7 +362,7 @@ $html .= '</div>';
echo $html;
// Getting al the threads
$threads = get_threads($my_forum);
$threads = get_threads($forumId);
//$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
$course_id = api_get_course_int_id();
@ -419,8 +377,8 @@ if (is_array($threads)) {
!('0' == $thread->getThreadReplies() && '0' == $thread->isVisible($courseEntity, $sessionEntity))
) {
/*$my_whatsnew_post_info = null;
if (isset($whatsnew_post_info[$my_forum][$thread['thread_id']])) {
$my_whatsnew_post_info = $whatsnew_post_info[$my_forum][$thread['thread_id']];
if (isset($whatsnew_post_info[$forumId][$thread['thread_id']])) {
$my_whatsnew_post_info = $whatsnew_post_info[$forumId][$thread['thread_id']];
}
$newPost = '';
if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
@ -429,7 +387,7 @@ if (is_array($threads)) {
//$name = api_get_person_name($thread['firstname'], $thread['lastname']);
$linkPostForum = '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$my_forum
$linkPostForum = '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$forumId
."&thread={$threadId}&search="
.Security::remove_XSS(urlencode($my_search)).'">'
.$thread->getThreadTitle().'</a>';
@ -556,8 +514,6 @@ if (is_array($threads)) {
.' '.$last_post;
$html .= '</div>';
$html .= '<div class="col-md-3">';
$cidreq = api_get_cidreq();
// Get attachment id.
/*if (isset($thread['post_id'])) {
$attachment_list = get_attachment($thread['post_id']);
@ -568,8 +524,8 @@ if (is_array($threads)) {
if (api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
) {
$iconsEdit .= '<a href="'.$forumUrl.'editthread.php?'.$cidreq
.'&forum='.$my_forum.'&thread='
$iconsEdit .= '<a href="'.$forumUrl.'editthread.php?'.api_get_cidreq()
.'&forum='.$forumId.'&thread='
.$thread->getIid()
.'&id_attach='.$id_attach.'">'
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
@ -581,8 +537,7 @@ if (is_array($threads)) {
ICON_SIZE_SMALL
);
} else {
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
.$my_forum.'&action=delete&content=thread&id='
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId.'&action=delete&content=thread&id='
.$thread->getIid()."\" onclick=\"javascript:if(!confirm('"
.addslashes(api_htmlentities(get_lang('Delete complete thread?'), ENT_QUOTES))
."')) return false;\">"
@ -594,7 +549,7 @@ if (is_array($threads)) {
$thread->getIid(),
$thread->isVisible($courseEntity, $sessionEntity),
[
'forum' => $my_forum,
'forum' => $forumId,
'gid' => $groupId,
]
);
@ -603,13 +558,11 @@ if (is_array($threads)) {
$thread->getIid(),
$thread->getLocked(),
[
'forum' => $my_forum,
'forum' => $forumId,
'gid' => api_get_group_id(),
]
);
$iconsEdit .= '<a href="viewforum.php?'.$cidreq.'&forum='
.$my_forum
.'&action=move&thread='.$threadId.'">'
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId.'&action=move&thread='.$threadId.'">'
.Display::return_icon('move.png', get_lang('Move Thread'), [], ICON_SIZE_SMALL)
.'</a>';
}
@ -625,17 +578,13 @@ if (is_array($threads)) {
}
$icon_liststd = 'user.png';
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
.$my_forum
."&action=notify&content=thread&id={$threadId}"
.'">'.Display::return_icon($iconnotify, get_lang('Notify me')).'</a>';
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId."&action=notify&content=thread&id={$threadId}".'">'.
Display::return_icon($iconnotify, get_lang('Notify me')).'</a>';
}
if (api_is_allowed_to_edit(null, true) && 'learnpath' != $origin) {
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
.$my_forum
."&action=liststd&content=thread&id={$threadId}"
.'">'.Display::return_icon($icon_liststd, get_lang('Learners list'), [], ICON_SIZE_SMALL)
$iconsEdit .= '<a href="'.$url.'&forum='.$forumId."&action=liststd&content=thread&id={$threadId}".'">'.
Display::return_icon($icon_liststd, get_lang('Learners list'), [], ICON_SIZE_SMALL)
.'</a>';
}
$html .= $iconsEdit;

@ -26,6 +26,7 @@ use ChamiloSession as Session;
* @Copyright Patrick Cool
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once 'forumfunction.inc.php';
Session::erase('_gid');
@ -45,23 +46,23 @@ function hidecontent(content){
// The section (tabs)
$this_section = SECTION_COURSES;
// Including additional library scripts.
$nameTools = get_lang('Forums');
$action = isset($_GET['action']) ? $_GET['action'] : '';
$categoryId = isset($_GET['forumcategory']) ? $_GET['forumcategory'] : 0;
$mainUrl = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$categoryId;
$formContent = handleForum($url);
$_user = api_get_user_info();
$_course = api_get_course_info();
$courseEntity = api_get_course_entity();
$sessionEntity = api_get_session_entity();
$action = isset($_GET['action']) ? $_GET['action'] : '';
$hideNotifications = api_get_course_setting('hide_forum_notifications');
$hideNotifications = 1 == $hideNotifications;
require_once 'forumfunction.inc.php';
/** @var CForumCategory $forumCategory */
$forumCategory = $repo->find($_GET['forumcategory']);
$forumCategory = $repo->find($categoryId);
$categoryId = $forumCategory->getIid();
// Are we in a lp ?
@ -117,11 +118,10 @@ if (!api_is_allowed_to_edit(false, true) && false === $categoryIsVisible) {
/* Action Links */
$html = '<div class="actions">';
$html .= '<a href="index.php?'.api_get_cidreq().'">'.
$html .= '<a href="'.$url.'">'.
Display::return_icon('back.png', get_lang('Back to forum overview'), '', ICON_SIZE_MEDIUM).'</a>';
if (api_is_allowed_to_edit(false, true)) {
$html .= '<a href="'.api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&forumcategory='
.$categoryId.'&action=add&content=forum"> '
$html .= '<a href="'.$mainUrl.'&forumcategory='.$categoryId.'&action=add_forum"> '
.Display::return_icon('new_forum.png', get_lang('Add a forum'), '', ICON_SIZE_MEDIUM).'</a>';
}
$html .= search_link();
@ -136,13 +136,6 @@ $logInfo = [
];
Event::registerLog($logInfo);
// Notification
if ('notify' === $action && isset($_GET['content']) && isset($_GET['id'])) {
$return_message = set_notification($_GET['content'], $_GET['id']);
echo Display::return_message($return_message, 'confirm', false);
}
if ('add' !== $action) {
// Step 2: We find all the forums.
$forum_list = get_forums();
@ -179,11 +172,9 @@ if ('add' !== $action) {
if (api_is_allowed_to_edit(false, true) &&
!(0 == $sessionCategoryId && 0 != $sessionId)
) {
$iconsEdit = '<a href="'.api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&action=edit_category&id='.$categoryId.'">'
$iconsEdit = '<a href="'.$mainUrl.'&action=edit_category&id='.$categoryId.'">'
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
$iconsEdit .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='
.Security::remove_XSS($_GET['forumcategory'])
.'&action=delete&content=forumcategory&id='.$forumCategory->getIid()
$iconsEdit .= '<a href="'.$url.'&action=delete&content=forumcategory&id='.$categoryId
."\" onclick=\"javascript:if(!confirm('"
.addslashes(api_htmlentities(get_lang('Delete forum category ?'), ENT_QUOTES))
."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)
@ -235,6 +226,20 @@ if ('add' !== $action) {
$html .= '</div>';
echo $html;
echo '<div class="forum_display">';
$notifications = [];
$em = Database::getManager();
$notifications = $em->getRepository('ChamiloCourseBundle:CForumNotification')->findBy(
['userId' => api_get_user_id()]
);
$forumNotifications = [];
foreach ($notifications as $notification) {
if ($notification->getForumId()) {
$forumNotifications[] = $notification->getForumId();
}
}
// The forums in this category.
$forums_in_category = get_forums_in_category($categoryId);
$forum_count = 0;
@ -415,14 +420,12 @@ if ('add' !== $action) {
$html .= '</div>';
$html .= '<div class="col-md-4">';
$url = api_get_path(WEB_CODE_PATH).'forum/index.php';
if (api_is_allowed_to_edit(false, true) &&
!(0 == $forum->getSessionId() && 0 != $sessionId)
) {
$html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$categoryId.'&action=edit_forum&content=forum&id='.$forumId.'">'
$html .= '<a href="'.$mainUrl.'&forumcategory='.$categoryId.'&action=edit_forum&id='.$forumId.'">'
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
$html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$categoryId.'&action=delete&content=forum&id='.$forumId
$html .= '<a href="'.$url.'&forumcategory='.$categoryId.'&action=delete&content=forum&id='.$forumId
."\" onclick=\"javascript:if(!confirm('"
.addslashes(api_htmlentities(get_lang('Delete forum ?'), ENT_QUOTES))
."')) return false;\">"
@ -448,14 +451,12 @@ if ('add' !== $action) {
}
$iconnotify = 'notification_mail_na.png';
if (is_array(isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : null)) {
if (in_array($forum['forum_id'], $_SESSION['forum_notification']['forum'])) {
$iconnotify = 'notification_mail.png';
}
if (in_array($forum->getIid(), $forumNotifications)) {
$iconnotify = 'notification_mail.png';
}
if (!api_is_anonymous() && false == $hideNotifications) {
$html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$categoryId.'&action=notify&content=forum&id='.$forumId.'">'.
$html .= '<a href="'.$url.'&forumcategory='.$categoryId.'&action=notify&content=forum&id='.$forumId.'">'.
Display::return_icon($iconnotify, get_lang('Notify me')).
'</a>';
}

Loading…
Cancel
Save