Browse Source

Fix forum threads iids for REST api - refs #8366

Angel Fernando Quiroz Campos 8 years ago
parent
commit
23d0e55cd4

+ 2 - 2
main/forum/forumfunction.inc.php

@@ -1503,7 +1503,7 @@ function get_forums(
     if ($id == '') {
         // Student
         // Select all the forum information of all forums (that are visible to students).
-        $sql = "SELECT * FROM $table_forums forum
+        $sql = "SELECT item_properties.*, forum.* FROM $table_forums forum
                 INNER JOIN ".$table_item_property." item_properties
                 ON (
                     forum.forum_id = item_properties.ref AND
@@ -1538,7 +1538,7 @@ function get_forums(
         // Course Admin
         if (api_is_allowed_to_edit()) {
             // Select all the forum information of all forums (that are not deleted).
-            $sql = "SELECT * FROM ".$table_forums." forum
+            $sql = "SELECT item_properties.*, forum.* FROM ".$table_forums." forum
                     INNER JOIN ".$table_item_property." item_properties
                     ON (
                         forum.forum_id = item_properties.ref AND

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

@@ -540,6 +540,10 @@ class Rest extends WebService
 
         $forumInfo = get_forums($forumId);
 
+        if (!isset($forumInfo['iid'])) {
+            throw new Exception(get_lang('NoForum'));
+        }
+
         /** @var Course $course */
         $course = Database::getManager()->find('ChamiloCoreBundle:Course', $forumInfo['c_id']);
 
@@ -550,7 +554,6 @@ class Rest extends WebService
         $webCoursePath = api_get_path(WEB_COURSE_PATH) . $course->getDirectory() . '/upload/forum/images/';
         $forum = [
             'id' => $forumInfo['iid'],
-            'forumId' => $forumInfo['forum_id'],
             'title' => $forumInfo['forum_title'],
             'description' => $forumInfo['forum_comment'],
             'image' => $forumInfo['forum_image'] ? ($webCoursePath . $forumInfo['forum_image']) : '',
@@ -561,7 +564,7 @@ class Rest extends WebService
 
         foreach ($threads as $thread) {
             $forum['threads'][] = [
-                'iid' => $thread['iid'],
+                'id' => $thread['iid'],
                 'title' => $thread['thread_title'],
                 'lastEditDate' => api_convert_and_format_date($thread['lastedit_date'], DATE_TIME_FORMAT_LONG_24H),
                 'numberOfReplies' => $thread['thread_replies'],

+ 2 - 1
main/webservices/api/v2.php

@@ -148,9 +148,10 @@ try {
     $restResponse->setErrorMessage(
         $exeption->getMessage()
     );
+
 }
 
-header('Content-Type: application/json');
+//header('Content-Type: application/json');
 header('Access-Control-Allow-Origin: *');
 
 echo $restResponse->format();