From 6003a96456d1f235a4f65292db6e8e6cb5faab98 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 16 Jul 2018 11:53:22 +1200 Subject: [PATCH] Start building export processor class. A fundamental cause of code mess in the Export class is that it is a mishmash of static functions with variables passed around crazily. This starts the process of moving work to a object oriented class. I think this migratory approach is the best plan to clean up the code I did move some vars to being accessed via 'self' but there is leakage across tests so going full OOO seems like a better approach --- CRM/Export/BAO/Export.php | 47 +---------- CRM/Export/BAO/ExportProcessor.php | 121 +++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 45 deletions(-) create mode 100644 CRM/Export/BAO/ExportProcessor.php diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 9fc4b83f49..f8a1dca2e5 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -130,50 +130,6 @@ class CRM_Export_BAO_Export { return self::relationshipReturnProperties; } - /** - * Get Querymode based on ExportMode - * - * @param int $exportMode - * Export mode. - * - * @return string $Querymode - * Query Mode - */ - public static function getQueryMode($exportMode) { - $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; - } - return $queryMode; - } - /** * Get default return property for export based on mode * @@ -397,6 +353,7 @@ class CRM_Export_BAO_Export { $queryOperator = 'AND' ) { + $processor = new CRM_Export_BAO_ExportProcessor($exportMode); $returnProperties = array(); $paymentFields = $selectedPaymentFields = FALSE; @@ -417,7 +374,7 @@ class CRM_Export_BAO_Export { self::$memberOfHouseholdRelationshipKey = CRM_Utils_Array::key('Household Member of', self::$relationshipTypes); self::$headOfHouseholdRelationshipKey = CRM_Utils_Array::key('Head of Household for', self::$relationshipTypes); - $queryMode = self::getQueryMode($exportMode); + $queryMode = $processor->getQueryMode(); if ($fields) { //construct return properties diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php new file mode 100644 index 0000000000..985eba5121 --- /dev/null +++ b/CRM/Export/BAO/ExportProcessor.php @@ -0,0 +1,121 @@ +setExportMode($exportMode); + $this->setQueryMode(); + } + + /** + * @return int + */ + public function getQueryMode() { + return $this->queryMode; + } + + /** + * Set the query mode based on the export mode. + */ + public function setQueryMode() { + + switch ($this->getExportMode()) { + case CRM_Export_Form_Select::CONTRIBUTE_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE; + break; + + case CRM_Export_Form_Select::EVENT_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_EVENT; + break; + + case CRM_Export_Form_Select::MEMBER_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_MEMBER; + break; + + case CRM_Export_Form_Select::PLEDGE_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE; + break; + + case CRM_Export_Form_Select::CASE_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_CASE; + break; + + case CRM_Export_Form_Select::GRANT_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_GRANT; + break; + + case CRM_Export_Form_Select::ACTIVITY_EXPORT: + $this->queryMode = CRM_Contact_BAO_Query::MODE_ACTIVITY; + break; + + default: + $this->queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS; + } + } + + /** + * @return int + */ + public function getExportMode() { + return $this->exportMode; + } + + /** + * @param int $exportMode + */ + public function setExportMode($exportMode) { + $this->exportMode = $exportMode; + } + +} -- 2.25.1