Bläddra i källkod

Merge pull request #705 from AngelFQC/BT9413

Fix web services from advanced suscription - refs BT9413
Yannick Warnier 9 år sedan
förälder
incheckning
c2cbbe3522

+ 1 - 1
main/admin/course_add.php

@@ -114,7 +114,7 @@ $obj = new GradeModel();
 $obj->fill_grade_model_select_in_form($form);
 $obj->fill_grade_model_select_in_form($form);
 
 
 //Extra fields
 //Extra fields
-$extra_field = new CourseField();
+$extra_field = new ExtraField('course');
 $extra = $extra_field->addElements($form);
 $extra = $extra_field->addElements($form);
 
 
 $htmlHeadXtra[] ='
 $htmlHeadXtra[] ='

+ 3 - 3
main/admin/course_edit.php

@@ -202,7 +202,7 @@ $form->addElement('text', 'disk_quota', array(get_lang('CourseQuota'), null, get
 $form->addRule('disk_quota', get_lang('ThisFieldIsRequired'), 'required');
 $form->addRule('disk_quota', get_lang('ThisFieldIsRequired'), 'required');
 $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
 $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
 
 
-$specialCourseField = new CourseField();
+$specialCourseField = new ExtraField('course');
 $specialCourseFieldInfo = $specialCourseField->get_handler_field_info_by_field_variable('special_course');
 $specialCourseFieldInfo = $specialCourseField->get_handler_field_info_by_field_variable('special_course');
 
 
 if (!empty($specialCourseFieldInfo)) {
 if (!empty($specialCourseFieldInfo)) {
@@ -231,8 +231,8 @@ if (!empty($specialCourseFieldInfo)) {
 }
 }
 
 
 //Extra fields
 //Extra fields
-$extra_field = new CourseField();
-$extra = $extra_field->addElements($form, $courseId);
+$extra_field = new ExtraField('course');
+$extra = $extra_field->addElements($form, $courseId, ['special_course']);
 
 
 $htmlHeadXtra[] = '
 $htmlHeadXtra[] = '
 <script>
 <script>

+ 2 - 1
main/admin/resume_session.php

@@ -25,6 +25,8 @@ $tool_name = get_lang('SessionOverview');
 $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
 $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
 $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
 $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
 
 
+$orig_param = '&origin=resume_session';
+
 // Database Table Definitions
 // Database Table Definitions
 $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
 $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
@@ -372,7 +374,6 @@ if ($session['nbr_courses'] == 0) {
             $downUrl
             $downUrl
         );
         );
 
 
-		$orig_param = '&origin=resume_session';
 		//hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
 		//hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
 		echo '
 		echo '
 		<tr>
 		<tr>

+ 0 - 28
main/inc/lib/CourseField.php

@@ -1,28 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
- * Manage the course extra fields
- * @package chamilo.library
- */
-/**
- * Manage the course extra fields
- *
- * Add the extra fields to the form excluding the Special Course Field
- */
-class CourseField extends ExtraField
-{
-
-    /**
-     * Special Course extra field
-     */
-    const SPECIAL_COURSE_FIELD = 'special_course';
-
-    /**
-     * Class constructor
-     */
-    public function __construct()
-    {
-        parent::__construct('course');
-    }
-}

+ 26 - 0
main/inc/lib/add_course.lib.inc.php

@@ -1508,4 +1508,30 @@ class AddCourse
         rmdir($tmp_dir_name);
         rmdir($tmp_dir_name);
         return $course_properties;
         return $course_properties;
     }
     }
+
+    /**
+     * Generate a new id for c_tool table 
+     * @param int $courseId The course id
+     * @return int the new id
+     */
+    public static function generateToolId($courseId)
+    {
+        $newIdResultData = Database::select(
+            'id + 1 AS new_id',
+            Database::get_course_table(TABLE_TOOL_LIST),
+            [
+                'where' => ['c_id = ?' => intval($courseId)],
+                'order' => 'id',
+                'limit' => 1
+            ],
+            'first'
+        );
+
+        if ($newIdResultData === false) {
+            return 1;
+        }
+
+        return $newIdResultData['new_id'] > 0 ? $newIdResultData['new_id'] : 1;
+    }
+
 }
 }

