From 5b408460c3fa3233aafe048bed539df2540f76db Mon Sep 17 00:00:00 2001 From: Christian Fasanando Date: Wed, 16 Feb 2011 02:32:00 -0500 Subject: [PATCH] Some fixes for webservices functions about report --- main/webservices/soap.php | 26 ++++++++++++- main/webservices/soap_course.php | 6 +-- main/webservices/soap_report.php | 52 +++++++++++++++++++++++--- main/webservices/soap_session.php | 4 +- main/webservices/soap_user.php | 8 ++-- main/webservices/webservice.php | 11 +++++- main/webservices/webservice_report.php | 39 ++++++++++++------- 7 files changed, 116 insertions(+), 30 deletions(-) mode change 100644 => 100755 main/webservices/soap.php mode change 100644 => 100755 main/webservices/soap_course.php mode change 100644 => 100755 main/webservices/soap_report.php mode change 100644 => 100755 main/webservices/soap_session.php mode change 100644 => 100755 main/webservices/soap_user.php mode change 100644 => 100755 main/webservices/webservice.php mode change 100644 => 100755 main/webservices/webservice_report.php diff --git a/main/webservices/soap.php b/main/webservices/soap.php old mode 100644 new mode 100755 index 654cb2ca3a..5b442f6c1c --- a/main/webservices/soap.php +++ b/main/webservices/soap.php @@ -70,6 +70,29 @@ $s->wsdl->addComplexType( ) ); +$s->wsdl->addComplexType( + 'extras', + 'complexType', + 'struct', + 'all', + '', + array( + 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'), + 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string') + ) +); + +$s->wsdl->addComplexType( + 'extra_field', + 'complexType', + 'array', + '', + 'SOAP-ENC:Array', + array(), + array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras' +); + +/* $s->wsdl->addComplexType( 'extra_field', 'complexType', @@ -81,6 +104,7 @@ $s->wsdl->addComplexType( 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string') ) ); +*/ $s->register( 'WS.test', @@ -95,4 +119,4 @@ require_once(dirname(__FILE__).'/soap_report.php'); // Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; -$s->service($HTTP_RAW_POST_DATA); +$s->service($HTTP_RAW_POST_DATA); \ No newline at end of file diff --git a/main/webservices/soap_course.php b/main/webservices/soap_course.php old mode 100644 new mode 100755 index 6603f32593..d64cca8e79 --- a/main/webservices/soap_course.php +++ b/main/webservices/soap_course.php @@ -71,7 +71,7 @@ $s->register( 'language' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', - 'extras' => 'tns:extra_field[]' + 'extras' => 'tns:extra_field' ), array('return' => 'xsd:int') ); @@ -92,7 +92,7 @@ $s->wsdl->addComplexType( 'language' => array('name' => 'language', 'type' => 'xsd:string'), 'course_id_field_name' => array('name' => 'course_id_field_name', 'type' => 'xsd:string'), 'course_id_value' => array('name' => 'course_id_value', 'type' => 'xsd:string'), - 'extras' => array('name' => 'extras', 'type' => 'tns:extra_field[]') + 'extras' => array('name' => 'extras', 'type' => 'tns:extra_field') ) ); @@ -144,7 +144,7 @@ $s->register( 'subscribe' => 'xsd:int', 'unsubscribe' => 'xsd:int', 'visual_code' => 'xsd:string', - 'extras' => 'tns:extra_field[]' + 'extras' => 'tns:extra_field' ) ); diff --git a/main/webservices/soap_report.php b/main/webservices/soap_report.php old mode 100644 new mode 100755 index a043ca3d2d..f8d07db64d --- a/main/webservices/soap_report.php +++ b/main/webservices/soap_report.php @@ -44,6 +44,7 @@ $s->wsdl->addComplexType( ) ); +/* $s->wsdl->addComplexType( 'user_result', 'complexType', @@ -54,6 +55,45 @@ $s->wsdl->addComplexType( 'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string'), 'result' => array('name' => 'result', 'type' => 'tns:result') ) +);*/ + + +$s->wsdl->addComplexType( + 'user_result', + 'complexType', + 'struct', + 'all', + '', + array( + 'id' => array('name' => 'id', 'type' => 'xsd:string'), + 'title' => array('name' => 'title', 'type' => 'xsd:string') + ) +); + +$s->wsdl->addComplexType( + 'progress_result', + 'complexType', + 'struct', + 'all', + '', + array( + 'progress_bar_mode' => array('name' => 'progress_bar_mode', 'type' => 'xsd:string'), + 'progress_db' => array('name' => 'progress_db', 'type' => 'xsd:string') + ) +); + +$s->wsdl->addComplexType( + 'score_result', + 'complexType', + 'struct', + 'all', + '', + array( + 'min_score' => array('name' => 'min_score', 'type' => 'xsd:string'), + 'max_score' => array('name' => 'max_score', 'type' => 'xsd:string'), + 'mastery_score' => array('name' => 'mastery_score', 'type' => 'xsd:string'), + 'current_score' => array('name' => 'current_score', 'type' => 'xsd:string'), + ) ); $s->wsdl->addComplexType( @@ -67,6 +107,8 @@ $s->wsdl->addComplexType( 'tns:user_result' ); + + $s->register( 'WSReport.GetTimeSpentOnPlatform', array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string'), @@ -93,20 +135,20 @@ $s->register( $s->register( 'WSReport.GetLearnpathsByCourse', - array('user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'), + array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string'), array('return' => 'tns:user_result_array') ); $s->register( 'WSReport.GetLearnpathProgress', - array('user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'), - array('return' => 'xsd:string') + array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'), + array('return' => 'tns:progress_result') ); $s->register( 'WSReport.GetLearnpathScoreSingleItem', - array('user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'), - array('return' => 'xsd:string') + array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'), + array('return' => 'tns:score_result') ); $s->register( diff --git a/main/webservices/soap_session.php b/main/webservices/soap_session.php old mode 100644 new mode 100755 index 4e39e5da7b..01f22a18ac --- a/main/webservices/soap_session.php +++ b/main/webservices/soap_session.php @@ -25,7 +25,7 @@ $s->register( 'user_id_value' => 'xsd:string', 'session_id_field_name' => 'xsd:string', 'session_id_value' => 'xsd:string', - 'extras' => 'tns:extra_field[]' + 'extras' => 'tns:extra_field' ), array('return' => 'xsd:int') ); @@ -54,7 +54,7 @@ $s->register( 'user_id_value' => 'xsd:string', 'session_id_field_name' => 'xsd:string', 'session_id_value' => 'xsd:string', - 'extras' => 'tns:extra_field[]' + 'extras' => 'tns:extra_field' ) ); diff --git a/main/webservices/soap_user.php b/main/webservices/soap_user.php old mode 100644 new mode 100755 index 12b3855e44..114f0d853f --- a/main/webservices/soap_user.php +++ b/main/webservices/soap_user.php @@ -98,7 +98,7 @@ $s->register( 'language' => 'xsd:string', 'phone' => 'xsd:string', 'expiration_date' => 'xsd:string', - 'extras' => 'tns:extra_field[]' + 'extras' => 'tns:extra_field' ), array('return' => 'xsd:int') ); @@ -123,7 +123,7 @@ $s->wsdl->addComplexType( 'language' => array('name' => 'language', 'type' => 'xsd:string'), 'phone' => array('name' => 'phone', 'type' => 'xsd:string'), 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'), - 'extras' => array('name' => 'extras', 'type' => 'tns:extra_field[]') + 'extras' => array('name' => 'extras', 'type' => 'tns:extra_field') ) ); @@ -176,7 +176,7 @@ $s->register( 'language' => 'xsd:string', 'phone' => 'xsd:string', 'expiration_date' => 'xsd:string', - 'extras' => 'tns:extra_field[]' + 'extras' => 'tns:extra_field' ) ); @@ -199,7 +199,7 @@ $s->wsdl->addComplexType( 'language' => array('name' => 'language', 'type' => 'xsd:string'), 'phone' => array('name' => 'phone', 'type' => 'xsd:string'), 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'), - 'extras' => array('name' => 'extras', 'type' => 'tns:extra_field[]') + 'extras' => array('name' => 'extras', 'type' => 'tns:extra_field') ) ); diff --git a/main/webservices/webservice.php b/main/webservices/webservice.php old mode 100644 new mode 100755 index 818486b1a4..ebb3e2744b --- a/main/webservices/webservice.php +++ b/main/webservices/webservice.php @@ -162,12 +162,19 @@ class WS { } } else { $course_code = CourseManager::get_course_code_from_original_id($course_id_value, $course_id_field_name); + if (!empty($course_code)) { + $course_info = CourseManager::get_course_information($course_code); + return $course_info['id']; + } else { + return new WSError(200, "Course not found"); + } + /* if($course_code == 0) { return new WSError(200, "Course not found"); } else { - $course_info = CourseManager::get_course_information($course_code); return $course_info['id']; - } + } + */ } } diff --git a/main/webservices/webservice_report.php b/main/webservices/webservice_report.php old mode 100644 new mode 100755 index 350245e2ff..cb4a45b407 --- a/main/webservices/webservice_report.php +++ b/main/webservices/webservice_report.php @@ -90,7 +90,7 @@ class WSReport extends WS { * @param string Course id value * @return array Array of id=>title of learning paths */ - public function GetLearnpathsByCourse($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $lp_id) { + public function GetLearnpathsByCourse($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) { $user_id = $this->getUserId($user_id_field_name, $user_id_value); if($user_id instanceof WSError) { return $user_id; @@ -101,11 +101,13 @@ class WSReport extends WS { } else { $course_code = CourseManager::get_course_code_from_course_id($course_id); } + require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php'; - $list = new LearnpathList($user_id,$course_code); + $lp = new LearnpathList($user_id,$course_code); + $list = $lp->list; $return = array(); foreach ($list as $id => $item) { - $return[] = array('id'=>$id, 'title' => $item); + $return[] = array('id'=>$id, 'title' => $item['lp_name']); } return $return; } @@ -119,7 +121,7 @@ class WSReport extends WS { * @param string Learnpath ID * @return double Between 0 and 100 (% of progress) */ - public function GetLearnpathProgress($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) { + public function GetLearnpathProgress($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) { $user_id = $this->getUserId($user_id_field_name, $user_id_value); if($user_id instanceof WSError) { return $user_id; @@ -132,8 +134,14 @@ class WSReport extends WS { } require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php'; $lp = new learnpath($course_code, $learnpath_id, $user_id); - return $lp['progress']; + $items = $lp->items[$learnpath_id]; + $return = array( + 'progress_bar_mode' => $lp->progress_bar_mode, + 'progress_db' => $lp->progress_db, + ); + return $return; } + /** * Gets score obtained in the given learning path by the given user, * assuming there is only one item (SCO) in the learning path @@ -145,7 +153,7 @@ class WSReport extends WS { * @param string Learnpath ID * @return double Generally between 0 and 100 */ - public function GetLearnpathScoreSingleItem($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) { + public function GetLearnpathScoreSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) { $user_id = $this->getUserId($user_id_field_name, $user_id_value); if($user_id instanceof WSError) { return $user_id; @@ -158,8 +166,13 @@ class WSReport extends WS { } require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php'; $lp = new learnpath($course_code, $learnpath_id, $user_id); - //return $lp['progress']; - return 100; + $return = array( + 'min_score' => $lp->items[$learnpath_id]->min_score, + 'max_score' => $lp->items[$learnpath_id]->max_score, + 'mastery_score' => $lp->items[$learnpath_id]->mastery_score, + 'current_score' => $lp->items[$learnpath_id]->current_score, + ); + return $return; } /** * Gets status obtained in the given learning path by the given user, @@ -173,8 +186,7 @@ class WSReport extends WS { * @param string Learnpath ID * @return string "not attempted", "passed", "completed", "failed", "incomplete" */ - public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name = 'chamilo_user_id', $user_id_value, $course_id_field_name = 'chamilo_course_id', $course_id_value, $learnpath_id) { - return null; + public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) { $verifKey = $this->verifyKey($secret_key); if($verifKey instanceof WSError) { $this->handleError($verifKey); @@ -188,13 +200,14 @@ class WSReport extends WS { return $course_id; } else { $course_code = CourseManager::get_course_code_from_course_id($course_id); - } + } require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php'; $lp = new learnpath($course_code, $learnpath_id, $user_id); -error_log('Ready to return status for '.$course_code.'-'.$learnpath_id.'-'.$user_id.': '.$lp->items[0]['status']); - return $lp->items[0]['status']; + return $lp->items[$learnpath_id]->status; } } + + public function test() { return 'Hello world!'; }