Fix Forum/ForumThread/ForumPost creation using resources

pull/3064/head
Julio 5 years ago
parent 4fe9ef9be0
commit 954ca5c18e
  1. 669
      public/main/forum/forumfunction.inc.php
  2. 45
      public/main/forum/iframe_thread.php
  3. 1
      public/main/forum/index.php
  4. 68
      public/main/forum/newthread.php
  5. 64
      public/main/forum/reply.php
  6. 192
      public/main/forum/viewforum.php
  7. 145
      public/main/forum/viewthread.php
  8. 9
      public/main/lp/learnpath.class.php
  9. 2
      src/CourseBundle/Entity/CForumCategory.php
  10. 2
      src/CourseBundle/Entity/CForumForum.php
  11. 3
      src/CourseBundle/Entity/CForumPost.php
  12. 7
      src/CourseBundle/Entity/CForumThread.php

File diff suppressed because it is too large Load Diff

@ -1,6 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumThread;
/**
* These files are a complete rework of the forum. The database structure is
* based on phpBB but all the code is rewritten. A lot of new functionalities
@ -17,8 +22,6 @@
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @copyright Ghent University
*
* @package chamilo.forum
*/
require_once __DIR__.'/../inc/global.inc.php';
@ -29,27 +32,31 @@ $nameTools = get_lang('Forums');
require_once 'forumfunction.inc.php';
/* Retrieving forum and forum categorie information */
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
// We are getting all the information about the current forum and forum category.
// Note pcool: I tried to use only one sql statement (and function) for this,
// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
$current_thread = get_thread_information(
$_GET['forum'],
$_GET['thread']
); // Note: this has to be validated that it is an existing thread.
$current_forum = get_forum_information($current_thread['forum_id']);
// Note: this has to be validated that it is an existing forum.
$current_forum_category = get_forumcategory_information(
$current_forum['forum_category']
);
$repo = Container::getForumRepository();
$forumEntity = null;
if (!empty($forumId)) {
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($forumId);
}
/* Is the user allowed here? */
$repoThread = Container::getForumThreadRepository();
$threadEntity = null;
if (!empty($threadId)) {
/** @var CForumThread $threadEntity */
$threadEntity = $repoThread->find($threadId);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
/* Is the user allowed here? */
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false, true) &&
($current_forum['visibility'] == 0 || $current_thread['visibility'] == 0)
($forumEntity->isVisible($courseEntity, $sessionEntity) == false || $threadEntity->isVisible($courseEntity, $sessionEntity) == false)
) {
api_not_allowed(false);
}
@ -64,12 +71,12 @@ $table_users = Database::get_main_table(TABLE_MAIN_USER);
// We are getting all the information about the current forum and forum category.
// Note pcool: I tried to use only one sql statement (and function) for this,
// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
$sql = "SELECT * FROM $table_posts posts
$sql = "SELECT * FROM $table_posts posts
INNER JOIN $table_users users
ON (posts.poster_id = users.user_id)
WHERE
posts.c_id = $course_id AND
posts.thread_id='".$current_thread['thread_id']."'
posts.thread_id='".$threadEntity->getIid()."'
ORDER BY posts.post_id ASC";
$result = Database::query($sql);

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CForumPost;

