From dabe5cd5db906cddebc0f5defef16185f32cbdbf Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 18 Sep 2020 16:11:50 +1200 Subject: [PATCH] [REF] Extract the code to determine the DAO name into a functions Note per https://github.com/civicrm/civicrm-core/pull/18512 my intent is actually to land on class inheritance rather than these switches but by starting to functionise them it becomes easier to start to determine what the functions should be --- CRM/Export/Form/Select.php | 109 +++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index 3570008e59..8710d85236 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -81,46 +81,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task { // FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts // FIXME: Or better still, use CRM_Core_DAO_AllCoreTables::getBriefName($daoName) to get the $entityShortName - switch ($this->getQueryMode()) { - case CRM_Contact_BAO_Query::MODE_CONTRIBUTE: - $entityShortname = 'Contribute'; - $entityDAOName = $entityShortname; - break; - - case CRM_Contact_BAO_Query::MODE_MEMBER: - $entityShortname = 'Member'; - $entityDAOName = 'Membership'; - break; - - case CRM_Contact_BAO_Query::MODE_EVENT: - $entityShortname = 'Event'; - $entityDAOName = $entityShortname; - break; - - case CRM_Contact_BAO_Query::MODE_PLEDGE: - $entityShortname = 'Pledge'; - $entityDAOName = $entityShortname; - break; - - case CRM_Contact_BAO_Query::MODE_CASE: - $entityShortname = 'Case'; - $entityDAOName = $entityShortname; - break; - - case CRM_Contact_BAO_Query::MODE_GRANT: - $entityShortname = 'Grant'; - $entityDAOName = $entityShortname; - break; - - case CRM_Contact_BAO_Query::MODE_ACTIVITY: - $entityShortname = 'Activity'; - $entityDAOName = $entityShortname; - break; - - default: - $entityShortname = $this->getComponentName(); - $entityDAOName = $this->controller->get('entity') ?? $entityShortname; - } + $entityShortname = $this->getEntityShortName(); if (in_array($entityShortname, $components)) { $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT'); @@ -134,7 +95,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task { } else { $this::$entityShortname = $entityShortname; - $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($entityDAOName)); + $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($this->getDAOName())); } } @@ -504,4 +465,70 @@ FROM {$this->_componentTable} return $componentName[1]; } + /** + * Get the DAO name for the given export. + * + * @return string + */ + protected function getDAOName(): string { + switch ($this->getQueryMode()) { + case CRM_Contact_BAO_Query::MODE_CONTRIBUTE: + return 'Contribute'; + + case CRM_Contact_BAO_Query::MODE_MEMBER: + return 'Membership'; + + case CRM_Contact_BAO_Query::MODE_EVENT: + return 'Event'; + + case CRM_Contact_BAO_Query::MODE_PLEDGE: + return 'Pledge'; + + case CRM_Contact_BAO_Query::MODE_CASE: + return 'Case'; + + case CRM_Contact_BAO_Query::MODE_GRANT: + return 'Grant'; + + case CRM_Contact_BAO_Query::MODE_ACTIVITY: + return 'Activity'; + + default: + return $this->controller->get('entity') ?? $this->getComponentName(); + } + } + + /** + * Get the entity short name for a given export. + * + * @return string + */ + protected function getEntityShortName(): string { + switch ($this->getQueryMode()) { + case CRM_Contact_BAO_Query::MODE_CONTRIBUTE: + return 'Contribute'; + + case CRM_Contact_BAO_Query::MODE_MEMBER: + return 'Member'; + + case CRM_Contact_BAO_Query::MODE_EVENT: + return 'Event'; + + case CRM_Contact_BAO_Query::MODE_PLEDGE: + return 'Pledge'; + + case CRM_Contact_BAO_Query::MODE_CASE: + return 'Case'; + + case CRM_Contact_BAO_Query::MODE_GRANT: + return 'Grant'; + + case CRM_Contact_BAO_Query::MODE_ACTIVITY: + return 'Activity'; + + default: + return $this->getComponentName(); + } + } + } -- 2.25.1