Skip to content

Commit

Permalink
Merge pull request #18783 from eileenmcnaughton/distinct
Browse files Browse the repository at this point in the history
dev/core#2066 Further cleanup on search actions
  • Loading branch information
monishdeb authored Oct 16, 2020
2 parents 7d41ce4 + ab3e9e4 commit 9c8c4e7
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 18 deletions.
18 changes: 18 additions & 0 deletions CRM/Activity/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
18 changes: 18 additions & 0 deletions CRM/Contact/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
18 changes: 18 additions & 0 deletions CRM/Contribute/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
48 changes: 43 additions & 5 deletions CRM/Core/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ public static function preProcessCommon(&$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));
}

Expand All @@ -187,7 +187,7 @@ public static function preProcessCommon(&$form) {
*/
public function setContactIDs() {
$this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent($this->_entityIds,
$this::$tableName
$this->getTableName()
);
}

Expand Down Expand Up @@ -297,4 +297,42 @@ public function getSearchFormValues() {
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';
}

}
18 changes: 18 additions & 0 deletions CRM/Event/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
22 changes: 9 additions & 13 deletions CRM/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,8 @@ public function preProcess() {
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;
Expand Down Expand Up @@ -159,7 +148,14 @@ public function preProcess() {
$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');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions CRM/Export/Form/Select/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
18 changes: 18 additions & 0 deletions CRM/Grant/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
18 changes: 18 additions & 0 deletions CRM/Member/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}
18 changes: 18 additions & 0 deletions CRM/Pledge/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ protected function isShowContactMergeOptions() {
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';
}

}

0 comments on commit 9c8c4e7

Please sign in to comment.