Merge pull request #13732 from mattwire/refactor_smartgroupquery_upper1
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Fee.php
index e477d320ab865019ae2f5d03cfe65e228572f46e..c69627a46463f66adbbcd2e0e3d2e271a93cec00 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -27,7 +27,7 @@
 
 /**
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 
 /**
@@ -544,7 +544,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
    */
   public function postProcess() {
     $eventTitle = '';
-    $params = $this->exportValues();
+    $params = $this->cleanMoneyFields($this->exportValues());
 
     $this->set('discountSection', 0);
 
@@ -600,7 +600,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
             if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
               $options[] = array(
                 'label' => trim($labels[$i]),
-                'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])),
+                'value' => $values[$i],
                 'weight' => $i,
                 'is_active' => 1,
                 'is_default' => $default == $i,
@@ -681,7 +681,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
                 ) {
                   $discountOptions[] = array(
                     'label' => trim($labels[$i]),
-                    'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])),
+                    'value' => $values[$i][$j],
                     'weight' => $i,
                     'is_active' => 1,
                     'is_default' => $default == $i,
@@ -808,4 +808,36 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
     return ts('Event Fees');
   }
 
+  /**
+   * Clean money fields in submitted params to remove formatting.
+   *
+   * @param array $params
+   *
+   * @return array
+   */
+  protected function cleanMoneyFields($params) {
+    foreach ($params['value'] as $index => $value) {
+      if (CRM_Utils_System::isNull($value)) {
+        unset($params['value'][$index]);
+      }
+      else {
+        $params['value'][$index] = CRM_Utils_Rule::cleanMoney(trim($value));
+      }
+    }
+    foreach ($params['discounted_value'] as $index => $discountedValueSet) {
+      foreach ($discountedValueSet as $innerIndex => $value) {
+        if (CRM_Utils_System::isNull($value)) {
+          unset($params['discounted_value'][$index][$innerIndex]);
+        }
+        else {
+          $params['discounted_value'][$index][$innerIndex] = CRM_Utils_Rule::cleanMoney(trim($value));
+        }
+      }
+      if (empty($params['discounted_value'][$index])) {
+        unset($params['discounted_value'][$index]);
+      }
+    }
+    return $params;
+  }
+
 }