+ 13 - 7
main/inc/lib/api.lib.php

@@ -1437,6 +1437,10 @@ function _api_format_user($user, $add_password = false)
 
 
     $result['profile_url'] = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_id;
     $result['profile_url'] = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_id;
 
 
+    if (isset($user['extra'])) {
+        $result['extra'] = $user['extra'];
+    }
+
     return $result;
     return $result;
 }
 }
 
 
@@ -1491,13 +1495,15 @@ function api_get_user_info(
                 }
                 }
             }
             }
             $result_array['user_is_online_in_chat'] = $user_online_in_chat;
             $result_array['user_is_online_in_chat'] = $user_online_in_chat;
-            if ($loadExtraData) {
-                $extraFieldValues = new ExtraFieldValue('user');
-                $values = $extraFieldValues->getAllValuesByItem($user_id);
-                if (!empty($values)) {
-                    foreach ($values as $value) {
-                        $result_array['extra'][$value['variable']] = $value['value'];
-                    }
+        }
+
+        if ($loadExtraData) {
+            $extraFieldValues = new ExtraFieldValue('user');
+            $values = $extraFieldValues->getAllValuesByItem($user_id);
+
+            if (!empty($values)) {
+                foreach ($values as $value) {
+                    $result_array['extra'][$value['variable']] = $value['value'];
                 }
                 }
             }
             }
         }
         }

+ 55 - 35
main/inc/lib/extra_field.lib.php

@@ -306,11 +306,11 @@ class ExtraField extends Model
      * Add elements to a form
      * Add elements to a form
      *
      *
      * @param FormValidator $form
      * @param FormValidator $form
-     * @param int           $itemId
-     *
+     * @param int $itemId
+     * @param array $exclude variables of extra field to exclude
      * @return array|bool
      * @return array|bool
      */
      */
