Change moderated workflow see BT#10894

If forum is moderated and user are able to edit posts:

- Student send post (status = "waiting moderation")
- Teacher rejects the post
- Student can see his post and can edit the post.
After editing the post changes to "waiting moderation" (automatically)
- Teacher accepts the post.
- Student can't change the published post.
pull/2487/head
jmontoyaa 8 years ago
parent ab40fa3597
commit ad0f69061f
  1. 43
      main/forum/forumfunction.inc.php
  2. 12
      main/forum/viewthread.php
  3. 35
      main/forum/viewthread_flat.inc.php
  4. 14
      main/forum/viewthread_nested.inc.php

@ -1985,13 +1985,13 @@ function getPosts(
->addCriteria($criteria)
->addOrderBy('p.postId', $orderDirection);
if ($filterModerated && $forumInfo['moderated'] == 1) {
if (!api_is_allowed_to_edit(false, true)) {
$userId = api_get_user_id();
$qb->andWhere(
"p.status = 1 OR
(p.status = ".CForumPost::STATUS_WAITING_MODERATION." AND p.posterId = $userId) OR
(p.status = ".CForumPost::STATUS_REJECTED." AND p.posterId = $userId) OR
(p.status IS NULL AND p.posterId = $userId)
"
);
@ -3564,7 +3564,7 @@ function show_edit_post_form(
$form->addElement('html', '</div>');
}
if ($current_forum['moderated']) {
if ($current_forum['moderated'] && api_is_allowed_to_edit(null, true)) {
$group = array();
$group[] = $form->createElement('radio', 'status', null, get_lang('Validated'), 1);
$group[] = $form->createElement('radio', 'status', null, get_lang('WaitingModeration'), 2);
@ -3687,19 +3687,27 @@ function store_edit_post($forumInfo, $values)
}
$status = '';
$updateStatus = false;
if ($forumInfo['moderated']) {
$status = $values['status']['status'];
if (api_is_allowed_to_edit(null, true)) {
$status = $values['status']['status'];
$updateStatus = true;
} else {
$status = CForumPost::STATUS_WAITING_MODERATION;
$updateStatus = true;
}
}
// Update the post_title and the post_text.
$params = [
'status' => $status,
'post_title' => $values['post_title'],
'post_text' => $values['post_text'],
'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : '',
];
if ($updateStatus) {
$params['status'] = $status;
}
$where = ['c_id = ? AND post_id = ?' => [$course_id, $values['post_id']]];
Database::update($table_posts, $params, $where);
// Update attached files
@ -5968,8 +5976,13 @@ function getPostStatus($current_forum, $row, $addWrapper = true)
$row['status'] = empty($row['status']) ? 2 : $row['status'];
$addUrl = false;
$showStatus = false;
if (api_is_allowed_to_edit(false, true)) {
$addUrl = true;
} else {
if ($row['user_id'] == api_get_user_id()) {
$showStatus = true;
}
}
$label = '';
@ -6002,10 +6015,12 @@ function getPostStatus($current_forum, $row, $addWrapper = true)
['class' => 'change_post_status']
);
} else {
$statusIcon .= Display::label(
Display::returnFontAwesomeIcon($icon).$label,
$buttonType
);
if ($showStatus) {
$statusIcon .= Display::label(
Display::returnFontAwesomeIcon($icon).$label,
$buttonType
);
}
}
if ($addWrapper) {
@ -6059,9 +6074,15 @@ function postIsEditableByStudent($forum, $post)
if (is_null($post['status'])) {
return true;
} else {
return $post['status'] == CForumPost::STATUS_WAITING_MODERATION;
return in_array($post['status'],
[
CForumPost::STATUS_WAITING_MODERATION,
CForumPost::STATUS_REJECTED,
]
);
}
} else {
return true;
}
}
}

