Set post_parent_id field in c_forum_post to null instead of 0

pull/2487/head
Angel Fernando Quiroz Campos 10 years ago
parent 7bd44d2fac
commit 00ff6fe1d2
  1. 60
      main/forum/forumfunction.inc.php
  2. 27
      main/webservices/cm_webservice_forum.php

@ -875,32 +875,36 @@ function deleteForumCategoryThread($content, $id)
*/ */
function delete_post($post_id) function delete_post($post_id)
{ {
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$post_id = intval($post_id); $post_id = intval($post_id);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$em = Database::getManager();
// Get parent_post_id of deleted post. $post = $em
$tab_post_info = get_post_information($post_id); ->getRepository('ChamiloCourseBundle:CForumPost')
->findOneBy(['cId' => $course_id, 'postId' => $post_id]);
if ($tab_post_info) { if ($post) {
$post_parent_id_of_deleted_post = intval($tab_post_info['post_parent_id']); $em
$thread_id_of_deleted_post = $tab_post_info['thread_id']; ->createQuery('
$forum_if_of_deleted_post = $tab_post_info['forum_id']; UPDATE ChamiloCourseBundle:CForumPost p
$sql = "UPDATE $table_posts SET p.postParentId = :parent_of_deleted_post
SET post_parent_id=$post_parent_id_of_deleted_post
WHERE WHERE
c_id = $course_id AND p.cId = :course AND
post_parent_id=$post_id AND p.postParentId = :post AND
thread_id=$thread_id_of_deleted_post AND p.threadId = :thread_of_deleted_post AND
forum_id=$forum_if_of_deleted_post"; p.forumId = :forum_of_deleted_post
')
Database::query($sql); ->execute([
'parent_of_deleted_post' => $post->getPostParentId(),
// Note: This has to be a recursive function that deletes all of the posts in this block. 'course' => $course_id,
$sql = "DELETE FROM $table_posts 'post' => $post->getPostId(),
WHERE c_id = $course_id AND post_id = ".intval($post_id).""; 'thread_of_deleted_post' => $post->getThreadId(),
Database::query($sql); 'forum_of_deleted_post' => $post->getForumId()
]);
$em->remove($post);
$em->flush();
// Delete attachment file about this post id. // Delete attachment file about this post id.
delete_attachment($post_id); delete_attachment($post_id);
@ -1867,7 +1871,7 @@ function getThreadInfo($threadId, $cId)
* *
* @return array containing all the information about the posts of a given thread * @return array containing all the information about the posts of a given thread
*/ */
function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1) function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postId = null, $depth = -1)
{ {
$list = []; $list = [];
@ -2498,7 +2502,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
'poster_name' => isset($values['poster_name']) ? $values['poster_name'] : '', 'poster_name' => isset($values['poster_name']) ? $values['poster_name'] : '',
'post_date' => $post_date, 'post_date' => $post_date,
'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : '', 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : '',
'post_parent_id' => 0, 'post_parent_id' => null,
'visible' => $visible, 'visible' => $visible,
]; ];
$last_post_id = Database::insert($table_posts, $params); $last_post_id = Database::insert($table_posts, $params);
@ -3379,7 +3383,7 @@ function show_edit_post_form(
$form->addElement('hidden', 'thread_id', $current_thread['thread_id']); $form->addElement('hidden', 'thread_id', $current_thread['thread_id']);
$form->addElement('hidden', 'id_attach', $id_attach); $form->addElement('hidden', 'id_attach', $id_attach);
if ($current_post['post_parent_id'] == 0) { if (empty($current_post['post_parent_id'])) {
$form->addElement('hidden', 'is_first_post_of_thread', '1'); $form->addElement('hidden', 'is_first_post_of_thread', '1');
} }
@ -3481,7 +3485,7 @@ function show_edit_post_form(
if ($forum_setting['allow_sticky'] && if ($forum_setting['allow_sticky'] &&
api_is_allowed_to_edit(null, true) && api_is_allowed_to_edit(null, true) &&
$current_post['post_parent_id'] == 0 empty($current_post['post_parent_id'])
) { ) {
// The sticky checkbox only appears when it is the first post of a thread. // The sticky checkbox only appears when it is the first post of a thread.
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost')); $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
@ -4264,12 +4268,12 @@ function store_move_post($values)
); );
// Moving the post to the newly created thread. // Moving the post to the newly created thread.
$sql = "UPDATE $table_posts SET thread_id='".intval($new_thread_id)."', post_parent_id='0' $sql = "UPDATE $table_posts SET thread_id='".intval($new_thread_id)."', post_parent_id = NULL
WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'"; WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
Database::query($sql); Database::query($sql);
// Resetting the parent_id of the thread to 0 for all those who had this moved post as parent. // Resetting the parent_id of the thread to 0 for all those who had this moved post as parent.
$sql = "UPDATE $table_posts SET post_parent_id='0' $sql = "UPDATE $table_posts SET post_parent_id = NULL
WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'"; WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
Database::query($sql); Database::query($sql);
@ -4328,12 +4332,12 @@ function store_move_post($values)
Database::query($sql); Database::query($sql);
// moving to the chosen thread // moving to the chosen thread
$sql = "UPDATE $table_posts SET thread_id='".intval($_POST['thread'])."', post_parent_id='0' $sql = "UPDATE $table_posts SET thread_id='".intval($_POST['thread'])."', post_parent_id = NULL
WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'"; WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
Database::query($sql); Database::query($sql);
// resetting the parent_id of the thread to 0 for all those who had this moved post as parent // resetting the parent_id of the thread to 0 for all those who had this moved post as parent
$sql = "UPDATE $table_posts SET post_parent_id='0' $sql = "UPDATE $table_posts SET post_parent_id = NULL
WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'"; WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
Database::query($sql); Database::query($sql);

@ -234,6 +234,7 @@ class WSCMForum extends WSCM
{ {
if($this->verifyUserPass($username, $password) == "valid") if($this->verifyUserPass($username, $password) == "valid")
{ {
$em = Database::getManager();
$course_db = CourseManager::get_course_information($course_code); $course_db = CourseManager::get_course_information($course_code);
$user_id = UserManager::get_user_id_from_username($username); $user_id = UserManager::get_user_id_from_username($username);
@ -251,19 +252,23 @@ class WSCMForum extends WSCM
$title = htmlentities($title); $title = htmlentities($title);
$content = htmlentities($content); $content = htmlentities($content);
$sql="INSERT INTO $table_posts (post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible) $postDate = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
VALUES ('".Database::escape_string($title)."',
'".Database::escape_string(isset($content) ? (api_html_entity_decode($content)) : null)."',
'".Database::escape_string($thread_id)."',
'".Database::escape_string($forum_id)."',
'".Database::escape_string($user_id)."',
'".Database::escape_string($post_date)."',
'".Database::escape_string(isset($post_notification)?$post_notification:null)."',
'".Database::escape_string(isset($my_post)?$my_post:null)."',
'".Database::escape_string($visible)."')";
$post = new \Chamilo\CourseBundle\Entity\CForumPost();
$post
->setPostTitle($title)
->setPostText(isset($content) ? (api_html_entity_decode($content)) : null)
->setThreadId($thread_id)
->setForumId($forum_id)
->setPosterId($user_id)
->setPostDate($postDate)
->setPostNotification(isset($post_notification) ? $post_notification : null)
->setPostParentId(isset($my_post) ? $my_post : null)
->setVisible($visible);
$em->persist($post);
$em->flush();
$result=Database::query($sql);
return "Post enviado!"; return "Post enviado!";
//return $sql; //return $sql;

Loading…
Cancel
Save