From d0fc2c670092ca9033da1f5551ce40027fe61dfb Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Thu, 22 Oct 2020 18:37:55 +0200 Subject: [PATCH] WIP #3981 @1.5 --- wp-content/mu-plugins/cube/src/Forms/Base.php | 15 ++++ .../cube/src/Forms/Builder/Fields/Date.php | 2 +- .../cube/src/Forms/Consultation.php | 78 ++++++++++--------- .../views/forms/consultation.blade.php | 6 +- 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/wp-content/mu-plugins/cube/src/Forms/Base.php b/wp-content/mu-plugins/cube/src/Forms/Base.php index 0082c83..45c58a3 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Base.php +++ b/wp-content/mu-plugins/cube/src/Forms/Base.php @@ -327,6 +327,21 @@ class Base return $this->fields[$name] ?? null; } + /** + * Remove a single field by name + * @param $name + * @return bool + */ + public function remove_field($name) { + + if (!$this->exists($name)) { + return false; + } + + unset($this->fields[$name]); + return true; + } + /** * Get all fields * @return array diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php index 59b792a..12bf30e 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php +++ b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php @@ -16,7 +16,7 @@ class Date extends Field 'wrap' => true, 'altInput' => true, 'altFormat' => 'd/m/Y', // Format shown to user (https://flatpickr.js.org/formatting/) - 'dateFormat' => 'Y-m-d', // Format returned to the input field + 'dateFormat' => 'd/m/Y', // Format returned to the input field ]; if (!isset($settings['flatpickr'])) $settings['flatpickr'] = []; diff --git a/wp-content/mu-plugins/cube/src/Forms/Consultation.php b/wp-content/mu-plugins/cube/src/Forms/Consultation.php index e516c7d..3b8b409 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Consultation.php +++ b/wp-content/mu-plugins/cube/src/Forms/Consultation.php @@ -34,6 +34,42 @@ class Consultation extends Base $this->add_fields([ + //=== PERSONAL INFORMATION + Text::field('last-name', _x('Nom', 'Nom de famille', 'ccv')), + Text::field('first-name', __('Prénom', 'ccv')), + Text::field('profession', __('Profession', 'ccv')), + Text::field('city', __('Ville (département)', 'ccv')), + Text::field('country', __('Pays', 'ccv')), + Text::field('phone', __('Tel', 'ccv')), + Email::field('email', __('Email', 'ccv')), + Radio::field('sex', __('Sexe', 'ccv')) + ->options([ + _x('M', 'Sexe (M)', 'ccv'), + _x('F', 'Sexe (F)', 'ccv'), + ]), + Text::field('age', __('Âge :', 'ccv')), + Textarea::field('message', __('Avez vous un message (ou une demande) spécifique à nous formuler ?', 'ccv'))->required(false), + + // Special field: if a surgeon is selected, their e-mail address will be override the default delivery address + Select::field('surgeon', __('Chirurgien spécifique')) + ->required(false) + ->options([ + 'Dr Guilhaume GENESTE' => 'dr.geneste@ccv-montpellier.fr', + 'Dr Grégory EDGARD-ROSA' => 'dr.edgard-rosa@ccv-montpellier.fr', + 'Dr Martin GRAU ORTIZ' => 'dr.grauortiz@ccv-montpellier.fr', + 'Dr Caroline HIRSH' => 'dr.hirsch@ccv-montpellier.fr', + ]), + + //=== IMAGERY + // This is a special case and will be output manually so only using this for the e-mail label + Radio::field('imagery-type', __('Imagerie', 'ccv'))->required(false), + Textarea::field('imagery-online', __('Images en ligne', 'ccv'))->required(false), // Again, a manually handled field + Checkbox::field('imagery-posted', __('Images envoyé par courrier', 'ccv'))->required(false), + + // Unique session identifier for uploads that go directly to CCV's NAS (upload.ccv-montpellier.fr) + // Made up of timestamp YYMMDDHHMM + nonce + Hidden::field('imagery-phone-token', __('ID sur le NAS', 'ccv'))->value(date('ymdHi') . '_'. wp_create_nonce('NAS-upload')), + //== SYMPTOMS Radio::field('main-problem', __('Problème principal', 'ccv')) ->options([ @@ -82,45 +118,17 @@ class Consultation extends Base Binary::field('infiltration', __('Infiltration ou thermocoagulation', 'ccv')), Textarea::field('surgeries', __('Indiquez ici vos précédentes chirurgies de la colonne et leurs dates (le cas échéant)', 'ccv'))->required(false), - //=== IMAGERY - // This is a special case and will be output manually so only using this for the e-mail label - Radio::field('imagery-type', __('Imagerie', 'ccv'))->required(false), - Textarea::field('imagery-online', __('Images en ligne', 'ccv'))->required(false), // Again, a manually handled field - Checkbox::field('imagery-posted', __('Images envoyé par courrier', 'ccv'))->required(false), - - // Unique session identifier for uploads that go directly to CCV's NAS (upload.ccv-montpellier.fr) - // Made up of timestamp YYMMDDHHMM + nonce - Hidden::field('imagery-phone-token', __('ID sur le NAS', 'ccv'))->value(date('ymdHi') . '_'. wp_create_nonce('NAS-upload')), - - //=== PERSONAL INFORMATION - Text::field('last-name', _x('Nom', 'Nom de famille', 'ccv')), - Text::field('first-name', __('Prénom', 'ccv')), - Text::field('profession', __('Profession', 'ccv')), - Text::field('city', __('Ville (département)', 'ccv')), - Text::field('country', __('Pays', 'ccv')), - Text::field('phone', __('Tel', 'ccv')), - Email::field('email', __('Email', 'ccv')), - Radio::field('sex', __('Sexe', 'ccv')) - ->options([ - _x('M', 'Sexe (M)', 'ccv'), - _x('F', 'Sexe (F)', 'ccv'), - ]), - Text::field('age', __('Âge :', 'ccv')), - Textarea::field('message', __('Avez vous un message (ou une demande) spécifique à nous formuler ?', 'ccv'))->required(false), - - // Special field: if a surgeon is selected, their e-mail address will be override the default delivery address - Select::field('surgeon', __('Chirurgien spécifique')) - ->required(false) - ->options([ - 'Dr Guilhaume GENESTE' => 'dr.geneste@ccv-montpellier.fr', - 'Dr Grégory EDGARD-ROSA' => 'dr.edgard-rosa@ccv-montpellier.fr', - 'Dr Martin GRAU ORTIZ' => 'dr.grauortiz@ccv-montpellier.fr', - 'Dr Caroline HIRSH' => 'dr.hirsch@ccv-montpellier.fr', - ]), ]); } public function pre_process() { + + // If the user didn't select the NAS upload option, there's no point including the NAS ID in the form data + // NOTE: This relies on the value of the field so make sure it is always the same in both places (consultation.blade.php) + if ($this->get_data('imagery-type') !== __('Images téléversées depuis portable')) { + $this->remove_field('imagery-phone-token'); + } + // If a surgeon is selected, send the form directly to them $surgeons = $this->get_field('surgeon')->get_options(); if (!empty($this->get_data('surgeon')) && array_key_exists($this->get_data('surgeon'), $surgeons)) { diff --git a/wp-content/themes/CCV/resources/views/forms/consultation.blade.php b/wp-content/themes/CCV/resources/views/forms/consultation.blade.php index 9e93cbe..516231a 100644 --- a/wp-content/themes/CCV/resources/views/forms/consultation.blade.php +++ b/wp-content/themes/CCV/resources/views/forms/consultation.blade.php @@ -127,7 +127,7 @@ {{-- IMAGES FROM CD --}}
- +
@@ -192,9 +192,11 @@
- {{-- IMAGES FROM PHONE --}} + {{-- IMAGES FROM PHONE (NAS UPLOAD) --}}
{!! $form->input('imagery-phone-token') !!} + {{-- ### NOTE: when this option isn't selected, the 'imagery-phone-token' field will be removed from the form --}} + {{-- This field is matched based on the value of the translated text below, so make sure to update Consultation::pre_process() too --}}
-- 2.39.5