From 29671d095560a83a242ad61d7d87f633eb5828cf Mon Sep 17 00:00:00 2001
From: Jaap Jansma <jaap.jansma@civicoop.org>
Date: Wed, 14 Aug 2019 13:47:15 +0200
Subject: [PATCH] Fixed issue with activity and actions on only the found
 record or all records

---
 .../Form/AbstractSearch.php                   |  2 ++
 .../Form/ActivitySearch.php                   | 34 +++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/CRM/DataprocessorSearch/Form/AbstractSearch.php b/CRM/DataprocessorSearch/Form/AbstractSearch.php
index fb71e5d3..c06983af 100644
--- a/CRM/DataprocessorSearch/Form/AbstractSearch.php
+++ b/CRM/DataprocessorSearch/Form/AbstractSearch.php
@@ -269,6 +269,8 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce
             'data' => $record,
           );
           $ids[] = $row['id'];
+        } else {
+          $ids[] = $row['id'];
         }
 
         $rows[] = $row;
diff --git a/CRM/DataprocessorSearch/Form/ActivitySearch.php b/CRM/DataprocessorSearch/Form/ActivitySearch.php
index e9686ea2..52467c47 100644
--- a/CRM/DataprocessorSearch/Form/ActivitySearch.php
+++ b/CRM/DataprocessorSearch/Form/ActivitySearch.php
@@ -8,6 +8,15 @@ 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
@@ -99,4 +108,29 @@ class CRM_DataprocessorSearch_Form_ActivitySearch extends CRM_DataprocessorSearc
     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->activity_ids = $ids;
+    $this->_queryParams[0] = array(
+      'activity_id',
+      '=',
+      array(
+        'IN' => $this->activity_ids,
+      ),
+      0,
+      0
+    );
+    $this->controller->set('queryParams', $this->_queryParams);
+  }
+
 }
\ No newline at end of file
-- 
GitLab