Added custom forms recall, and addded costs with totals and enabled priority display...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 21 Dec 2017 17:36:23 +0000 (12:36 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 21 Dec 2017 17:36:23 +0000 (12:36 -0500)
Removed extraneous trigger_error statements used for testing.

classes/customFieldSupport.php
classes/data/dataCustomFields.php
classes/data/dataCustomFieldsOption.php
setup/commonHooks.php
views/admin/customFields/index.html
views/front/customFields/displayForm.html

index 60007ee..73c16d5 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-use No3x\WPML\ORM\Model\User;
-
 /**
  * Gaslight Media Associate
  * Custom Fields Support Class
@@ -152,7 +150,7 @@ class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
                     case 'text':
                     case 'textarea':
                     case 'picklist':
-         
+
                         $formField[$fieldId] = '';
 
                         // If the expected form field exists
@@ -182,7 +180,7 @@ class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
                         $fieldRes['field_data'] = ($in ? 'Yes' : 'No');
 
                         break;
-                        
+
                     default:
                         break;
 
index 344a74c..e93c288 100644 (file)
@@ -86,7 +86,7 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
      * @access public
      */
     public $recordId = false;
-    
+
     /**
      * Constructor
      *
@@ -175,7 +175,7 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
                 'type'      => 'checkbox',
                 'use'       => 'a'
             ),
-            
+
             // required field
             'required' => array(
                 'field'    => 'required',
@@ -206,44 +206,44 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
 
         // Get field type description from ini file.
         $r['field_type_descr'] = $this->config['custom_field_type'][$r['field_type']];
-        
+
         // If doing the following actions
         if (in_array($action, array('l','g'))) {
 
-            // Try to get additional data for specific field types            
+            // Try to get additional data for specific field types
             switch ($r['field_type']) {
-                
+
                 case 'picklist':
-                    
+
                     if (!isset($FieldOptions)) {
                         require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFieldsOption.php';
                         $FieldOptions = new GlmDataFieldsCustomFieldsOption($this->wpdb, $this->config);
                     }
-                    
+
                     // Try to get any options for this picklist
                     $options = $FieldOptions->getList('T.field_id = '.$r['id']);
-                    
+
                     $r['options'] = false;
                     if (is_array($options) && count($options) > 0) {
                         $r['options'] = $options;
                     }
-                    
+
                     break;
-                    
+
                 default:
                     break;
             }
-            
+
             // If get stored data flag is set and we have a stored data record ID
             if ($this->getStoredData && $this->recordId) {
-                
-                // If we don't have it yet, instatiate the custom field data class 
+
+                // If we don't have it yet, instatiate the custom field data class
                 if (!isset($CustomFieldData)) {
                     require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/data/dataCustomFieldsData.php';
                     $CustomFieldData = new GlmDataFieldsCustomFieldsData($this->wpdb, $this->config);
                 }
-                
-                // Get stored data for the current field 
+
+                // Get stored data for the current field
                 $customFieldData = $CustomFieldData->getEntry($r['id'], 'field_id', "T.record_id = ".$this->recordId);
 
                 // Place the save field data into the current result
@@ -253,63 +253,73 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
                     'integer_data' => $customFieldData['integer_data'],
                     'float_data' => $customFieldData['float_data']
                 ));
-                
+
+                // Add a few data shortcuts
                 $r['stored'] = '';
-                
+                $r['cost'] = '0';
+
                 switch ($r['field_type']) {
-                    
+
                     case 'text':
                     case 'textarea':
                         $r['stored'] = $r['text_data'];
                         break;
-                    
+
                     case 'checkbox':
                         $r['stored'] = ($r['checkbox_data'] ? 'Yes' : 'No');
                         break;
-                        
+
                     case 'picklist':
-                        
+
                         // set default picklist option
                         if (isset($r['options']) && count($options) > 0) {
                             foreach($r['options'] as $optKey=>$optVal) {
+
                                 $val = false;
                                 $name = 'No';
+
+                                // If this option is the selected one
                                 if ($optVal['option_value'] == $customFieldData['text_data']) {
+
                                     $val = true;
                                     $name = 'Yes';
+
+                                    // Add shortcuts for some useful data
                                     $r['stored'] = $optVal['option_value'];
-                                    $r['option_text'] = $optVal['option_text'];
+                                    $r['cost'] = $optVal['option_cost'];
                                 }
+
                                 $r['options'][$optKey]['option_default']['value'] = $val;
                                 $r['options'][$optKey]['option_default']['name'] = $name;
+
                             }
                         }
-                        
+
                         break;
-                    
+
                     case 'integer':
                         $r['stored'] = $r['integer_data'];
                         break;
-                        
+
                     case 'float':
                         $r['stored'] = $r['float_data'];
                         break;
-                        
+
                 }
 
             }
-            
-ini_set(log_errors_max_len,4096);
-trigger_error('Form Fields: '.print_r($r, 1), E_USER_NOTICE);
-        
+
+        // ini_set('log_errors_max_len',4096);
+        // trigger_error('Form Fields: '.print_r($r, 1), E_USER_NOTICE);
+
         }
         return $r;
     }
-    
+
     /*
      * Get form fields along with any stored data
      *
-     * @param 
+     * @param
      * @param string $a Action being performed (l, i, g, ...)
      *
      * @return object Class object
@@ -318,20 +328,37 @@ trigger_error('Form Fields: '.print_r($r, 1), E_USER_NOTICE);
     public function getFormWithData($fid, $recordId = false)
     {
         // Save current status of get stored data flag
-        $savedGetStoredDataState = $this->getStoredData;   
-        
+        $savedGetStoredDataState = $this->getStoredData;
+
         // Set stored data flag and record ID
         $this->getStoredData = true;
         $this->recordId = $recordId;
-        
+
+        $result = array(
+            'form'              => false,
+            'hasPriorityField'  => false,
+            'totalCost'         => 0
+        );
+
         // Try to get the form
-        $form = $this->getList("fid = '$fid'");
-        
+        $result['form'] = $this->getList("fid = '$fid'");
+
+        // Check if there's any priority display fields or fields with selected cost
+        foreach ($result['form'] as $field) {
+            if ($field['priority_display']['value'] || $field['cost'] > 0) {
+                $result['hasPriorityField'] = true;
+            }
+
+            if ($field['cost'] > 0) {
+                $result['totalCost'] += $field['cost'];
+            }
+        }
+
         // Restore saved stored data flag
         $this->getStoredData = $savedGetStoredDataState;
 
-        return $form;
-        
+        return $result;
+
     }
 
 }
index c2acf53..95dd95a 100644 (file)
@@ -148,7 +148,7 @@ class GlmDataFieldsCustomFieldsOption extends GlmDataAbstract
             // Option Cost
             'option_cost' => array(
                 'field'    => 'option_cost',
-                'type'     => 'money',
+                'type'     => 'float',
                 'default'  => 0,
                 'use'      => 'a'
             ),
index 1de61a4..0003c1f 100644 (file)
@@ -206,15 +206,10 @@ add_filter( 'glm-members-customfields-form-data-recall', function( $content, $fi
         trigger_error('Custom Fields Filter Called: glm-members-customfields-form-data-recall', E_USER_NOTICE);
     }
     
-    require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomField.php';
-    $CustomFields = new GlmCustomFields($this->wpdb, $this->config);
-    
-    $form = $CustomFieldSupport->getFormWithData($fid, $recordId, $priorityDisplay);
-    
-ini_set(log_errors_max_len, 5192);
-trigger_error('Form Data Recall: '.print_r($form, 1), E_USER_NOTICE);
+    require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+    $CustomFields = new GlmDataFieldsCustomFields($this->wpdb, $this->config);
     
-    // Consider using a shortcode to build the HTML 
+    $content = $CustomFields->getFormWithData($fid, $recordId, $priorityDisplay);
     
     return $content;
     
index a657777..cc1d6d4 100644 (file)
                     </select>
                 </td>
             </tr>
+            <tr>
+                <th>Priority:</th>
+                <td><input type="checkbox" id="{$fid}_editPriority" name="priority_display" value="1" /></td>
+            </tr>
             <tr>
                 <th>Required:</th>
                 <td><input type="checkbox" id="{$fid}_editRequired" name="required" value="1" /></td>
                 {$t.required.name}
             </td>
             <td style="width: 10%; text-align: left;" colspan="2">
-<!--                <div class="{$fid}_EditFieldButton  button button-secondary glm-button-small" data-fieldId="{$t.id}" data-fieldName="{$t.field_name|escape:'html'}" data-fieldPrompt="{$t.field_prompt|escape:'html'}" data-fieldType="{$t.field_type.name|escape:'html'}" data-required="{$t.required.value}">Edit</div>
+<!--                <div class="{$fid}_EditFieldButton  button button-secondary glm-button-small" 
+                        data-fieldId="{$t.id}" 
+                        data-fieldName="{$t.field_name|escape:'html'}" 
+                        data-fieldPrompt="{$t.field_prompt|escape:'html'}" 
+                        data-fieldType="{$t.field_type.name|escape:'html'}" 
+                        data-priority="{$t.priority_display.value}"
+                        data-required="{$t.required.value}"
+                    >Edit</div>
  -->                 
                 <div class="{$fid}_DeleteFieldButton button button-secondary glm-button-small" data-fieldId="{$t.id}">Delete</div>
  {if $t.field_type=='picklist'}
@@ -194,6 +205,7 @@ jQuery(document).ready(function($) {
         $('#{$fid}_NewFieldName').val('');
         $('#{$fid}_NewFieldPrompt').val('');
         $('#{$fid}_NewFieldType').prop('selectedIndex',0);
+        $('#{$fid}_NewFieldPriorityDisplay').removeAttr('checked');
         $('#{$fid}_NewFieldRequired').removeAttr('checked');
     });
     // Submit form
@@ -201,14 +213,15 @@ jQuery(document).ready(function($) {
 
         // Collect the new field data
         var formData = {
-            'action':       'glm_members_admin_ajax',
-            'glm_action':   'customFields',
-            'option':       'addNewField',
-            'fid':          '{$fid}',
-            'field_name':   $('#{$fid}_NewFieldName').val(),
-            'field_prompt': $('#{$fid}_NewFieldPrompt').val(),
-            'field_type':   $('#{$fid}_NewFieldType').val(),
-            'required':     $('#{$fid}_NewFieldRequired').is(':checked')
+            'action':           'glm_members_admin_ajax',
+            'glm_action':       'customFields',
+            'option':           'addNewField',
+            'fid':              '{$fid}',
+            'field_name':       $('#{$fid}_NewFieldName').val(),
+            'field_prompt':     $('#{$fid}_NewFieldPrompt').val(),
+            'field_type':       $('#{$fid}_NewFieldType').val(),
+            'priority_display': $('#{$fid}_NewFieldPriorityDisplay').is(':checked'),
+            'required':         $('#{$fid}_NewFieldRequired').is(':checked')
         };
 
         // Submit new field data - expect field new ID back
@@ -262,6 +275,7 @@ jQuery(document).ready(function($) {
         var fieldName   = $(this).attr('data-fieldName');
         var fieldPrompt = $(this).attr('data-fieldPrompt');
         var fieldType   = $(this).attr('data-fieldType');
+        var priority    = $(this).attr('data-priority');
         var required    = $(this).attr('data-required');
         
         $('#editFieldID').val(fieldID);
index 12a1b45..37d9939 100644 (file)
@@ -1,5 +1,5 @@
 {if $haveForm}
-  {foreach $formFields as $field}
+  {foreach $formFields.form as $field}
     {if $field.field_type == 'text'}
                         <div class="glm-row">
                             <div class="glm-small-12 glm-large-12 glm-columns glm-nowrap{if $field.required.value} glm-required{/if}">{$field.field_prompt}</div>
@@ -67,4 +67,3 @@
         });
     </script>
 {/if}
-   
\ No newline at end of file