Prechádzať zdrojové kódy

Fix "thread" import in chamilo format see BT#10885

jmontoyaa 7 rokov pred
rodič
commit
d613095de7

+ 57 - 10
main/lp/learnpath.class.php

@@ -13144,9 +13144,56 @@ EOD;
             );
         }
 
+        require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
+
+        /*if (!empty($itemList['thread'])) {
+            $postList = [];
+            foreach ($itemList['thread'] as $postId) {
+                $post = get_post_information($postId);
+                if ($post) {
+                    if (!isset($itemList['forum'])) {
+                        $itemList['forum'] = [];
+                    }
+                    $itemList['forum'][] = $post['forum_id'];
+                    $postList[] = $postId;
+                }
+            }
+
+            if (!empty($postList)) {
+                $courseBuilder->build_forum_posts(
+                    $this->get_course_int_id(),
+                    null,
+                    null,
+                    $postList
+                );
+            }
+        }*/
+
+        if (!empty($itemList['thread'])) {
+            $threadList = [];
+            $em = Database::getManager();
+            $repo = $em->getRepository('ChamiloCourseBundle:CForumThread');
+            foreach ($itemList['thread'] as $threadId) {
+                /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */
+                $thread = $repo->find($threadId);
+                if ($thread) {
+                    $itemList['forum'][] = $thread->getForumId();
+                    $threadList[] = $thread->getIid();
+                }
+            }
+
+            if (!empty($threadList)) {
+                $courseBuilder->build_forum_topics(
+                    api_get_session_id(),
+                    $this->get_course_int_id(),
+                    null,
+                    $threadList
+                );
+            }
+        }
+
         $forumCategoryList = [];
         if (isset($itemList['forum'])) {
-            require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
             foreach ($itemList['forum'] as $forumId) {
                 $forumInfo = get_forums($forumId);
                 $forumCategoryList[] = $forumInfo['forum_category'];
@@ -13162,15 +13209,6 @@ EOD;
             );
         }
 
-        if (!empty($itemList['student_publication'])) {
-            $courseBuilder->build_works(
-                api_get_session_id(),
-                $this->get_course_int_id(),
-                true,
-                $itemList['student_publication']
-            );
-        }
-
         if (!empty($itemList['forum'])) {
             $courseBuilder->build_forums(
                 api_get_session_id(),
@@ -13189,6 +13227,15 @@ EOD;
             );
         }
 
+        if (!empty($itemList['student_publication'])) {
+            $courseBuilder->build_works(
+                api_get_session_id(),
+                $this->get_course_int_id(),
+                true,
+                $itemList['student_publication']
+            );
+        }
+
         $courseBuilder->build_learnpaths(
             api_get_session_id(),
             $this->get_course_int_id(),

+ 22 - 7
src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php

@@ -356,6 +356,7 @@ class CourseBuilder
 
         $idCondition = '';
         if (!empty($idList)) {
+            $idList = array_unique($idList);
             $idList = array_map('intval', $idList);
             $idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
         }
@@ -393,6 +394,7 @@ class CourseBuilder
 
         $idCondition = '';
         if (!empty($idList)) {
+            $idList = array_unique($idList);
             $idList = array_map('intval', $idList);
             $idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
         }
@@ -414,13 +416,13 @@ class CourseBuilder
      * @param int   $session_id      Internal session ID
      * @param int   $courseId        Internal course ID
      * @param bool  $withBaseContent Whether to include content from the course without session or not
-     * @param array $id_list         If you want to restrict the structure to only the given IDs
+     * @param array $idList          If you want to restrict the structure to only the given IDs
      */
     public function build_forum_topics(
         $session_id = 0,
         $courseId = 0,
         $withBaseContent = false,
-        $id_list = []
+        $idList = []
     ) {
         $table = Database::get_course_table(TABLE_FORUM_THREAD);
 
@@ -430,15 +432,22 @@ class CourseBuilder
             $withBaseContent
         );
 
+        $idCondition = '';
+        if (!empty($idList)) {
+            $idList = array_map('intval', $idList);
+            $idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
+        }
+
         $sql = "SELECT * FROM $table WHERE c_id = $courseId
                 $sessionCondition
+                $idCondition
                 ORDER BY thread_title ";
         $result = Database::query($sql);
 
         while ($obj = Database::fetch_object($result)) {
-            $forum_topic = new ForumTopic($obj);
-            $this->course->add_resource($forum_topic);
-            $this->build_forum_posts($courseId, $obj->thread_id, $obj->forum_id, true);
+            $forumTopic = new ForumTopic($obj);
+            $this->course->add_resource($forumTopic);
+            $this->build_forum_posts($courseId, $obj->thread_id, $obj->forum_id);
         }
     }
 
@@ -449,13 +458,13 @@ class CourseBuilder
      * @param int  $courseId        Internal course ID
      * @param int  $thread_id       Internal thread ID
      * @param int  $forum_id        Internal forum ID
-     * @param bool $only_first_post Whether to only copy the first post or not
+     * @param array $idList
      */
     public function build_forum_posts(
         $courseId = 0,
         $thread_id = null,
         $forum_id = null,
-        $only_first_post = false
+        $idList = []
     ) {
         $table = Database::get_course_table(TABLE_FORUM_POST);
         $sql = "SELECT * FROM $table WHERE c_id = $courseId ";
@@ -464,6 +473,12 @@ class CourseBuilder
             $thread_id = intval($thread_id);
             $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
         }
+
+        if (!empty($idList)) {
+            $idList = array_map('intval', $idList);
+            $sql .= ' AND iid IN ("'.implode('","', $idList).'") ';
+        }
+
         $sql .= " ORDER BY post_id ASC LIMIT 1";
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {