Add forum id in function getCourseForumThread + format code

pull/2487/head
jmontoyaa 9 years ago
parent 98aeb95b53
commit 86495f56f9
  1. 59
      main/webservices/api/v2.php

@ -35,9 +35,7 @@ try {
Rest::init(); Rest::init();
$password = isset($_POST['password']) ? $_POST['password'] : null; $password = isset($_POST['password']) ? $_POST['password'] : null;
$isValid = Rest::isValidUser($username, $password); $isValid = Rest::isValidUser($username, $password);
if (!$isValid) { if (!$isValid) {
throw new Exception(get_lang('InvalideUserDetected')); throw new Exception(get_lang('InvalideUserDetected'));
} }
@ -51,112 +49,76 @@ try {
case Rest::SAVE_GCM_ID: case Rest::SAVE_GCM_ID:
$gcmId = isset($_POST['registration_id']) ? Security::remove_XSS($_POST['registration_id']) : null; $gcmId = isset($_POST['registration_id']) ? Security::remove_XSS($_POST['registration_id']) : null;
$restApi->setGcmId($gcmId); $restApi->setGcmId($gcmId);
$restResponse->setData(['status' => true]); $restResponse->setData(['status' => true]);
break; break;
case Rest::GET_USER_MESSAGES: case Rest::GET_USER_MESSAGES:
$lastMessageId = isset($_POST['last']) ? intval($_POST['last']) : 0; $lastMessageId = isset($_POST['last']) ? intval($_POST['last']) : 0;
$messages = $restApi->getUserMessages($lastMessageId); $messages = $restApi->getUserMessages($lastMessageId);
$restResponse->setData($messages); $restResponse->setData($messages);
break; break;
case Rest::GET_USER_COURSES: case Rest::GET_USER_COURSES:
$courses = $restApi->getUserCourses(); $courses = $restApi->getUserCourses();
$restResponse->setData($courses); $restResponse->setData($courses);
break; break;
case Rest::GET_COURSE_INFO: case Rest::GET_COURSE_INFO:
$courseInfo = $restApi->getCourseInfo(); $courseInfo = $restApi->getCourseInfo();
$restResponse->setData($courseInfo); $restResponse->setData($courseInfo);
break; break;
case Rest::GET_COURSE_DESCRIPTIONS: case Rest::GET_COURSE_DESCRIPTIONS:
$descriptions = $restApi->getCourseDescriptions(); $descriptions = $restApi->getCourseDescriptions();
$restResponse->setData($descriptions); $restResponse->setData($descriptions);
break; break;
case Rest::GET_COURSE_DOCUMENTS: case Rest::GET_COURSE_DOCUMENTS:
$directoryId = isset($_POST['dir_id']) ? Security::remove_XSS($_POST['dir_id']) : null; $directoryId = isset($_POST['dir_id']) ? Security::remove_XSS($_POST['dir_id']) : null;
$documents = $restApi->getCourseDocuments($directoryId); $documents = $restApi->getCourseDocuments($directoryId);
$restResponse->setData($documents); $restResponse->setData($documents);
break; break;
case Rest::GET_COURSE_ANNOUNCEMENTS: case Rest::GET_COURSE_ANNOUNCEMENTS:
$announcements = $restApi->getCourseAnnouncements(); $announcements = $restApi->getCourseAnnouncements();
$restResponse->setData($announcements); $restResponse->setData($announcements);
break; break;
case Rest::GET_COURSE_ANNOUNCEMENT: case Rest::GET_COURSE_ANNOUNCEMENT:
$announcementId = isset($_POST['announcement']) ? Security::remove_XSS($_POST['announcement']) : 0; $announcementId = isset($_POST['announcement']) ? Security::remove_XSS($_POST['announcement']) : 0;
$announcement = $restApi->getCourseAnnouncement($announcementId); $announcement = $restApi->getCourseAnnouncement($announcementId);
$restResponse->setData($announcement); $restResponse->setData($announcement);
break; break;
case Rest::GET_COURSE_AGENDA: case Rest::GET_COURSE_AGENDA:
$agenda = $restApi->getCourseAgenda(); $agenda = $restApi->getCourseAgenda();
$restResponse->setData($agenda); $restResponse->setData($agenda);
break; break;
case Rest::GET_COURSE_NOTEBOOKS: case Rest::GET_COURSE_NOTEBOOKS:
$notebooks = $restApi->getCourseNotebooks(); $notebooks = $restApi->getCourseNotebooks();
$restResponse->setData($notebooks); $restResponse->setData($notebooks);
break; break;
case Rest::GET_COURSE_FORUM_CATEGORIES: case Rest::GET_COURSE_FORUM_CATEGORIES:
$forums = $restApi->getCourseForumCategories(); $forums = $restApi->getCourseForumCategories();
$restResponse->setData($forums); $restResponse->setData($forums);
break; break;
case Rest::GET_COURSE_FORUM: case Rest::GET_COURSE_FORUM:
$forumId = isset($_POST['forum']) ? Security::remove_XSS($_POST['forum']) : 0; $forumId = isset($_POST['forum']) ? Security::remove_XSS($_POST['forum']) : 0;
$forum = $restApi->getCourseForum($forumId); $forum = $restApi->getCourseForum($forumId);
$restResponse->setData($forum); $restResponse->setData($forum);
break; break;
case Rest::GET_COURSE_FORUM_THREAD: case Rest::GET_COURSE_FORUM_THREAD:
$threadId = isset($_POST['thread']) ? Security::remove_XSS($_POST['thread']) : 0; $forumId = isset($_POST['forum']) ? intval($_POST['forum']) : 0;
$threadId = isset($_POST['thread']) ? intval($_POST['thread']) : 0;
$thread = $restApi->getCourseForumThread($threadId); $thread = $restApi->getCourseForumThread($forumId, $threadId);
$restResponse->setData($thread); $restResponse->setData($thread);
break; break;
case Rest::GET_PROFILE: case Rest::GET_PROFILE:
$userInfo = $restApi->getUserProfile(); $userInfo = $restApi->getUserProfile();
$restResponse->setData($userInfo); $restResponse->setData($userInfo);
break; break;
case Rest::GET_COURSE_LEARNPATHS: case Rest::GET_COURSE_LEARNPATHS:
$data = $restApi->getCourseLearnPaths(); $data = $restApi->getCourseLearnPaths();
$restResponse->setData($data); $restResponse->setData($data);
break; break;
case Rest::GET_COURSE_LEARNPATH: case Rest::GET_COURSE_LEARNPATH:
$lpId = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : 0; $lpId = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : 0;
$restApi->showLearningPath($lpId); $restApi->showLearningPath($lpId);
break; break;
case Rest::SAVE_FORUM_POST: case Rest::SAVE_FORUM_POST:
if ( if (
empty($_POST['title']) || empty($_POST['text']) || empty($_POST['thread']) || empty($_POST['forum']) empty($_POST['title']) || empty($_POST['text']) || empty($_POST['thread']) || empty($_POST['forum'])
@ -178,47 +140,34 @@ try {
]; ];
$data = $restApi->saveForumPost($postValues, $forumId); $data = $restApi->saveForumPost($postValues, $forumId);
$restResponse->setData($data); $restResponse->setData($data);
break; break;
case Rest::GET_USER_SESSIONS: case Rest::GET_USER_SESSIONS:
$courses = $restApi->getUserSessions(); $courses = $restApi->getUserSessions();
$restResponse->setData($courses); $restResponse->setData($courses);
break; break;
case Rest::SAVE_USER_MESSAGE: case Rest::SAVE_USER_MESSAGE:
$receivers = isset($_POST['receivers']) ? $_POST['receivers'] : []; $receivers = isset($_POST['receivers']) ? $_POST['receivers'] : [];
$subject = !empty($_POST['subject']) ? $_POST['subject'] : null; $subject = !empty($_POST['subject']) ? $_POST['subject'] : null;
$text = !empty($_POST['text']) ? $_POST['text'] : null; $text = !empty($_POST['text']) ? $_POST['text'] : null;
$data = $restApi->saveUserMessage($subject, $text, $receivers); $data = $restApi->saveUserMessage($subject, $text, $receivers);
$restResponse->setData($data); $restResponse->setData($data);
break; break;
case Rest::GET_MESSAGE_USERS: case Rest::GET_MESSAGE_USERS:
$search = !empty($_REQUEST['q']) ? $_REQUEST['q'] : null; $search = !empty($_REQUEST['q']) ? $_REQUEST['q'] : null;
if (!$search || strlen($search) < 2) { if (!$search || strlen($search) < 2) {
throw new Exception(get_lang('TooShort')); throw new Exception(get_lang('TooShort'));
} }
$data = $restApi->getMessageUsers($search); $data = $restApi->getMessageUsers($search);
$restResponse->setData($data); $restResponse->setData($data);
break; break;
case Rest::SAVE_COURSE_NOTEBOOK: case Rest::SAVE_COURSE_NOTEBOOK:
$title = !empty($_POST['title'])? $_POST['title'] : null; $title = !empty($_POST['title'])? $_POST['title'] : null;
$text = !empty($_POST['text'])? $_POST['text'] : null; $text = !empty($_POST['text'])? $_POST['text'] : null;
$data = $restApi->saveCourseNotebook($title, $text); $data = $restApi->saveCourseNotebook($title, $text);
$restResponse->setData($data); $restResponse->setData($data);
break; break;
case Rest::SAVE_FORUM_THREAD: case Rest::SAVE_FORUM_THREAD:
if ( if (
empty($_POST['title']) || empty($_POST['text']) || empty($_POST['forum']) empty($_POST['title']) || empty($_POST['text']) || empty($_POST['forum'])
@ -237,10 +186,8 @@ try {
]; ];
$data = $restApi->saveForumThread($threadInfo, $forumId); $data = $restApi->saveForumThread($threadInfo, $forumId);
$restResponse->setData($data); $restResponse->setData($data);
break; break;
default: default:
throw new Exception(get_lang('InvalidAction')); throw new Exception(get_lang('InvalidAction'));
} }

Loading…
Cancel
Save