|
@@ -73,129 +73,6 @@ class WSUser extends WS
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Creates a user.
|
|
|
- *
|
|
|
- * @param string API secret key
|
|
|
- * @param string User first name
|
|
|
- * @param string User last name
|
|
|
- * @param int User status
|
|
|
- * @param string Login name
|
|
|
- * @param string Password (encrypted or not)
|
|
|
- * @param string Encrypt method. Leave blank if you are passing the password in clear text,
|
|
|
- * set to the encrypt method used to encrypt the password otherwise. Remember
|
|
|
- * to include the salt in the extra fields if you are encrypting the password
|
|
|
- * @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id
|
|
|
- * @param string User id value. Leave blank if you are using the internal user_id
|
|
|
- * @param int Visibility. Set by default to 1
|
|
|
- * @param string User email. Set by default to an empty string
|
|
|
- * @param string Language. Set by default to english
|
|
|
- * @param string Phone. Set by default to an empty string
|
|
|
- * @param string Expiration date. Set to null by default
|
|
|
- * @param array Extra fields. An array with elements of the form
|
|
|
- * array('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field'). Set to an empty array by default
|
|
|
- *
|
|
|
- * @return int New user id generated by the system
|
|
|
- */
|
|
|
- public function CreateUser(
|
|
|
- $secret_key,
|
|
|
- $firstname,
|
|
|
- $lastname,
|
|
|
- $status,
|
|
|
- $login,
|
|
|
- $password,
|
|
|
- $encrypt_method,
|
|
|
- $user_id_field_name,
|
|
|
- $user_id_value,
|
|
|
- $visibility = 1,
|
|
|
- $email = '',
|
|
|
- $language = 'english',
|
|
|
- $phone = '',
|
|
|
- $expiration_date = '0000-00-00 00:00:00',
|
|
|
- $extras = []
|
|
|
- ) {
|
|
|
- // First, verify the secret key
|
|
|
- $verifKey = $this->verifyKey($secret_key);
|
|
|
- if ($verifKey instanceof WSError) {
|
|
|
- $this->handleError($verifKey);
|
|
|
- } else {
|
|
|
- $result = $this->createUserHelper(
|
|
|
- $firstname,
|
|
|
- $lastname,
|
|
|
- $status,
|
|
|
- $login,
|
|
|
- $password,
|
|
|
- $encrypt_method,
|
|
|
- $user_id_field_name,
|
|
|
- $user_id_value,
|
|
|
- $visibility,
|
|
|
- $email,
|
|
|
- $language,
|
|
|
- $phone,
|
|
|
- $expiration_date,
|
|
|
- $extras
|
|
|
- );
|
|
|
- if ($result instanceof WSError) {
|
|
|
- $this->handleError($result);
|
|
|
- } else {
|
|
|
- return $result;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Creates multiple users.
|
|
|
- *
|
|
|
- * @param string API secret key
|
|
|
- * @param array Users array. Each member of this array must follow the structure imposed by the CreateUser method
|
|
|
- *
|
|
|
- * @return array Array with elements of the form
|
|
|
- * array('user_id_value' => 'original value sent', 'user_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
|
|
|
- */
|
|
|
- public function CreateUsers($secret_key, $users)
|
|
|
- {
|
|
|
- $verifKey = $this->verifyKey($secret_key);
|
|
|
- if ($verifKey instanceof WSError) {
|
|
|
- $this->handleError($verifKey);
|
|
|
- } else {
|
|
|
- $results = [];
|
|
|
- foreach ($users as $user) {
|
|
|
- $result_tmp = [];
|
|
|
- // re-initialize variables just in case
|
|
|
- $firstname = $lastname = $status = $login = $password = $encrypt_method = $user_id_field_name = $user_id_value = $visibility = $email = $language = $phone = $expiration_date = $extras = null;
|
|
|
- extract($user);
|
|
|
- $result = $this->createUserHelper(
|
|
|
- $firstname,
|
|
|
- $lastname,
|
|
|
- $status,
|
|
|
- $login,
|
|
|
- $password,
|
|
|
- $encrypt_method,
|
|
|
- $user_id_field_name,
|
|
|
- $user_id_value,
|
|
|
- $visibility,
|
|
|
- $email,
|
|
|
- $language,
|
|
|
- $phone,
|
|
|
- $expiration_date,
|
|
|
- $extras
|
|
|
- );
|
|
|
- if ($result instanceof WSError) {
|
|
|
- $result_tmp['result'] = $result->toArray();
|
|
|
- $result_tmp['user_id_value'] = $user_id_value;
|
|
|
- $result_tmp['user_id_generated'] = 0;
|
|
|
- } else {
|
|
|
- $result_tmp['result'] = $this->getSuccessfulResult();
|
|
|
- $result_tmp['user_id_value'] = $user_id_value;
|
|
|
- $result_tmp['user_id_generated'] = $result;
|
|
|
- }
|
|
|
- $results[] = $result_tmp;
|
|
|
- }
|
|
|
-
|
|
|
- return $results;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Edits user info.
|
|
|
*
|
|
@@ -341,80 +218,6 @@ class WSUser extends WS
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Creates a user (helper method).
|
|
|
- *
|
|
|
- * @param string User first name
|
|
|
- * @param string User last name
|
|
|
- * @param int User status
|
|
|
- * @param string Login name
|
|
|
- * @param string Password (encrypted or not)
|
|
|
- * @param string Encrypt method. Leave blank if you are passing the password in clear text,
|
|
|
- * set to the encrypt method used to encrypt the password otherwise. Remember
|
|
|
- * to include the salt in the extra fields if you are encrypting the password
|
|
|
- * @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id
|
|
|
- * @param string User id value. Leave blank if you are using the internal user_id
|
|
|
- * @param int visibility
|
|
|
- * @param string user email
|
|
|
- * @param string language
|
|
|
- * @param string phone
|
|
|
- * @param string Expiration date
|
|
|
- * @param array Extra fields. An array with elements of the form
|
|
|
- * array('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field').
|
|
|
- *
|
|
|
- * @return mixed New user id generated by the system, WSError otherwise
|
|
|
- */
|
|
|
- protected function createUserHelper(
|
|
|
- $firstname,
|
|
|
- $lastname,
|
|
|
- $status,
|
|
|
- $login,
|
|
|
- $password,
|
|
|
- $encrypt_method,
|
|
|
- $user_id_field_name,
|
|
|
- $user_id_value,
|
|
|
- $visibility,
|
|
|
- $email,
|
|
|
- $language,
|
|
|
- $phone,
|
|
|
- $expiration_date,
|
|
|
- $extras = []
|
|
|
- ) {
|
|
|
- // Add the original user id field name and value to the extra fields if needed
|
|
|
- $extras_associative = [];
|
|
|
- if ($user_id_field_name != "chamilo_user_id") {
|
|
|
- $extras_associative[$user_id_field_name] = $user_id_value;
|
|
|
- }
|
|
|
- if (!empty($extras)) {
|
|
|
- foreach ($extras as $extra) {
|
|
|
- $extras_associative[$extra['field_name']] = $extra['field_value'];
|
|
|
- }
|
|
|
- }
|
|
|
- $result = UserManager::create_user(
|
|
|
- $firstname,
|
|
|
- $lastname,
|
|
|
- $status,
|
|
|
- $email,
|
|
|
- $login,
|
|
|
- $password,
|
|
|
- '',
|
|
|
- $language,
|
|
|
- $phone,
|
|
|
- '',
|
|
|
- PLATFORM_AUTH_SOURCE,
|
|
|
- $expiration_date,
|
|
|
- $visibility,
|
|
|
- 0,
|
|
|
- $extras_associative,
|
|
|
- $encrypt_method
|
|
|
- );
|
|
|
- if (!$result) {
|
|
|
- return new WSError(104, 'There was an error creating the user');
|
|
|
- } else {
|
|
|
- return $result;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Edits user info (helper method).
|
|
|
*
|