]> _ Git - ccv-wordpress.git/commitdiff
WIP #3981 @1.5
authorStephen Cameron <stephen@cubedesigners.com>
Thu, 22 Oct 2020 16:37:55 +0000 (18:37 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Thu, 22 Oct 2020 16:37:55 +0000 (18:37 +0200)
wp-content/mu-plugins/cube/src/Forms/Base.php
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php
wp-content/mu-plugins/cube/src/Forms/Consultation.php
wp-content/themes/CCV/resources/views/forms/consultation.blade.php

index 0082c83b5441f1a7b487f6ab6f1cf80462948eb6..45c58a348277380f56e4130f06f1c3eb28d39b24 100644 (file)
@@ -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
index 59b792a27f800e784f348b9dfdbe4b2332732e26..12bf30e58967b3e8dcb889bfb675a3038d188ab4 100644 (file)
@@ -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'] = [];
index e516c7d23ce1970bcadf71504b38fd094dfeaba3..3b8b409c9470fafc0758b6bc63ba0a9528d7c510 100644 (file)
@@ -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)) {
index 9e93cbe6fb45f52841e5fe7e5a2fb824592f2252..516231a15c33f9cbfef25d496ff9f2b8cdff0675 100644 (file)
 
     {{-- IMAGES FROM CD --}}
     <div class="imagery-type-wrapper flex mb-8">
-      <input type="radio" id="imagery_cd" name="imagery-type" value="{{ __('') }}">
+      <input type="radio" id="imagery_cd" name="imagery-type" value="{{ __('Images sur CD (Purview)') }}">
       <label for="imagery_cd" class="imagery-icon">@svg('imagery-cd', 'w-22 md:w-20 sm:w-16')</label>
       <div class="ml-4">
         <div class="text-lg sm:text-base font-normal leading-tight mb-1">
       </div>
     </div>
 
-    {{-- IMAGES FROM PHONE --}}
+    {{-- IMAGES FROM PHONE (NAS UPLOAD) --}}
     <div class="imagery-type-wrapper flex mb-8">
       {!! $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 --}}
       <input type="radio" id="imagery_phone" name="imagery-type" value="{{ __('Images téléversées depuis portable') }}">
       <label for="imagery_phone" class="imagery-icon">@svg('imagery-phone', 'w-22 md:w-20 sm:w-16')</label>
       <div class="ml-4">