Browse Source

GraphQL: Remove create course webservice #2644

Create course implemented in mutation
Angel Fernando Quiroz Campos 6 years ago
parent
commit
aedeb8a24e

+ 0 - 71
main/webservices/cm_soap_course.php

@@ -58,77 +58,6 @@ $s->register(
     ['return' => 'tns:course_result_array']
 );
 
-$s->register(
-    'WSCMCourse.CreateCourse',
-    [
-        'secret_key' => 'xsd:string',
-        'title' => 'xsd:string',
-        'category_code' => 'xsd:string',
-        'wanted_code' => 'xsd:string',
-        'tutor_name' => 'xsd:string',
-        'course_admin_user_id_field_name' => 'xsd:string',
-        'course_admin_user_id_value' => 'xsd:string',
-        'language' => 'xsd:string',
-        'course_id_field_name' => 'xsd:string',
-        'course_id_value' => 'xsd:string',
-        'extras' => 'tns:extra_field[]',
-    ],
-    ['return' => 'xsd:int']
-);
-
-$s->wsdl->addComplexType(
-    'course_create',
-    'complexType',
-    'struct',
-    'all',
-    '',
-    [
-        'title' => ['name' => 'title', 'type' => 'xsd:string'],
-        'category_code' => ['name' => 'category_code', 'type' => 'xsd:string'],
-        'wanted_code' => ['name' => 'wanted_code', 'type' => 'xsd:int'],
-        'tutor_name' => ['name' => 'tutor_name', 'type' => 'xsd:string'],
-        'course_admin_user_id_field_name' => ['name' => 'course_admin_user_id_field_name', 'type' => 'xsd:string'],
-        'course_admin_user_id_value' => ['name' => 'course_admin_user_id_value', 'type' => 'xsd:string'],
-        'language' => ['name' => 'language', 'type' => 'xsd:string'],
-        'course_id_field_name' => ['name' => 'course_id_field_name', 'type' => 'xsd:string'],
-        'course_id_value' => ['name' => 'course_id_value', 'type' => 'xsd:string'],
-        'extras' => ['name' => 'extras', 'type' => 'tns:extra_field[]'],
-    ]
-);
-
-$s->wsdl->addComplexType(
-    'course_create_result',
-    'complexType',
-    'struct',
-    'all',
-    '',
-    [
-        'course_id_value' => ['name' => 'course_id_value', 'type' => 'xsd:string'],
-        'course_id_generated' => ['name' => 'course_id_generated', 'type' => 'xsd:int'],
-        'result' => ['name' => 'result', 'type' => 'tns:result'],
-    ]
-);
-
-$s->wsdl->addComplexType(
-    'course_create_result_array',
-    'complexType',
-    'array',
-    '',
-    'SOAP-ENC:Array',
-    [],
-    [['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_create_result[]']],
-    'tns:course_create_result'
-);
-
-$s->register(
-    'WSCMCourse.CreateCourses',
-    [
-        'secret_key' => 'xsd:string',
-        'courses' => 'tns:course_create[]',
-    ],
-    ['return' => 'tns:course_create_result_array']
-);
-
 $s->register(
     'WSCMCourse.EditCourse',
     [

+ 0 - 172
main/webservices/cm_webservice_course.php

@@ -74,111 +74,6 @@ class WSCMCourse extends WSCM
         }
     }
 
-    /**
-     * Creates a course.
-     *
-     * @param string API secret key
-     * @param string Title
-     * @param string Category code
-     * @param string Wanted code. If it's not defined, it will be generated automatically
-     * @param string Tutor name
-     * @param string Course admin user id field name
-     * @param string Course admin user id value
-     * @param string Course language
-     * @param string Course id field name
-     * @param string Course id value
-     * @param array Course extra fields
-     *
-     * @return int Course id generated
-     */
-    public function CreateCourse(
-        $secret_key,
-        $title,
-        $category_code,
-        $wanted_code,
-        $tutor_name,
-        $course_admin_user_id_field_name,
-        $course_admin_user_id_value,
-        $language,
-        $course_id_field_name,
-        $course_id_value,
-        $extras
-    ) {
-        // First, verify the secret key
-        $verifKey = $this->verifyKey($secret_key);
-        if ($verifKey instanceof WSError) {
-            $this->handleError($verifKey);
-        } else {
-            $result = $this->createCourseHelper(
-                $title,
-                $category_code,
-                $wanted_code,
-                $tutor_name,
-                $course_admin_user_id_field_name,
-                $course_admin_user_id_value,
-                $language,
-                $course_id_field_name,
-                $course_id_value,
-                $extras
-            );
-            if ($result instanceof WSError) {
-                $this->handleError($result);
-            } else {
-                return $result;
-            }
-        }
-    }
-
-    /**
-     * Create multiple courses.
-     *
-     * @param string API secret key
-     * @param array Courses to be created, with elements following the structure presented in CreateCourse
-     *
-     * @return array Array with elements of the form
-     *               array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
-     */
-    public function CreateCourses($secret_key, $courses)
-    {
-        // First, verify the secret key
-        $verifKey = $this->verifyKey($secret_key);
-        if ($verifKey instanceof WSCMError) {
-            $this->handleError($verifKey);
-        } else {
-            $results = [];
-            foreach ($courses as $course) {
-                $result_tmp = [];
-                //reinitialize variables just in case
-                $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
-                extract($course);
-                $result = $this->createCourseHelper(
-                    $title,
-                    $category_code,
-                    $wanted_code,
-                    $tutor_name,
-                    $course_admin_user_id_field_name,
-                    $course_admin_user_id_value,
-                    $language,
-                    $course_id_field_name,
-                    $course_id_value,
-                    $extras
-                );
-                if ($result instanceof WSCMError) {
-                    $result_tmp['result'] = $result->toArray();
-                    $result_tmp['course_id_value'] = $course_id_value;
-                    $result_tmp['course_id_generated'] = 0;
-                } else {
-                    $result_tmp['result'] = $this->getSuccessfulResult();
-                    $result_tmp['course_id_value'] = $course_id_value;
-                    $result_tmp['course_id_generated'] = $result;
-                }
-                $results[] = $result_tmp;
-            }
-
-            return $results;
-        }
-    }
-
     /**
      * Edits a course.
      *
@@ -511,73 +406,6 @@ class WSCMCourse extends WSCM
         }
     }
 
-    /**
-     * Creates a course (helper method).
-     *
-     * @param string Title
-     * @param string Category code
-     * @param string Wanted code. If it's not defined, it will be generated automatically
-     * @param string Tutor name
-     * @param string Course admin user id field name
-     * @param string Course admin user id value
-     * @param string Course language
-     * @param string Course id field name
-     * @param string Course id value
-     * @param array Course extra fields
-     *
-     * @return mixed Generated id if creation was successful, WSError otherwise
-     */
-    protected function createCourseHelper(
-        $title,
-        $category_code,
-        $wanted_code,
-        $tutor_name,
-        $course_admin_user_id_field_name,
-        $course_admin_user_id_value,
-        $language,
-        $course_id_field_name,
-        $course_id_value,
-        $extras
-    ) {
-        // Add the original course id field name and value to the extra fields if needed
-        $extras_associative = [];
-        if ($course_id_field_name != "chamilo_course_id") {
-            $extras_associative[$course_id_field_name] = $course_id_value;
-        }
-        foreach ($extras as $extra) {
-            $extras_associative[$extra['field_name']] = $extra['field_value'];
-        }
-        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
-        if ($course_admin_id instanceof WSError) {
-            return $course_admin_id;
-        }
-        if ($wanted_code == '') {
-            $wanted_code = CourseManager::generate_course_code($title);
-        }
-        $result = create_course(
-            $wanted_code,
-            $title,
-            $tutor_name,
-            $category_code,
-            $language,
-            $course_admin_id,
-            $this->_configuration['db_prefix'],
-            0
-        );
-        if (!$result) {
-            return new WSError(202, 'There was an error creating the course');
-        } else {
-            // Update extra fields
-            foreach ($extras_associative as $fname => $fvalue) {
-                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
-            }
-            // Get course id
-            $course_info = CourseManager::get_course_information($result);
-
-            return $course_info['real_id'];
-        }
-    }
-
     /**
      * Edits a course (helper method).
      *

+ 0 - 71
main/webservices/soap_course.php

@@ -65,77 +65,6 @@ $s->register(
     ['return' => 'tns:course_result_array']
 );
 
-$s->register(
-    'WSCourse.CreateCourse',
-    [
-        'secret_key' => 'xsd:string',
-        'title' => 'xsd:string',
-        'category_code' => 'xsd:string',
-        'wanted_code' => 'xsd:string',
-        'tutor_name' => 'xsd:string',
-        'course_admin_user_id_field_name' => 'xsd:string',
-        'course_admin_user_id_value' => 'xsd:string',
-        'language' => 'xsd:string',
-        'course_id_field_name' => 'xsd:string',
-        'course_id_value' => 'xsd:string',
-        'extras' => 'tns:extra_field',
-    ],
-    ['return' => 'xsd:int']
-);
-
-$s->wsdl->addComplexType(
-    'course_create',
-    'complexType',
-    'struct',
-    'all',
-    '',
-    [
-        'title' => ['name' => 'title', 'type' => 'xsd:string'],
-        'category_code' => ['name' => 'category_code', 'type' => 'xsd:string'],
-        'wanted_code' => ['name' => 'wanted_code', 'type' => 'xsd:int'],
-        'tutor_name' => ['name' => 'tutor_name', 'type' => 'xsd:string'],
-        'course_admin_user_id_field_name' => ['name' => 'course_admin_user_id_field_name', 'type' => 'xsd:string'],
-        'course_admin_user_id_value' => ['name' => 'course_admin_user_id_value', 'type' => 'xsd:string'],
-        'language' => ['name' => 'language', 'type' => 'xsd:string'],
-        'course_id_field_name' => ['name' => 'course_id_field_name', 'type' => 'xsd:string'],
-        'course_id_value' => ['name' => 'course_id_value', 'type' => 'xsd:string'],
-        'extras' => ['name' => 'extras', 'type' => 'tns:extra_field'],
-    ]
-);
-
-$s->wsdl->addComplexType(
-    'course_create_result',
-    'complexType',
-    'struct',
-    'all',
-    '',
-    [
-        'course_id_value' => ['name' => 'course_id_value', 'type' => 'xsd:string'],
-        'course_id_generated' => ['name' => 'course_id_generated', 'type' => 'xsd:int'],
-        'result' => ['name' => 'result', 'type' => 'tns:result'],
-    ]
-);
-
-$s->wsdl->addComplexType(
-    'course_create_result_array',
-    'complexType',
-    'array',
-    '',
-    'SOAP-ENC:Array',
-    [],
-    [['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_create_result[]']],
-    'tns:course_create_result'
-);
-
-$s->register(
-    'WSCourse.CreateCourses',
-    [
-        'secret_key' => 'xsd:string',
-        'courses' => 'tns:course_create[]',
-    ],
-    ['return' => 'tns:course_create_result_array']
-);
-
 $s->register(
     'WSCourse.EditCourse',
     [

+ 0 - 179
main/webservices/webservice_course.php

@@ -76,111 +76,6 @@ class WSCourse extends WS
         }
     }
 
-    /**
-     * Creates a course.
-     *
-     * @param string API secret key
-     * @param string Title
-     * @param string Category code
-     * @param string Wanted code. If it's not defined, it will be generated automatically
-     * @param string Tutor name
-     * @param string Course admin user id field name
-     * @param string Course admin user id value
-     * @param string Course language
-     * @param string Course id field name
-     * @param string Course id value
-     * @param array Course extra fields
-     *
-     * @return int Course id generated
-     */
-    public function CreateCourse(
-        $secret_key,
-        $title,
-        $category_code,
-        $wanted_code,
-        $tutor_name,
-        $course_admin_user_id_field_name,
-        $course_admin_user_id_value,
-        $language,
-        $course_id_field_name,
-        $course_id_value,
-        $extras
-    ) {
-        // First, verify the secret key
-        $verifKey = $this->verifyKey($secret_key);
-        if ($verifKey instanceof WSError) {
-            $this->handleError($verifKey);
-        } else {
-            $result = $this->createCourseHelper(
-                $title,
-                $category_code,
-                $wanted_code,
-                $tutor_name,
-                $course_admin_user_id_field_name,
-                $course_admin_user_id_value,
-                $language,
-                $course_id_field_name,
-                $course_id_value,
-                $extras
-            );
-            if ($result instanceof WSError) {
-                $this->handleError($result);
-            } else {
-                return $result;
-            }
-        }
-    }
-
-    /**
-     * Create multiple courses.
-     *
-     * @param string API secret key
-     * @param array Courses to be created, with elements following the structure presented in CreateCourse
-     *
-     * @return array Array with elements of the form
-     *               array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
-     */
-    public function CreateCourses($secret_key, $courses)
-    {
-        // First, verify the secret key
-        $verifKey = $this->verifyKey($secret_key);
-        if ($verifKey instanceof WSError) {
-            $this->handleError($verifKey);
-        } else {
-            $results = [];
-            foreach ($courses as $course) {
-                $result_tmp = [];
-                // re-initialize variables just in case
-                $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0;
-                extract($course);
-                $result = $this->createCourseHelper(
-                    $title,
-                    $category_code,
-                    $wanted_code,
-                    $tutor_name,
-                    $course_admin_user_id_field_name,
-                    $course_admin_user_id_value,
-                    $language,
-                    $course_id_field_name,
-                    $course_id_value,
-                    $extras
-                );
-                if ($result instanceof WSError) {
-                    $result_tmp['result'] = $result->toArray();
-                    $result_tmp['course_id_value'] = $course_id_value;
-                    $result_tmp['course_id_generated'] = 0;
-                } else {
-                    $result_tmp['result'] = $this->getSuccessfulResult();
-                    $result_tmp['course_id_value'] = $course_id_value;
-                    $result_tmp['course_id_generated'] = $result;
-                }
-                $results[] = $result_tmp;
-            }
-
-            return $results;
-        }
-    }
-
     /**
      * Edits a course.
      *
@@ -507,80 +402,6 @@ class WSCourse extends WS
         }
     }
 
-    /**
-     * Creates a course (helper method).
-     *
-     * @param string Title
-     * @param string Category code
-     * @param string Wanted code. If it's not defined, it will be generated automatically
-     * @param string Tutor name
-     * @param string Course admin user id field name
-     * @param string Course admin user id value
-     * @param string Course language
-     * @param string Course id field name
-     * @param string Course id value
-     * @param array Course extra fields
-     *
-     * @return mixed Generated id if creation was successful, WSError otherwise
-     */
-    protected function createCourseHelper(
-        $title,
-        $category_code,
-        $wanted_code,
-        $tutor_name,
-        $course_admin_user_id_field_name,
-        $course_admin_user_id_value,
-        $language,
-        $course_id_field_name,
-        $course_id_value,
-        $extras
-    ) {
-        // Add the original course id field name and value to the extra fields if needed
-        $extras_associative = [];
-        if ($course_id_field_name != "chamilo_course_id") {
-            $extras_associative[$course_id_field_name] = $course_id_value;
-        }
-        foreach ($extras as $extra) {
-            $extras_associative[$extra['field_name']] = $extra['field_value'];
-        }
-        $course_admin_id = $this->getUserId(
-            $course_admin_user_id_field_name,
-            $course_admin_user_id_value
-        );
-        if ($course_admin_id instanceof WSError) {
-            return $course_admin_id;
-        }
-        if ($wanted_code == '') {
-            $wanted_code = CourseManager::generate_course_code($title);
-        }
-        $result = create_course(
-            $wanted_code,
-            $title,
-            $tutor_name,
-            $category_code,
-            $language,
-            $course_admin_id,
-            $this->_configuration['db_prefix'],
-            0
-        );
-        if (!$result) {
-            return new WSError(202, 'There was an error creating the course');
-        } else {
-            // Update extra fields
-            foreach ($extras_associative as $fname => $fvalue) {
-                CourseManager::update_course_extra_field_value(
-                    $result,
-                    $fname,
-                    $fvalue
-                );
-            }
-            // Get course id
-            $course_info = CourseManager::get_course_information($result);
-
-            return $course_info['real_id'];
-        }
-    }
-
     /**
      * Edits a course (helper method).
      *