@ -125,8 +125,7 @@ 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) &&
if (!api_is_allowed_to_edit(false, true) &&
($current_forum['visibility'] == 0 || $current_thread['visibility'] == 0)
) {
api_not_allowed(false);
@ -134,8 +133,7 @@ if (
/* Actions */
$my_action = isset($_GET['action']) ? $_GET['action'] : '';
if (
$my_action == 'delete' &&
if ($my_action == 'delete' &&
isset($_GET['content']) &&
isset($_GET['id']) &&
(api_is_allowed_to_edit(false, true) ||
@ -181,8 +179,7 @@ if ($my_message != 'PostDeletedSpecial') {
// The reply to thread link should only appear when the forum_category is
// 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 &&
if (($current_forum_category &&
$current_forum_category['locked'] == 0) &&
$current_forum['locked'] == 0 &&
$current_thread['locked'] == 0 ||
@ -199,8 +196,7 @@ if ($my_message != 'PostDeletedSpecial') {
. '</a>';
}
// new thread link
if (
(
if ((
api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) ||

@ -30,17 +30,14 @@ if (isset($current_thread['thread_id'])) {
$increment = 0;
$clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']);
$locked = api_resource_is_locked_by_gradebook(
$clean_thread_id,
LINK_FORUM_THREAD
);
$closedPost = null;
if (!empty($rows)) {
$postCount = count($rows);
foreach ($rows as $row) {
if ($row['user_id'] == '0') {
$name = prepare4display($row['poster_name']);
@ -141,13 +138,13 @@ if (isset($current_thread['thread_id'])) {
if ($origin != 'learnpath') {
$html .= Display::tag(
'p',
api_convert_and_format_date($row['post_date']),
Display::dateToStringAgoAndLongDate($row['post_date']),
array('class' => 'post-date')
);
} else {
$html .= Display::tag(
'p',
api_convert_and_format_date($row['post_date'], DATE_TIME_FORMAT_SHORT),
Display::dateToStringAgoAndLongDate($row['post_date']),
array('class' => 'text-muted')
);
}
@ -157,8 +154,6 @@ if (isset($current_thread['thread_id'])) {
$id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
$iconEdit = '';
$statusIcon = '';
// The user who posted it can edit his thread only if the course admin allowed
// this in the properties of the forum
// The course admin him/herself can do this off course always
@ -171,7 +166,7 @@ if (isset($current_thread['thread_id'])) {
)
) {
if (api_is_allowed_to_session_edit(false, true)) {
if ($locked == false) {
if ($locked == false && postIsEditableByStudent($current_forum, $row)) {
$iconEdit .= "<a href=\"editpost.php?" . api_get_cidreq() . "&forum=" . $clean_forum_id
. "&thread=" . $clean_thread_id . "&post=" . $row['post_id']
. "&edit=edition&id_attach=" . $id_attach . "\">"
@ -206,13 +201,13 @@ if (isset($current_thread['thread_id'])) {
}
}
if (
GroupManager::is_tutor_of_group($userId, $groupInfo) ||
(api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
)
$statusIcon = getPostStatus($current_forum, $row);
if (GroupManager::is_tutor_of_group($userId, $groupInfo) ||
(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'],
@ -245,9 +240,12 @@ if (isset($current_thread['thread_id'])) {
}
$userCanEdit = $current_thread['thread_peer_qualify'] == 1 && $row['poster_id'] != $userId;
/*if ($row['poster_id'] != $userId && $current_forum['moderated'] == 1 && $row['status']) {
}*/
if (api_is_allowed_to_edit(null, true)) {
$userCanEdit = true;
}
if ($increment > 0 && $locked == false && $userCanEdit) {
$iconEdit .= "<a href=\"forumqualify.php?" . api_get_cidreq() . "&forum=" . $my_forum_id
. "&thread=" . $clean_thread_id . "&action=list&post=" . $row['post_id']
@ -257,8 +255,13 @@ if (isset($current_thread['thread_id'])) {
. "</a> ";
}
}
if ($iconEdit != '') {
$html .= '<div class="tools-icons">' . $iconEdit . $statusIcon.'</div>';
if (!empty($iconEdit)) {
$html .= '<div class="tools-icons">'.$iconEdit.' '.$statusIcon.'</div>';
} else {
if (!empty(strip_tags($statusIcon))) {
$html .= '<div class="tools-icons">'.$statusIcon.'</div>';
}
}
$html .= $closedPost;
$html .= '</div>';

@ -23,7 +23,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($current_forum, $_GET['thread'], $sortDirection, true);
$posts = getPosts($current_forum, $_GET['thread'], $sortDirection, true);
$count = 0;
$clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']);
@ -37,7 +37,7 @@ $postCount = 1;
$allowUserImageForum = api_get_course_setting('allow_user_image_forum');
foreach ($rows as $post) {
foreach ($posts as $post) {
// The style depends on the status of the message: approved or not.
if ($post['visible'] == '0') {
$titleclass = 'forum_message_post_title_2_be_approved';
@ -162,8 +162,7 @@ foreach ($rows as $post) {
}
}
if (
api_is_allowed_to_edit(false, true) &&
if (api_is_allowed_to_edit(false, true) &&
!(
api_is_course_coach() &&
$current_forum['session_id'] != $sessionId
@ -213,9 +212,12 @@ foreach ($rows as $post) {
}
$statusIcon = getPostStatus($current_forum, $post);
if ($iconEdit != '') {
if (!empty($iconEdit)) {
$html .= '<div class="tools-icons">'.$iconEdit.' '.$statusIcon.'</div>';
} else {
if (!empty(strip_tags($statusIcon))) {
$html .= '<div class="tools-icons">'.$statusIcon.'</div>';
}
}
$buttonReply = '';

Loading…
Cancel
Save