@ -1,6 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
/**
* These files are a complete rework of the forum. The database structure is
* based on phpBB but all the code is rewritten. A lot of new functionalities
@ -18,9 +22,8 @@
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @Copyright Ghent University
* @Copyright Patrick Cool
*
* @package chamilo.forum
*/
require_once __DIR__.'/../inc/global.inc.php';
// The section (tabs).
@ -38,13 +41,24 @@ require_once 'forumfunction.inc.php';
// Are we in a lp ?
$origin = api_get_origin();
/* MAIN DISPLAY SECTION */
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$repo = Container::getForumRepository();
$forumEntity = null;
if (!empty($forumId)) {
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($forumId);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
$current_forum = get_forum_information($_GET['forum']);
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
$current_forum_category = $forumEntity->getForumCategory();
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => (int) $_GET['forum'],
'tool_id' => $forumId,
'tool_id_detail' => 0,
'action' => 'add-thread',
'action_details' => '',
@ -59,39 +73,41 @@ if (api_is_in_gradebook()) {
}
/* Is the user allowed here? */
// The user is not allowed here if:
// 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
if (!api_is_allowed_to_edit(false, true) && //is a student
(
($current_forum_category && false == $current_forum_category->isVisible($courseEntity, $sessionEntity)) ||
false == $current_forum_category->isVisible($courseEntity, $sessionEntity)
)
) {
api_not_allowed();
api_not_allowed(true);
}
// 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category['visibility'] && $current_forum_category['locked'] != 0) || $current_forum['locked'] != 0)
(($current_forum_category->isVisible($courseEntity, $sessionEntity) &&
$current_forum_category->getLocked() != 0) || $forumEntity->getLocked() != 0)
) {
api_not_allowed();
}
// 3. new threads are not allowed and the user is not a course manager
if (!api_is_allowed_to_edit(false, true) &&
$current_forum['allow_new_threads'] != 1
$forumEntity->getAllowNewThreads() != 1
) {
api_not_allowed();
}
// 4. anonymous posts are not allowed and the user is not logged in
if (!$_user['user_id'] && $current_forum['allow_anonymous'] != 1) {
if (!$_user['user_id'] && $forumEntity->getAllowAnonymous() != 1) {
api_not_allowed();
}
// 5. Check user access
if ($current_forum['forum_of_group'] != 0) {
if ($forumEntity->getForumOfGroup() != 0) {
$show_forum = GroupManager::user_has_access(
api_get_user_id(),
$current_forum['forum_of_group'],
$forumEntity->getForumOfGroup(),
GroupManager::GROUP_TOOL_FORUM
);
if (!$show_forum) {
@ -125,13 +141,15 @@ if (!empty($groupId)) {
];
} else {
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools];
if ($current_forum_category) {
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$current_forum_category->getIid(),
'name' => $current_forum_category->getCatTitle(),
];
}
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$current_forum_category['cat_id'],
'name' => $current_forum_category['cat_title'],
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']),
'name' => $current_forum['forum_title'],
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.$forumId,
'name' => $forumEntity->getForumTitle(),
];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Create thread')];
}
@ -141,7 +159,6 @@ $htmlHeadXtra[] = "
$(function() {
$('#reply-add-attachment').on('click', function(e) {
e.preventDefault();
var newInputFile = $('<input>', {
type: 'file',
name: 'user_upload[]'
@ -152,9 +169,8 @@ $htmlHeadXtra[] = "
</script>
";
$form = show_add_post_form(
$current_forum,
'newthread',
$form = newThread(
$forumEntity,
isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null
);
@ -173,7 +189,7 @@ echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.$cidreq.'">'.
echo '</div>';
// Set forum attachment data into $_SESSION
getAttachedFiles($current_forum['forum_id'], 0, 0);
getAttachedFiles($forumEntity->getIid(), 0, 0);
if ($form) {
$form->display();

@ -1,6 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumThread;
/**
* These files are a complete rework of the forum. The database structure is
* based on phpBB but all the code is rewritten. A lot of new functionalities
@ -14,9 +19,8 @@
* - sticky messages
* - new view option: nested view
* - quoting a message.
*
* @package chamilo.forum
*/
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
@ -32,7 +36,22 @@ require_once 'forumfunction.inc.php';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
/* MAIN DISPLAY SECTION */
$repo = Container::getForumRepository();
$forumEntity = null;
if (!empty($forumId)) {
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($forumId);
}
$repoThread = Container::getForumThreadRepository();
$threadEntity = null;
if (!empty($threadId)) {
/** @var CForumThread $threadEntity */
$threadEntity = $repoThread->find($threadId);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
/* Retrieving forum and forum categorie information */
// We are getting all the information about the current forum and forum category.
@ -42,7 +61,7 @@ $threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
$current_thread = get_thread_information($forumId, $threadId);
// Note: This has to be validated that it is an existing forum.
$current_forum = get_forum_information($current_thread['forum_id']);
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
$current_forum_category = $forumEntity->getForumCategory();
/* Is the user allowed here? */
// The user is not allowed here if
@ -52,24 +71,25 @@ $current_forum_category = get_forumcategory_information($current_forum['forum_ca
// The only exception is the course manager
// I have split this is several pieces for clarity.
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
(($current_forum_category && !$current_forum_category->isVisible($courseEntity, $sessionEntity)) ||
!$forumEntity->isVisible($courseEntity, $sessionEntity))
) {
api_not_allowed(true);
}
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['locked'] != 0) ||
$current_forum['locked'] != 0 || $current_thread['locked'] != 0)
(($current_forum_category && $current_forum_category->getLocked()!= 0) ||
$forumEntity->getLocked() != 0 || $threadEntity->getLocked() != 0)
) {
api_not_allowed(true);
}
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
if (!$_user['user_id'] && $forumEntity->getAllowAnonymous() == 0) {
api_not_allowed(true);
}
if ($current_forum['forum_of_group'] != 0) {
if ($forumEntity->getForumOfGroup() != 0) {
$show_forum = GroupManager::user_has_access(
api_get_user_id(),
$current_forum['forum_of_group'],
$forumEntity->getForumOfGroup() ,
GroupManager::GROUP_TOOL_FORUM
);
if (!$show_forum) {
@ -98,11 +118,11 @@ if (!empty($groupId)) {
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
'name' => $current_forum['forum_title'],
'name' => $forumEntity->getForumTitle(),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
'name' => $current_thread['thread_title'],
'name' => $threadEntity->getThreadTitle(),
];
$interbreadcrumb[] = [
@ -115,16 +135,16 @@ if (!empty($groupId)) {
'name' => $nameTools,
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(),
'name' => $current_forum_category['cat_title'],
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category->getIid().'&'.api_get_cidreq(),
'name' => $current_forum_category->getCatTitle(),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq(),
'name' => $current_forum['forum_title'],
'name' => $forumEntity->getForumTitle(),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&thread='.$threadId.'&'.api_get_cidreq(),
'name' => $current_thread['thread_title'],
'name' => $threadEntity->getThreadTitle(),
];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Reply')];
}
@ -162,7 +182,8 @@ $logInfo = [
Event::registerLog($logInfo);
$form = show_add_post_form(
$current_forum,
$forumEntity,
$threadEntity,
$my_action,
$my_elements
);
@ -173,7 +194,6 @@ if ($origin == 'learnpath') {
// The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
Display::display_header();
}
/* Action links */
if ($origin != 'learnpath') {
echo '<div class="actions">';
@ -191,12 +211,12 @@ if ($origin != 'learnpath') {
echo '<div class="forum_title">';
echo '<h1>';
echo Display::url(
prepare4display($current_forum['forum_title']),
'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $current_forum['forum_id']]),
['class' => empty($current_forum['visibility']) ? 'text-muted' : null]
prepare4display($forumEntity->getForumTitle()),
'viewforum.php?'.api_get_cidreq().'&'.http_build_query(['forum' => $forumId]),
['class' => empty($forumEntity->isVisible($courseEntity, $sessionEntity)) ? 'text-muted' : null]
);
echo '</h1>';
echo '<p class="forum_description">'.prepare4display($current_forum['forum_comment']).'</p>';
echo '<p class="forum_description">'.prepare4display($forumEntity->getForumComment()).'</p>';
echo '</div>';
if ($form) {
$form->display();

@ -1,6 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumPost;
/**
@ -20,21 +23,15 @@ use Chamilo\CourseBundle\Entity\CForumPost;
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @Copyright Ghent University
* @Copyright Patrick Cool
*
* @package chamilo.forum
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_FORUM;
// Notification for unauthorized people.
api_protect_course_script(true);
api_protect_course_group(GroupManager::GROUP_TOOL_FORUM);
// The section (tabs).
$this_section = SECTION_COURSES;
$nameTools = get_lang('Forums');
// Are we in a lp ?
$origin = api_get_origin();
require_once 'forumfunction.inc.php';
@ -46,13 +43,21 @@ $courseId = api_get_course_int_id();
$groupInfo = GroupManager::get_group_properties($groupId);
$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();
/* MAIN DISPLAY SECTION */
$my_forum = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$forumEntity = null;
if (!empty($my_forum)) {
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($my_forum);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
$my_forum = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
// Note: This has to be validated that it is an existing forum.
$current_forum = get_forum_information($my_forum);
$isForumOpenByDateAccess = api_is_date_in_date_range($current_forum['start_time'], $current_forum['end_time']);
$isForumOpenByDateAccess = api_is_date_in_date_range($forumEntity->getStartTime(), $forumEntity->getEndTime());
if (!$isForumOpenByDateAccess && !$isAllowedToEdit) {
if ($origin) {
@ -66,7 +71,7 @@ if (empty($current_forum)) {
api_not_allowed();
}
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
$current_forum_category = $forumEntity->getForumCategory();
$is_group_tutor = false;
if (!empty($groupId)) {
@ -80,18 +85,19 @@ if (!empty($groupId)) {
// Course
if (!api_is_allowed_to_edit(false, true) && //is a student
(
($current_forum_category && $current_forum_category['visibility'] == 0) ||
$current_forum['visibility'] == 0
($current_forum_category && false == $current_forum_category->isVisible($courseEntity, $sessionEntity)) ||
false == $current_forum_category->isVisible($courseEntity, $sessionEntity)
)
) {
api_not_allowed(true);
}
} else {
// Course
if (!api_is_allowed_to_edit(false, true) && (
($current_forum_category && $current_forum_category['visibility'] == 0) ||
$current_forum['visibility'] == 0
) //forum category or forum visibility is false
if (!api_is_allowed_to_edit(false, true) && //is a student
(
($current_forum_category && false == $current_forum_category->isVisible($courseEntity, $sessionEntity)) ||
false == $current_forum_category->isVisible($courseEntity, $sessionEntity)
)
) {
api_not_allowed(true);
}
@ -137,18 +143,19 @@ if (!empty($groupId)) {
'url' => $forumUrl.'index.php?search='.Security::remove_XSS($my_search),
'name' => get_lang('Forum Categories'),
];
$interbreadcrumb[] = [
'url' => $forumUrl.'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']
'url' => $forumUrl.'viewforumcategory.php?forumcategory='.$current_forum_category->getIid()
.'&search='.Security::remove_XSS(urlencode($my_search)),
'name' => prepare4display($current_forum_category['cat_title']),
'name' => prepare4display($current_forum_category->getCatTitle()),
];
$interbreadcrumb[] = [
'url' => '#',
'name' => Security::remove_XSS($current_forum['forum_title']),
'name' => Security::remove_XSS($forumEntity->getForumTitle()),
];
}
if ($origin == 'learnpath') {
if ('learnpath' == $origin) {
Display::display_reduced_header();
} else {
// The last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string.
@ -157,7 +164,7 @@ if ($origin == 'learnpath') {
/* Actions */
// Change visibility of a forum or a forum category.
if (($my_action == 'invisible' || $my_action == 'visible') &&
if (('invisible' == $my_action || 'visible' == $my_action) &&
isset($_GET['content']) &&
isset($_GET['id']) &&
$isAllowedToEdit
@ -165,20 +172,20 @@ if (($my_action == 'invisible' || $my_action == 'visible') &&
$message = change_visibility($_GET['content'], $_GET['id'], $_GET['action']);
}
// Locking and unlocking.
if (($my_action == 'lock' || $my_action == 'unlock') &&
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 ($my_action == 'delete' &&
if ('delete' == $my_action &&
isset($_GET['content']) &&
isset($_GET['id']) &&
$isAllowedToEdit
) {
$locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
if ($locked == false) {
if (false == $locked) {
$message = deleteForumCategoryThread($_GET['content'], $_GET['id']);
// Delete link
@ -189,19 +196,19 @@ if ($my_action == 'delete' &&
api_get_session_id()
);
$link_id = $link_info['id'];
if ($link_info !== false) {
if (false !== $link_info) {
GradebookUtils::remove_resource_from_course_gradebook($link_id);
}
}
}
// Moving.
if ($my_action == 'move' && isset($_GET['thread']) &&
if ('move' == $my_action && isset($_GET['thread']) &&
$isAllowedToEdit
) {
$message = move_thread_form();
}
// Notification.
if ($my_action == 'notify' &&
if ('notify' == $my_action &&
isset($_GET['content']) &&
isset($_GET['id']) &&
api_is_allowed_to_session_edit(false, true)
@ -211,7 +218,7 @@ if ($my_action == 'notify' &&
}
// Student list
if ($my_action == 'liststd' &&
if ('liststd' == $my_action &&
isset($_GET['content']) &&
isset($_GET['id']) &&
(api_is_allowed_to_edit(null, true) || $is_group_tutor)
@ -239,7 +246,7 @@ if ($my_action == 'liststd' &&
$table_list = Display::page_subheader(get_lang('Users list of the thread').': '.get_name_thread_by_id($_GET['id']));
if ($nrorow3 > 0 || $nrorow3 == -2) {
if ($nrorow3 > 0 || -2 == $nrorow3) {
$url = api_get_cidreq().'&forum='.$my_forum.'&action='
.Security::remove_XSS($_GET['action']).'&content='
.Security::remove_XSS($_GET['content'], STUDENT).'&id='.intval($_GET['id']);
@ -265,7 +272,7 @@ if ($my_action == 'liststd' &&
$table_list .= '<tr >';
$table_list .= '<th height="24">'.get_lang('First names and last names').'</th>';
if ($listType == 'qualify') {
if ('qualify' == $listType) {
$table_list .= '<th>'.get_lang('Score').'</th>';
}
if (api_is_allowed_to_edit(null, true)) {
@ -278,7 +285,7 @@ if ($my_action == 'liststd' &&
if (Database::num_rows($student_list) > 0) {
while ($row_student_list = Database::fetch_array($student_list)) {
$userInfo = api_get_user_info($row_student_list['id']);
if ($counter_stdlist % 2 == 0) {
if (0 == $counter_stdlist % 2) {
$class_stdlist = 'row_odd';
} else {
$class_stdlist = 'row_even';
@ -287,7 +294,7 @@ if ($my_action == 'liststd' &&
$table_list .= UserManager::getUserProfileLink($userInfo);
$table_list .= '</td>';
if ($listType == 'qualify') {
if ('qualify' == $listType) {
$table_list .= '<td>'.$row_student_list['qualify'].'/'.$max_qualify.'</td>';
}
if (api_is_allowed_to_edit(null, true)) {
@ -304,10 +311,10 @@ if ($my_action == 'liststd' &&
.$current_qualify_thread.'">'
.Display::return_icon($icon_qualify, get_lang('Grade activity')).'</a></td></tr>';
}
$counter_stdlist++;
++$counter_stdlist;
}
} else {
if ($listType === 'qualify') {
if ('qualify' === $listType) {
$table_list .= '<tr><td colspan="2">'.get_lang('There are no qualified learners').'</td></tr>';
} else {
$table_list .= '<tr><td colspan="2">'.get_lang('There are no unqualified learners').'</td></tr>';
@ -321,7 +328,7 @@ if ($my_action == 'liststd' &&
}
}
if ($origin == 'learnpath') {
if ('learnpath' == $origin) {
echo '<div style="height:15px">&nbsp;</div>';
}
@ -332,7 +339,7 @@ if (!empty($message)) {
/* Action links */
echo '<div class="actions">';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
if (!empty($groupId)) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq().'">'
.Display::return_icon('back.png', get_lang('Back to')
@ -350,10 +357,10 @@ if ($origin != 'learnpath') {
// 2. the course member is here and new threads are allowed
// 3. a visitor is here and new threads AND allowed AND anonymous posts are allowed
if (api_is_allowed_to_edit(false, true) ||
($current_forum['allow_new_threads'] == 1 && isset($_user['user_id'])) ||
($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
(1 == $current_forum['allow_new_threads'] && isset($_user['user_id'])) ||
(1 == $current_forum['allow_new_threads'] && !isset($_user['user_id']) && 1 == $current_forum['allow_anonymous'])
) {
if ($current_forum['locked'] != 1 && $current_forum['locked'] != 1) {
if (1 != $forumEntity->getLocked() && 1 != $forumEntity->getLocked()) {
if (!api_is_anonymous() && !api_is_invitee()) {
if ($my_forum == strval(intval($my_forum))) {
echo '<a href="'.$forumUrl.'newthread.php?'.api_get_cidreq().'&forum='
@ -374,9 +381,7 @@ if (api_is_allowed_to_edit(false, true) ||
}
echo '</div>';
/* Display */
$titleForum = $current_forum['forum_title'];
$descriptionForum = $current_forum['forum_comment'];
$descriptionForum = $forumEntity->getForumComment();
$iconForum = Display::return_icon(
'forum_yellow.png',
get_lang('Forum'),
@ -386,10 +391,10 @@ $iconForum = Display::return_icon(
$html = '';
$html .= '<div class="topic-forum">';
// The current forum
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
$html .= Display::tag(
'h3',
$iconForum.' '.$titleForum,
$iconForum.' '.$forumEntity->getForumTitle(),
[
'class' => 'title-forum', ]
);
@ -410,37 +415,36 @@ echo $html;
// Getting al the threads
$threads = get_threads($my_forum);
$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
//$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
$course_id = api_get_course_int_id();
echo '<div class="forum_display">';
if (is_array($threads)) {
$html = '';
$count = 1;
foreach ($threads as $row) {
foreach ($threads as $thread) {
$threadId = $thread->getIid();
// Thread who have no replies yet and the only post is invisible should not be displayed to students.
if (api_is_allowed_to_edit(false, true) ||
!($row['thread_replies'] == '0' && $row['visibility'] == '0')
!('0' == $thread->getThreadReplies() && '0' == $thread->isVisible($courseEntity, $sessionEntity))
) {
$my_whatsnew_post_info = null;
if (isset($whatsnew_post_info[$my_forum][$row['thread_id']])) {
$my_whatsnew_post_info = $whatsnew_post_info[$my_forum][$row['thread_id']];
/*$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']];
}
$newPost = '';
if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
$newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
}
}*/
$name = api_get_person_name($row['firstname'], $row['lastname']);
//$name = api_get_person_name($thread['firstname'], $thread['lastname']);
$linkPostForum = '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$my_forum
."&thread={$row['thread_id']}&search="
."&thread={$threadId}&search="
.Security::remove_XSS(urlencode($my_search)).'">'
.$row['thread_title'].'</a>';
.$thread->getThreadTitle().'</a>';
$html = '';
$html .= '<div class="panel panel-default forum '.($row['thread_sticky'] ? 'sticky' : '').'">';
$html .= '<div class="panel panel-default forum '.($thread->getThreadSticky() ? 'sticky' : '').'">';
$html .= '<div class="panel-body">';
$html .= '<div class="row">';
$html .= '<div class="col-md-6">';
@ -448,36 +452,32 @@ if (is_array($threads)) {
$html .= '<div class="col-md-2">';
// display the author name
$tab_poster_info = api_get_user_info($row['user_id']);
$tab_poster_info = api_get_user_info($thread->getThreadPosterId());
$poster_username = sprintf(get_lang('Login: %s'), $tab_poster_info['username']);
$authorName = '';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
$authorName = display_user_link(
$row['user_id'],
api_get_person_name($row['firstname'], $row['lastname']),
$thread->getThreadPosterId(),
$tab_poster_info['complete_name'],
'',
$poster_username
);
} else {
$authorName = Display::tag(
'span',
api_get_person_name(
$row['firstname'],
$row['lastname']
),
$tab_poster_info['complete_name'],
[
'title' => api_htmlentities($poster_username, ENT_QUOTES),
]
);
}
$_user = api_get_user_info($row['user_id']);
$iconStatus = $_user['icon_status'];
$iconStatus = $tab_poster_info['icon_status'];
$last_post_info = get_last_post_by_thread(
$row['c_id'],
$row['thread_id'],
$row['forum_id'],
$thread->getCId(),
$threadId,
$thread->getForum()->getIid(),
api_is_allowed_to_edit()
);
$last_post = null;
@ -492,7 +492,7 @@ if (is_array($threads)) {
);
}
$html .= '<div class="thumbnail">'.display_user_image($row['user_id'], $name, $origin).'</div>';
$html .= '<div class="thumbnail">'.display_user_image($thread->getThreadPosterId(), $poster_username, $origin).'</div>';
$html .= '</div>';
$html .= '<div class="col-md-10">';
$html .= Display::tag(
@ -508,13 +508,13 @@ if (is_array($threads)) {
$html .= '<p>'.Security::remove_XSS(cut($last_post_info['post_text'], 140)).'</p>';
}
$html .= '<p>'.Display::dateToStringAgoAndLongDate($row['insert_date']).'</p>';
$html .= '<p>'.Display::dateToStringAgoAndLongDate($thread->getThreadDate()).'</p>';
if ($current_forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) {
if (1 == $forumEntity->isModerated() && api_is_allowed_to_edit(false, true)) {
$waitingCount = getCountPostsWithStatus(
CForumPost::STATUS_WAITING_MODERATION,
$current_forum,
$row['thread_id']
$thread['thread_id']
);
if (!empty($waitingCount)) {
$html .= Display::label(
@ -533,19 +533,19 @@ if (is_array($threads)) {
$html .= '<div class="row">';
$html .= '<div class="col-md-4">'
.Display::return_icon('post-forum.png', null, null, ICON_SIZE_SMALL)
." {$row['thread_replies']} ".get_lang('Replies').'<br>';
." {$thread->getThreadReplies()} ".get_lang('Replies').'<br>';
$html .= Display::return_icon(
'post-forum.png',
null,
null,
ICON_SIZE_SMALL
).' '.$row['thread_views'].' '.get_lang('Views').'<br>'.$newPost;
).' '.$thread->getThreadReplies().' '.get_lang('Views').'<br>';
$html .= '</div>';
$last_post_info = get_last_post_by_thread(
$row['c_id'],
$row['thread_id'],
$row['forum_id'],
$thread->getCId(),
$threadId,
$thread->getForum()->getIid(),
api_is_allowed_to_edit()
);
$last_post = null;
@ -569,21 +569,21 @@ if (is_array($threads)) {
$cidreq = api_get_cidreq();
// Get attachment id.
if (isset($row['post_id'])) {
$attachment_list = get_attachment($row['post_id']);
}
/*if (isset($thread['post_id'])) {
$attachment_list = get_attachment($thread['post_id']);
}*/
$id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
$iconsEdit = '';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
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='
.intval($row['thread_id'])
.$thread->getIid()
.'&id_attach='.$id_attach.'">'
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
if (api_resource_is_locked_by_gradebook($row['thread_id'], LINK_FORUM_THREAD)) {
if (api_resource_is_locked_by_gradebook($thread->getIid(), LINK_FORUM_THREAD)) {
$iconsEdit .= Display::return_icon(
'delete_na.png',
get_lang('This option is not available because this activity is contained by an assessment, which is currently locked. To unlock the assessment, ask your platform administrator.'),
@ -593,7 +593,7 @@ if (is_array($threads)) {
} else {
$iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
.$my_forum.'&action=delete&content=thread&id='
.$row['thread_id']."\" onclick=\"javascript:if(!confirm('"
.$thread->getIid()."\" onclick=\"javascript:if(!confirm('"
.addslashes(api_htmlentities(get_lang('Delete complete thread?'), ENT_QUOTES))
."')) return false;\">"
.Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL).'</a>';
@ -601,8 +601,8 @@ if (is_array($threads)) {
$iconsEdit .= return_visible_invisible_icon(
'thread',
$row['thread_id'],
$row['visibility'],
$thread->getIid(),
$thread->isVisible($courseEntity, $sessionEntity),
[
'forum' => $my_forum,
'gid' => $groupId,
@ -610,8 +610,8 @@ if (is_array($threads)) {
);
$iconsEdit .= return_lock_unlock_icon(
'thread',
$row['thread_id'],
$row['locked'],
$thread->getIid(),
$thread->getLocked(),
[
'forum' => $my_forum,
'gid' => api_get_group_id(),
@ -619,7 +619,7 @@ if (is_array($threads)) {
);
$iconsEdit .= '<a href="viewforum.php?'.$cidreq.'&forum='
.$my_forum
.'&action=move&thread='.$row['thread_id'].'">'
.'&action=move&thread='.$threadId.'">'
.Display::return_icon('move.png', get_lang('Move Thread'), [], ICON_SIZE_SMALL)
.'</a>';
}
@ -629,7 +629,7 @@ if (is_array($threads)) {
isset($_SESSION['forum_notification']['thread']) ? $_SESSION['forum_notification']['thread'] : null
)
) {
if (in_array($row['thread_id'], $_SESSION['forum_notification']['thread'])) {
if (in_array($threadId, $_SESSION['forum_notification']['thread'])) {
$iconnotify = 'notification_mail.png';
}
}
@ -637,14 +637,14 @@ if (is_array($threads)) {
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={$row['thread_id']}"
."&action=notify&content=thread&id={$threadId}"
.'">'.Display::return_icon($iconnotify, get_lang('Notify me')).'</a>';
}
if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
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={$row['thread_id']}"
."&action=liststd&content=thread&id={$threadId}"
.'">'.Display::return_icon($icon_liststd, get_lang('Learners list'), [], ICON_SIZE_SMALL)
.'</a>';
}
@ -666,6 +666,6 @@ if (is_array($threads)) {
echo '</div>';
echo isset($table_list) ? $table_list : '';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
Display::display_footer();
}

@ -1,23 +1,20 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumPost;
use Chamilo\CourseBundle\Entity\CForumThread;
/**
* @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
*
* @package chamilo.forum
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_FORUM;
$this_section = SECTION_COURSES;
// Notification for unauthorized people.
api_protect_course_script(true);
require_once 'forumfunction.inc.php';
$nameTools = get_lang('Forum');
$forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
@ -29,9 +26,25 @@ $my_search = null;
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
$repo = Container::getForumRepository();
$forumEntity = null;
if (!empty($forumId)) {
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($forumId);
}
$repoThread = Container::getForumThreadRepository();
$threadEntity = null;
if (!empty($threadId)) {
/** @var CForumThread $threadEntity */
$threadEntity = $repoThread->find($threadId);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
/* MAIN DISPLAY SECTION */
/* Retrieving forum and forum category information */
// We are getting all the information about the current forum and forum category.
// Note pcool: I tried to use only one sql statement (and function) for this,
// but the problem is that the visibility of the forum AND forum category are stored in the item_property table.
@ -39,7 +52,7 @@ $threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
$current_thread = get_thread_information($forumId, $threadId);
// Note: This has to be validated that it is an existing forum.
$current_forum = get_forum_information($current_thread['forum_id']);
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
$current_forum_category = $forumEntity->getForumCategory();
$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
if (api_is_in_gradebook()) {
@ -59,17 +72,17 @@ $(function() {
$("span").on("click", ".change_post_status", function() {
var updateDiv = $(this).parent();
var postId = updateDiv.attr("id");
$.ajax({
url: "'.$ajaxURL.'&post_id="+postId,
type: "GET",
success: function(data) {
updateDiv.html(data);
}
}
});
});
});
});
</script>';
/* Actions */
@ -150,15 +163,15 @@ if (!empty($groupId)) {
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq()."&search=".Security::remove_XSS(urlencode($my_search)),
'name' => Security::remove_XSS($current_forum['forum_title']),
'name' => Security::remove_XSS($forumEntity->getForumTitle()),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.$forumId.'&'.api_get_cidreq().'&thread='.$threadId,
'name' => Security::remove_XSS($current_thread['thread_title']),
'name' => Security::remove_XSS($threadEntity->getThreadTitle()),
];
} else {
$my_search = isset($_GET['search']) ? $_GET['search'] : '';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(
urlencode($my_search)
@ -168,14 +181,14 @@ if (!empty($groupId)) {
$interbreadcrumb[] = [
'url' => api_get_path(
WEB_CODE_PATH
).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']."&search=".Security::remove_XSS(
).'forum/viewforumcategory.php?forumcategory='.$current_forum_category->getIid()."&search=".Security::remove_XSS(
urlencode($my_search)
),
'name' => Security::remove_XSS($current_forum_category['cat_title']),
'name' => Security::remove_XSS($current_forum_category->getCatTitle()),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId."&search=".Security::remove_XSS(urlencode($my_search)),
'name' => Security::remove_XSS($current_forum['forum_title']),
'name' => Security::remove_XSS($forumEntity->getForumTitle()),
];
$interbreadcrumb[] = [
'url' => '#',
@ -187,21 +200,21 @@ if (!empty($groupId)) {
// If the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false, true) &&
($current_forum['visibility'] == 0 || $current_thread['visibility'] == 0)
(0 == $current_forum['visibility'] || 0 == $current_thread['visibility'])
) {
api_not_allowed();
}
// this increases the number of times the thread has been viewed
increase_thread_view($threadId);
if ($origin == 'learnpath') {
if ('learnpath' == $origin) {
$template = new Template('', false, false, true, true, false);
} else {
$template = new Template();
}
$actions = '<span style="float:right;">'.search_link().'</span>';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
$actions .= '<a href="'.$forumUrl.'viewforum.php?forum='.$forumId.'&'.api_get_cidreq().'">'
.Display::return_icon('back.png', get_lang('Back to forum'), '', ICON_SIZE_MEDIUM).'</a>';
}
@ -210,13 +223,13 @@ if ($origin != 'learnpath') {
// not locked AND the forum is not locked AND the thread is not locked.
// If one of the three levels is locked then the link should not be displayed.
if (($current_forum_category &&
$current_forum_category['locked'] == 0) &&
$current_forum['locked'] == 0 &&
$current_thread['locked'] == 0 ||
0 == $current_forum_category->getLocked()) &&
0 == $forumEntity->getLocked() &&
0 == $threadEntity->getLocked() ||
api_is_allowed_to_edit(false, true)
) {
// The link should only appear when the user is logged in or when anonymous posts are allowed.
if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
if ($_user['user_id'] || (1 == $forumEntity->getAllowAnonymous() && !$_user['user_id'])) {
// reply link
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
$actions .= '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='
@ -228,10 +241,10 @@ if (($current_forum_category &&
if ((
api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)) ||
($current_forum['allow_new_threads'] == 1 && isset($_user['user_id'])) ||
($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
(1 == $forumEntity->getAllowNewThreads() && isset($_user['user_id'])) ||
(1 == $forumEntity->getAllowNewThreads() && !isset($_user['user_id']) && 1 == $forumEntity->getAllowAnonymous())
) {
if ($current_forum['locked'] != 1 && $current_forum['locked'] != 1) {
if (1 != $forumEntity->getLocked() && 1 != $forumEntity->getLocked()) {
$actions .= '&nbsp;&nbsp;';
} else {
$actions .= get_lang('Forum blocked');
@ -245,7 +258,7 @@ $template->assign('origin', api_get_origin());
/* Display Forum Category and the Forum information */
if (!isset($_SESSION['view'])) {
$viewMode = $current_forum['default_view'];
$viewMode = $forumEntity->getDefaultView();
} else {
$viewMode = $_SESSION['view'];
}
@ -260,7 +273,7 @@ if (empty($viewMode)) {
$viewMode = 'flat';
}
if ($current_thread['thread_peer_qualify'] == 1) {
if (1 == $current_thread['thread_peer_qualify']) {
Display::addFlash(Display::return_message(get_lang('To get the expected score in this forum, your contribution will have to be scored by another student, and you will have to score at least 2 other student\'s contributions. Until you reach this objective, even if scored, your contribution will show as a 0 score in the global grades for this course.'), 'info'));
}
@ -270,7 +283,7 @@ $allowReport = reportAvailable();
$origin = api_get_origin();
//delete attachment file
if (isset($_GET['action']) &&
$_GET['action'] == 'delete_attach' &&
'delete_attach' == $_GET['action'] &&
isset($_GET['id_attach'])
) {
delete_attachment(0, $_GET['id_attach']);
@ -283,8 +296,8 @@ $userId = api_get_user_id();
$groupId = api_get_group_id();
// Decide whether we show the latest post first
$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC');
$posts = getPosts($current_forum, $threadId, $sortDirection, true);
$sortDirection = isset($_GET['posts_order']) && 'desc' === $_GET['posts_order'] ? 'DESC' : ('learnpath' != $origin ? 'ASC' : 'DESC');
$posts = getPosts($forumEntity, $threadId, $sortDirection, true);
$count = 0;
$group_id = api_get_group_id();
$locked = api_resource_is_locked_by_gradebook($threadId, LINK_FORUM_THREAD);
@ -314,7 +327,7 @@ foreach ($posts as $post) {
}
$post['user_data'] = '';
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
if ($allowUserImageForum) {
$post['user_data'] = '<div class="thumbnail">'.
display_user_image($posterId, $name, $origin).'</div>';
@ -345,7 +358,7 @@ foreach ($posts as $post) {
);
}
if ($origin != 'learnpath') {
if ('learnpath' != $origin) {
$post['user_data'] .= Display::tag(
'p',
Display::dateToStringAgoAndLongDate($post['post_date']),
@ -368,11 +381,11 @@ foreach ($posts as $post) {
$askForRevision = '';
if ((isset($groupInfo['iid']) && $tutorGroup) ||
($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
(1 == $forumEntity->getAllowEdit() && $posterId == $userId) ||
(api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
!(api_is_session_general_coach() && $forumEntity->getSessionId() != $sessionId))
) {
if ($locked == false && postIsEditableByStudent($current_forum, $post)) {
if (false == $locked && postIsEditableByStudent($current_forum, $post)) {
$editUrl = api_get_path(WEB_CODE_PATH).'forum/editpost.php?'.api_get_cidreq();
$editUrl .= "&forum=$forumId&thread=$threadId&post={$post['post_id']}&id_attach=$id_attach";
$iconEdit .= "<a href='".$editUrl."'>"
@ -392,7 +405,7 @@ foreach ($posts as $post) {
api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
) {
if ($locked == false) {
if (false == $locked) {
$deleteUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query(
[
'forum' => $forumId,
@ -438,7 +451,7 @@ foreach ($posts as $post) {
}
}
$userCanQualify = $currentThread['thread_peer_qualify'] == 1 && $post['poster_id'] != $userId;
$userCanQualify = 1 == $currentThread['thread_peer_qualify'] && $post['poster_id'] != $userId;
if (api_is_allowed_to_edit(null, true)) {
$userCanQualify = true;
}
@ -490,7 +503,7 @@ foreach ($posts as $post) {
$posterId,
$threadId
);
if ($locked == false) {
if (false == $locked) {
$iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()
."&forum=$forumId&thread=$threadId&action=list&post={$post['post_id']}"
."&user={$post['user_id']}&user_id={$post['user_id']}"
@ -505,7 +518,7 @@ foreach ($posts as $post) {
$reportButton = getReportButton($post['post_id'], $current_thread);
}
$statusIcon = getPostStatus($current_forum, $post);
$statusIcon = getPostStatus($forumEntity, $post);
if (!empty($iconEdit)) {
$post['user_data'] .= "<div class='tools-icons'> $iconEdit $statusIcon </div>";
} else {
@ -518,10 +531,10 @@ foreach ($posts as $post) {
$buttonQuote = '';
$waitingValidation = '';
if (($current_forum_category && $current_forum_category['locked'] == 0) &&
$current_forum['locked'] == 0 && $current_thread['locked'] == 0 || api_is_allowed_to_edit(false, true)
if (($current_forum_category && 0 == $current_forum_category->getLocked()) &&
0 == $forumEntity->getLocked() && 0 == $threadEntity->getLocked() || api_is_allowed_to_edit(false, true)
) {
if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
if ($userId || (1 == $forumEntity->getAllowAnonymous() && !$userId)) {
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
$buttonReply = Display::toolbarButton(
get_lang('Reply to this message'),
@ -549,8 +562,8 @@ foreach ($posts as $post) {
['id' => "quote-post-{$post['post_id']}"]
);
if ($current_forum['moderated'] && !api_is_allowed_to_edit(false, true)) {
if (empty($post['status']) || $post['status'] == CForumPost::STATUS_WAITING_MODERATION) {
if ($forumEntity->isModerated() && !api_is_allowed_to_edit(false, true)) {
if (empty($post['status']) || CForumPost::STATUS_WAITING_MODERATION == $post['status']) {
$buttonReply = '';
$buttonQuote = '';
}
@ -559,21 +572,21 @@ foreach ($posts as $post) {
}
} else {
$closedPost = '';
if ($current_forum_category && $current_forum_category['locked'] == 1) {
if ($current_forum_category && 1 == $current_forum_category->getLocked()) {
$closedPost = Display::tag(
'div',
'<em class="fa fa-exclamation-triangle"></em> '.get_lang('Forum category Locked'),
['class' => 'alert alert-warning post-closed']
);
}
if ($current_forum['locked'] == 1) {
if (1 == $forumEntity->getLocked()) {
$closedPost = Display::tag(
'div',
'<em class="fa fa-exclamation-triangle"></em> '.get_lang('Forum blocked'),
['class' => 'alert alert-warning post-closed']
);
}
if ($current_thread['locked'] == 1) {
if (1 == $threadEntity->getLocked()) {
$closedPost = Display::tag(
'div',
'<em class="fa fa-exclamation-triangle"></em> '.get_lang('Thread is locked.'),
@ -585,8 +598,8 @@ foreach ($posts as $post) {
}
// note: this can be removed here because it will be displayed in the tree
if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
!empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
/*if (isset($whatsnew_post_info[$forumId][$threadId][$post['post_id']]) &&
!empty($whatsnew_post_info[$forumId][$threadId][$post['post_id']]) &&
!empty($whatsnew_post_info[$forumId][$post['thread_id']])
) {
$post_image = Display::return_icon('forumpostnew.gif');
@ -594,12 +607,12 @@ foreach ($posts as $post) {
$post_image = Display::return_icon('forumpost.gif');
}
if ($post['post_notification'] == '1' && $post['poster_id'] == $userId) {
if ('1' == $post['post_notification'] && $post['poster_id'] == $userId) {
$post_image .= Display::return_icon(
'forumnotification.gif',
get_lang('You will be notified')
);
}
}*/
$post['current'] = false;
if (isset($_GET['post_id']) && $_GET['post_id'] == $post['post_id']) {
@ -636,7 +649,7 @@ foreach ($posts as $post) {
$post['post_attachments'] .= $attachment['path'];
$post['post_attachments'] .= ' "> '.$user_filename.' </a>';
$post['post_attachments'] .= '<span class="forum_attach_comment" >'.$attachment['comment'].'</span>';
if (($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
if ((1 == $current_forum['allow_edit'] && $post['user_id'] == $userId) ||
(api_is_allowed_to_edit(false, true) && !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
) {
$post['post_attachments'] .= '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
@ -652,8 +665,8 @@ foreach ($posts as $post) {
$postList[] = $post;
// The post has been displayed => it can be removed from the what's new array
unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
//unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
//unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
$count++;
}
@ -662,28 +675,28 @@ $template->assign('posts', $postList);
$formToString = '';
$showForm = true;
if (!api_is_allowed_to_edit(false, true) &&
(($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0)
(($current_forum_category && 0 == $current_forum_category['visibility']) || 0 == $current_forum['visibility'])
) {
$showForm = false;
}
if (!api_is_allowed_to_edit(false, true) &&
(
($current_forum_category && $current_forum_category['locked'] != 0) ||
$current_forum['locked'] != 0 || $current_thread['locked'] != 0
($current_forum_category && 0 != $current_forum_category->getLocked()) ||
0 != $forumEntity->getLocked() || 0 != $threadEntity->getLocked()
)
) {
$showForm = false;
}
if (!$_user['user_id'] && $current_forum['allow_anonymous'] == 0) {
if (!$_user['user_id'] && 0 == $forumEntity->getAllowAnonymous()) {
$showForm = false;
}
if ($current_forum['forum_of_group'] != 0) {
if (0 != $forumEntity->getForumOfGroup()) {
$show_forum = GroupManager::user_has_access(
api_get_user_id(),
$current_forum['forum_of_group'],
$forumEntity->getForumOfGroup(),
GroupManager::GROUP_TOOL_FORUM
);
if (!$show_forum) {
@ -693,8 +706,8 @@ if ($current_forum['forum_of_group'] != 0) {
if ($showForm) {
$form = show_add_post_form(
$current_forum,
'replythread',
$forumEntity,
$threadEntity,
null,
false
);

@ -10370,19 +10370,20 @@ class learnpath
$a_threads = get_threads($forumId);
if (is_array($a_threads)) {
foreach ($a_threads as $thread) {
$threadId = $thread->getIid();
$link = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum['forum_id'].'&thread='.$thread['thread_id'],
api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId,
['target' => '_blank']
);
$return .= '<li class="lp_resource_element" data_id="'.$thread['thread_id'].'" data_type="'.TOOL_THREAD.'" title="'.$thread['thread_title'].'" >';
$return .= '<li class="lp_resource_element" data_id="'.$thread->getIid().'" data_type="'.TOOL_THREAD.'" title="'.$thread->getThreadTitle().'" >';
$return .= '&nbsp;<a class="moved" href="#">';
$return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
$return .= ' </a>';
$return .= Display::return_icon('forumthread.png', get_lang('Thread'), [], ICON_SIZE_TINY);
$return .= '<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_THREAD.'&thread_id='.$thread['thread_id'].'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($thread['thread_title']).' '.$link.'</a>';
$return .= '<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_THREAD.'&thread_id='.$threadId.'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($thread->getThreadTitle()).' '.$link.'</a>';
$return .= '</li>';
}
}

@ -19,7 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="session_id", columns={"session_id"})
* }
* )
* @ORM\Entity()
* @ORM\Entity
*/
class CForumCategory extends AbstractResource implements ResourceInterface
{

@ -18,7 +18,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="course", columns={"c_id"})
* }
* )
* @ORM\Entity()
* @ORM\Entity
*/
class CForumForum extends AbstractResource implements ResourceInterface
{

@ -22,7 +22,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="c_id_visible_post_date", columns={"c_id", "visible", "post_date"})
* }
* )
* @ORM\Entity()
* @ORM\Entity
*/
class CForumPost extends AbstractResource implements ResourceInterface
{
@ -133,6 +133,7 @@ class CForumPost extends AbstractResource implements ResourceInterface
public function __construct()
{
$this->postId = 0;
}
public function __toString(): string

@ -19,7 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="idx_forum_thread_forum_id", columns={"forum_id"})
* }
* )
* @ORM\Entity()
* @ORM\Entity
*/
class CForumThread extends AbstractResource implements ResourceInterface
{
@ -178,14 +178,13 @@ class CForumThread extends AbstractResource implements ResourceInterface
*/
protected $itemProperty;
/**
* Constructor.
*/
public function __construct()
{
$this->threadPeerQualify = false;
$this->threadReplies = 0;
$this->threadViews = 0;
$this->locked = 0;
$this->threadId = 0;
}
public function __toString(): string

Loading…
Cancel
Save