|
|
|
@ -960,8 +960,6 @@ function store_forum($values, $courseInfo = [], $returnId = false) |
|
|
|
|
|
|
|
|
|
$forumId = $forum->getIid(); |
|
|
|
|
if ($forumId > 0) { |
|
|
|
|
$sql = "UPDATE $table_forums SET forum_id = iid WHERE iid = $forumId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
$courseCode = $courseInfo['code']; |
|
|
|
|
$subscribe = (int) api_get_course_setting('subscribe_users_to_forum_notifications'); |
|
|
|
|
|
|
|
|
@ -1045,7 +1043,7 @@ function delete_post($post_id) |
|
|
|
|
/** @var CForumPost $post */ |
|
|
|
|
$post = $em |
|
|
|
|
->getRepository('ChamiloCourseBundle:CForumPost') |
|
|
|
|
->findOneBy(['cId' => $course_id, 'postId' => $post_id]); |
|
|
|
|
->findOneBy(['cId' => $course_id, 'iid' => $post_id]); |
|
|
|
|
|
|
|
|
|
if ($post) { |
|
|
|
|
$em |
|
|
|
@ -1061,7 +1059,7 @@ function delete_post($post_id) |
|
|
|
|
->execute([ |
|
|
|
|
'parent_of_deleted_post' => $post->getPostParentId(), |
|
|
|
|
'course' => $course_id, |
|
|
|
|
'post' => $post->getPostId(), |
|
|
|
|
'post' => $post->getIid(), |
|
|
|
|
'thread_of_deleted_post' => $post->getThread() ? $post->getThread()->getIid() : 0, |
|
|
|
|
'forum_of_deleted_post' => $post->getForum(), |
|
|
|
|
]); |
|
|
|
@ -1084,9 +1082,9 @@ function delete_post($post_id) |
|
|
|
|
$sql = "UPDATE $table_threads |
|
|
|
|
SET |
|
|
|
|
thread_replies = thread_replies - 1, |
|
|
|
|
thread_last_post = ".(int) ($last_post_of_thread['post_id']).", |
|
|
|
|
thread_last_post = ".(int) ($last_post_of_thread['iid']).", |
|
|
|
|
thread_date='".Database::escape_string($last_post_of_thread['post_date'])."' |
|
|
|
|
WHERE c_id = $course_id AND thread_id = ".(int) ($_GET['thread']); |
|
|
|
|
WHERE c_id = $course_id AND iid = ".(int) ($_GET['thread']); |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
return 'PostDeleted'; |
|
|
|
@ -1094,7 +1092,7 @@ function delete_post($post_id) |
|
|
|
|
if (!$last_post_of_thread) { |
|
|
|
|
// We deleted the very single post of the thread so we need to delete the entry in the thread table also. |
|
|
|
|
$sql = "DELETE FROM $table_threads |
|
|
|
|
WHERE c_id = $course_id AND thread_id = ".(int) ($_GET['thread']); |
|
|
|
|
WHERE c_id = $course_id AND iid = ".(int) ($_GET['thread']); |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
return 'PostDeletedSpecial'; |
|
|
|
@ -1124,9 +1122,9 @@ function check_if_last_post_of_thread($thread_id) |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
|
return Database::fetch_array($result); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1675,7 +1673,7 @@ function get_last_post_by_thread($course_id, $thread_id, $forum_id, $show_visibl |
|
|
|
|
$sql .= ' AND visible = 1 '; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sql .= ' ORDER BY post_id DESC LIMIT 1'; |
|
|
|
|
$sql .= ' ORDER BY iid DESC LIMIT 1'; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (Database::num_rows($result)) { |
|
|
|
|
return Database::fetch_array($result, 'ASSOC'); |
|
|
|
@ -1719,7 +1717,7 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ |
|
|
|
|
|
|
|
|
|
// First get the threads to make sure there is no inconsistency in the |
|
|
|
|
// database between forum and thread |
|
|
|
|
$sql = "SELECT thread_id FROM $table_threads |
|
|
|
|
$sql = "SELECT iid as thread_id FROM $table_threads |
|
|
|
|
WHERE |
|
|
|
|
forum_id = $forum_id AND |
|
|
|
|
c_id = $course_id AND |
|
|
|
@ -1736,7 +1734,7 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ |
|
|
|
|
$threadsList = implode(',', $threads); |
|
|
|
|
// Now get the posts that are linked to these threads |
|
|
|
|
$sql = "SELECT |
|
|
|
|
post.post_id, |
|
|
|
|
post.iid as post_id, |
|
|
|
|
post.forum_id, |
|
|
|
|
post.poster_id, |
|
|
|
|
post.poster_name, |
|
|
|
@ -1754,11 +1752,10 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ |
|
|
|
|
$table_item_property thread_properties, |
|
|
|
|
$table_item_property forum_properties |
|
|
|
|
WHERE |
|
|
|
|
post.forum_id = $forum_id |
|
|
|
|
AND post.thread_id IN ($threadsList) |
|
|
|
|
AND post.poster_id = users.user_id |
|
|
|
|
AND post.thread_id = thread_properties.ref |
|
|
|
|
AND thread_properties.tool='".TOOL_FORUM_THREAD."' |
|
|
|
|
post.forum_id = $forum_id AND |
|
|
|
|
post.thread_id IN ($threadsList) AND |
|
|
|
|
post.poster_id = users.id AND |
|
|
|
|
post.thread_id = thread_properties.ref AND thread_properties.tool='".TOOL_FORUM_THREAD."' |
|
|
|
|
AND post.forum_id=forum_properties.ref |
|
|
|
|
AND forum_properties.tool='".TOOL_FORUM."' |
|
|
|
|
AND post.c_id = $course_id AND |
|
|
|
@ -1920,11 +1917,12 @@ function getThreadInfo($threadId, $cId) |
|
|
|
|
{ |
|
|
|
|
$repo = Database::getManager()->getRepository('ChamiloCourseBundle:CForumThread'); |
|
|
|
|
/** @var CForumThread $forumThread */ |
|
|
|
|
$forumThread = $repo->findOneBy(['threadId' => $threadId, 'cId' => $cId]); |
|
|
|
|
$forumThread = $repo->findOneBy(['iid' => $threadId, 'cId' => $cId]); |
|
|
|
|
|
|
|
|
|
$thread = []; |
|
|
|
|
if ($forumThread) { |
|
|
|
|
$thread['threadId'] = $forumThread->getThreadId(); |
|
|
|
|
$thread['iid'] = $forumThread->getIid(); |
|
|
|
|
$thread['threadId'] = $forumThread->getIid(); |
|
|
|
|
$thread['threadTitle'] = $forumThread->getThreadTitle(); |
|
|
|
|
$thread['forumId'] = $forumThread->getForum() ? $forumThread->getForum()->getIid() : 0; |
|
|
|
|
$thread['sessionId'] = $forumThread->getSessionId(); |
|
|
|
@ -1999,7 +1997,7 @@ function getPosts( |
|
|
|
|
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p'); |
|
|
|
|
$qb->select('p') |
|
|
|
|
->addCriteria($criteria) |
|
|
|
|
->addOrderBy('p.postId', $orderDirection); |
|
|
|
|
->addOrderBy('p.iid', $orderDirection); |
|
|
|
|
|
|
|
|
|
if ($filterModerated && 1 == $forum->isModerated()) { |
|
|
|
|
if (!api_is_allowed_to_edit(false, true)) { |
|
|
|
@ -2023,7 +2021,7 @@ function getPosts( |
|
|
|
|
$postInfo = [ |
|
|
|
|
'iid' => $post->getIid(), |
|
|
|
|
'c_id' => $post->getCId(), |
|
|
|
|
'post_id' => $post->getPostId(), |
|
|
|
|
'post_id' => $post->getIid(), |
|
|
|
|
'post_title' => $post->getPostTitle(), |
|
|
|
|
'post_text' => $post->getPostText(), |
|
|
|
|
'thread_id' => $post->getThread() ? $post->getThread()->getIid() : 0, |
|
|
|
@ -2043,7 +2041,7 @@ function getPosts( |
|
|
|
|
if (!empty($posterId)) { |
|
|
|
|
$user = api_get_user_entity($posterId); |
|
|
|
|
if ($user) { |
|
|
|
|
$postInfo['user_id'] = $user->getUserId(); |
|
|
|
|
$postInfo['user_id'] = $user->getId(); |
|
|
|
|
$postInfo['username'] = $user->getUsername(); |
|
|
|
|
$postInfo['username_canonical'] = $user->getUsernameCanonical(); |
|
|
|
|
$postInfo['lastname'] = $user->getLastname(); |
|
|
|
@ -2064,7 +2062,7 @@ function getPosts( |
|
|
|
|
$threadId, |
|
|
|
|
$orderDirection, |
|
|
|
|
$recursive, |
|
|
|
|
$post->getPostId(), |
|
|
|
|
$post->getIid(), |
|
|
|
|
$depth |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
@ -2368,7 +2366,7 @@ function updateThread($values) |
|
|
|
|
'thread_title' => $values['thread_title'], |
|
|
|
|
'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : 0, |
|
|
|
|
]; |
|
|
|
|
$where = ['c_id = ? AND thread_id = ?' => [$courseId, $values['thread_id']]]; |
|
|
|
|
$where = ['c_id = ? AND iid = ?' => [$courseId, $values['thread_id']]]; |
|
|
|
|
Database::update($threadTable, $params, $where); |
|
|
|
|
|
|
|
|
|
$id = $values['thread_id']; |
|
|
|
@ -2382,8 +2380,7 @@ function updateThread($values) |
|
|
|
|
$gradebookLink = null; |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
if (!empty($linkInfo) && isset($linkInfo['id'])) { |
|
|
|
|
$linkId = $linkInfo['id']; |
|
|
|
|
$gradebookLink = $em->getRepository('ChamiloCoreBundle:GradebookLink')->find($linkId); |
|
|
|
|
$gradebookLink = $em->getRepository('ChamiloCoreBundle:GradebookLink')->find($linkInfo['id']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// values 1 or 0 |
|
|
|
@ -2430,7 +2427,7 @@ function updateThread($values) |
|
|
|
|
'thread_weight' => 0, |
|
|
|
|
'thread_peer_qualify' => 0, |
|
|
|
|
]; |
|
|
|
|
$where = ['c_id = ? AND thread_id = ?' => [$courseId, $values['thread_id']]]; |
|
|
|
|
$where = ['c_id = ? AND iid = ?' => [$courseId, $values['thread_id']]]; |
|
|
|
|
Database::update($threadTable, $params, $where); |
|
|
|
|
|
|
|
|
|
if (!empty($linkInfo)) { |
|
|
|
@ -2540,10 +2537,6 @@ function store_thread( |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$thread->setThreadId($thread->getIid()); |
|
|
|
|
$em->persist($thread); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
/*api_item_property_update( |
|
|
|
|
$courseInfo, |
|
|
|
|
TOOL_FORUM_THREAD, |
|
|
|
@ -2641,19 +2634,13 @@ function store_thread( |
|
|
|
|
]; |
|
|
|
|
Event::registerLog($logInfo); |
|
|
|
|
|
|
|
|
|
if ($postId) { |
|
|
|
|
$post->setPostId($postId); |
|
|
|
|
$em->persist($post); |
|
|
|
|
$em->flush(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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 = '".$postId."' |
|
|
|
|
WHERE |
|
|
|
|
c_id = $course_id AND |
|
|
|
|
thread_id='".$thread->getIid()."'"; |
|
|
|
|
iid = '".$thread->getIid()."'"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
$message = get_lang('The new thread has been added'); |
|
|
|
|
|
|
|
|
@ -3300,11 +3287,6 @@ function saveThreadScore( |
|
|
|
|
VALUES (".$course_id.", '".$user_id."','".$thread_id."',".(float) $thread_qualify.", '".$currentUserId."','".$qualify_time."','".$session_id."')"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
$insertId = Database::insert_id(); |
|
|
|
|
if ($insertId) { |
|
|
|
|
$sql = "UPDATE $table_threads_qualify SET id = iid |
|
|
|
|
WHERE iid = $insertId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 'insert'; |
|
|
|
|
} else { |
|
|
|
@ -3485,13 +3467,6 @@ function saveThreadScoreHistory( |
|
|
|
|
$sql = "INSERT INTO $table_threads_qualify_log (c_id, user_id, thread_id, qualify, qualify_user_id,qualify_time,session_id) |
|
|
|
|
VALUES(".$course_id.", '".$user_id."','".$thread_id."',".(float) $row[0].", '".$qualify_user_id."','".$row[1]."','')"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
$insertId = Database::insert_id(); |
|
|
|
|
if ($insertId) { |
|
|
|
|
$sql = "UPDATE $table_threads_qualify_log SET id = iid |
|
|
|
|
WHERE iid = $insertId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -4033,7 +4008,7 @@ function increase_thread_view($thread_id) |
|
|
|
|
SET thread_views = thread_views + 1 |
|
|
|
|
WHERE |
|
|
|
|
c_id = $course_id AND |
|
|
|
|
thread_id = '".(int) $thread_id."'"; |
|
|
|
|
iid = '".(int) $thread_id."'"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -4058,7 +4033,7 @@ function updateThreadInfo($threadId, $lastPostId, $post_date) |
|
|
|
|
thread_date = '".Database::escape_string($post_date)."' |
|
|
|
|
WHERE |
|
|
|
|
c_id = $course_id AND |
|
|
|
|
thread_id='".Database::escape_string($threadId)."'"; // this needs to be cleaned first |
|
|
|
|
iid ='".Database::escape_string($threadId)."'"; // this needs to be cleaned first |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -4110,7 +4085,7 @@ function get_whats_new() |
|
|
|
|
post_date > '".Database::escape_string($lastForumAccess)."'"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
while ($row = Database::fetch_array($result)) { |
|
|
|
|
$postInfo[$row['forum_id']][$row['thread_id']][$row['post_id']] = $row['post_date']; |
|
|
|
|
$postInfo[$row['forum_id']][$row['thread_id']][$row['iid']] = $row['post_date']; |
|
|
|
|
} |
|
|
|
|
Session::write('whatsnew_post_info', $postInfo); |
|
|
|
|
} |
|
|
|
@ -4587,11 +4562,11 @@ function store_move_post($values) |
|
|
|
|
// Resetting the last post of the old thread and decreasing the number of replies and the thread. |
|
|
|
|
$sql = "SELECT * FROM $table_posts |
|
|
|
|
WHERE c_id = $course_id AND thread_id='".$threadId."' |
|
|
|
|
ORDER BY post_id DESC"; |
|
|
|
|
ORDER BY iid DESC"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$row = Database::fetch_array($result); |
|
|
|
|
$sql = "UPDATE $table_threads SET |
|
|
|
|
thread_last_post='".$row['post_id']."', |
|
|
|
|
thread_last_post='".$row['iid']."', |
|
|
|
|
thread_replies=thread_replies-1 |
|
|
|
|
WHERE |
|
|
|
|
c_id = $course_id AND |
|
|
|
@ -5523,7 +5498,7 @@ function get_notifications($content, $id) |
|
|
|
|
|
|
|
|
|
$id = (int) $id; |
|
|
|
|
|
|
|
|
|
$sql = "SELECT user.id as user_id, user.firstname, user.lastname, user.email, user.user_id user |
|
|
|
|
$sql = "SELECT user.id as user_id, user.firstname, user.lastname, user.email, user.id user |
|
|
|
|
FROM $table_users user, $table_notification notification |
|
|
|
|
WHERE |
|
|
|
|
notification.c_id = $course_id AND user.active = 1 AND |
|
|
|
@ -6288,12 +6263,12 @@ function getAttachmentIdsByPostId($postId, $courseId = 0) |
|
|
|
|
} |
|
|
|
|
if ($courseId > 0) { |
|
|
|
|
$forumAttachmentTable = Database::get_course_table(TABLE_FORUM_ATTACHMENT); |
|
|
|
|
$sql = "SELECT id FROM $forumAttachmentTable |
|
|
|
|
$sql = "SELECT iid FROM $forumAttachmentTable |
|
|
|
|
WHERE c_id = $courseId AND post_id = $postId"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (false !== $result && Database::num_rows($result) > 0) { |
|
|
|
|
while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
|
|
|
$array[] = $row['id']; |
|
|
|
|
$array[] = $row['iid']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|