diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php index 08622c494e..804a80dbc6 100644 --- a/public/main/forum/forumfunction.inc.php +++ b/public/main/forum/forumfunction.inc.php @@ -654,7 +654,6 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true) $values['item_id'] = $values['forum_category_id']; } else { - $category = new CForumCategory(); $category ->setCatTitle($clean_cat_title) @@ -839,6 +838,7 @@ function store_forum($values, $courseInfo = [], $returnId = false) $session = api_get_session_entity($session_id); if (isset($values['forum_id'])) { + // Edit $repo->getEntityManager()->persist($forum); $repo->getEntityManager()->flush(); @@ -2094,10 +2094,11 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ * @param int|null $courseId Optional If is null then it is considered the current course * @param int|null $sessionId Optional. If is null then it is considered the current session * + * @return CForumThread[] */ function get_threads($forum_id, $courseId = null, $sessionId = null) { - $repo = Container::getForumRepository(); + $repo = Container::getForumThreadRepository(); $courseId = empty($courseId) ? api_get_course_int_id() : $courseId; $course = api_get_course_entity($courseId); $session = api_get_session_entity($sessionId); @@ -2232,7 +2233,7 @@ function getThreadInfo($threadId, $cId) /** * Retrieve all posts of a given thread. * - * @param array $forumInfo + * @param CForumForum $forum * @param int $threadId The thread ID * @param string $orderDirection Optional. The direction for sort the posts * @param bool $recursive Optional. If the list is recursive @@ -2244,7 +2245,7 @@ function getThreadInfo($threadId, $cId) * @return array containing all the information about the posts of a given thread */ function getPosts( - $forumInfo, + CForumForum $forum, $threadId, $orderDirection = 'ASC', $recursive = false, @@ -2262,7 +2263,7 @@ function getPosts( $criteria = Criteria::create(); $criteria ->where(Criteria::expr()->eq('thread', $threadId)) - ->andWhere(Criteria::expr()->eq('cId', $forumInfo['c_id'])) + ->andWhere(Criteria::expr()->eq('cId', $forum->getCId())) ->andWhere($visibleCriteria) ; @@ -2291,7 +2292,7 @@ function getPosts( ->addCriteria($criteria) ->addOrderBy('p.postId', $orderDirection); - if ($filterModerated && $forumInfo['moderated'] == 1) { + if ($filterModerated && $forum->isModerated() == 1) { if (!api_is_allowed_to_edit(false, true)) { $userId = api_get_user_id(); $qb->andWhere( @@ -2349,7 +2350,7 @@ function getPosts( $list = array_merge( $list, getPosts( - $forumInfo, + $forum, $threadId, $orderDirection, $recursive, @@ -2873,7 +2874,7 @@ function updateThread($values) * @version february 2006, dokeos 1.8 */ function store_thread( - $current_forum, + CForumForum $forum, $values, $courseInfo = [], $showMessage = true, @@ -2888,11 +2889,9 @@ function store_thread( $groupInfo = GroupManager::get_group_properties($groupId); $sessionId = $sessionId ?: api_get_session_id(); - $em = Database::getManager(); $table_threads = Database::get_course_table(TABLE_FORUM_THREAD); $upload_ok = 1; $has_attachment = false; - if (!empty($_FILES['user_upload']['name'])) { $upload_ok = process_uploaded_file($_FILES['user_upload']); $has_attachment = true; @@ -2914,16 +2913,14 @@ function store_thread( $post_date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); $visible = 1; - if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) { + if ($forum->getApprovalDirectPost() == '1' && !api_is_allowed_to_edit(null, true)) { $visible = 0; // The post has not been approved yet. } $clean_post_title = $values['post_title']; - $forum = $em->find('ChamiloCourseBundle:CForumForum', $values['forum_id']); - // We first store an entry in the forum_thread table because the thread_id is used in the forum_post table. - $lastThread = new CForumThread(); - $lastThread + $thread = new CForumThread(); + $thread ->setCId($course_id) ->setThreadTitle($clean_post_title) ->setForum($forum) @@ -2934,16 +2931,27 @@ function store_thread( ->setThreadTitleQualify( isset($values['calification_notebook_title']) ? $values['calification_notebook_title'] : null ) - ->setThreadQualifyMax(isset($values['numeric_calification']) ? (int) $values['numeric_calification'] : 0) + ->setThreadQualifyMax(isset($values['numeric_calification']) ? (int)$values['numeric_calification'] : 0) ->setThreadWeight(isset($values['weight_calification']) ? (int) $values['weight_calification'] : 0) ->setThreadPeerQualify(isset($values['thread_peer_qualify']) ? (bool) $values['thread_peer_qualify'] : false) ->setSessionId($sessionId) ->setLpItemId(isset($values['lp_item_id']) ? (int) $values['lp_item_id'] : 0) - ->setThreadId(0) - ->setLocked(0) ; + $user = api_get_user_entity(api_get_user_id()); + $course = api_get_course_entity($course_id); + $session = api_get_session_entity($sessionId); - $em->persist($lastThread); + $repo = Container::getForumThreadRepository(); + $em = $repo->getEntityManager(); + //$em->persist($thread); + $resourceNode = $repo->createNodeForResource($thread, $user, $forum->getResourceNode()); + $repo->addResourceNodeToCourse( + $resourceNode, + ResourceLink::VISIBILITY_PUBLISHED, + $course, + $session, + null + ); $em->flush(); // Add option gradebook qualify. @@ -2956,7 +2964,7 @@ function store_thread( $values['category_id'], $courseCode, 5, - $lastThread->getIid(), + $thread->getIid(), $resourcename, $values['weight_calification'], $values['numeric_calification'], @@ -2966,16 +2974,15 @@ function store_thread( ); } - if ($lastThread->getIid()) { - $lastThread->setThreadId($lastThread->getIid()); - - $em->merge($lastThread); + if ($thread->getIid()) { + $thread->setThreadId($thread->getIid()); + $em->persist($thread); $em->flush(); - api_item_property_update( + /*api_item_property_update( $courseInfo, TOOL_FORUM_THREAD, - $lastThread->getIid(), + $thread->getIid(), 'ForumThreadAdded', $userId, $groupInfo, @@ -2983,7 +2990,7 @@ function store_thread( null, null, $sessionId - ); + );*/ // If the forum properties tell that the posts have to be approved // we have to put the whole thread invisible, @@ -2993,31 +3000,31 @@ function store_thread( // visible in this case (otherwise the teacher would have // to make the thread visible AND the post. // Default behaviour - api_set_default_visibility( - $lastThread->getIid(), + /*api_set_default_visibility( + $thread->getIid(), TOOL_FORUM_THREAD, $groupId, $courseInfo, $sessionId, $userId - ); + );*/ if ($visible == 0) { - api_item_property_update( + /*api_item_property_update( $courseInfo, TOOL_FORUM_THREAD, - $lastThread->getIid(), + $thread->getIid(), 'invisible', $userId, $groupInfo - ); + );*/ $visible = 1; } $logInfo = [ 'tool' => TOOL_FORUM, 'tool_id' => $values['forum_id'], - 'tool_id_detail' => $lastThread->getIid(), + 'tool_id_detail' => $thread->getIid(), 'action' => 'new-thread', 'action_details' => '', 'info' => $clean_post_title, @@ -3026,12 +3033,12 @@ function store_thread( } // We now store the content in the table_post table. - $lastPost = new CForumPost(); - $lastPost + $post = new CForumPost(); + $post ->setCId($course_id) ->setPostTitle($clean_post_title) ->setPostText($values['post_text']) - ->setThread($lastThread) + ->setThread($thread) ->setForumId($values['forum_id']) ->setPosterId($userId) ->setPosterName(isset($values['poster_name']) ? $values['poster_name'] : null) @@ -3042,34 +3049,43 @@ function store_thread( ->setPostId(0) ->setStatus(CForumPost::STATUS_VALIDATED); - if ($current_forum['moderated']) { - $lastPost->setStatus( + if ($forum->isModerated()) { + $post->setStatus( api_is_course_admin() ? CForumPost::STATUS_VALIDATED : CForumPost::STATUS_WAITING_MODERATION ); } - $em->persist($lastPost); + $repo = Container::getForumPostRepository(); + $em = $repo->getEntityManager(); + $resourceNode = $repo->createNodeForResource($post, $user, $thread->getResourceNode()); + $em->persist($resourceNode); + $repo->addResourceNodeToCourse( + $resourceNode, + ResourceLink::VISIBILITY_PUBLISHED, + $course, + $session, + null + ); + $em->persist($post); $em->flush(); - $lastPostId = $lastPost->getIid(); - - $lastThread->setThreadLastPost($lastPostId); - - $em->merge($lastThread); + $postId = $post->getIid(); + $thread->setThreadLastPost($postId); + $em->persist($thread); $em->flush(); $logInfo = [ 'tool' => TOOL_FORUM, 'tool_id' => $values['forum_id'], - 'tool_id_detail' => $lastThread->getIid(), + 'tool_id_detail' => $thread->getIid(), 'action' => 'new-post', 'info' => $clean_post_title, ]; Event::registerLog($logInfo); - if ($lastPostId) { - $lastPost->setPostId($lastPostId); - $em->merge($lastPost); + if ($postId) { + $post->setPostId($postId); + $em->persist($post); $em->flush(); } @@ -3079,7 +3095,7 @@ function store_thread( editAttachedFile( [ 'comment' => $_POST['file_comments'][$key], - 'post_id' => $lastPostId, + 'post_id' => $postId, ], $id ); @@ -3089,15 +3105,15 @@ function store_thread( // Now we have to update the thread table to fill the thread_last_post // field (so that we know when the thread has been updated for the last time). $sql = "UPDATE $table_threads - SET thread_last_post = '".Database::escape_string($lastPostId)."' + SET thread_last_post = '".Database::escape_string($postId)."' WHERE c_id = $course_id AND - thread_id='".Database::escape_string($lastThread->getIid())."'"; + thread_id='".Database::escape_string($thread->getIid())."'"; $result = Database::query($sql); $message = get_lang('The new thread has been added'); // Overwrite default message. - if ($current_forum['moderated'] && + if ($forum->isModerated() && !api_is_allowed_to_edit(null, true) ) { $message = get_lang('Your message has to be approved before people can view it.'); @@ -3122,7 +3138,7 @@ function store_thread( if ($result) { add_forum_attachment_file( isset($values['file_comment']) ? $values['file_comment'] : null, - $lastPostId + $postId ); } } @@ -3130,7 +3146,7 @@ function store_thread( $message .= '
'; } - if ($current_forum['approval_direct_post'] == '1' && + if ($forum->getApprovalDirectPost() == '1' && !api_is_allowed_to_edit(null, true) ) { $message .= get_lang('Your message has to be approved before people can view it.').'
'; @@ -3139,19 +3155,19 @@ function store_thread( } else { $message .= get_lang('You can now return to the').' '. get_lang('Forum').'
'; - $message .= get_lang('You can now return to the').' '. + $message .= get_lang('You can now return to the').' '. get_lang('Message').''; } - $reply_info['new_post_id'] = $lastPostId; + $reply_info['new_post_id'] = $postId; $my_post_notification = isset($values['post_notification']) ? $values['post_notification'] : null; if ($my_post_notification == 1) { - set_notification('thread', $lastThread->getIid(), true); + set_notification('thread', $thread->getIid(), true); } send_notification_mails( - $current_forum['forum_id'], - $lastThread->getIid(), + $forum, + $thread, $reply_info, $courseInfo['code'] ); @@ -3166,15 +3182,14 @@ function store_thread( Display::addFlash(Display::return_message($message, 'success', false)); } - return $lastThread; + return $thread; } /** * This function displays the form that is used to add a post. This can be a new thread or a reply. * - * @param array $current_forum + * @param array $current_forum * @param string $action is the parameter that determines if we are - * 1. newthread: adding a new thread (both empty) => No I-frame * 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled) * 3. replymessage: Replying to a message ($action =replymessage) => I-frame with the complete thread (if enabled) * (I first thought to put and I-frame with the message only) @@ -3184,17 +3199,13 @@ function store_thread( * @param bool $showPreview * * @return FormValidator - * - * @author Patrick Cool , Ghent University - * - * @version february 2006, dokeos 1.8 */ -function show_add_post_form($current_forum, $action, $form_values = '', $showPreview = true) +function show_add_post_form(CForumForum $current_forum, CForumThread $thread, $action, $form_values = '', $showPreview = true) { $_user = api_get_user_info(); $action = isset($action) ? Security::remove_XSS($action) : ''; - $myThread = isset($_GET['thread']) ? (int) $_GET['thread'] : ''; - $forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : ''; + $threadId = $thread->getIid(); + $forumId = $current_forum->getIid(); $my_post = isset($_GET['post']) ? (int) $_GET['post'] : ''; $giveRevision = isset($_GET['give_revision']) && $_GET['give_revision'] == 1; @@ -3202,7 +3213,7 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre [ 'action' => $action, 'forum' => $forumId, - 'thread' => $myThread, + 'thread' => $threadId, 'post' => $my_post, ] ).'&'.api_get_cidreq(); @@ -3217,11 +3228,11 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre // Setting the form elements. $form->addElement('hidden', 'forum_id', $forumId); - $form->addElement('hidden', 'thread_id', $myThread); + $form->addElement('hidden', 'thread_id', $threadId); $form->addElement('hidden', 'action', $action); // If anonymous posts are allowed we also display a form to allow the user to put his name or username in. - if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) { + if ($current_forum->getAllowAnonymous() == 1 && !isset($_user['user_id'])) { $form->addElement('text', 'poster_name', get_lang('Name')); $form->applyFilter('poster_name', 'html_filter'); } @@ -3245,7 +3256,7 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre ); $form->addRule('post_text', get_lang('Required field'), 'required'); - if (in_array($action, ['newthread', 'replythread', 'replymessage', 'quote'])) { + if (in_array($action, ['replythread', 'replymessage', 'quote'])) { $extraFields = new ExtraField('forum_post'); $extraFields->addElements( $form, @@ -3261,74 +3272,15 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre $iframe = null; if ($showPreview) { - $myThread = Security::remove_XSS($myThread); - if ($action != 'newthread' && !empty($myThread)) { + if ($action != 'newthread' && !empty($threadId)) { $iframe = ""; + )."&forum=".$forumId."&thread=".$threadId."#".$my_post."\" width=\"100%\">"; } if (!empty($iframe)) { $form->addElement('label', get_lang('Thread'), $iframe); } } - if (Gradebook::is_active() && - (api_is_course_admin() || api_is_session_general_coach() || api_is_course_tutor()) && !($myThread) - ) { - $form->addElement('advanced_settings', 'advanced_params', get_lang('Advanced settings')); - $form->addElement('html', ''); - } - - if ($action === 'newthread') { - Skill::addSkillsToForm($form, ITEM_TYPE_FORUM_THREAD, 0); - } - - if (api_is_allowed_to_edit(null, true) && $action == 'newthread') { - $form->addElement('checkbox', 'thread_sticky', '', get_lang('This is a sticky message (appears always on top and has a special sticky icon)')); - } - if (in_array($action, ['quote', 'replymessage'])) { $form->addFile('user_upload[]', get_lang('Attachment')); $form->addButton( @@ -3365,14 +3317,12 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre } // Setting the class and text of the form title and submit button. - if ($action == 'quote') { + if ($action === 'quote') { $form->addButtonCreate(get_lang('Quote this message'), 'SubmitPost'); - } elseif ($action == 'replythread') { + } elseif ($action === 'replythread') { $form->addButtonCreate(get_lang('Reply to this thread'), 'SubmitPost'); - } elseif ($action == 'replymessage') { + } elseif ($action === 'replymessage') { $form->addButtonCreate(get_lang('Reply to this message'), 'SubmitPost'); - } else { - $form->addButtonCreate(get_lang('Create thread'), 'SubmitPost'); } $defaults['thread_peer_qualify'] = 0; @@ -3423,7 +3373,7 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre // The course admin can make a thread sticky (=appears with special icon and always on top). $form->addRule('post_title', get_lang('Required field'), 'required'); - if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) { + if ($current_forum->getAllowAnonymous() == 1 && !isset($_user['user_id'])) { $form->addRule( 'poster_name', get_lang('Required field'), @@ -3455,18 +3405,10 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre $threadId = 0; switch ($action) { - case 'newthread': - $myThread = store_thread($current_forum, $values); - if ($myThread) { - $threadId = $myThread->getIid(); - Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $threadId); - $postId = $myThread->getThreadLastPost(); - } - break; case 'quote': case 'replythread': case 'replymessage': - $postId = store_reply($current_forum, $values); + $postId = store_reply($current_forum, $thread, $values); break; } @@ -3493,7 +3435,260 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre ); } - if (in_array($action, ['newthread', 'replythread', 'replymessage', 'quote'])) { + if (in_array($action, ['replythread', 'replymessage', 'quote'])) { + $extraFieldValues = new ExtraFieldValue('forum_post'); + $params = [ + 'item_id' => $postId, + 'extra_ask_for_revision' => isset($values['extra_ask_for_revision']) ? $values['extra_ask_for_revision'] : '', + ]; + $extraFieldValues->saveFieldValues( + $params, + false, + false, + ['ask_for_revision'] + ); + } + } + + $url = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&'.http_build_query( + [ + 'forum' => $forumId, + 'thread' => $threadId, + ] + ); + + Security::clear_token(); + header('Location: '.$url); + exit; + } + } else { + $token = Security::get_token(); + $form->addElement('hidden', 'sec_token'); + $form->setConstants(['sec_token' => $token]); + + // Delete from $_SESSION forum attachment from other posts + // and keep only attachments for new post + clearAttachedFiles(FORUM_NEW_POST); + // Get forum attachment ajax table to add it to form + $attachmentAjaxTable = getAttachmentsAjaxTable(0, $current_forum->getIid()); + $ajaxHtml = $attachmentAjaxTable; + $form->addElement('html', $ajaxHtml); + + return $form; + } +} + +function newThread(CForumForum $current_forum, $form_values = '', $showPreview = true) +{ + $_user = api_get_user_info(); + $forumId = $current_forum->getIid(); + $my_post = isset($_GET['post']) ? (int) $_GET['post'] : ''; + $giveRevision = isset($_GET['give_revision']) && $_GET['give_revision'] == 1; + + $url = api_get_self().'?'.http_build_query( + [ + 'action' => $action, + 'forum' => $forumId, + 'post' => $my_post, + ] + ).'&'.api_get_cidreq(); + + $form = new FormValidator( + 'thread', + 'post', + $url + ); + + // Setting the form elements. + $form->addElement('hidden', 'forum_id', $forumId); + $form->addElement('hidden', 'thread_id', 0); + $form->addElement('hidden', 'action', $action); + + // If anonymous posts are allowed we also display a form to allow the user to put his name or username in. + if ($current_forum->getAllowAnonymous() == 1 && !isset($_user['user_id'])) { + $form->addElement('text', 'poster_name', get_lang('Name')); + $form->applyFilter('poster_name', 'html_filter'); + } + + $form->addElement('text', 'post_title', get_lang('Title')); + $form->addHtmlEditor( + 'post_text', + get_lang('Text'), + true, + false, + api_is_allowed_to_edit(null, true) ? [ + 'ToolbarSet' => 'Forum', + 'Width' => '100%', + 'Height' => '300', + ] : [ + 'ToolbarSet' => 'ForumStudent', + 'Width' => '100%', + 'Height' => '300', + 'UserStatus' => 'student', + ] + ); + $form->addRule('post_text', get_lang('Required field'), 'required'); + + + $extraFields = new ExtraField('forum_post'); + $extraFields->addElements( + $form, + null, + [], //exclude + false, // filter + false, // tag as select + ['ask_for_revision'], //show only fields + [], // order fields + [] // extra data); + ); + + if (Gradebook::is_active() && + (api_is_course_admin() || api_is_session_general_coach() || api_is_course_tutor()) + ) { + $form->addElement('advanced_settings', 'advanced_params', get_lang('Advanced settings')); + $form->addElement('html', ''); + } + + Skill::addSkillsToForm($form, ITEM_TYPE_FORUM_THREAD, 0); + $form->addElement('checkbox', 'thread_sticky', '', get_lang('This is a sticky message (appears always on top and has a special sticky icon)')); + + $form->addFile('user_upload', get_lang('Attachment')); + + if ($giveRevision) { + $hide = api_get_configuration_value('hide_forum_post_revision_language'); + $form->addHidden('give_revision', 1); + if ($hide === false) { + $extraField = new ExtraField('forum_post'); + $extraField->addElements( + $form, + null, + [], //exclude + false, // filter + false, // tag as select + ['revision_language'], //show only fields + [], // order fields + [] // extra data + ); + } else { + $form->addHidden('extra_revision_language', 1); + } + } + $form->addButtonCreate(get_lang('Create thread'), 'SubmitPost'); + + $defaults['thread_peer_qualify'] = 0; + if (!empty($form_values)) { + $defaults['post_title'] = prepare4display($form_values['post_title']); + $defaults['post_text'] = prepare4display($form_values['post_text']); + $defaults['post_notification'] = (int) $form_values['post_notification']; + $defaults['thread_sticky'] = (int) $form_values['thread_sticky']; + $defaults['thread_peer_qualify'] = (int) $form_values['thread_peer_qualify']; + } + + $form->setDefaults(isset($defaults) ? $defaults : []); + + // The course admin can make a thread sticky (=appears with special icon and always on top). + $form->addRule('post_title', get_lang('Required field'), 'required'); + if ($current_forum->getAllowAnonymous() == 1 && !isset($_user['user_id'])) { + $form->addRule( + 'poster_name', + get_lang('Required field'), + 'required' + ); + } + + // Validation or display + if ($form->validate()) { + $check = Security::check_token('post'); + if ($check) { + $values = $form->getSubmitValues(); + if (isset($values['thread_qualify_gradebook']) && + $values['thread_qualify_gradebook'] == '1' && + empty($values['weight_calification']) + ) { + Display::addFlash( + Display::return_message( + get_lang('You must assign a score to this activity').' '.get_lang('Back').'', + 'error', + false + ) + ); + + return false; + } + + $postId = 0; + $threadId = 0; + + $newThread = store_thread($current_forum, $values); + if ($newThread) { + Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $newThread->getIid()); + $postId = $newThread->getThreadLastPost(); + + if ($postId) { + $postInfo = get_post_information($postId); + if ($postInfo) { + $threadId = $postInfo['thread_id']; + } + + if (isset($values['give_revision']) && $values['give_revision'] == 1) { + $extraFieldValues = new ExtraFieldValue('forum_post'); + $revisionLanguage = isset($values['extra_revision_language']) ? $values['extra_revision_language'] : ''; + + $params = [ + 'item_id' => $postId, + 'extra_revision_language' => $revisionLanguage, + ]; + + $extraFieldValues->saveFieldValues( + $params, + false, + false, + ['revision_language'] + ); + } $extraFieldValues = new ExtraFieldValue('forum_post'); $params = [ 'item_id' => $postId, @@ -3528,7 +3723,7 @@ function show_add_post_form($current_forum, $action, $form_values = '', $showPre // and keep only attachments for new post clearAttachedFiles(FORUM_NEW_POST); // Get forum attachment ajax table to add it to form - $attachmentAjaxTable = getAttachmentsAjaxTable(0, $current_forum['forum_id']); + $attachmentAjaxTable = getAttachmentsAjaxTable(0, $current_forum->getIid()); $ajaxHtml = $attachmentAjaxTable; $form->addElement('html', $ajaxHtml); @@ -3831,18 +4026,15 @@ function current_qualify_of_thread($threadId, $sessionId, $userId) * This function stores a reply in the forum_post table. * It also updates the forum_threads table (thread_replies +1 , thread_last_post, thread_date). * - * @param array $current_forum - * @param array $values - * @param int $courseId Optional - * @param int $userId Optional + * @param CForumForum $current_forum + * @param CForumThread $thread + * @param array $values + * @param int $courseId Optional + * @param int $userId Optional * * @return int post id - * - * @author Patrick Cool , Ghent University - * - * @version february 2006, dokeos 1.8 */ -function store_reply($current_forum, $values, $courseId = 0, $userId = 0) +function store_reply(CForumForum $current_forum, CForumThread $thread, $values, $courseId = 0, $userId = 0) { $courseId = !empty($courseId) ? $courseId : api_get_course_int_id(); $_course = api_get_course_info_by_id($courseId); @@ -3850,7 +4042,7 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0) $post_date = api_get_utc_datetime(); $userId = $userId ?: api_get_user_id(); - if ($current_forum['allow_anonymous'] == 1) { + if ($current_forum->getAllowAnonymous() == 1) { if (api_is_anonymous() && empty($userId)) { $userId = api_get_anonymous_id(); } @@ -3861,7 +4053,7 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0) } $visible = 1; - if ($current_forum['approval_direct_post'] == '1' && + if ($current_forum->getApprovalDirectPost() == '1' && !api_is_allowed_to_edit(null, true) ) { $visible = 0; @@ -3871,23 +4063,39 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0) $new_post_id = 0; if ($upload_ok) { - // We first store an entry in the forum_post table. - $new_post_id = Database::insert( - $table_posts, - [ - 'c_id' => $courseId, - 'post_title' => $values['post_title'], - 'post_text' => isset($values['post_text']) ? ($values['post_text']) : null, - 'thread_id' => $values['thread_id'], - 'forum_id' => $values['forum_id'], - 'poster_id' => $userId, - 'post_id' => 0, - 'post_date' => $post_date, - 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : null, - 'post_parent_id' => isset($values['post_parent_id']) ? $values['post_parent_id'] : null, - 'visible' => $visible, - ] + $post = new CForumPost(); + $post + ->setCId($courseId) + ->setPostTitle($values['post_title']) + ->setPostText(isset($values['post_text']) ? ($values['post_text']) : null) + ->setThread($thread) + ->setForumId($current_forum->getIid()) + ->setPosterId($userId) + ->setPostNotification(isset($values['post_notification']) ? $values['post_notification'] : null) + ->setPostParentId(isset($values['post_parent_id']) ? $values['post_parent_id'] : null) + ->setVisible($visible) + ->setPostDate(api_get_utc_datetime(null, false, true)) + ; + + $repo = Container::getForumPostRepository(); + + $user = api_get_user_entity(api_get_user_id()); + $course = api_get_course_entity($courseId); + $session = api_get_session_entity(); + + $em = $repo->getEntityManager(); + //$em->persist($thread); + $resourceNode = $repo->createNodeForResource($post, $user, $thread->getResourceNode()); + $repo->addResourceNodeToCourse( + $resourceNode, + ResourceLink::VISIBILITY_PUBLISHED, + $course, + $session, + null ); + $em->flush(); + + $new_post_id = $post->getIid(); if ($new_post_id) { $sql = "UPDATE $table_posts SET post_id = iid WHERE iid = $new_post_id"; @@ -3912,7 +4120,7 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0) updateThreadInfo($values['thread_id'], $new_post_id, $post_date); // Update the forum. - api_item_property_update( + /*api_item_property_update( $_course, TOOL_FORUM, $values['forum_id'], @@ -3927,15 +4135,15 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0) $new_post_id, 'NewPost', $userId - ); + );*/ - if ($current_forum['approval_direct_post'] == '1' && + if ($current_forum->getApprovalDirectPost() == '1' && !api_is_allowed_to_edit(null, true) ) { $message .= '
'.get_lang('Your message has to be approved before people can view it.').'
'; } - if ($current_forum['moderated'] && + if ($current_forum->isModerated() && !api_is_allowed_to_edit(null, true) ) { $message .= '
'.get_lang('Your message has to be approved before people can view it.').'
'; @@ -3948,8 +4156,8 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0) } send_notification_mails( - $values['forum_id'], - $values['thread_id'], + $current_forum, + $thread, $values ); add_forum_attachment_file('', $new_post_id); @@ -4476,13 +4684,14 @@ function get_unaproved_messages($forum_id) * was added to a given thread. * * @param array reply information - * - * @author Patrick Cool , Ghent University - * - * @version february 2006, dokeos 1.8 */ -function send_notification_mails($forumId, $thread_id, $reply_info) +function send_notification_mails(CForumForum $forum, CForumThread $thread, $reply_info) { + $_course = api_get_course_info(); + $courseEntity = $_course['entity']; + $sessionId = api_get_session_id(); + $sessionEntity = api_get_session_entity($sessionId); + $table = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE); // First we need to check if @@ -4490,43 +4699,40 @@ function send_notification_mails($forumId, $thread_id, $reply_info) // 2. the forum is visible // 3. the thread is visible // 4. the reply is visible (=when there is) - $current_thread = get_thread_information($forumId, $thread_id); - $current_forum = get_forum_information($current_thread['forum_id'], $current_thread['c_id']); $current_forum_category = null; - if (isset($current_forum['forum_category'])) { - $current_forum_category = get_forumcategory_information($current_forum['forum_category']); + if ($forum->getForumCategory()) { + $current_forum_category = $forum->getForumCategory(); } $send_mails = false; - if ($current_thread['visibility'] == '1' && - $current_forum['visibility'] == '1' && - ($current_forum_category && $current_forum_category['visibility'] == '1') && - $current_forum['approval_direct_post'] != '1' + if ($thread->isVisible($courseEntity, $sessionEntity) && + $forum->isVisible($courseEntity, $sessionEntity) && + ($current_forum_category && $forum->getForumCategory()->isVisible($courseEntity, $sessionEntity)) && + $forum->getApprovalDirectPost() != '1' ) { $send_mails = true; } // The forum category, the forum, the thread and the reply are visible to the user - if ($send_mails && !empty($forumId)) { + if ($send_mails && !empty($forum)) { $postId = isset($reply_info['new_post_id']) ? $reply_info['new_post_id'] : 0; - send_notifications($forumId, $thread_id, $postId); + send_notifications($forum, $thread, $postId); } else { $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); - if (isset($current_forum['forum_id'])) { + if ($forum) { $sql = "SELECT * FROM $table_notification WHERE c_id = ".api_get_course_int_id()." AND ( - forum_id = '".intval($current_forum['forum_id'])."' OR - thread_id = '".intval($thread_id)."' + forum_id = '".$forum->getIid()."' OR + thread_id = '".$thread->getIid()."' ) "; - $result = Database::query($sql); $user_id = api_get_user_id(); while ($row = Database::fetch_array($result)) { $sql = "INSERT INTO $table (c_id, thread_id, post_id, user_id) - VALUES (".api_get_course_int_id().", '".intval($thread_id)."', '".intval($reply_info['new_post_id'])."', '$user_id' )"; + VALUES (".api_get_course_int_id().", '".$thread->getIid()."', '".intval($reply_info['new_post_id'])."', '$user_id' )"; Database::query($sql); } } @@ -4628,38 +4834,35 @@ function handle_mail_cue($content, $id) /** * This function sends the mails for the mail notification. * + * @param array $userInfo + * @param CForumForum $forum + * @param CForumThread $thread * @param array - * @param array - * @param array - * @param array - * - * @author Patrick Cool , Ghent University * - * @version february 2006, dokeos 1.8 */ -function send_mail($userInfo, $forumInfo, $thread_information, $postInfo = []) +function send_mail($userInfo, CForumForum $forum, CForumThread $thread, $postInfo = []) { - if (empty($userInfo) || empty($forumInfo) || empty($thread_information)) { + if (empty($userInfo) || empty($forum) || empty($thread)) { return false; } $_course = api_get_course_info(); $user_id = api_get_user_id(); + $forumId = $forum->getIid(); + $threadId = $thread->getIid(); + + $thread_link = api_get_path(WEB_CODE_PATH). + 'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId; - $thread_link = ''; - if (isset($thread_information) && is_array($thread_information)) { - $thread_link = api_get_path(WEB_CODE_PATH). - 'forum/viewthread.php?'.api_get_cidreq().'&forum='.$thread_information['forum_id'].'&thread='.$thread_information['thread_id']; - } $email_body = get_lang('Dear').' '.api_get_person_name($userInfo['firstname'], $userInfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).",
\n\r"; - $email_body .= get_lang('New Post in the forum').': '.$forumInfo['forum_title'].' - '.$thread_information['thread_title']."
\n"; + $email_body .= get_lang('New Post in the forum').': '.$forum->getForumTitle().' - '.$thread->getThreadTitle()."
\n"; $courseId = api_get_configuration_value('global_forums_course_id'); - $subject = get_lang('New Post in the forum').' - '.$_course['official_code'].': '.$forumInfo['forum_title'].' - '.$thread_information['thread_title']."
\n"; + $subject = get_lang('New Post in the forum').' - '.$_course['official_code'].': '.$forum->getForumTitle().' - '.$thread->getThreadTitle()."
\n"; $courseInfoTitle = get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] -
\n"; if (!empty($courseId) && $_course['real_id'] == $courseId) { - $subject = get_lang('New Post in the forum').': '.$forumInfo['forum_title'].' - '.$thread_information['thread_title']."
\n"; + $subject = get_lang('New Post in the forum').': '.$forum->getForumTitle().' - '.$thread->getThreadTitle()."
\n"; $courseInfoTitle = "
\n"; } $email_body .= $courseInfoTitle; @@ -5818,21 +6021,18 @@ function get_notifications($content, $id) * * @since May 2008, dokeos 1.8.5 */ -function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0) +function send_notifications(CForumForum $forum, CForumThread $thread, $post_id = 0) { - $forum_id = (int) $forum_id; - // Users who subscribed to the forum - if ($forum_id != 0) { - $users_to_be_notified_by_forum = get_notifications('forum', $forum_id); - } else { + if (!$forum) { return false; } - $current_thread = get_thread_information($forum_id, $thread_id); + // Users who subscribed to the forum + $users_to_be_notified_by_forum = get_notifications('forum', $forum->getIid()); // User who subscribed to the thread - if ($thread_id != 0) { - $users_to_be_notified_by_thread = get_notifications('thread', $thread_id); + if (!$thread) { + $users_to_be_notified_by_thread = get_notifications('thread', $thread->getIid()); } $postInfo = []; @@ -5842,12 +6042,11 @@ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0) // Merging the two $users_to_be_notified = array_merge($users_to_be_notified_by_forum, $users_to_be_notified_by_thread); - $forumInfo = get_forum_information($forum_id); if (is_array($users_to_be_notified)) { foreach ($users_to_be_notified as $value) { $userInfo = api_get_user_info($value['user_id']); - send_mail($userInfo, $forumInfo, $current_thread, $postInfo); + send_mail($userInfo, $forum, $thread, $postInfo); } } } @@ -6620,16 +6819,16 @@ function getForumCategoryByTitle($title, $courseId, $sessionId = 0) } /** - * @param array $current_forum + * @param CForumForum $forum * @param array $row * @param bool $addWrapper * * @return string */ -function getPostStatus($current_forum, $row, $addWrapper = true) +function getPostStatus(CForumForum $forum, $row, $addWrapper = true) { $statusIcon = ''; - if ($current_forum['moderated']) { + if ($forum->isModerated()) { if ($addWrapper) { $statusIcon = '

'; } diff --git a/public/main/forum/iframe_thread.php b/public/main/forum/iframe_thread.php index ea0e6452ea..0c22cd5056 100644 --- a/public/main/forum/iframe_thread.php +++ b/public/main/forum/iframe_thread.php @@ -1,6 +1,11 @@ , 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); diff --git a/public/main/forum/index.php b/public/main/forum/index.php index fe7776e900..fa1ef4d2e3 100644 --- a/public/main/forum/index.php +++ b/public/main/forum/index.php @@ -1,4 +1,5 @@ , 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 = $('', { type: 'file', name: 'user_upload[]' @@ -152,9 +169,8 @@ $htmlHeadXtra[] = " "; -$form = show_add_post_form( - $current_forum, - 'newthread', +$form = newThread( + $forumEntity, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null ); @@ -173,7 +189,7 @@ echo ''. echo ''; // Set forum attachment data into $_SESSION -getAttachedFiles($current_forum['forum_id'], 0, 0); +getAttachedFiles($forumEntity->getIid(), 0, 0); if ($form) { $form->display(); diff --git a/public/main/forum/reply.php b/public/main/forum/reply.php index 535b9d98af..d801d26d5c 100644 --- a/public/main/forum/reply.php +++ b/public/main/forum/reply.php @@ -1,6 +1,11 @@ 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 '
'; @@ -191,12 +211,12 @@ if ($origin != 'learnpath') { echo '
'; echo '

'; 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 '

'; -echo '

'.prepare4display($current_forum['forum_comment']).'

'; +echo '

'.prepare4display($forumEntity->getForumComment()).'

'; echo '
'; if ($form) { $form->display(); diff --git a/public/main/forum/viewforum.php b/public/main/forum/viewforum.php index c9192d03a2..e78798de06 100644 --- a/public/main/forum/viewforum.php +++ b/public/main/forum/viewforum.php @@ -1,6 +1,9 @@ , 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 .= ''; $table_list .= ''.get_lang('First names and last names').''; - if ($listType == 'qualify') { + if ('qualify' == $listType) { $table_list .= ''.get_lang('Score').''; } 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 .= ''; - if ($listType == 'qualify') { + if ('qualify' == $listType) { $table_list .= ''.$row_student_list['qualify'].'/'.$max_qualify.''; } 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')).'
'; } - $counter_stdlist++; + ++$counter_stdlist; } } else { - if ($listType === 'qualify') { + if ('qualify' === $listType) { $table_list .= ''.get_lang('There are no qualified learners').''; } else { $table_list .= ''.get_lang('There are no unqualified learners').''; @@ -321,7 +328,7 @@ if ($my_action == 'liststd' && } } -if ($origin == 'learnpath') { +if ('learnpath' == $origin) { echo '
 
