Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

jmontoyaa 8 years ago
parent
commit
85d841a472

+ 3 - 7
main/exercice/fill_blanks.class.php

@@ -149,15 +149,11 @@ class FillBlanks extends Question
         if (isset($listAnswersInfo) && count($listAnswersInfo["tabweighting"]) > 0) {
 
             foreach ($listAnswersInfo["tabweighting"] as $i => $weighting) {
-                if (!empty($i)) {
-                    echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
-                }
+                echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
             }
             foreach ($listAnswersInfo["tabinputsize"] as $i => $sizeOfInput) {
-                if (!empty($i)) {
-                    echo 'document.getElementById("sizeofinput['.$i.']").value = "'.$sizeOfInput.'";';
-                    echo '$("#samplesize\\\['.$i.'\\\]").width('.$sizeOfInput.');';
-                }
+                echo 'document.getElementById("sizeofinput['.$i.']").value = "'.$sizeOfInput.'";';
+                echo '$("#samplesize\\\['.$i.'\\\]").width('.$sizeOfInput.');';
             }
         }
 

+ 34 - 30
main/forum/forumfunction.inc.php

@@ -891,32 +891,36 @@ function deleteForumCategoryThread($content, $id)
  */
 function delete_post($post_id)
 {
-    $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
     $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
     $post_id = intval($post_id);
     $course_id = api_get_course_int_id();
+    $em = Database::getManager();
 
-    // Get parent_post_id of deleted post.
-    $tab_post_info = get_post_information($post_id);
+    $post = $em
+        ->getRepository('ChamiloCourseBundle:CForumPost')
+        ->findOneBy(['cId' => $course_id, 'postId' => $post_id]);
 
-    if ($tab_post_info) {
-        $post_parent_id_of_deleted_post = intval($tab_post_info['post_parent_id']);
-        $thread_id_of_deleted_post = $tab_post_info['thread_id'];
-        $forum_if_of_deleted_post = $tab_post_info['forum_id'];
-        $sql = "UPDATE $table_posts
-                SET post_parent_id=$post_parent_id_of_deleted_post
+    if ($post) {
+        $em
+            ->createQuery('
+                UPDATE ChamiloCourseBundle:CForumPost p
+                SET p.postParentId = :parent_of_deleted_post
                 WHERE
-                    c_id = $course_id AND
-                    post_parent_id=$post_id AND
-                    thread_id=$thread_id_of_deleted_post AND
-                    forum_id=$forum_if_of_deleted_post";
-
-        Database::query($sql);
-
-        // Note: This has to be a recursive function that deletes all of the posts in this block.
-        $sql = "DELETE FROM $table_posts
-                WHERE c_id = $course_id AND post_id = ".intval($post_id)."";
-        Database::query($sql);
+                    p.cId = :course AND
+                    p.postParentId = :post AND
+                    p.threadId = :thread_of_deleted_post AND
+                    p.forumId = :forum_of_deleted_post
+            ')
+            ->execute([
+                'parent_of_deleted_post' => $post->getPostParentId(),
+                'course' => $course_id,
+                'post' => $post->getPostId(),
+                'thread_of_deleted_post' => $post->getThreadId(),
+                'forum_of_deleted_post' => $post->getForumId()
+            ]);
+
+        $em->remove($post);
+        $em->flush();
 
         // Delete attachment file about this post id.
         delete_attachment($post_id);
@@ -1884,7 +1888,7 @@ function getThreadInfo($threadId, $cId)
  *
  * @return array containing all the information about the posts of a given thread
  */
-function getPosts($forumInfo, $threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1)
+function getPosts($forumInfo, $threadId, $orderDirection = 'ASC', $recursive = false, $postId = null, $depth = -1)
 {
     $list = [];
 
@@ -2526,7 +2530,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
             'poster_name' => isset($values['poster_name']) ? $values['poster_name'] : '',
             'post_date' => $post_date,
             'post_notification' => isset($values['post_notification']) ? (int) $values['post_notification'] : 0,
-            'post_parent_id' => 0,
+            'post_parent_id' => null,
             'visible' => $visible,
             'post_id' => 0
         ];
@@ -2801,6 +2805,7 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
         'post_text',
         get_lang('Text'),
         true,
+        false,
         api_is_allowed_to_edit(null, true) ? array(
             'ToolbarSet' => 'Forum',
             'Width' => '100%',
@@ -2967,8 +2972,7 @@ function show_add_post_form($current_forum, $forum_setting, $action = '', $id =
             }
             Security::clear_token();
 
-            // Add new thread in table forum_thread.
-            store_thread($current_forum, $values);
+            return $values;
         }
     } else {
         $token = Security::get_token();
@@ -3415,7 +3419,7 @@ function show_edit_post_form(
     $form->addElement('hidden', 'thread_id', $current_thread['thread_id']);
     $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');
     }
 
@@ -3531,7 +3535,7 @@ function show_edit_post_form(
 
     if ($forum_setting['allow_sticky'] &&
         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.
         $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
@@ -4321,12 +4325,12 @@ function store_move_post($values)
         );
 
         // 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'])."'";
         Database::query($sql);
 
         // 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'])."'";
         Database::query($sql);
 
@@ -4385,12 +4389,12 @@ function store_move_post($values)
         Database::query($sql);
 
         // 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'])."'";
         Database::query($sql);
 
         // 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'])."'";
         Database::query($sql);
 

+ 6 - 1
main/forum/newthread.php

@@ -168,7 +168,7 @@ echo '</div>';
 // Set forum attachment data into $_SESSION
 getAttachedFiles($current_forum['forum_id'], 0, 0);
 
-show_add_post_form(
+$values = show_add_post_form(
     $current_forum,
     $forum_setting,
     'newthread',
@@ -176,6 +176,11 @@ show_add_post_form(
     isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null
 );
 
+if (!empty($values) && isset($values['SubmitPost'])) {
+    // Add new thread in table forum_thread.
+    store_thread($current_forum, $values);
+}
+
 if (isset($origin) && $origin == 'learnpath') {
     Display::display_reduced_footer();
 } else {

+ 16 - 11
main/webservices/cm_webservice_forum.php

@@ -234,6 +234,7 @@ class WSCMForum extends WSCM
     {
         if($this->verifyUserPass($username, $password) == "valid")
         {
+            $em = Database::getManager();
             $course_db = CourseManager::get_course_information($course_code);
 
             $user_id = UserManager::get_user_id_from_username($username);
@@ -251,19 +252,23 @@ class WSCMForum extends WSCM
             $title = htmlentities($title);
             $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)
-                            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)."')";
+            $postDate = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
 
+            $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 $sql;
 

+ 18 - 2
tests/features/forum.feature

@@ -23,9 +23,25 @@ Feature: Forum tool
     Then I should see "The forum has been added"
 
   Scenario: Create a forum thread
-    Given I am on "/main/forum/newthread.php?forum=5"
+    Given I am on "/main/forum/newthread.php?forum=1"
     When I fill in the following:
       | post_title | Thread One                                     |
       | post_text  | This is a the first thread in a forum for test |
     And I press "SubmitPost"
-    Then I should see "The new thread has been added"
+    Then I should see "The new thread has been added"
+
+  Scenario: Reply to forum message
+    Given I am on "/main/forum/reply.php?forum=1&thread=1&post=1&action=replymessage"
+    When I fill in the following:
+      | post_text | This is a reply to the first message for test |
+    And I press "SubmitPost"
+    Then I should see "The reply has been added"
+
+  Scenario: Delete a forum message
+    Given I am on "/main/forum/viewthread.php?forum=1&thread=1&action=delete&content=post&id=2"
+    Then I should see "Post has been deleted"
+
+  Scenario: Quote a forum message
+    Given I am on "/main/forum/reply.php?forum=1&thread=1&post=1&action=quote"
+    When I press "SubmitPost"
+    Then I should see "The reply has been added"