CRM-16713 Find Contributions: Search by Premium
[civicrm-core.git] / CRM / Contribute / Form / Search.php
index b8bafbf584f6fbf56df665282642b0b804eb41b4..a0e769d3cbf688ad52e8c19c0931456e46459855 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
 
   /**
-   * The params that are sent to the query
+   * The params that are sent to the query.
    *
    * @var array
    */
   protected $_queryParams;
 
   /**
-   * Are we restricting ourselves to a single contact
+   * Are we restricting ourselves to a single contact.
    *
    * @var boolean
    */
   protected $_single = FALSE;
 
   /**
-   * Are we restricting ourselves to a single contact
+   * Are we restricting ourselves to a single contact.
    *
    * @var boolean
    */
@@ -66,16 +66,16 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
   protected $_defaults;
 
   /**
-   * Prefix for the controller
+   * Prefix for the controller.
    */
   protected $_prefix = "contribute_";
 
   /**
-   * Processing needed for buildForm and later
+   * Processing needed for buildForm and later.
    *
    * @return void
    */
-  function preProcess() {
+  public function preProcess() {
     $this->set('searchFormName', 'Search');
 
     /**
@@ -169,7 +169,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    *
    * @return void
@@ -260,7 +260,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
 
     foreach (array(
                'contribution_amount_low',
-               'contribution_amount_high'
+               'contribution_amount_high',
              ) as $f) {
       if (isset($this->_formValues[$f])) {
         $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
@@ -269,17 +269,24 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
 
     $config = CRM_Core_Config::singleton();
     if (!empty($_POST)) {
-      foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status') as $element) {
-        $value = CRM_Utils_Array::value($element, $this->_formValues);
-        if ($value && is_array($value)) {
-          $this->_formValues[$element] = array('IN' => $value);
-        }
-      }
-
-      foreach (array('contribution_source', 'contribution_trxn_id') as $element) {
+      $specialParams = array(
+        'financial_type_id',
+        'contribution_soft_credit_type_id',
+        'contribution_status_id',
+        'contribution_source',
+        'contribution_trxn_id',
+        'contribution_page_id',
+        'contribution_product_id',
+      );
+      foreach ($specialParams as $element) {
         $value = CRM_Utils_Array::value($element, $this->_formValues);
         if ($value) {
-          $this->_formValues[$element] = array('LIKE' => "%$value%");
+          if (is_array($value)) {
+            $this->_formValues[$element] = array('IN' => $value);
+          }
+          else {
+            $this->_formValues[$element] = array('LIKE' => "%$value%");
+          }
         }
       }
 
@@ -462,4 +469,5 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
   public function getTitle() {
     return ts('Find Contributions');
   }
+
 }