From d8753da5dbe9505bab0696aebae94488bc374e4d Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Fri, 28 Feb 2020 13:37:54 +0000
Subject: [PATCH] Search tasks (eg. Export) work with
 Member,Contribute,Participant,Case (already worked with activity)

---
 .../Controller/ContributionSearch.php         |  1 +
 .../Controller/MembershipSearch.php           |  1 +
 .../Controller/ParticipantSearch.php          |  1 +
 .../Form/AbstractSearch.php                   | 14 +++++++++
 .../Form/ActivitySearch.php                   | 16 ++--------
 CRM/DataprocessorSearch/Form/CaseSearch.php   | 27 ++++++++++++++++-
 .../Form/ContributionSearch.php               | 25 ++++++++++++++++
 .../Form/MembershipSearch.php                 | 25 ++++++++++++++++
 .../Form/ParticipantSearch.php                | 29 +++++++++++++++++--
 9 files changed, 123 insertions(+), 16 deletions(-)

diff --git a/CRM/DataprocessorSearch/Controller/ContributionSearch.php b/CRM/DataprocessorSearch/Controller/ContributionSearch.php
index ca1427e0..f5a7bd2c 100644
--- a/CRM/DataprocessorSearch/Controller/ContributionSearch.php
+++ b/CRM/DataprocessorSearch/Controller/ContributionSearch.php
@@ -26,6 +26,7 @@ class CRM_DataprocessorSearch_Controller_ContributionSearch extends CRM_Core_Con
   public function __construct($title = NULL, $modal = TRUE, $action = CRM_Core_Action::NONE) {
     parent::__construct($title, $modal);
 
+    $this->set('component_mode', CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
     $this->_stateMachine = new CRM_DataprocessorSearch_StateMachine_ContributionSearch($this, $action);
 
     // create and instantiate the pages
diff --git a/CRM/DataprocessorSearch/Controller/MembershipSearch.php b/CRM/DataprocessorSearch/Controller/MembershipSearch.php
index 6ebe8033..9dda9651 100644
--- a/CRM/DataprocessorSearch/Controller/MembershipSearch.php
+++ b/CRM/DataprocessorSearch/Controller/MembershipSearch.php
@@ -26,6 +26,7 @@ class CRM_DataprocessorSearch_Controller_MembershipSearch extends CRM_Core_Contr
   public function __construct($title = NULL, $modal = TRUE, $action = CRM_Core_Action::NONE) {
     parent::__construct($title, $modal);
 
+    $this->set('component_mode', CRM_Contact_BAO_Query::MODE_MEMBER);
     $this->_stateMachine = new CRM_DataprocessorSearch_StateMachine_MembershipSearch($this, $action);
 
     // create and instantiate the pages
diff --git a/CRM/DataprocessorSearch/Controller/ParticipantSearch.php b/CRM/DataprocessorSearch/Controller/ParticipantSearch.php
index 068b8fc1..d371a673 100644
--- a/CRM/DataprocessorSearch/Controller/ParticipantSearch.php
+++ b/CRM/DataprocessorSearch/Controller/ParticipantSearch.php
@@ -26,6 +26,7 @@ class CRM_DataprocessorSearch_Controller_ParticipantSearch extends CRM_Core_Cont
   public function __construct($title = NULL, $modal = TRUE, $action = CRM_Core_Action::NONE) {
     parent::__construct($title, $modal);
 
+    $this->set('component_mode', CRM_Contact_BAO_Query::MODE_EVENT);
     $this->_stateMachine = new CRM_DataprocessorSearch_StateMachine_ParticipantSearch($this, $action);
 
     // create and instantiate the pages
diff --git a/CRM/DataprocessorSearch/Form/AbstractSearch.php b/CRM/DataprocessorSearch/Form/AbstractSearch.php
index 29dd4bbf..48caa7e6 100644
--- a/CRM/DataprocessorSearch/Form/AbstractSearch.php
+++ b/CRM/DataprocessorSearch/Form/AbstractSearch.php
@@ -46,6 +46,20 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce
    */
   protected $currentUrl;
 
+  /**
+   * The params that are sent to the query.
+   *
+   * @var array
+   */
+  protected $_queryParams;
+
+  /**
+   * The array of entity IDs from the form
+   *
+   * @var array
+   */
+  protected $entityIDs;
+
   /**
    * Returns the name of the ID field in the dataset.
    *
diff --git a/CRM/DataprocessorSearch/Form/ActivitySearch.php b/CRM/DataprocessorSearch/Form/ActivitySearch.php
index 52467c47..f70710b4 100644
--- a/CRM/DataprocessorSearch/Form/ActivitySearch.php
+++ b/CRM/DataprocessorSearch/Form/ActivitySearch.php
@@ -8,16 +8,6 @@ use CRM_Dataprocessor_ExtensionUtil as E;
 
 class CRM_DataprocessorSearch_Form_ActivitySearch extends CRM_DataprocessorSearch_Form_AbstractSearch {
 
-  /**
-   * The params that are sent to the query.
-   *
-   * @var array
-   */
-  protected $_queryParams;
-
-  protected $activity_ids;
-
-
   /**
    * Returns the name of the default Entity
    *
@@ -120,12 +110,12 @@ class CRM_DataprocessorSearch_Form_ActivitySearch extends CRM_DataprocessorSearc
    *
    */
   protected function alterRows(&$rows, $ids) {
-    $this->activity_ids = $ids;
+    $this->entityIDs = $ids;
     $this->_queryParams[0] = array(
       'activity_id',
       '=',
       array(
-        'IN' => $this->activity_ids,
+        'IN' => $this->entityIDs,
       ),
       0,
       0
@@ -133,4 +123,4 @@ class CRM_DataprocessorSearch_Form_ActivitySearch extends CRM_DataprocessorSearc
     $this->controller->set('queryParams', $this->_queryParams);
   }
 
-}
\ No newline at end of file
+}
diff --git a/CRM/DataprocessorSearch/Form/CaseSearch.php b/CRM/DataprocessorSearch/Form/CaseSearch.php
index b6e97952..a7065029 100644
--- a/CRM/DataprocessorSearch/Form/CaseSearch.php
+++ b/CRM/DataprocessorSearch/Form/CaseSearch.php
@@ -141,4 +141,29 @@ class CRM_DataprocessorSearch_Form_CaseSearch extends CRM_DataprocessorSearch_Fo
     return $hiddenFields;
   }
 
-}
\ No newline at end of file
+  /**
+   * Return altered rows
+   *
+   * Save the ids into the queryParams value. So that when an action is done on the selected record
+   * or on all records, the queryParams will hold all the activity ids so that in the next step only the selected record, or the first
+   * 50 records are populated.
+   *
+   * @param array $rows
+   * @param array $ids
+   *
+   */
+  protected function alterRows(&$rows, $ids) {
+    $this->entityIDs = $ids;
+    $this->_queryParams[0] = array(
+      'case_id',
+      '=',
+      array(
+        'IN' => $this->entityIDs,
+      ),
+      0,
+      0
+    );
+    $this->controller->set('queryParams', $this->_queryParams);
+  }
+
+}
diff --git a/CRM/DataprocessorSearch/Form/ContributionSearch.php b/CRM/DataprocessorSearch/Form/ContributionSearch.php
index 657e1c46..4c745f90 100644
--- a/CRM/DataprocessorSearch/Form/ContributionSearch.php
+++ b/CRM/DataprocessorSearch/Form/ContributionSearch.php
@@ -107,4 +107,29 @@ class CRM_DataprocessorSearch_Form_ContributionSearch extends CRM_DataprocessorS
     return $this->_taskList;
   }
 