-    public function addElements($form, $itemId = 0)
+    public function addElements($form, $itemId = 0, $exclude = [])
     {
     {
         if (empty($form)) {
         if (empty($form)) {
             return false;
             return false;
@@ -333,7 +333,8 @@ class ExtraField extends Model
             $extraData,
             $extraData,
             false,
             false,
             $extraFields,
             $extraFields,
-            $itemId
+            $itemId,
+            $exclude
         );
         );
 
 
         return $extra;
         return $extra;
@@ -633,7 +634,7 @@ class ExtraField extends Model
      * @param int $user_id
      * @param int $user_id
      * @param array $extra
      * @param array $extra
      * @param int $itemId
      * @param int $itemId
-     *
+     * @param array $exclude variables of extra field to exclude
      * @return array
      * @return array
      */
      */
     public function set_extra_fields_in_form(
     public function set_extra_fields_in_form(
@@ -641,7 +642,8 @@ class ExtraField extends Model
         $extraData,
         $extraData,
         $admin_permissions = false,
         $admin_permissions = false,
         $extra = array(),
         $extra = array(),
-        $itemId = null
+        $itemId = null,
+        $exclude = []
     ) {
     ) {
         $type = $this->type;
         $type = $this->type;
 
 
@@ -673,6 +675,10 @@ class ExtraField extends Model
                     if ($field_details['visible'] == 0) {
                     if ($field_details['visible'] == 0) {
                         continue;
                         continue;
                     }
                     }
+
+                    if (in_array($field_details['variable'], $exclude)) {
+                        continue;
+                    }
                 }
                 }
 
 
                 switch ($field_details['field_type']) {
                 switch ($field_details['field_type']) {
@@ -1275,9 +1281,12 @@ EOF;
                         );
                         );
 
 
                         if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) {
                         if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) {
-                            if (file_exists(api_get_path(SYS_CODE_PATH) . $extraData[$fieldVariable])) {
+                            $cleanImagePath = str_replace(api_get_path(SYS_PATH), '', $extraData[$fieldVariable]);
+                            $webImagePath = api_get_path(WEB_PATH) . $cleanImagePath;
+
+                            if (file_exists(api_get_path(SYS_PATH) . $cleanImagePath)) {
                                 $fieldTexts[] = Display::img(
                                 $fieldTexts[] = Display::img(
-                                    api_get_path(WEB_CODE_PATH) . $extraData[$fieldVariable],
+                                    $webImagePath,
                                     $field_details['display_text'],
                                     $field_details['display_text'],
                                     array('width' => '300')
                                     array('width' => '300')
                                 );
                                 );
@@ -1339,10 +1348,13 @@ EOF;
                         if (is_array($extraData) &&
                         if (is_array($extraData) &&
                             array_key_exists($fieldVariable, $extraData)
                             array_key_exists($fieldVariable, $extraData)
                         ) {
                         ) {
-                            if (file_exists(api_get_path(SYS_CODE_PATH) . $extraData[$fieldVariable])) {
+                            $cleanFilePath = str_replace(api_get_path(SYS_PATH), '', $extraData[$fieldVariable]);
+                            $webFilePath = api_get_path(WEB_PATH) . $cleanFilePath;
+
+                            if (file_exists(api_get_path(SYS_PATH) . $cleanFilePath)) {
                                 $fieldTexts[] = Display::url(
                                 $fieldTexts[] = Display::url(
-                                    api_get_path(WEB_CODE_PATH) . $extraData[$fieldVariable],
-                                    api_get_path(WEB_CODE_PATH) . $extraData[$fieldVariable],
+                                    $webFilePath,
+                                    $webFilePath,
                                     array(
                                     array(
                                         'title' => $field_details['display_text'],
                                         'title' => $field_details['display_text'],
                                         'target' => '_blank'
                                         'target' => '_blank'
@@ -2041,35 +2053,43 @@ EOF;
                     }
                     }
                     break;
                     break;
                 case ExtraField::FIELD_TYPE_FILE_IMAGE:
                 case ExtraField::FIELD_TYPE_FILE_IMAGE:
-                    if ($valueData !== false && !empty($valueData['value'])) {
-                        if (file_exists(api_get_path(SYS_UPLOAD_PATH) . $valueData['value'])) {
-                            $image = Display::img(
-                                api_get_path(WEB_UPLOAD_PATH) . $valueData['value'],
-                                $field['display_text'],
-                                array('width' => '300')
-                            );
+                    if ($valueData === false || empty($valueData['value'])) {
+                        break;
+                    }
 
 
-                            $displayedValue = Display::url(
-                                $image,
-                                api_get_path(WEB_UPLOAD_PATH) . $valueData['value'],
-                                array('target' => '_blank')
-                            );
-                        }
+                    if (!file_exists(api_get_path(SYS_UPLOAD_PATH) . $valueData['value'])) {
+                        break;
                     }
                     }
+
+                    $image = Display::img(
+                        api_get_path(WEB_UPLOAD_PATH) . $valueData['value'],
+                        $field['display_text'],
+                        array('width' => '300')
+                    );
+
+                    $displayedValue = Display::url(
+                        $image,
+                        api_get_path(WEB_UPLOAD_PATH) . $valueData['value'],
+                        array('target' => '_blank')
+                    );
                     break;
                     break;
                 case ExtraField::FIELD_TYPE_FILE:
                 case ExtraField::FIELD_TYPE_FILE:
-                    if ($valueData !== false && !empty($valueData['value'])) {
-                        if (file_exists(api_get_path(SYS_UPLOAD_PATH) . $valueData['value'])) {
-                            $displayedValue = Display::url(
-                                get_lang('Download'),
-                                api_get_path(WEB_UPLOAD_PATH) . $valueData['value'],
-                                array(
-                                'title' => $field['display_text'],
-                                'target' => '_blank'
-                                )
-                            );
-                        }
+                    if ($valueData === false || empty($valueData['value'])) {
+                        break;
+                    }
+
+                    if (!file_exists(api_get_path(SYS_UPLOAD_PATH) . $valueData['value'])) {
+                        break;
                     }
                     }
+
+                    $displayedValue = Display::url(
+                        get_lang('Download'),
+                        api_get_path(WEB_UPLOAD_PATH) . $valueData['value'],
+                        array(
+                            'title' => $field['display_text'],
+                            'target' => '_blank'
+                        )
+                    );
                     break;
                     break;
                 default:
                 default:
                     $displayedValue = $valueData['value'];
                     $displayedValue = $valueData['value'];

+ 20 - 3
main/inc/lib/plugin.class.php

@@ -439,9 +439,26 @@ class Plugin
         if (!Database::num_rows($result)) {
         if (!Database::num_rows($result)) {
             $tool_link = "$plugin_name/start.php";
             $tool_link = "$plugin_name/start.php";
             $visibility = AddCourse::string2binary(api_get_setting('course_create_active_tools', $plugin_name));
             $visibility = AddCourse::string2binary(api_get_setting('course_create_active_tools', $plugin_name));
-            $sql = "INSERT INTO $t_tool VALUES
-            ($courseId, NULL, '$plugin_name', '$tool_link', '$plugin_name.png',' ".$visibility."','0', 'squaregrey.gif','NO','_self','plugin','0')";
-            Database::query($sql);
+
+            $cToolId = AddCourse::generateToolId($courseId);
+
+            Database::insert(
+                $t_tool,
+                [
+                    'id' => $cToolId,
+                    'c_id' => $courseId,
+                    'name' => $plugin_name,
+                    'link' => $tool_link,
+                    'image' => "$plugin_name.png",
+                    'visibility' => $visibility,
+                    'admin' => 0,
+                    'address' => 'squaregrey.gif',
+                    'added_tool' => 'NO',
+                    'target' => '_self',
+                    'category' => 'plugin',
+                    'session_id' => 0
+                ]
+            );
         }
         }
     }
     }
 
 

+ 4 - 4
main/inc/lib/sessionmanager.lib.php

@@ -211,7 +211,7 @@ class SessionManager
                 }
                 }
 
 
                 if (!empty($session_id)) {
                 if (!empty($session_id)) {
-                    $extraFields['session_id'] = $session_id;
+                    $extraFields['item_id'] = $session_id;
 
 
                     $sessionFieldValue = new ExtraFieldValue('session');
                     $sessionFieldValue = new ExtraFieldValue('session');
                     $sessionFieldValue->saveFieldValues($extraFields);
                     $sessionFieldValue->saveFieldValues($extraFields);
@@ -1451,7 +1451,7 @@ class SessionManager
                     'id = ?' => $id
                     'id = ?' => $id
                 ));
                 ));
 
 
-                $extraFields['session_id'] = $id;
+                $extraFields['item_id'] = $id;
 
 
                 $sessionFieldValue = new ExtraFieldValue('session');
                 $sessionFieldValue = new ExtraFieldValue('session');
                 $sessionFieldValue->saveFieldValues($extraFields);
                 $sessionFieldValue->saveFieldValues($extraFields);
@@ -5593,7 +5593,7 @@ class SessionManager
                 array(
                 array(
                     'where' => array(
                     'where' => array(
                         "session_category_id = ? AND id IN (
                         "session_category_id = ? AND id IN (
-                            SELECT sfv.session_id FROM $joinTable
+                            SELECT sfv.item_id FROM $joinTable
                             WHERE
                             WHERE
                                 sf.extra_field_type = $extraFieldType AND
                                 sf.extra_field_type = $extraFieldType AND
                                 sfv.item_id = session.id AND
                                 sfv.item_id = session.id AND
@@ -5758,7 +5758,7 @@ class SessionManager
                             item_id IN $sessionIdsString AND
                             item_id IN $sessionIdsString AND
                             extra_field_type = $extraFieldType
                             extra_field_type = $extraFieldType
                 ";
                 ";
-                $result = Database::result($sql);
+                $result = Database::query($sql);
                 $sessionFieldValueList = Database::store_result($result, 'ASSOC');
                 $sessionFieldValueList = Database::store_result($result, 'ASSOC');
 
 
                 // Check if session field values had result
                 // Check if session field values had result

+ 13 - 9
main/inc/lib/usermanager.lib.php

@@ -1129,18 +1129,22 @@ class UserManager
      * @param int User id
      * @param int User id
      * @return bool True if user id was found, false otherwise
      * @return bool True if user id was found, false otherwise
      */
      */
-    public static function is_user_id_valid($user_id)
+    public static function is_user_id_valid($userId)
     {
     {
-        $user_id = (int) $user_id;
-        $table_user = Database :: get_main_table(TABLE_MAIN_USER);
-        $sql = "SELECT user_id FROM $table_user WHERE user_id = '".$user_id."'";
-        $res = Database::query($sql);
-        $num_rows = Database::num_rows($res);
-        if ($num_rows == 0) {
+        $resultData = Database::select(
+            'COUNT(1) AS count',
+            Database::get_main_table(TABLE_MAIN_USER),
+            [
+                'where' => ['id = ?' => intval($userId)]
+            ],
+            'first'
+        );
+
+        if ($resultData === false) {
             return false;
             return false;
-        } else {
-            return true;
         }
         }
+
+        return $resultData['count'] > 0;
     }
     }
 
 
     /**
     /**

+ 8 - 0
main/webservices/registration.soap.php

@@ -569,6 +569,10 @@ function WSCreateUser($params) {
                 active = '".Database::escape_string($active)."'";
                 active = '".Database::escape_string($active)."'";
     $result = Database::query($sql);-*/
     $result = Database::query($sql);-*/
 
 
+    if (isset($original_user_id_name) && isset($original_user_id_value)) {
+        $_SESSION['ws_' . $original_user_id_name] = $original_user_id_value;
+    }
+    
     /** @var User $user */
     /** @var User $user */
     $userId = UserManager::create_user(
     $userId = UserManager::create_user(
         $firstName,
         $firstName,
@@ -613,6 +617,10 @@ function WSCreateUser($params) {
             $original_user_id_value
             $original_user_id_value
         );
         );
 
 
+        if (isset($original_user_id_name) && isset($original_user_id_value)) {
+            unset($_SESSION['ws_' . $original_user_id_name]);
+        }
+
         if (is_array($extra_list) && count($extra_list) > 0) {
         if (is_array($extra_list) && count($extra_list) > 0) {
             foreach ($extra_list as $extra) {
             foreach ($extra_list as $extra) {
                 $extra_field_name = $extra['field_name'];
                 $extra_field_name = $extra['field_name'];

+ 2 - 0
plugin/advanced_subscription/lang/english.php

@@ -19,6 +19,8 @@ $strings['course_session_credit_year_start_date'] = 'Year start date';
 $strings['course_session_credit_year_start_date_help'] = "a date (dd/mm)";
 $strings['course_session_credit_year_start_date_help'] = "a date (dd/mm)";
 $strings['min_profile_percentage'] = "Minimum required of completed percentage profile";
 $strings['min_profile_percentage'] = "Minimum required of completed percentage profile";
 $strings['min_profile_percentage_help'] = "Percentage number( > 0.00 y < 100.00)";
 $strings['min_profile_percentage_help'] = "Percentage number( > 0.00 y < 100.00)";
+$strings['secret_key'] = 'Secret key';
+$strings['terms_and_conditions'] = 'Terms and conditions';
 
 
 /* String for error message about requirements */
 /* String for error message about requirements */
 $strings['AdvancedSubscriptionNotConnected'] = "You are not connected to platform. Please login first";
 $strings['AdvancedSubscriptionNotConnected'] = "You are not connected to platform. Please login first";

+ 2 - 0
plugin/advanced_subscription/lang/spanish.php

@@ -19,6 +19,8 @@ $strings['course_session_credit_year_start_date'] = 'Fecha de inicio';
 $strings['course_session_credit_year_start_date_help'] = "Fecha de inicio del año (día/mes)";
 $strings['course_session_credit_year_start_date_help'] = "Fecha de inicio del año (día/mes)";
 $strings['min_profile_percentage'] = 'Porcentage de perfil completado mínimo requerido';
 $strings['min_profile_percentage'] = 'Porcentage de perfil completado mínimo requerido';
 $strings['min_profile_percentage_help'] = 'Número porcentage ( > 0.00 y < 100.00)';
 $strings['min_profile_percentage_help'] = 'Número porcentage ( > 0.00 y < 100.00)';
+$strings['secret_key'] = 'LLave secreta';
+$strings['terms_and_conditions'] = 'Términos y condiciones';
 
 
 /* String for error message about requirements */
 /* String for error message about requirements */
 $strings['AdvancedSubscriptionNotConnected'] = "Usted no está conectado en la plataforma. Por favor ingrese su usuario / constraseña para poder inscribirse";
 $strings['AdvancedSubscriptionNotConnected'] = "Usted no está conectado en la plataforma. Por favor ingrese su usuario / constraseña para poder inscribirse";

+ 1 - 1
plugin/advanced_subscription/src/AdvancedSubscriptionPlugin.php

@@ -1312,7 +1312,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
             INNER JOIN $tSessionField AS sf ON sfv.field_id = sf.id
             INNER JOIN $tSessionField AS sf ON sfv.field_id = sf.id
             INNER JOIN $tSessionUser AS su ON s.id = su.session_id
             INNER JOIN $tSessionUser AS su ON s.id = su.session_id
             WHERE
             WHERE
-                sf.extra_field_type = $extraFieldType
+                sf.extra_field_type = $extraFieldType AND
                 sf.variable = 'is_induction_session' AND
                 sf.variable = 'is_induction_session' AND
                 su.relation_type = 0 AND
                 su.relation_type = 0 AND
                 su.user_id = " . intval($userId);
                 su.user_id = " . intval($userId);

+ 1 - 1
plugin/advanced_subscription/src/admin_view.php

@@ -68,7 +68,7 @@ if (!empty($sessionId)) {
         $studentId = intval($student['user_id']);
         $studentId = intval($student['user_id']);
         $data['studentUserId'] = $studentId;
         $data['studentUserId'] = $studentId;
 
 
-        $student['area'] = api_get_user_info($studentId)['extra']['area'];
+        $student['area'] = api_get_user_info($studentId, false, false, true)['extra']['area'];
         $student['userLink'] = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$studentId;
         $student['userLink'] = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$studentId;
         $data['queueId'] = intval($student['queue_id']);
         $data['queueId'] = intval($student['queue_id']);
         $data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED;
         $data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED;

+ 2 - 0
plugin/createdrupaluser/lang/english.php

@@ -10,3 +10,5 @@ $strings['plugin_comment'] = 'This plugin creates users in an associated Drupal
 
 
 $strings['drupal_domain'] = 'Drupal website URL';
 $strings['drupal_domain'] = 'Drupal website URL';
 $strings['drupal_domain_help'] = 'The server domain name should be written with a trailing slash and with the protocol, e.g. http://www.example.com/';
 $strings['drupal_domain_help'] = 'The server domain name should be written with a trailing slash and with the protocol, e.g. http://www.example.com/';
+
+$strings['DruaplUserId'] = 'Drupal user ID';

+ 2 - 0
plugin/createdrupaluser/lang/spanish.php

@@ -10,3 +10,5 @@ $strings['plugin_comment'] = 'Este plugin permite crear usuarios en un sitio web
 
 
 $strings['drupal_domain'] = 'URL del sitio web Drupal';
 $strings['drupal_domain'] = 'URL del sitio web Drupal';
 $strings['drupal_domain_help'] = 'La dirección del servidor debe escribirse con el protocolo al comienzo y con la barra al final, por ejemplo http://www.example.com/';
 $strings['drupal_domain_help'] = 'La dirección del servidor debe escribirse con el protocolo al comienzo y con la barra al final, por ejemplo http://www.example.com/';
+
+$strings['DrupalUserId'] = 'ID de usuario Drupal';

+ 56 - 0
plugin/createdrupaluser/src/CreateDrupalUser.php

@@ -9,6 +9,8 @@
  */
  */
 class CreateDrupalUser extends Plugin implements HookPluginInterface
 class CreateDrupalUser extends Plugin implements HookPluginInterface
 {
 {
+    const EXTRAFIELD_VARIABLE_NAME = 'drupal_user_id';
+
     /**
     /**
      * Class constructor
      * Class constructor
      */
      */
@@ -38,6 +40,7 @@ class CreateDrupalUser extends Plugin implements HookPluginInterface
      */
      */
     public function install()
     public function install()
     {
     {
+        $this->createExtraField();
         $this->installHook();
         $this->installHook();
     }
     }
 
 
@@ -48,6 +51,7 @@ class CreateDrupalUser extends Plugin implements HookPluginInterface
     public function uninstall()
     public function uninstall()
     {
     {
         $this->uninstallHook();
         $this->uninstallHook();
+        $this->deleteExtraField();
     }
     }
 
 
     /**
     /**
@@ -74,4 +78,56 @@ class CreateDrupalUser extends Plugin implements HookPluginInterface
         }
         }
     }
     }
 
 
+    /**
+     * Get the drupal_user_id extra field information
+     * @return array The info
+     */
+    private function getExtraFieldInfo()
+    {
+        $extraField = new ExtraField('user');
+        $extraFieldHandler = $extraField->get_handler_field_info_by_field_variable(
+            self::EXTRAFIELD_VARIABLE_NAME
+        );
+
+        return $extraFieldHandler;
+    }
+
+    /**
+     * Create the drupal_user_id when it not exists
+     */
+    private function createExtraField()
+    {
+        $extraFieldExists = $this->getExtraFieldInfo() !== false;
+
+        if (!$extraFieldExists) {
+            $extraField = new ExtraField('user');
+            $extraField->save(
+                [
+                    'field_type' => ExtraField::FIELD_TYPE_INTEGER,
+                    'variable' => self::EXTRAFIELD_VARIABLE_NAME,
+                    'display_text' => get_plugin_lang('DrupalUserId', 'CreateDrupalUser'),
+                    'default_value' => null,
+                    'field_order' => null,
+                    'visible' => false,
+                    'changeable' => false,
+                    'filter' => null
+                ]
+            );
+        }
+    }
+
+    /**
+     * Delete the drupal_user_id and values
+     */
+    private function deleteExtraField()
+    {
+        $extraFieldInfo = $this->getExtraFieldInfo();
+        $extraFieldExists = $extraFieldInfo !== false;
+
+        if ($extraFieldExists) {
+            $extraField = new ExtraField('user');
+            $extraField->delete($extraFieldInfo['id']);
+        }
+    }
+
 }
 }

+ 10 - 1
plugin/createdrupaluser/src/HookCreateDrupalUser.php

@@ -54,7 +54,16 @@ class HookCreateDrupalUser extends HookObserver implements HookCreateUserObserve
             );
             );
 
 
             $client = new SoapClient(null, $options);
             $client = new SoapClient(null, $options);
-            $drupalUserId = $client->addUser($fields, $extraFields);
+            
+            if (isset($_SESSION['ws_drupal_user_id'])) {
+                $drupalUserId = $_SESSION['ws_drupal_user_id'];
+                return true;
+            }
+
+            if ($drupalUserId === false) {
+                $drupalUserId = $client->addUser($fields, $extraFields);
+            }
+
             if ($drupalUserId !== false) {
             if ($drupalUserId !== false) {
                 UserManager::update_extra_field_value($return, 'drupal_user_id', $drupalUserId);
                 UserManager::update_extra_field_value($return, 'drupal_user_id', $drupalUserId);
             }
             }

+ 1 - 1
tests/scripts/insert_session_fields.php

@@ -186,7 +186,7 @@ $shortDescription = new ExtraField('session');
 $shortDescription->save(array(
 $shortDescription->save(array(
     'field_type' => ExtraField::FIELD_TYPE_TEXT,
     'field_type' => ExtraField::FIELD_TYPE_TEXT,
     'variable' => 'short_description',
     'variable' => 'short_description',
-    'display_text' => get_lang('ShortSescription'),
+    'display_text' => get_lang('ShortDescription'),
     'visible' => 1,
     'visible' => 1,
     'changeable' => 1
     'changeable' => 1
 ));
 ));

+ 10 - 1
tests/scripts/insert_sessions_categories.php

@@ -5,6 +5,9 @@
  */
  */
 require_once '../../main/inc/global.inc.php';
 require_once '../../main/inc/global.inc.php';
 api_protect_admin_script();
 api_protect_admin_script();
+
+$accessUrlId = api_get_current_access_url_id();
+
 $categories = array(
 $categories = array(
     'capacitaciones',
     'capacitaciones',
     'programas',
     'programas',
@@ -13,5 +16,11 @@ $categories = array(
 );
 );
 $tableSessionCategory = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
 $tableSessionCategory = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
 foreach ($categories as $category) {
 foreach ($categories as $category) {
-    Database::query("INSERT INTO $tableSessionCategory (name) VALUES ('$category')");
+    Database::insert(
+        $tableSessionCategory,
+        [
+            'name' => $category,
+            'access_url_id' => $accessUrlId
+        ]
+    );
 }
 }