Sfoglia il codice sorgente

Web services cleanup and bug fixes

Guillaume Viguier 14 anni fa
parent
commit
57ece0a285

+ 1 - 1
main/inc/lib/course.lib.php

@@ -2230,7 +2230,7 @@ class CourseManager {
 	public static function get_course_category($code) {
 		$table_categories = Database::get_main_table(TABLE_MAIN_CATEGORY);
 		$sql = "SELECT * FROM $table_categories WHERE code = '$code';";
-		return Database::store_result(Database::query($sql));
+		return Database::fetch_array(Database::query($sql));
 	}
 
 	/*

+ 1 - 1
main/inc/lib/course_description.lib.php

@@ -39,7 +39,7 @@ class CourseDescription
 		$course_code = CourseManager::get_course_code_from_course_id($course_id);
 		// Get course info
 		$course_info = CourseManager::get_course_information($course_code);
-		$t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION, $course_info['dbName']);
+		$t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION, $course_info['db_name']);
 		$sql = "SELECT * FROM $t_course_desc WHERE session_id = '0';";
 		$sql_result = Database::query($sql);
 		$results = array();

+ 48 - 4
main/webservices/soap_course.php

@@ -32,6 +32,17 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'course_result_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_result[]')),
+	'tns:course_result'
+);
+
 $s->register(
 	'WSCourse.DeleteCourse',
 	array('secret_key' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string')
@@ -40,7 +51,7 @@ $s->register(
 $s->register(
 	'WSCourse.DeleteCourses',
 	array('secret_key' => 'xsd:string', 'courses' => 'tns:course_id[]'),
-	array('return' => 'tns:course_result[]')
+	array('return' => 'tns:course_result_array')
 );
 
 $s->register(
@@ -94,13 +105,24 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'course_create_result_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_create_result[]')),
+	'tns:course_create_result'
+);
+
 $s->register(
 	'WSCourse.CreateCourses',
 	array(
 		'secret_key' => 'xsd:string',
 		'courses' => 'tns:course_create[]'
 	),
-	array('return' => 'tns:course_create_result[]')
+	array('return' => 'tns:course_create_result_array')
 );
 
 $s->register(
@@ -140,13 +162,24 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'course_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course[]')),
+	'tns:course'
+);
+
 $s->register(
 	'WSCourse.ListCourses',
 	array(
 		'secret_key' => 'xsd:string',
 		'course_id_field_name' => 'xsd:string'
 	),
-	array('return' => 'tns:course[]')
+	array('return' => 'tns:course_array')
 );
 
 $s->register(
@@ -185,6 +218,17 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'course_description_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_description[]')),
+	'tns:course_description'
+);
+
 $s->register(
 	'WSCourse.GetCourseDescriptions',
 	array(
@@ -192,7 +236,7 @@ $s->register(
 		'course_id_field_name' => 'xsd:string',
 		'course_id_value' => 'xsd:string'
 	),
-	array('return' => 'tns:course_description[]')
+	array('return' => 'tns:course_description_array')
 );
 
 $s->register(

+ 38 - 5
main/webservices/soap_user.php

@@ -32,6 +32,17 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'user_result_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_result[]')),
+	'tns:user_result'
+);
+
 $s->register(
 	'WSUser.DisableUser',
 	array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string')
@@ -40,7 +51,7 @@ $s->register(
 $s->register(
 	'WSUser.DisableUsers',
 	array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
-	array('return' => 'tns:user_result[]')
+	array('return' => 'tns:user_result_array')
 );
 
 $s->register(
@@ -51,7 +62,7 @@ $s->register(
 $s->register(
 	'WSUser.EnableUsers',
 	array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
-	array('return' => 'tns:user_result[]')
+	array('return' => 'tns:user_result_array')
 );
 
 $s->register(
@@ -62,7 +73,7 @@ $s->register(
 $s->register(
 	'WSUser.DeleteUsers',
 	array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
-	array('return' => 'tns:user_result[]')
+	array('return' => 'tns:user_result_array')
 );
 
 $s->register(
@@ -124,13 +135,24 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'user_create_result_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_create_result[]')),
+	'tns:user_create_result'
+);
+
 $s->register(
 	'WSUser.CreateUsers',
 	array(
 		'secret_key' => 'xsd:string',
 		'users' => 'tns:user_create[]'
 	),
-	array('return' => 'tns:user_create_result[]')
+	array('return' => 'tns:user_create_result_array')
 );
 
 $s->register(
@@ -188,11 +210,22 @@ $s->wsdl->addComplexType(
 	)
 );
 
+$s->wsdl->addComplexType(
+	'user_edit_result_array',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_edit_result[]')),
+	'tns:user_edit_result'
+);
+
 $s->register(
 	'WSUser.EditUsers',
 	array(
 		'secret_key' => 'xsd:string',
 		'users' => 'tns:user_edit[]'
 	),
-	array('return' => 'tns:user_edit_result[]')
+	array('return' => 'tns:user_edit_result_array')
 );

+ 6 - 9
main/webservices/webservice_course.php

@@ -24,11 +24,8 @@ class WSCourse extends WS {
 			return $course_id;
 		} else {
 			$course_code = CourseManager::get_course_code_from_course_id($course_id);
-			if(!CourseManager::delete_course($course_code)) {
-				return new WSError(201, "There was a problem while deleting this course");
-			} else {
-				return true;
-			}
+			CourseManager::delete_course($course_code);
+			return true;
 		}
 	}
 	
@@ -112,7 +109,7 @@ class WSCourse extends WS {
 		if($wanted_code == '') {
 			$wanted_code = generate_course_code($title);
 		}
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $course_admin_id, $this->_configuration['db_prefix'], 0);
+		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
 		if($result == false) {
 			return new WSError(202, 'There was an error creating the course');
 		} else {
@@ -308,7 +305,7 @@ class WSCourse extends WS {
 				$course_tmp['id'] = $course['id'];
 				$course_tmp['code'] = $course['code'];
 				$course_tmp['title'] = $course['title'];
-				$course_tmp['language'] = $course['language'];
+				$course_tmp['language'] = $course['course_language'];
 				$course_tmp['visibility'] = $course['visibility'];
 				
 				// Determining category name
@@ -483,9 +480,9 @@ class WSCourse extends WS {
 				}
 				if($exists == false) {
 					$cd->set_progress(0);
-					$cd->insert($course_info['dbName']);
+					$cd->insert($course_info['db_name']);
 				} else {
-					$cd->update($course_info['dbName']);
+					$cd->update($course_info['db_name']);
 				}
 			}
 		}

+ 51 - 0
tests/test_webservices.php

@@ -46,10 +46,37 @@ class TestSoapWebService extends UnitTestCase {
 		return $user;
 	}
 	
+	protected function getCourseArray() {
+		$course = array(
+			'title' => 'My test course',
+			'category_code' => 'LANG',
+			'wanted_code' => '110',
+			'tutor_name' => 'Guillaume Viguier',
+			'course_admin_user_id_field_name' => 'chamilo_user_id',
+			'course_admin_user_id_value' => '1',
+			'language' => 'spanish',
+			'course_id_field_name' => 'chamilo_course_id',
+			'course_id_value' => '',
+			'extras' => array());
+		return $course;
+	}
+	
 	protected function soapCall($method, $arguments) {
 		return $this->_client->__soapCall($method, $arguments);
 	}
 	
+	protected function createUser() {
+		$user = $this->getUserArray();
+		$result = $this->soapCall('WSUser.CreateUser', array_merge(array('secret_key' => $this->_secret_key), $user));
+		return $result;
+	}
+	
+	protected function createCourse() {
+		$course = $this->getCourseArray();
+		$result = $this->soapCall('WSCourse.CreateCourse', array_merge(array('secret_key' => $this->_secret_key), $course));
+		return $result;
+	}
+	
 	public function testTest() {
 		$result = $this->soapCall('WS.test', array());
 		$this->assertEqual($result, "success");
@@ -87,6 +114,30 @@ class TestSoapWebService extends UnitTestCase {
 		//Delete user created
 		$this->soapCall('WSUser.DeleteUser', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => $result));
 	}
+	
+	/*public function testCourseCreation() {
+		$course = $this->getCourseArray();
+		$result = $this->soapCall('WSCourse.CreateCourse', array_merge(array('secret_key' => $this->_secret_key), $course));
+		$this->assertIsA($result, 'int');
+		// Delete course created
+		$this->soapCall('WSCourse.DeleteCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => $result));
+	}*/
+	
+	/*public function testCourseSubscriptionAndUnsubscription() {
+		//$course_id = $this->createCourse();
+		//$user_id = $this->createUser();
+		//echo $course_id.';'.$user_id;
+		//$this->soapCall('WSCourse.SubscribeUserToCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38, 'status' => 1));
+		//$this->soapCall('WSCourse.UnsubscribeUserFromCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38));
+	}*/
+	
+	/*public function testCourseDescriptions() {
+		//$this->soapCall('WSCourse.EditCourseDescription', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'course_desc_id' => 1, 'course_desc_title' => 'My description', 'course_desc_content' => 'This is my new description'));
+		//$result = $this->soapCall('WSCourse.GetCourseDescriptions', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8));
+		//var_dump($result);
+		$result = $this->soapCall('WSCourse.ListCourses', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id'));
+		var_dump($result);
+	}*/
 }