Skip to content

Commit

Permalink
[REF] Extract getIDS functionality
Browse files Browse the repository at this point in the history
With this change made we are ready to start exposing some actions to search kit
  • Loading branch information
eileenmcnaughton committed Mar 26, 2021
1 parent f0c2d25 commit 0a2728c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
18 changes: 3 additions & 15 deletions CRM/Contribute/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,9 @@ public static function preProcessCommon(&$form): void {

$form->_task = $values['task'] ?? NULL;

$ids = $form->getSelectedIDs($values);
if (!$ids) {
$result = $form->getSearchQueryResults();
while ($result->fetch()) {
$ids[] = $result->contribution_id;
}
$form->assign('totalSelectedContributions', $form->get('rowCount'));
}

if (!empty($ids)) {
$form->_componentClause = ' civicrm_contribution.id IN ( ' . implode(',', $ids) . ' ) ';

$form->assign('totalSelectedContributions', count($ids));
}

$ids = $form->getIDs();
$form->_componentClause = $form->getComponentClause();
$form->assign('totalSelectedContributions', count($ids));
$form->_contributionIds = $form->_componentIds = $ids;
$form->set('contributionIds', $form->_contributionIds);
$form->setNextUrl('contribute');
Expand Down
48 changes: 45 additions & 3 deletions CRM/Contribute/Form/Task/TaskTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
trait CRM_Contribute_Form_Task_TaskTrait {

/**
* Query result object.
* Selected IDs for the action.
*
* @var \CRM_Core_DAO
* @var array
*/
protected $queryBAO;
protected $ids;

/**
* Get the results from the BAO_Query object based search.
Expand Down Expand Up @@ -96,4 +96,46 @@ public function isQueryIncludesSoftCredits(): bool {
return (bool) CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($this->getQueryParams());
}

/**
* Get ids selected for the task.
*
* @return array|bool
* @throws \CRM_Core_Exception
*/
public function getIDs() {
if (!$this->ids) {
$this->ids = $this->calculateIDS();
}
return $this->ids;
}

/**
* @return array|bool|string[]
* @throws \CRM_Core_Exception
*/
protected function calculateIDS() {
if ($this->controller->get('id')) {
return explode(',', $this->controller->get('id'));
}
$ids = $this->getSelectedIDs($this->getSearchFormValues());
if (!$ids) {
$result = $this->getSearchQueryResults();
while ($result->fetch()) {
$ids[] = $result->contribution_id;
}
}
return $ids;
}

/**
* Get the clause to add to queries to hone the results.
*
* In practice this generally means the query to limit by selected ids.
*
* @throws \CRM_Core_Exception
*/
public function getComponentClause(): string {
return ' civicrm_contribution.id IN ( ' . implode(',', $this->getIDs()) . ' ) ';
}

}

0 comments on commit 0a2728c

Please sign in to comment.