[REF] Extract getIDS functionality
authoreileen <emcnaughton@wikimedia.org>
Fri, 26 Mar 2021 01:37:52 +0000 (14:37 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 26 Mar 2021 01:43:45 +0000 (14:43 +1300)
With this change made we are ready to start exposing some actions to search kit

CRM/Contribute/Form/Task.php
CRM/Contribute/Form/Task/TaskTrait.php

index 53df76a8b5073d0bfaa8c9d761dab231a85df530..e9b72c8c923fb45a9c603d789e69b22bcac1b1e0 100644 (file)
@@ -49,21 +49,9 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {
 
     $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');
index e08185ace1dab00614249ce9d6d104172a123a7d..6dedf99ec371c50fd00d86e2f78887cfb7c2582b 100644 (file)
 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.
@@ -96,4 +96,46 @@ trait CRM_Contribute_Form_Task_TaskTrait {
     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()) . ' ) ';
+  }
+
 }