From: eileen Date: Fri, 16 Oct 2020 01:59:42 +0000 (+1300) Subject: dev/core#2066 Further cleanup on search actions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ab3e9e4c52018cfae67b86248a34639fc46647e0;p=civicrm-core.git dev/core#2066 Further cleanup on search actions Most of the noise is in the shared pre-process code so my focus is on paring that down --- diff --git a/CRM/Activity/Export/Form/Select.php b/CRM/Activity/Export/Form/Select.php index ef856053fc..d50e2a8329 100644 --- a/CRM/Activity/Export/Form/Select.php +++ b/CRM/Activity/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Activity_Export_Form_Select extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_activity'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'activity_id'; + } + } diff --git a/CRM/Contact/Export/Form/Select.php b/CRM/Contact/Export/Form/Select.php index d15ff7afd0..41fe6c5e3a 100644 --- a/CRM/Contact/Export/Form/Select.php +++ b/CRM/Contact/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Contact_Export_Form_Select extends CRM_Export_Form_Select { return TRUE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_contact'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'contact_id'; + } + } diff --git a/CRM/Contribute/Export/Form/Select.php b/CRM/Contribute/Export/Form/Select.php index 921c059564..9ad30badd6 100644 --- a/CRM/Contribute/Export/Form/Select.php +++ b/CRM/Contribute/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Contribute_Export_Form_Select extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_contribution'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'contribution_id'; + } + } diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index 4dd9e128b8..d23f253c73 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -156,17 +156,17 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form { } $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form->getQueryMode()); - $query->_distinctComponentClause = " ( " . $form::$tableName . ".id )"; - $query->_groupByComponentClause = " GROUP BY " . $form::$tableName . ".id "; + $query->_distinctComponentClause = $form->getDistinctComponentClause(); + $query->_groupByComponentClause = $form->getGroupByComponentClause(); $result = $query->searchQuery(0, 0, $sortOrder); - $selector = $form::$entityShortname . '_id'; + $selector = $form->getEntityAliasField(); while ($result->fetch()) { $entityIds[] = $result->$selector; } } if (!empty($entityIds)) { - $form->_componentClause = ' ' . $form::$tableName . '.id IN ( ' . implode(',', $entityIds) . ' ) '; + $form->_componentClause = ' ' . $form->getTableName() . '.id IN ( ' . implode(',', $entityIds) . ' ) '; $form->assign('totalSelected' . ucfirst($form::$entityShortname) . 's', count($entityIds)); } @@ -187,7 +187,7 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form { */ public function setContactIDs() { $this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent($this->_entityIds, - $this::$tableName + $this->getTableName() ); } @@ -297,4 +297,42 @@ SELECT contact_id return $this->controller->exportValues('Basic'); } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + CRM_Core_Error::deprecatedFunctionWarning('function should be overridden'); + return $this::$tableName; + } + + /** + * Get the clause for grouping by the component. + * + * @return string + */ + public function getDistinctComponentClause() { + return " ( " . $this->getTableName() . ".id )"; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getGroupByComponentClause() { + return " GROUP BY " . $this->getTableName() . ".id "; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + CRM_Core_Error::deprecatedFunctionWarning('function should be overridden'); + return $this::$entityShortname . '_id'; + } + } diff --git a/CRM/Event/Export/Form/Select.php b/CRM/Event/Export/Form/Select.php index f281decc23..835200669d 100644 --- a/CRM/Event/Export/Form/Select.php +++ b/CRM/Event/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Event_Export_Form_Select extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_participant'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'participant_id'; + } + } diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index 95a9e3a83e..82ddb1b7b4 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -95,19 +95,8 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task { throw new CRM_Core_Exception('Unreachable code'); } $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT'); - $formTaskClassName = "CRM_{$entityShortname}_Form_Task"; - - if (isset($formTaskClassName::$entityShortname)) { - $this::$entityShortname = $formTaskClassName::$entityShortname; - if (isset($formTaskClassName::$tableName)) { - $this::$tableName = $formTaskClassName::$tableName; - } - } - else { - $this::$entityShortname = $entityShortname; - $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($this->getDAOName())); - } + $this::$entityShortname = strtolower($entityShortname); $values = $this->getSearchFormValues(); $count = 0; @@ -159,7 +148,14 @@ FROM {$this->_componentTable} $this->set('selectAll', $this->_selectAll); $this->set('exportMode', $this->_exportMode); $this->set('componentClause', $this->_componentClause); - $this->set('componentTable', $this->_componentTable); + $this->set('componentTable', $this->getTableName()); + } + + /** + * Get the name of the table for the relevant entity. + */ + public function getTableName() { + throw new CRM_Core_Exception('should be over-riden'); } /** diff --git a/CRM/Export/Form/Select/Case.php b/CRM/Export/Form/Select/Case.php index cb7ac3e1c7..fe2356e85f 100644 --- a/CRM/Export/Form/Select/Case.php +++ b/CRM/Export/Form/Select/Case.php @@ -41,4 +41,22 @@ class CRM_Export_Form_Select_Case extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_case'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'case_id'; + } + } diff --git a/CRM/Grant/Export/Form/Select.php b/CRM/Grant/Export/Form/Select.php index a8c8d0df80..6bade5bccd 100644 --- a/CRM/Grant/Export/Form/Select.php +++ b/CRM/Grant/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Grant_Export_Form_Select extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_grant'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'grant_id'; + } + } diff --git a/CRM/Member/Export/Form/Select.php b/CRM/Member/Export/Form/Select.php index 61896fe766..764784f535 100644 --- a/CRM/Member/Export/Form/Select.php +++ b/CRM/Member/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Member_Export_Form_Select extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_membership'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'membership_id'; + } + } diff --git a/CRM/Pledge/Export/Form/Select.php b/CRM/Pledge/Export/Form/Select.php index 55e77b1ed4..d7495ed210 100644 --- a/CRM/Pledge/Export/Form/Select.php +++ b/CRM/Pledge/Export/Form/Select.php @@ -36,4 +36,22 @@ class CRM_Pledge_Export_Form_Select extends CRM_Export_Form_Select { return FALSE; } + /** + * Get the name of the table for the relevant entity. + * + * @return string + */ + public function getTableName() { + return 'civicrm_pledge'; + } + + /** + * Get the group by clause for the component. + * + * @return string + */ + public function getEntityAliasField() { + return 'pledge_id'; + } + }