From 885bb43eab5a8ecbc5230be4525ec412cab3df5f Mon Sep 17 00:00:00 2001 From: jmontoya Date: Fri, 4 Mar 2016 14:38:45 +0100 Subject: [PATCH] Adding post moderation see BT#10894 --- app/Migrations/Schema/V111/Version111.php | 4 +- main/forum/editpost.php | 38 ++++-- main/forum/forumfunction.inc.php | 109 ++++++++++++++---- main/forum/reply.php | 98 +++++++++------- main/forum/viewthread.php | 45 ++------ main/forum/viewthread_flat.inc.php | 42 +++---- main/forum/viewthread_nested.inc.php | 6 +- main/forum/viewthread_threaded.inc.php | 7 +- main/inc/lib/api.lib.php | 3 +- .../CourseBundle/Entity/CForumForum.php | 27 ++++- .../CourseBundle/Entity/CForumPost.php | 27 +++++ 11 files changed, 268 insertions(+), 138 deletions(-) diff --git a/app/Migrations/Schema/V111/Version111.php b/app/Migrations/Schema/V111/Version111.php index ab9b05bf7a..ad4246ccd9 100644 --- a/app/Migrations/Schema/V111/Version111.php +++ b/app/Migrations/Schema/V111/Version111.php @@ -36,7 +36,6 @@ class Version111 extends AbstractMigrationChamilo $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','true','Yes') "); $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_my_files','false','No') "); - $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_invisible_in_session',NULL,'radio','Session','false','ExerciseInvisibleInSessionTitle','ExerciseInvisibleInSessionComment','',NULL, 1)"); $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','true','Yes') "); $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','false','No') "); @@ -44,7 +43,8 @@ class Version111 extends AbstractMigrationChamilo $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('configure_exercise_visibility_in_course',NULL,'radio','Session','false','ConfigureExerciseVisibilityInCourseTitle','ConfigureExerciseVisibilityInCourseComment','',NULL, 1)"); $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','true','Yes') "); $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','false','No') "); - + $this->addSql("ALTER TABLE c_forum_forum ADD moderated TINYINT(1) DEFAULT NULL"); + $this->addSql("ALTER TABLE c_forum_post ADD status INT DEFAULT NULL"); } /** diff --git a/main/forum/editpost.php b/main/forum/editpost.php index 1f3bdf95e0..554d50f5b0 100755 --- a/main/forum/editpost.php +++ b/main/forum/editpost.php @@ -73,23 +73,41 @@ if (!empty($gradebook) && $gradebook == 'view') { } if ($origin == 'group') { - $_clean['toolgroup'] = (int) $_SESSION['toolgroup']; + $_clean['toolgroup'] = api_get_group_id(); $group_properties = GroupManager::get_group_properties($_clean['toolgroup']); - $interbreadcrumb[] = array('url' => '../group/group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')); - $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['toolgroup'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']); - $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&gidReq='.$_SESSION['toolgroup'].'&forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title'])); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), + 'name' => get_lang('Groups'), + ); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), + 'name' => get_lang('GroupSpace').' '.$group_properties['name'], + ); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']), + 'name' => prepare4display($current_forum['forum_title']), + ); $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost')); } else { - $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq(), 'name' => $nameTools); - $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => prepare4display($current_forum_category['cat_title'])); - $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title'])); - $interbreadcrumb[] = array('url' => 'viewthread.php?'.api_get_cidreq().'&origin='.$origin.'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']), 'name' => prepare4display($current_thread['thread_title'])); + $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(), 'name' => $nameTools); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&'.api_get_cidreq(), + 'name' => prepare4display($current_forum_category['cat_title']), + ); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.intval($_GET['forum']).'&'.api_get_cidreq(), + 'name' => prepare4display($current_forum['forum_title']), + ); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&origin='.$origin.'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread']), + 'name' => prepare4display($current_thread['thread_title']), + ); $interbreadcrumb[] = array('url' => 'javascript: void (0);', 'name' => get_lang('EditPost')); } /* Resource Linker */ -if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) { +if (isset($_POST['add_resources']) && $_POST['add_resources'] == get_lang('Resources')) { $_SESSION['formelements'] = $_POST; $_SESSION['origin'] = $_SERVER['REQUEST_URI']; $_SESSION['breadcrumbs'] = $interbreadcrumb; @@ -212,7 +230,7 @@ $values = show_edit_post_form( ); if (!empty($values) and isset($_POST['SubmitPost'])) { - store_edit_post($values); + store_edit_post($current_forum, $values); } // Footer diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 92138280b9..e32b18a39f 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -24,6 +24,7 @@ use ChamiloSession as Session; use Doctrine\Common\Collections\Criteria; +use Chamilo\CourseBundle\Entity\CForumPost; define('FORUM_NEW_POST', 0); @@ -231,10 +232,7 @@ function show_add_forumcategory_form($inputvalues = array(), $lp_id) function show_add_forum_form($inputvalues = array(), $lp_id) { $_course = api_get_course_info(); - - $gradebook = Security::remove_XSS($_GET['gradebook']); - // Initialize the object. - $form = new FormValidator('forumcategory', 'post', 'index.php?gradebook='.$gradebook.'&'.api_get_cidreq()); + $form = new FormValidator('forumcategory', 'post', 'index.php?'.api_get_cidreq()); // The header for the form if (!empty($inputvalues)) { @@ -242,7 +240,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id) } else { $form_title = get_lang('AddForum'); } - $session_header = isset($_SESSION['session_name']) ? ' ('.$_SESSION['session_name'].') ' : ''; + $session_header = api_get_session_name(); $form->addElement('header', $form_title.$session_header); // We have a hidden field if we are editing. @@ -251,6 +249,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id) $form->addElement('hidden', 'forum_id', $my_forum_id); } $lp_id = intval($lp_id); + // hidden field if from learning path $form->addElement('hidden', 'lp_id', $lp_id); @@ -285,6 +284,11 @@ function show_add_forum_form($inputvalues = array(), $lp_id) $form->addButtonAdvancedSettings('advanced_params'); $form->addElement('html', ''; -/* End new display forum */ -// The form for the reply -$my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : ''; -$my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : ''; -$my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : ''; -$values = show_add_post_form( - $current_forum, - $forum_setting, - $my_action, - $my_post, - $my_elements -); -if (!empty($values) && isset($_POST['SubmitPost'])) { - $result = store_reply($current_forum, $values); - //@todo split the show_add_post_form function - $origin = isset($_GET['origin']) && $_GET['origin'] === 'learnpath' ? 'learnpath' : null; - - $url = 'viewthread.php?' . http_build_query([ - 'forum' => $current_thread['forum_id'], - 'gradebook' => $gradebook, - 'thread' => intval($_GET['thread']), - 'gidReq' => api_get_group_id(), - 'origin' => $origin, - 'msg' => $result['msg'], - 'type' => $result['type'] - ]); - echo ' - '; -} + +echo $form; if ($origin == 'learnpath') { Display::display_reduced_footer(); diff --git a/main/forum/viewthread.php b/main/forum/viewthread.php index 6353ed07f7..f80da5045e 100755 --- a/main/forum/viewthread.php +++ b/main/forum/viewthread.php @@ -61,20 +61,19 @@ $sessionId = api_get_session_id(); if ($origin == 'group') { $group_properties = GroupManager::get_group_properties($groupId); $interbreadcrumb[] = array( - 'url' => '../group/group.php', + 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'name' => get_lang('Groups') ); $interbreadcrumb[] = array( - 'url' => '../group/group_space.php?' . api_get_cidreq(), + 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?' . api_get_cidreq(), 'name' => get_lang('GroupSpace') . ' ' . $group_properties['name'] ); $interbreadcrumb[] = array( - 'url' => 'viewforum.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq() - . "&origin=$origin&search=" . Security::remove_XSS(urlencode($my_search)), + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq(). "&search=" . Security::remove_XSS(urlencode($my_search)), 'name' => Security::remove_XSS($current_forum['forum_title']) ); $interbreadcrumb[] = array( - 'url' => 'viewthread.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq(). '&thread=' . intval($_GET['thread']), + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum=' . intval($_GET['forum']) . '&' . api_get_cidreq(). '&thread=' . intval($_GET['thread']), 'name' => Security::remove_XSS($current_thread['thread_title']) ); @@ -85,22 +84,15 @@ if ($origin == 'group') { Display::display_reduced_header(); } else { $interbreadcrumb[] = array( - 'url' => 'index.php?' - . (isset($gradebook) ? "gradebook=$gradebook&" : '') - . 'search=' . Security::remove_XSS(urlencode($my_search)), + 'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search=' . Security::remove_XSS(urlencode($my_search)), 'name' => $nameTools ); $interbreadcrumb[] = array( - 'url' => 'viewforumcategory.php?forumcategory=' - . $current_forum_category['cat_id'] - . "&origin=$origin&search=" - . Security::remove_XSS(urlencode($my_search)), + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='. $current_forum_category['cat_id']. "&search=". Security::remove_XSS(urlencode($my_search)), 'name' => Security::remove_XSS($current_forum_category['cat_title']) ); $interbreadcrumb[] = array( - 'url' => 'viewforum.php?forum=' . intval($_GET['forum']) - . "&origin=$origin&search=" - . Security::remove_XSS(urlencode($my_search)), + 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum=' . intval($_GET['forum']). "&search=". Security::remove_XSS(urlencode($my_search)), 'name' => Security::remove_XSS($current_forum['forum_title']) ); $interbreadcrumb[] = array( @@ -138,9 +130,7 @@ if ( ) { $message = delete_post($_GET['id']); } -if ( - ($my_action == 'invisible' || - $my_action == 'visible') && +if (($my_action == 'invisible' || $my_action == 'visible') && isset($_GET['id']) && (api_is_allowed_to_edit(false, true) || GroupManager::is_tutor_of_group(api_get_user_id(), $groupId)) @@ -186,7 +176,7 @@ if ($my_message != 'PostDeletedSpecial') { 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'] OR ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) { + if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) { // reply link if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) { echo ' 'text-info']) . " | $name"; - $html .= Display::tag( 'p', $name, @@ -201,11 +199,15 @@ if (isset($current_thread['thread_id'])) { api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId) ) { + $statusIcon = getPostStatus($current_forum, $row); $iconEdit .= return_visible_invisible_icon( - 'post', $row['post_id'], $row['visible'], array( - 'forum' => $clean_forum_id, - 'thread' => $clean_thread_id, - 'origin' => $origin, + 'post', + $row['post_id'], + $row['visible'], + array( + 'forum' => $clean_forum_id, + 'thread' => $clean_thread_id, + 'origin' => $origin, ) ); $iconEdit .= ""; @@ -219,14 +221,8 @@ if (isset($current_thread['thread_id'])) { } } - $user_status = api_get_status_of_user_in_course( - $row['user_id'], api_get_course_int_id() - ); - - $current_qualify_thread = showQualify( - '1', $row['poster_id'], $_GET['thread'] - ); - + $user_status = api_get_status_of_user_in_course($row['user_id'], api_get_course_int_id()); + $current_qualify_thread = showQualify('1', $row['poster_id'], $_GET['thread']); if ( ( $current_thread['thread_peer_qualify'] == 1 || @@ -254,27 +250,33 @@ if (isset($current_thread['thread_id'])) { } } if ($iconEdit != '') { - $html .= '
' . $iconEdit . '
'; + $html .= '
' . $iconEdit . $statusIcon.'
'; } + + $html .= $closedPost; $html .= ''; $html .= '
'; $titlePost = Display::tag( - 'h3', $row['post_title'], + 'h3', + $row['post_title'], array('class' => 'forum_post_title') ); + $html .= Display::tag( - 'div', $titlePost, + 'div', + $titlePost, array('class' => 'post-header') ); // see comments inside forumfunction.inc.php to lower filtering and allow more visual changes $html .= Display::tag( - 'div', $row['post_text'], + 'div', + $row['post_text'], array('class' => 'post-body') ); $html .= '
'; @@ -307,10 +309,8 @@ if (isset($current_thread['thread_id'])) { $attachment_list = getAllAttachment($row['post_id']); if (!empty($attachment_list) && is_array($attachment_list)) { foreach ($attachment_list as $attachment) { - $realname = $attachment['path']; $user_filename = $attachment['filename']; - $html .= Display::return_icon('attachment.gif', get_lang('Attachment')); $html .= '
' . $user_filename . ' '; diff --git a/main/forum/viewthread_nested.inc.php b/main/forum/viewthread_nested.inc.php index ef704ac080..6e4126661f 100755 --- a/main/forum/viewthread_nested.inc.php +++ b/main/forum/viewthread_nested.inc.php @@ -25,7 +25,7 @@ if (isset($_GET['action']) && // Decide whether we show the latest post first $sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC'); -$rows = getPosts($_GET['thread'], $sortDirection, true); +$rows = getPosts($current_forum, $_GET['thread'], $sortDirection, true); $count = 0; $clean_forum_id = intval($_GET['forum']); $clean_thread_id = intval($_GET['thread']); @@ -191,8 +191,10 @@ foreach ($rows as $post) { } } + $statusIcon = getPostStatus($current_forum, $post); + if ($iconEdit != '') { - $html .= '
' . $iconEdit . '
'; + $html .= '
' . $iconEdit . ' '.$statusIcon.'
'; } if (($current_forum_category && $current_forum_category['locked'] == 0) && diff --git a/main/forum/viewthread_threaded.inc.php b/main/forum/viewthread_threaded.inc.php index b8701b41cc..097656c233 100755 --- a/main/forum/viewthread_threaded.inc.php +++ b/main/forum/viewthread_threaded.inc.php @@ -24,7 +24,7 @@ $forumUrl = api_get_path(WEB_CODE_PATH) . 'forum/'; $_user = api_get_user_info(); $sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : 'ASC'; -$rows = getPosts($_GET['thread'], $sortDirection, true); +$rows = getPosts($current_forum, $_GET['thread'], $sortDirection, true); $sessionId = api_get_session_id(); $currentThread = get_thread_information($_GET['thread']); $post_id = isset($_GET['post']) ? (int) $_GET['post'] : 0; @@ -263,7 +263,7 @@ if ( // Verified the post minor -$my_post = getPosts($_GET['thread']); +$my_post = getPosts($current_forum, $_GET['thread']); $id_posts = array(); if (!empty($my_post) && is_array($my_post)) { @@ -279,7 +279,7 @@ if (!empty($my_post) && is_array($my_post)) { if ( GroupManager::is_tutor_of_group(api_get_user_id(), $groupId) || api_is_allowed_to_edit(false, true) && - !(api_is_course_coach() &&$current_forum['session_id'] != $sessionId) + !(api_is_course_coach() && $current_forum['session_id'] != $sessionId) ) { if ($locked == false) { echo ""; } - echo return_visible_invisible_icon( 'post', $rows[$display_post_id]['post_id'], diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index c50dd937a4..d0bb67e965 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -2175,13 +2175,12 @@ function api_get_group_id() return Session::read('_gid', 0); } - /** * Gets the current or given session name * @param int Session ID (optional) * @return string The session name, or null if unfound */ -function api_get_session_name($session_id) { +function api_get_session_name($session_id = 0) { if (empty($session_id)) { $session_id = api_get_session_id(); if (empty($session_id)) { return null; } diff --git a/src/Chamilo/CourseBundle/Entity/CForumForum.php b/src/Chamilo/CourseBundle/Entity/CForumForum.php index 21066ea7dd..b2fa8d52d5 100644 --- a/src/Chamilo/CourseBundle/Entity/CForumForum.php +++ b/src/Chamilo/CourseBundle/Entity/CForumForum.php @@ -183,11 +183,18 @@ class CForumForum /** * @var integer - * + * * @ORM\Column(name="lp_id", type="integer", options={"unsigned":true}) */ private $lpId; + /** + * @var boolean + * + * @ORM\Column(name="moderated", type="boolean", nullable=true) + */ + private $moderated; + /** * Set forumTitle * @@ -715,4 +722,22 @@ class CForumForum return $this->lpId; } + /** + * @return boolean + */ + public function isModerated() + { + return $this->moderated; + } + + /** + * @param $moderated + * @return $this + */ + public function setModerated($moderated) + { + $this->moderated = $moderated; + + return $this; + } } diff --git a/src/Chamilo/CourseBundle/Entity/CForumPost.php b/src/Chamilo/CourseBundle/Entity/CForumPost.php index 7835c3cf90..b92881eaca 100644 --- a/src/Chamilo/CourseBundle/Entity/CForumPost.php +++ b/src/Chamilo/CourseBundle/Entity/CForumPost.php @@ -115,6 +115,13 @@ class CForumPost */ private $visible; + /** + * @var integer + * + * @ORM\Column(name="status", type="integer", nullable=true) + */ + private $status; + /** * Set postTitle * @@ -390,4 +397,24 @@ class CForumPost { return $this->cId; } + + /** + * @return int + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param int $status + * @return CForumPost + */ + public function setStatus($status) + { + $this->status = $status; + + return $this; + } + }