Fix export contribution to share tasktrait
authoreileen <emcnaughton@wikimedia.org>
Fri, 19 Mar 2021 20:55:47 +0000 (09:55 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 19 Mar 2021 21:06:18 +0000 (10:06 +1300)
CRM/Contribute/Export/Form/Select.php
CRM/Contribute/Form/Task.php
CRM/Contribute/Form/Task/TaskTrait.php [new file with mode: 0644]

index 9ad30badd631521ec3e5ad89264893618ce7b849..4e57be122f48c5ddd241895e0eeb359ac4c577e0 100644 (file)
  */
 class CRM_Contribute_Export_Form_Select extends CRM_Export_Form_Select {
 
+  use CRM_Contribute_Form_Task_TaskTrait;
+
   /**
    * Call the pre-processing function.
+   *
+   * @throws \CRM_Core_Exception
    */
   protected function callPreProcessing(): void {
     CRM_Contribute_Form_Task::preProcessCommon($this);
index 79fea13c6c71787c22c9cc20a445e9d49a3dfa79..1cef21bc6cc8bbaf6ffe52820bca164d0fcc1c02 100644 (file)
@@ -21,6 +21,8 @@
  */
 class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {
 
+  use CRM_Contribute_Form_Task_TaskTrait;
+
   /**
    * The array that holds all the contribution ids.
    *
@@ -42,60 +44,6 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {
    */
   public $_includesSoftCredits = FALSE;
 
-  /**
-   * Get the results from the BAO_Query object based search.
-   *
-   * @return CRM_Core_DAO
-   *
-   * @throws \CRM_Core_Exception
-   */
-  public function getSearchQueryResults(): CRM_Core_DAO {
-    $form = $this;
-    $queryParams = $form->get('queryParams');
-    $isTest = FALSE;
-    if (is_array($queryParams)) {
-      foreach ($queryParams as $fields) {
-        if ($fields[0] === 'contribution_test') {
-          $isTest = TRUE;
-          break;
-        }
-      }
-    }
-    if (!$isTest) {
-      $queryParams[] = [
-        'contribution_test',
-        '=',
-        0,
-        0,
-        0,
-      ];
-    }
-    $returnProperties = ['contribution_id' => 1];
-    $sortOrder = $sortCol = NULL;
-    if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
-      $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
-      //Include sort column in select clause.
-      $sortCol = trim(str_replace(['`', 'asc', 'desc'], '', $sortOrder));
-      $returnProperties[$sortCol] = 1;
-    }
-
-    $form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
-    $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE,
-      CRM_Contact_BAO_Query::MODE_CONTRIBUTE
-    );
-    // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this
-    // can we remove? if not why not?
-    if ($form->_includesSoftCredits) {
-      $query->_rowCountClause = " count(civicrm_contribution.id)";
-      $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
-    }
-    else {
-      $query->_distinctComponentClause = ' civicrm_contribution.id';
-      $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id ';
-    }
-    return $query->searchQuery(0, 0, $sortOrder);
-  }
-
   /**
    * Build all the data structures needed to build the form.
    */
diff --git a/CRM/Contribute/Form/Task/TaskTrait.php b/CRM/Contribute/Form/Task/TaskTrait.php
new file mode 100644 (file)
index 0000000..552d46d
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+
+/**
+ * This class provides shared contribution task functionality.
+ */
+trait CRM_Contribute_Form_Task_TaskTrait {
+
+  /**
+   * Get the results from the BAO_Query object based search.
+   *
+   * @return CRM_Core_DAO
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function getSearchQueryResults(): CRM_Core_DAO {
+    $form = $this;
+    $queryParams = $form->get('queryParams');
+    $isTest = FALSE;
+    if (is_array($queryParams)) {
+      foreach ($queryParams as $fields) {
+        if ($fields[0] === 'contribution_test') {
+          $isTest = TRUE;
+          break;
+        }
+      }
+    }
+    if (!$isTest) {
+      $queryParams[] = [
+        'contribution_test',
+        '=',
+        0,
+        0,
+        0,
+      ];
+    }
+    $returnProperties = ['contribution_id' => 1];
+    $sortOrder = $sortCol = NULL;
+    if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
+      $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
+      //Include sort column in select clause.
+      $sortCol = trim(str_replace(['`', 'asc', 'desc'], '', $sortOrder));
+      $returnProperties[$sortCol] = 1;
+    }
+
+    $form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
+    $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE,
+      CRM_Contact_BAO_Query::MODE_CONTRIBUTE
+    );
+    // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this
+    // can we remove? if not why not?
+    if ($form->_includesSoftCredits) {
+      $query->_rowCountClause = " count(civicrm_contribution.id)";
+      $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
+    }
+    else {
+      $query->_distinctComponentClause = ' civicrm_contribution.id';
+      $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id ';
+    }
+    return $query->searchQuery(0, 0, $sortOrder);
+  }
+
+}