From 1e6a13d146718aba13b4e21cc00703018375fadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien?= Date: Tue, 16 Jun 2020 17:01:27 +0200 Subject: [PATCH] Save customer language. --- application/config/migration.php | 2 +- application/controllers/Appointments.php | 2 + .../language/english/translations_lang.php | 2 + .../language/french/translations_lang.php | 2 + .../language/german/translations_lang.php | 1 + .../migrations/020_add_language_to_users.php | 48 +++++++++++++++++++ application/views/backend/customers.php | 5 ++ assets/js/backend_customers.js | 7 +++ assets/js/backend_customers_helper.js | 11 +++++ 9 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 application/migrations/020_add_language_to_users.php diff --git a/application/config/migration.php b/application/config/migration.php index c6de3a74..957d49d0 100755 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 19; +$config['migration_version'] = 20; /* diff --git a/application/controllers/Appointments.php b/application/controllers/Appointments.php index 09c8b61d..3916238f 100755 --- a/application/controllers/Appointments.php +++ b/application/controllers/Appointments.php @@ -1024,6 +1024,8 @@ class Appointments extends CI_Controller { $appointment['location'] = $service['location']; } + // save customer language (the language which is used to render the booking page) + $customer['language'] = $this->config->item('language'); $customer_id = $this->customers_model->add($customer); $appointment['id_users_customer'] = $customer_id; diff --git a/application/language/english/translations_lang.php b/application/language/english/translations_lang.php index 21ac685c..80d6e4d6 100755 --- a/application/language/english/translations_lang.php +++ b/application/language/english/translations_lang.php @@ -20,6 +20,8 @@ $lang['address'] = 'Address'; $lang['city'] = 'City'; $lang['zip_code'] = 'Zip Code'; $lang['notes'] = 'Notes'; +$lang['language'] = 'Language'; +$lang['no_language'] = 'No language'; $lang['fields_are_required'] = 'Fields with * are required!'; $lang['step_four_title'] = 'Confirm Appointment'; $lang['confirm'] = 'Confirm'; diff --git a/application/language/french/translations_lang.php b/application/language/french/translations_lang.php index dc4f37dc..eb3c4bdd 100755 --- a/application/language/french/translations_lang.php +++ b/application/language/french/translations_lang.php @@ -20,6 +20,8 @@ $lang['address'] = 'Adresse'; $lang['city'] = 'Ville'; $lang['zip_code'] = 'Code postal'; $lang['notes'] = 'Commentaires'; +$lang['language'] = 'Langue'; +$lang['no_language'] = 'Pas de langue'; $lang['fields_are_required'] = 'Les champs avec * sont obligatoires'; $lang['step_four_title'] = 'Confirmez votre rendez-vous'; $lang['confirm'] = 'Confirmation'; diff --git a/application/language/german/translations_lang.php b/application/language/german/translations_lang.php index d8af8f51..26beae18 100755 --- a/application/language/german/translations_lang.php +++ b/application/language/german/translations_lang.php @@ -20,6 +20,7 @@ $lang['address'] = 'Adresse'; $lang['city'] = 'Stadt'; $lang['zip_code'] = 'Postleitzahl'; $lang['notes'] = 'Bemerkungen'; +$lang['language'] = 'Sprache'; $lang['fields_are_required'] = 'Die Felder mit einem * sind Pflichtfelder!'; $lang['step_four_title'] = 'Bitte bestätigen Sie die Terminauswahl'; $lang['confirm'] = 'Bestätigung'; diff --git a/application/migrations/020_add_language_to_users.php b/application/migrations/020_add_language_to_users.php new file mode 100644 index 00000000..2a28bc02 --- /dev/null +++ b/application/migrations/020_add_language_to_users.php @@ -0,0 +1,48 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.4.0 + * ---------------------------------------------------------------------------- */ + +/** + * Class Migration_Add_language_to_users + * + * @property CI_DB_query_builder db + * @property CI_DB_forge dbforge + */ +class Migration_Add_language_to_users extends CI_Migration { + /** + * Upgrade method. + */ + public function up() + { + if ( ! $this->db->field_exists('language', 'users')) + { + $fields = [ + 'language' => [ + 'type' => 'VARCHAR', + 'constraint' => '256', + 'default' => '', + 'after' => 'timezone' + ] + ]; + + $this->dbforge->add_column('users', $fields); + } + } + + /** + * Downgrade method. + */ + public function down() + { + $this->dbforge->drop_column('users', 'language'); + } +} diff --git a/application/views/backend/customers.php b/application/views/backend/customers.php index 3f1d527f..d4bf2d10 100755 --- a/application/views/backend/customers.php +++ b/application/views/backend/customers.php @@ -132,6 +132,11 @@ +
+ + +
+
diff --git a/assets/js/backend_customers.js b/assets/js/backend_customers.js index bb1a021e..ccf52b6a 100644 --- a/assets/js/backend_customers.js +++ b/assets/js/backend_customers.js @@ -42,6 +42,13 @@ window.BackendCustomers = window.BackendCustomers || {}; exports.initialize = function (defaultEventHandlers) { defaultEventHandlers = defaultEventHandlers || false; + // Fill available service categories listbox. + availableLanguages.forEach(function (language) { + $('#language').append(new Option(language, language)); + }); + + $('#language').append(new Option('- ' + EALang.no_language + ' -', null)).val('null'); + helper = new CustomersHelper(); helper.resetForm(); helper.filter(''); diff --git a/assets/js/backend_customers_helper.js b/assets/js/backend_customers_helper.js index 9956d2fd..f5bb98e5 100644 --- a/assets/js/backend_customers_helper.js +++ b/assets/js/backend_customers_helper.js @@ -150,6 +150,12 @@ timezone: $('#timezone').val() }; + if ($('#language').val() !== 'null') { + customer.language = $('#language').val(); + } else { + customer.language = ''; + } + if ($('#customer-id').val()) { customer.id = $('#customer-id').val(); } @@ -279,6 +285,8 @@ $('.record-details').find('input, textarea').val(''); $('.record-details').find('input, textarea').prop('readonly', true); + $('#language').val('null'); + $('#customer-appointments').empty(); $('#appointment-details').toggleClass('hidden', true).empty(); $('#edit-customer, #delete-customer').prop('disabled', true); @@ -310,6 +318,9 @@ $('#notes').val(customer.notes); $('#timezone').val(customer.timezone); + var language = (customer.language !== '') ? customer.language : 'null'; + $('#language').val(language); + $('#customer-appointments').empty(); customer.appointments.forEach(function (appointment) { if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && parseInt(appointment.id_users_provider) !== GlobalVariables.user.id) {