$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');
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.
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()) . ' ) ';
+ }
+
}