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

Loading…
Cancel
Save