CRM-14106 - Regex targeting other conditionals
[civicrm-core.git] / CRM / Contribute / BAO / Contribution / Utils.php
index 624a1009078d881c1109ea916bd74ea4b5345799..bfeaa0138ddce636e9e75e0dc8285510e9080350 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -65,7 +65,7 @@ class CRM_Contribute_BAO_Contribution_Utils {
     if (isset($paymentParams['financial_type'])) {
       $contributionType->id = $paymentParams['financial_type'];
     }
-    elseif (CRM_Utils_Array::value('pledge_id', $form->_values)) {
+    elseif (!empty($form->_values['pledge_id'])) {
       $contributionType->id = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge',
         $form->_values['pledge_id'],
         'financial_type_id'
@@ -200,7 +200,7 @@ class CRM_Contribute_BAO_Contribution_Utils {
       }
     }
     elseif ($form->_values['is_monetary'] && $form->_amount > 0.0) {
-      if (CRM_Utils_Array::value('is_recur', $paymentParams) &&
+      if (!empty($paymentParams['is_recur']) &&
         $form->_contributeMode == 'direct'
       ) {
 
@@ -240,10 +240,10 @@ class CRM_Contribute_BAO_Contribution_Utils {
 
     if (is_a($result, 'CRM_Core_Error')) {
       //make sure to cleanup db for recurring case.
-      if (CRM_Utils_Array::value('contributionID', $paymentParams)) {
+      if (!empty($paymentParams['contributionID'])) {
         CRM_Contribute_BAO_Contribution::deleteContribution($paymentParams['contributionID']);
       }
-      if (CRM_Utils_Array::value('contributionRecurID', $paymentParams)) {
+      if (!empty($paymentParams['contributionRecurID'])) {
         CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($paymentParams['contributionRecurID']);
       }
 
@@ -255,7 +255,7 @@ class CRM_Contribute_BAO_Contribution_Utils {
       }
       $membershipResult[1] = $result;
     }
-    elseif ($result) {
+    elseif ($result || ($form->_amount == 0.0 && !$form->_params['is_pay_later'])) {
       if ($result) {
         $form->_params = array_merge($form->_params, $result);
       }
@@ -279,9 +279,8 @@ class CRM_Contribute_BAO_Contribution_Utils {
 
       // check if pending was set to true by payment processor
       $pending = FALSE;
-      if (CRM_Utils_Array::value('contribution_status_pending',
-          $form->_params
-        )) {
+      if (!empty($form->_params
+['contribution_status_pending'])) {
         $pending = TRUE;
       }
       if (!(!empty($paymentParams['is_recur']) && $form->_contributeMode == 'direct')) {
@@ -380,7 +379,7 @@ INNER JOIN   civicrm_contact AS contact ON ( contact.id = contrib.contact_id )
     if (!empty($config->fiscalYearStart) && ($config->fiscalYearStart['M'] != 1 || $config->fiscalYearStart['d'] != 1)) {
       $yearClause = "CASE
         WHEN (MONTH(contrib.receive_date)>= " . $config->fiscalYearStart['M'] . "
-               && DAYOFMONTH(contrib.receive_date)>= " . $config->fiscalYearStart['d'] . " )
+          && DAYOFMONTH(contrib.receive_date)>= " . $config->fiscalYearStart['d'] . " )
           THEN
             concat(YEAR(contrib.receive_date), '-',YEAR(contrib.receive_date)+1)
           ELSE
@@ -418,7 +417,7 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     }
     $created = TRUE;
 
-    if (CRM_Utils_Array::value('cms_create_account', $params)) {
+    if (!empty($params['cms_create_account'])) {
       $params['contactID'] = $contactID;
       if (!CRM_Core_BAO_CMSUser::create($params, $mail)) {
         CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
@@ -602,11 +601,11 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
 
       if ($riskInfo['google-order-number']['VALUE'] == $apiParams[2]['google-order-number']['VALUE']) {
         foreach ($riskInfo['risk-information']['billing-address'] as $field => $info) {
-          if (CRM_Utils_Array::value($field, $mapper['location'])) {
+          if (!empty($mapper['location'][$field])) {
             $params['address'][1][$mapper['location'][$field]] = $info['VALUE'];
           }
-          elseif (CRM_Utils_Array::value($field, $mapper['contact'])) {
-            if ($newOrder && CRM_Utils_Array::value('structured-name', $newOrder['buyer-billing-address'])) {
+          elseif (!empty($mapper['contact'][$field])) {
+            if ($newOrder && !empty($newOrder['buyer-billing-address']['structured-name'])) {
               foreach ($newOrder['buyer-billing-address']['structured-name'] as $namePart => $nameValue) {
                 $params[$mapper['contact'][$namePart]] = $nameValue['VALUE'];
               }
@@ -615,7 +614,7 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
               $params[$mapper['contact'][$field]] = $info['VALUE'];
             }
           }
-          elseif (CRM_Utils_Array::value($field, $mapper['transaction'])) {
+          elseif (!empty($mapper['transaction'][$field])) {
             $transaction[$mapper['transaction'][$field]] = $info['VALUE'];
           }
         }
@@ -661,7 +660,7 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
         }
 
         foreach ($localMapper as $localKey => $localVal) {
-          if (CRM_Utils_Array::value($localKey, $mapper['transaction'])) {
+          if (!empty($mapper['transaction'][$localKey])) {
             $transaction[$mapper['transaction'][$localKey]] = $localVal;
           }
         }
@@ -693,7 +692,7 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     $dedupeParams['check_permission'] = FALSE;
     $dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
     // if we find more than one contact, use the first one
-    if (CRM_Utils_Array::value(0, $dupeIds)) {
+    if (!empty($dupeIds[0])) {
       $params['contact_id'] = $dupeIds[0];
     }
     $contact = CRM_Contact_BAO_Contact::create($params);