CRM-12463
authoryashodha <yashodha.chaku@webaccess.co.in>
Sat, 4 May 2013 22:43:49 +0000 (04:13 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Sat, 4 May 2013 22:44:12 +0000 (04:14 +0530)
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/SoftCredit.php

index 91eebcd0fad5d9945dd3266f739c58bfad43f2ce..0b5fc26bf5a721feb1f181858769b2ff681ffea3 100644 (file)
@@ -955,32 +955,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       }
     }
 
-    // if honor roll fields are populated but no PCP is selected
-    if (!CRM_Utils_Array::value('pcp_made_through_id', $fields)) {
-      if (CRM_Utils_Array::value('pcp_display_in_roll', $fields) ||
-        CRM_Utils_Array::value('pcp_roll_nickname', $fields) ||
-        CRM_Utils_Array::value('pcp_personal_note', $fields)
-      ) {
-        $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
-      }
-    }
-
-    if (!empty($fields['soft_credit_amount'])) {
-      $repeat = array_count_values($fields['soft_credit_contact_select_id']);
-      foreach ($fields['soft_credit_amount'] as $key => $val) {
-        if (!empty($fields['soft_credit_contact_select_id'][$key])) {
-          if ($repeat[$fields['soft_credit_contact_select_id'][$key]] > 1) {
-            $errors["soft_credit_contact_select_id[$key]"] = ts('You cannot enter multiple soft credits for the same contact.');  
-          }
-          if ($fields['soft_credit_amount'][$key] && ($fields['soft_credit_amount'][$key] > $fields['total_amount'])) {
-            $errors["soft_credit_amount[$key]"] = ts('Soft credit amount cannot be more than the total amount.');
-          }
-          if (empty($fields['soft_credit_amount'][$key])) {
-            $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
-          }
-        }
-      }
-    }
+    $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields);
 
     if (CRM_Utils_Array::value('total_amount', $fields) && (CRM_Utils_Array::value('net_amount', $fields) || CRM_Utils_Array::value('fee_amount', $fields))) {
       $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
@@ -1007,6 +982,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       }
     }
 
+    $errors = array_merge($errors, $softErrors);
     return $errors;
   }
 
index 5958e801099d7400a9be12413b73b729b454ff1b..7b51243095c3d097419839205d4c5964fa144eb1 100644 (file)
@@ -105,5 +105,46 @@ class CRM_Contribute_Form_SoftCredit {
       $defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo);
     }
   }
+
+  /**
+   * global form rule
+   *
+   * @param array $fields  the input form values
+   *
+   * @return true if no errors, else array of errors
+   * @access public
+   * @static
+   */
+  static function formRule($fields) {
+    $errors = array();
+
+    // if honor roll fields are populated but no PCP is selected
+    if (!CRM_Utils_Array::value('pcp_made_through_id', $fields)) {
+      if (CRM_Utils_Array::value('pcp_display_in_roll', $fields) ||
+        CRM_Utils_Array::value('pcp_roll_nickname', $fields) ||
+        CRM_Utils_Array::value('pcp_personal_note', $fields)
+      ) {
+        $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
+      }
+    }
+
+    if (!empty($fields['soft_credit_amount'])) {
+      $repeat = array_count_values($fields['soft_credit_contact_select_id']);
+      foreach ($fields['soft_credit_amount'] as $key => $val) {
+        if (!empty($fields['soft_credit_contact_select_id'][$key])) {
+          if ($repeat[$fields['soft_credit_contact_select_id'][$key]] > 1) {
+            $errors["soft_credit_contact_select_id[$key]"] = ts('You cannot enter multiple soft credits for the same contact.');
+          }
+          if ($fields['soft_credit_amount'][$key] && ($fields['soft_credit_amount'][$key] > $fields['total_amount'])) {
+            $errors["soft_credit_amount[$key]"] = ts('Soft credit amount cannot be more than the total amount.');
+          }
+          if (empty($fields['soft_credit_amount'][$key])) {
+            $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
+          }
+        }
+      }
+    }
+    return $errors;
+  }
 }