';
// 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 .= '
'.display_user_image($row['user_id'], $name, $origin).'
';
+ $html .= '
'.display_user_image($thread->getThreadPosterId(), $poster_username, $origin).'
';
$html .= '
';
$html .= Display::tag(
@@ -508,13 +508,13 @@ if (is_array($threads)) {
$html .= '
'.Security::remove_XSS(cut($last_post_info['post_text'], 140)).'
';
}
- $html .= '
'.Display::dateToStringAgoAndLongDate($row['insert_date']).'
';
+ $html .= '
'.Display::dateToStringAgoAndLongDate($thread->getThreadDate()).'
';
- 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 .= '
';
$html .= '
'
.Display::return_icon('post-forum.png', null, null, ICON_SIZE_SMALL)
- ." {$row['thread_replies']} ".get_lang('Replies').'
';
+ ." {$thread->getThreadReplies()} ".get_lang('Replies').'
';
$html .= Display::return_icon(
'post-forum.png',
null,
null,
ICON_SIZE_SMALL
- ).' '.$row['thread_views'].' '.get_lang('Views').'
'.$newPost;
+ ).' '.$thread->getThreadReplies().' '.get_lang('Views').'
';
$html .= '
';
$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 .= '
'
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'';
- 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 .= '
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).'';
@@ -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 .= '
'
+ .'&action=move&thread='.$threadId.'">'
.Display::return_icon('move.png', get_lang('Move Thread'), [], ICON_SIZE_SMALL)
.'';
}
@@ -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 .= '
'.Display::return_icon($iconnotify, get_lang('Notify me')).'';
}
- if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
+ if (api_is_allowed_to_edit(null, true) && 'learnpath' != $origin) {
$iconsEdit .= '
'.Display::return_icon($icon_liststd, get_lang('Learners list'), [], ICON_SIZE_SMALL)
.'';
}
@@ -666,6 +666,6 @@ if (is_array($threads)) {
echo '
';
echo isset($table_list) ? $table_list : '';
-if ($origin != 'learnpath') {
+if ('learnpath' != $origin) {
Display::display_footer();
}
diff --git a/public/main/forum/viewthread.php b/public/main/forum/viewthread.php
index 528bee9570..7eee99dbd9 100644
--- a/public/main/forum/viewthread.php
+++ b/public/main/forum/viewthread.php
@@ -1,23 +1,20 @@
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);
- }
+ }
});
- });
+ });
});
-
+
';
/* 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 = '
'.search_link().'';
-if ($origin != 'learnpath') {
+if ('learnpath' != $origin) {
$actions .= '
'
.Display::return_icon('back.png', get_lang('Back to forum'), '', ICON_SIZE_MEDIUM).'';
}
@@ -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 .= '
'.
display_user_image($posterId, $name, $origin).'';
@@ -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 .= "
';
$post['post_attachments'] .= '';
- 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'] .= '