diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index bded12b030..9d3f3e819c 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -1845,7 +1845,7 @@ function get_threads($forum_id, $course_code = null) INNER JOIN $table_item_property item_properties ON thread.thread_id = item_properties.ref AND - item_properties.c_id = thread.c_id + item_properties.c_id = thread.c_id AND item_properties.c_id = $course_id AND item_properties.tool = '".TABLE_FORUM_THREAD."' $groupCondition LEFT JOIN $table_users users diff --git a/main/inc/ajax/lp.ajax.php b/main/inc/ajax/lp.ajax.php index 10cc42a1c4..e156a9afc6 100755 --- a/main/inc/ajax/lp.ajax.php +++ b/main/inc/ajax/lp.ajax.php @@ -166,6 +166,7 @@ switch ($action) { case 'get_forum_thread': $lpId = isset($_GET['lp']) ? intval($_GET['lp']) : 0; $lpItemId = isset($_GET['lp_item']) ? intval($_GET['lp_item']) : 0; + $sessionId = api_get_session_id(); if (empty($lpId) || empty($lpItemId)) { echo json_encode([ @@ -180,39 +181,69 @@ switch ($action) { api_get_user_id() ); - $forum = $learningPath->getForum(); - + $lpItem = $learningPath->getItem($lpItemId); - if (empty($forum)) { + if (empty($lpItem)) { echo json_encode([ 'error' => true, ]); break; } - $lpItem = $learningPath->getItem($lpItemId); + $forum = $learningPath->getForum($sessionId); - if (empty($lpItem)) { + if (empty($forum)) { + require_once '../../forum/forumfunction.inc.php'; + + $forumCategory = getForumCategoryByTitle( + get_lang('LearningPaths'), + $course_id, + $sessionId + ); + + if (empty($forumCategory)) { + $forumCategoryId = store_forumcategory( + [ + 'lp_id' => 0, + 'forum_category_title' => get_lang('LearningPaths'), + 'forum_category_comment' => null + ], + [], + false + ); + } else { + $forumCategoryId = $forumCategory['cat_id']; + } + + $forumId = $learningPath->createForum($forumCategoryId); + } else { + $forumId = $forum['forum_id']; + } + + $basisForumThread = $lpItem->getForumThread($course_id); + + if (empty($basisForumThread)) { echo json_encode([ 'error' => true, ]); break; } - $forumThread = $lpItem->getForumThread($course_id, api_get_session_id()); + $forumThread = $lpItem->getForumThread($course_id, $sessionId); if (empty($forumThread)) { - echo json_encode([ - 'error' => true, - ]); - break; + $lpItem->createForumTthread($forumId); + + $forumThread = $lpItem->getForumThread($course_id, $sessionId); } + $forumThreadId = $forumThread['thread_id']; + echo json_encode([ 'error' => false, 'forumId' => intval($forum['forum_id']), - 'threadId' => intval($forumThread['thread_id']) + 'threadId' => intval($forumThreadId) ]); break; default: diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 66f52d70fa..cb8de28ce1 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -10640,7 +10640,7 @@ EOD; * Get the forum for this learning path * @return boolean */ - public function getForum() + public function getForum($sessionId = 0) { $forumTable = Database::get_course_table(TABLE_FORUM); $itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); @@ -10667,7 +10667,7 @@ EOD; 'where' => [ 'ip.visibility != ? AND ' => 2, 'ip.tool = ? AND ' => TOOL_FORUM, - 'f.session_id = ? AND ' => $this->lp_session_id, + 'f.session_id = ? AND ' => $sessionId, 'f.c_id = ? AND ' => intval($this->course_int_id), 'f.lp_id = ?' => intval($this->lp_id) ] diff --git a/main/newscorm/lp_controller.php b/main/newscorm/lp_controller.php index 97a46ba220..7ceb80e09e 100755 --- a/main/newscorm/lp_controller.php +++ b/main/newscorm/lp_controller.php @@ -1309,7 +1309,9 @@ switch ($action) { } if (!empty($forumCategoryId)) { - $forum = $_SESSION['oLP']->getForum(); + $forum = $_SESSION['oLP']->getForum( + $_SESSION['oLP']->lp_session_id + ); $forumId = !empty($forum) ? $forum['forum_id'] : 0; if (empty($forumId)) { diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index b55758def5..cc29dc9b1f 100755 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1649,6 +1649,7 @@ var loadForumThead = function(lpId, lpItemId) { ); $.when(loadForum).done(function(forumThreadData) { + console.log(forumThreadData); if (forumThreadData.error) { $('#forum-container').hide(); return;