+  /**
+   * Return altered rows
+   *
+   * Save the ids into the queryParams value. So that when an action is done on the selected record
+   * or on all records, the queryParams will hold all the activity ids so that in the next step only the selected record, or the first
+   * 50 records are populated.
+   *
+   * @param array $rows
+   * @param array $ids
+   *
+   */
+  protected function alterRows(&$rows, $ids) {
+    $this->entityIDs = $ids;
+    $this->_queryParams[0] = array(
+      'contribution_id',
+      '=',
+      array(
+        'IN' => $this->entityIDs,
+      ),
+      0,
+      0
+    );
+    $this->controller->set('queryParams', $this->_queryParams);
+  }
+
 }
diff --git a/CRM/DataprocessorSearch/Form/MembershipSearch.php b/CRM/DataprocessorSearch/Form/MembershipSearch.php
index 9694ec23..f25f0e41 100644
--- a/CRM/DataprocessorSearch/Form/MembershipSearch.php
+++ b/CRM/DataprocessorSearch/Form/MembershipSearch.php
@@ -107,4 +107,29 @@ class CRM_DataprocessorSearch_Form_MembershipSearch extends CRM_DataprocessorSea
     return $this->_taskList;
   }
 
+  /**
+   * Return altered rows
+   *
+   * Save the ids into the queryParams value. So that when an action is done on the selected record
+   * or on all records, the queryParams will hold all the activity ids so that in the next step only the selected record, or the first
+   * 50 records are populated.
+   *
+   * @param array $rows
+   * @param array $ids
+   *
+   */
+  protected function alterRows(&$rows, $ids) {
+    $this->entityIDs = $ids;
+    $this->_queryParams[0] = array(
+      'membership_id',
+      '=',
+      array(
+        'IN' => $this->entityIDs,
+      ),
+      0,
+      0
+    );
+    $this->controller->set('queryParams', $this->_queryParams);
+  }
+
 }
diff --git a/CRM/DataprocessorSearch/Form/ParticipantSearch.php b/CRM/DataprocessorSearch/Form/ParticipantSearch.php
index 3e81d0e3..c46bf4e7 100644
--- a/CRM/DataprocessorSearch/Form/ParticipantSearch.php
+++ b/CRM/DataprocessorSearch/Form/ParticipantSearch.php
@@ -16,7 +16,7 @@ class CRM_DataprocessorSearch_Form_ParticipantSearch extends CRM_DataprocessorSe
   public function getDefaultEntity() {
     return 'Contact';
   }
-  
+
   /**
    * Returns the url for view of the record action
    *
@@ -107,4 +107,29 @@ class CRM_DataprocessorSearch_Form_ParticipantSearch extends CRM_DataprocessorSe
     return $this->_taskList;
   }
 
-}
\ No newline at end of file
+  /**
+   * Return altered rows
+   *
+   * Save the ids into the queryParams value. So that when an action is done on the selected record
+   * or on all records, the queryParams will hold all the activity ids so that in the next step only the selected record, or the first
+   * 50 records are populated.
+   *
+   * @param array $rows
+   * @param array $ids
+   *
+   */
+  protected function alterRows(&$rows, $ids) {
+    $this->entityIDs = $ids;
+    $this->_queryParams[0] = array(
+      'participant_id',
+      '=',
+      array(
+        'IN' => $this->entityIDs,
+      ),
+      0,
+      0
+    );
+    $this->controller->set('queryParams', $this->_queryParams);
+  }
+
+}
-- 
GitLab