'; } @@ -332,7 +339,7 @@ if (!empty($message)) { /* Action links */ echo '
'; -if ($origin != 'learnpath') { +if ('learnpath' != $origin) { if (!empty($groupId)) { echo '' .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 ''; // 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 '
'; 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 = '' - .$row['thread_title'].''; + .$thread->getThreadTitle().''; $html = ''; - $html .= '
'; + $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; @@ -448,36 +452,32 @@ if (is_array($threads)) { $html .= '
'; // 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 .= '
'; $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 .= "" @@ -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 .= "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', ' '.get_lang('Forum category Locked'), ['class' => 'alert alert-warning post-closed'] ); } - if ($current_forum['locked'] == 1) { + if (1 == $forumEntity->getLocked()) { $closedPost = Display::tag( 'div', ' '.get_lang('Forum blocked'), ['class' => 'alert alert-warning post-closed'] ); } - if ($current_thread['locked'] == 1) { + if (1 == $threadEntity->getLocked()) { $closedPost = Display::tag( 'div', ' '.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.' '; $post['post_attachments'] .= ''.$attachment['comment'].''; - 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'] .= '  '; + $return .= '
  • '; $return .= ' '; $return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY); $return .= ' '; $return .= Display::return_icon('forumthread.png', get_lang('Thread'), [], ICON_SIZE_TINY); - $return .= ''. - Security::remove_XSS($thread['thread_title']).' '.$link.''; + $return .= ''. + Security::remove_XSS($thread->getThreadTitle()).' '.$link.''; $return .= '
  • '; } } diff --git a/src/CourseBundle/Entity/CForumCategory.php b/src/CourseBundle/Entity/CForumCategory.php index 5428139996..668b5013cd 100644 --- a/src/CourseBundle/Entity/CForumCategory.php +++ b/src/CourseBundle/Entity/CForumCategory.php @@ -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 { diff --git a/src/CourseBundle/Entity/CForumForum.php b/src/CourseBundle/Entity/CForumForum.php index eefd8afb6e..07ee068d00 100644 --- a/src/CourseBundle/Entity/CForumForum.php +++ b/src/CourseBundle/Entity/CForumForum.php @@ -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 { diff --git a/src/CourseBundle/Entity/CForumPost.php b/src/CourseBundle/Entity/CForumPost.php index b95855f1c5..69d2699dd8 100644 --- a/src/CourseBundle/Entity/CForumPost.php +++ b/src/CourseBundle/Entity/CForumPost.php @@ -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 diff --git a/src/CourseBundle/Entity/CForumThread.php b/src/CourseBundle/Entity/CForumThread.php index 79da509dca..87bf9fe58d 100644 --- a/src/CourseBundle/Entity/CForumThread.php +++ b/src/CourseBundle/Entity/CForumThread.php @@ -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