Fixed problems with certain result fields not included if unable to retrieve stored...
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 9 Jan 2018 17:36:02 +0000 (12:36 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 9 Jan 2018 17:36:02 +0000 (12:36 -0500)
classes/data/dataCustomFields.php

index 517b5d6..0a5d106 100644 (file)
@@ -242,6 +242,11 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
                     break;
             }
 
+            // Add some things that might be expected event if no good recordId
+            $r['stored'] = '';
+            $r['cost'] = '0';
+            $r['text_data'] = '';
+
             // If get stored data flag is set and we have a stored data record ID
             if ($this->getStoredData && $this->recordId) {
 
@@ -254,64 +259,65 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
                 // 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
-                $r = array_merge($r, array(
-                    'text_data'     => $customFieldData['text_data'],
-                    'checkbox_data' => $customFieldData['checkbox_data'],
-                    'integer_data' => $customFieldData['integer_data'],
-                    'float_data' => $customFieldData['float_data']
-                ));
+                // If we have good field data
+                if ($customFieldData) {
 
-                // Add a few data shortcuts
-                $r['stored'] = '';
-                $r['cost'] = '0';
+                    // Place the save field data into the current result
+                    $r = array_merge($r, array(
+                        'text_data'     => $customFieldData['text_data'],
+                        'checkbox_data' => $customFieldData['checkbox_data'],
+                        'integer_data' => $customFieldData['integer_data'],
+                        'float_data' => $customFieldData['float_data']
+                    ));
 
-                switch ($r['field_type']) {
+                    switch ($r['field_type']) {
 
-                    case 'text':
-                    case 'textarea':
-                        $r['stored'] = $r['text_data'];
-                        break;
+                        case 'text':
+                        case 'textarea':
+                            $r['stored'] = $r['text_data'];
+                            break;
 
-                    case 'checkbox':
-                        $r['stored'] = ($r['checkbox_data'] ? 'Yes' : 'No');
-                        break;
+                        case 'checkbox':
+                            $r['stored'] = ($r['checkbox_data'] ? 'Yes' : 'No');
+                            break;
 
-                    case 'picklist':
+                        case 'picklist':
 
-                        // set default picklist option
-                        if (isset($r['options']) && count($options) > 0) {
-                            foreach($r['options'] as $optKey=>$optVal) {
+                            // set default picklist option
+                            if (isset($r['options']) && count($options) > 0) {
+                                foreach($r['options'] as $optKey=>$optVal) {
 
-                                $val = false;
-                                $name = 'No';
+                                    $val = false;
+                                    $name = 'No';
 
-                                // If this option is the selected one
-                                if ($optVal['option_value'] == $customFieldData['text_data']) {
+                                    // If this option is the selected one
+                                    if ($optVal['option_value'] == $customFieldData['text_data']) {
 
-                                    $val = true;
-                                    $name = 'Yes';
+                                        $val = true;
+                                        $name = 'Yes';
 
-                                    // Add shortcuts for some useful data
-                                    $r['stored'] = $optVal['option_value'];
-                                    $r['cost'] = $optVal['option_cost'];
-                                }
+                                        // Add shortcuts for some useful data
+                                        $r['stored'] = $optVal['option_value'];
+                                        $r['cost'] = $optVal['option_cost'];
+                                    }
 
-                                $r['options'][$optKey]['option_default']['value'] = $val;
-                                $r['options'][$optKey]['option_default']['name'] = $name;
+                                    $r['options'][$optKey]['option_default']['value'] = $val;
+                                    $r['options'][$optKey]['option_default']['name'] = $name;
 
+                                }
                             }
-                        }
 
-                        break;
+                            break;
+
+                        case 'integer':
+                            $r['stored'] = $r['integer_data'];
+                            break;
 
-                    case 'integer':
-                        $r['stored'] = $r['integer_data'];
-                        break;
+                        case 'float':
+                            $r['stored'] = $r['float_data'];
+                            break;
 
-                    case 'float':
-                        $r['stored'] = $r['float_data'];
-                        break;
+                    }
 
                 }
 
@@ -339,8 +345,12 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
         $savedGetStoredDataState = $this->getStoredData;
 
         // Set stored data flag and record ID
-        $this->getStoredData = true;
-        $this->recordId = $recordId;
+        $this->recordId = $recordId - 0;
+
+        // If we have a recordId, try to get stored data
+        if ($recordId) {
+            $this->getStoredData = true;
+        }
 
         $result = array(
             'form'              => false,
@@ -351,7 +361,6 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
         // Try to get the form in the specified sort order.
         $result['form'] = $this->getList("fid = '$fid'", 'field_order');
 
-
         // Check if there's any priority display fields or fields with selected cost
         if (is_array($result['form']) && count($result['form']) > 0) {
             foreach ($result['form'] as $field) {