Split up some of CRM_Export_BAO_Export::ExportComponents into smaller tighter functions
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 28 Aug 2015 00:01:27 +0000 (00:01 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 28 Aug 2015 00:01:27 +0000 (00:01 +0000)
CRM/Export/BAO/Export.php

index 0d4326b65d3b7d3c6779dda3821b980a9b547a25..aa8c6627240d86606efac7ded618e3b96d75eb4c 100644 (file)
@@ -43,6 +43,117 @@ class CRM_Export_BAO_Export {
   // CRM-7675
   const EXPORT_ROW_COUNT = 10000;
 
+  /**
+   * Get Querymode based on ExportMode
+   *
+   * @param int $exportMode
+   *   Export mode.
+   *
+   * return string Querymode
+   */
+  public function getQueryMode($exportMode) {
+    switch ($exportMode) {
+      case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
+        break;
+
+      case CRM_Export_Form_Select::EVENT_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
+        break;
+
+      case CRM_Export_Form_Select::MEMBER_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
+        break;
+
+      case CRM_Export_Form_Select::PLEDGE_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
+        break;
+
+      case CRM_Export_Form_Select::CASE_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
+        break;
+
+      case CRM_Export_Form_Select::GRANT_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_GRANT;
+        break;
+
+      case CRM_Export_Form_Select::ACTIVITY_EXPORT:
+        $queryMode = CRM_Contact_BAO_Query::MODE_ACTIVITY;
+        break;
+    }
+    return $queryMode;
+  }
+
+  /**
+   * Get default return property for export based on mode
+   *
+   * @param int $exportMode
+   *   Export mode.
+   * return returnProperties
+   */
+  function defultReturnProperty($exportMode) {
+    // hack to add default returnproperty based on export mode
+    if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
+      $returnProperties['contribution_id'] = 1;
+    }
+    elseif ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
+      $returnProperties['participant_id'] = 1;
+      if (!empty($returnProperties['participant_role'])) {
+        unset($returnProperties['participant_role']);
+        $returnProperties['participant_role_id'] = 1;
+      }
+    }
+    elseif ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
+      $returnProperties['membership_id'] = 1;
+    }
+    elseif ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
+      $returnProperties['pledge_id'] = 1;
+    }
+    elseif ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
+      $returnProperties['case_id'] = 1;
+    }
+    elseif ($exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
+      $returnProperties['grant_id'] = 1;
+    }
+    elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
+      $returnProperties['activity_id'] = 1;
+    }
+    return $returnProperties;
+  }
+
+  /**
+   * Get Export component
+   *
+   * @param int $exportMode
+   *   Export mode.
+   *
+   * return string component
+   */
+   public function exportComponent($exportMode) {
+    switch ($exportMode) {
+      case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
+        $component = 'civicrm_contribution';
+        break;
+
+      case CRM_Export_Form_Select::EVENT_EXPORT:
+        $component = 'civicrm_participant';
+        break;
+
+      case CRM_Export_Form_Select::MEMBER_EXPORT:
+        $component = 'civicrm_membership';
+        break;
+
+      case CRM_Export_Form_Select::PLEDGE_EXPORT:
+        $component = 'civicrm_pledge';
+        break;
+
+      case CRM_Export_Form_Select::GRANT_EXPORT:
+        $component = 'civicrm_grant';
+        break;
+    }
+    return $component;
+  }
+
   /**
    * Get the list the export fields.
    *
@@ -106,35 +217,8 @@ class CRM_Export_BAO_Export {
     );
     $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
 
-    switch ($exportMode) {
-      case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
-        break;
-
-      case CRM_Export_Form_Select::EVENT_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
-        break;
-
-      case CRM_Export_Form_Select::MEMBER_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
-        break;
-
-      case CRM_Export_Form_Select::PLEDGE_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
-        break;
-
-      case CRM_Export_Form_Select::CASE_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
-        break;
-
-      case CRM_Export_Form_Select::GRANT_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_GRANT;
-        break;
-
-      case CRM_Export_Form_Select::ACTIVITY_EXPORT:
-        $queryMode = CRM_Contact_BAO_Query::MODE_ACTIVITY;
-        break;
-    }
+    $queryMode = self::getQueryMode($exportMode);
+  
     if ($fields) {
       //construct return properties
       $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
@@ -247,34 +331,7 @@ class CRM_Export_BAO_Export {
           }
         }
       }
-
-      // hack to add default returnproperty based on export mode
-      if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
-        $returnProperties['contribution_id'] = 1;
-      }
-      elseif ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
-        $returnProperties['participant_id'] = 1;
-        if (!empty($returnProperties['participant_role'])) {
-          unset($returnProperties['participant_role']);
-          $returnProperties['participant_role_id'] = 1;
-        }
-      }
-      elseif ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
-        $returnProperties['membership_id'] = 1;
-      }
-      elseif ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
-        $returnProperties['pledge_id'] = 1;
-      }
-      elseif ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
-        $returnProperties['case_id'] = 1;
-      }
-      elseif ($exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
-        $returnProperties['grant_id'] = 1;
-      }
-      elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
-        $returnProperties['activity_id'] = 1;
-      }
-    }
+      self::defultReturnProperty($exportMode);
     else {
       $primary = TRUE;
       $fields = CRM_Contact_BAO_Contact::exportableFields('All', TRUE, TRUE);
@@ -473,27 +530,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
           }
         }
         else {
-          switch ($exportMode) {
-            case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
-              $component = 'civicrm_contribution';
-              break;
-
-            case CRM_Export_Form_Select::EVENT_EXPORT:
-              $component = 'civicrm_participant';
-              break;
-
-            case CRM_Export_Form_Select::MEMBER_EXPORT:
-              $component = 'civicrm_membership';
-              break;
-
-            case CRM_Export_Form_Select::PLEDGE_EXPORT:
-              $component = 'civicrm_pledge';
-              break;
-
-            case CRM_Export_Form_Select::GRANT_EXPORT:
-              $component = 'civicrm_grant';
-              break;
-          }
+          self::exportComponent($exportMode);
 
           if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
             $relIDs = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids);