From d61c1241c33206ea40cb4b10508fabc6c4abd415 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 28 Oct 2021 20:47:32 -0500 Subject: [PATCH] Webservice: Add method to show course home - refs BT#19195 --- main/inc/lib/webservices/Rest.php | 30 ++++++++++++++++++++++++++++++ main/webservices/api/v2.php | 3 +++ 2 files changed, 33 insertions(+) diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php index 15907d4b8a..b2dd4f7f4e 100644 --- a/main/inc/lib/webservices/Rest.php +++ b/main/inc/lib/webservices/Rest.php @@ -39,6 +39,7 @@ class Rest extends WebService const GET_PROFILE = 'user_profile'; + const VIEW_COURSE_HOME = 'view_course_home'; const GET_COURSE_INFO = 'course_info'; const GET_COURSE_DESCRIPTIONS = 'course_descriptions'; const GET_COURSE_DOCUMENTS = 'course_documents'; @@ -401,6 +402,8 @@ class Rest extends WebService $courses = CourseManager::get_courses_list_by_user_id($userId); $data = []; + $webCodePath = api_get_path(WEB_CODE_PATH).'webservices/api/v2.php?'; + foreach ($courses as $courseInfo) { /** @var Course $course */ $course = Database::getManager()->find('ChamiloCoreBundle:Course', $courseInfo['real_id']); @@ -416,6 +419,14 @@ class Rest extends WebService 'urlPicture' => $picturePath, 'teachers' => $teachers, 'isSpecial' => !empty($courseInfo['special_course']), + 'url' => $webCodePath.http_build_query( + [ + 'action' => self::VIEW_COURSE_HOME, + 'api_key' => $this->apiKey, + 'username' => $this->user->getUsername(), + 'course' => $course->getId() + ] + ), ]; } @@ -1189,6 +1200,8 @@ class Rest extends WebService $data = []; $sessionsByCategory = UserManager::get_sessions_by_category($this->user->getId(), false); + $webCodePath = api_get_path(WEB_CODE_PATH).'webservices/api/v2.php?'; + foreach ($sessionsByCategory as $category) { $categorySessions = []; @@ -1210,6 +1223,15 @@ class Rest extends WebService 'pictureUrl' => $courseInfo['course_image_large'], 'urlPicture' => $courseInfo['course_image_large'], 'teachers' => $teachers, + 'url' => $webCodePath.http_build_query( + [ + 'action' => self::VIEW_COURSE_HOME, + 'api_key' => $this->apiKey, + 'username' => $this->user->getUsername(), + 'course' => $courseInfo['real_id'], + 'session' => $sessions['session_id'], + ] + ), ]; } @@ -2917,6 +2939,14 @@ class Rest extends WebService ); } + public function viewCourseHome() + { + $url = api_get_course_url($this->course->getCode(), $this->session ? $this->session->getId() : 0); + + header("Location: $url"); + exit; + } + public function viewDocumentInFrame(int $documentId) { $courseCode = $this->course->getCode(); diff --git a/main/webservices/api/v2.php b/main/webservices/api/v2.php index 98f42ebcc0..324c900cc7 100644 --- a/main/webservices/api/v2.php +++ b/main/webservices/api/v2.php @@ -172,6 +172,9 @@ try { $restResponse->setData($userInfo); break; + case Rest::VIEW_COURSE_HOME: + $restApi->viewCourseHome(); + break; case Rest::GET_COURSE_INFO: $courseInfo = $restApi->getCourseInfo(); $restResponse->setData($courseInfo);