Sfoglia il codice sorgente

Fix serving forum tool for api REST - refs BT#8366

Angel Fernando Quiroz Campos 8 anni fa
parent
commit
1da50f697d
2 ha cambiato i file con 15 aggiunte e 19 eliminazioni
  1. 10 8
      main/forum/forumfunction.inc.php
  2. 5 11
      main/inc/lib/webservices/Rest.php

+ 10 - 8
main/forum/forumfunction.inc.php

@@ -1815,22 +1815,23 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
 /**
  * Retrieve all the threads of a given forum
  *
- * @param int   forum id
- * @param string course db name
+ * @param int $forum_id
+ * @param int|null $courseId Optional If is null then it is considered the current course
+ * @param int|null $sessionId Optional. If is null then it is considered the current session
  * @return an array containing all the information about the threads
  *
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  * @version february 2006, dokeos 1.8
  */
-function get_threads($forum_id)
+function get_threads($forum_id, $courseId = null, $sessionId = null)
 {
     $groupId = api_get_group_id();
-    $sessionId = api_get_session_id();
+    $sessionId = $sessionId !== NULL ? intval($sessionId) : api_get_session_id();
     $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
     $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
     $table_users = Database :: get_main_table(TABLE_MAIN_USER);
 
-    $courseId = api_get_course_int_id();
+    $courseId = $courseId !== NULL ? intval($courseId) : api_get_course_int_id();
     $groupInfo = GroupManager::get_group_properties($groupId);
     $groupCondition = '';
     if (!empty($groupInfo)) {
@@ -2084,19 +2085,20 @@ function get_post_information($post_id)
 /**
  * This function retrieves all the information of a thread
  *
+ * @param int $forumId
  * @param $thread_id integer that indicates the forum
- *
+ * @param int|null $sessionId Optional. If is null then it is considered the current session
  * @return array returns
  *
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  * @version february 2006, dokeos 1.8
  */
-function get_thread_information($forumId, $thread_id)
+function get_thread_information($forumId, $thread_id, $sessionId = null)
 {
     $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
     $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
     $thread_id = intval($thread_id);
-    $sessionId = api_get_session_id();
+    $sessionId = $sessionId !== null ? intval($sessionId) : api_get_session_id();
     $sessionCondition = api_get_session_condition($sessionId, true, false, 'threads.session_id');
     $forumCondition = '';
     if (!empty($forumId)) {

+ 5 - 11
main/inc/lib/webservices/Rest.php

@@ -559,20 +559,13 @@ class Rest extends WebService
     {
         require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
 
-        $forumInfo = get_forums($forumId);
+        $forumInfo = get_forums($forumId, $this->course->getCode());
 
         if (!isset($forumInfo['iid'])) {
             throw new Exception(get_lang('NoForum'));
         }
 
-        /** @var Course $course */
-        $course = Database::getManager()->find('ChamiloCoreBundle:Course', $forumInfo['c_id']);
-
-        if (!$course) {
-            throw new Exception(get_lang('NoCourse'));
-        }
-
-        $webCoursePath = api_get_path(WEB_COURSE_PATH) . $course->getDirectory() . '/upload/forum/images/';
+        $webCoursePath = api_get_path(WEB_COURSE_PATH) . $this->course->getDirectory() . '/upload/forum/images/';
         $forum = [
             'id' => $forumInfo['iid'],
             'title' => $forumInfo['forum_title'],
@@ -581,7 +574,7 @@ class Rest extends WebService
             'threads' => []
         ];
 
-        $threads = get_threads($forumInfo['iid']);
+        $threads = get_threads($forumInfo['iid'], $this->course->getId());
 
         foreach ($threads as $thread) {
             $forum['threads'][] = [
@@ -598,6 +591,7 @@ class Rest extends WebService
     }
 
     /**
+     * @param int $forumId
      * @param int $threadId
      * @return array
      */
@@ -615,7 +609,7 @@ class Rest extends WebService
             'posts' => []
         ];
 
-        $forumInfo = get_forums($threadInfo['forum_id']);
+        $forumInfo = get_forums($threadInfo['forum_id'], $this->course->getCode());
 
         $postsInfo = getPosts($forumInfo, $threadInfo['iid'], 'ASC');