Merge pull request #6270 from systopia/CRM-16845
[civicrm-core.git] / CRM / Contact / BAO / SavedSearch.php
index 31c70839f234553ab90bc8e7d7da70c0996f1646..182218994d1cf3d52ed91f6062c797eb362d97b6 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$
  *
  */
@@ -40,7 +40,7 @@
 class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
 
   /**
-   * Class constructor
+   * Class constructor.
    *
    * @return \CRM_Contact_BAO_SavedSearch CRM_Contact_BAO_SavedSearch
    */
@@ -66,8 +66,9 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects.
+   * Retrieve DB object based on input parameters.
+   *
+   * It also stores all the retrieved values in the default array.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
@@ -75,7 +76,6 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
    *   (reference ) an assoc array to hold the flattened values.
    *
    * @return CRM_Contact_BAO_SavedSearch
-   * @static
    */
   public static function retrieve(&$params, &$defaults) {
     $savedSearch = new CRM_Contact_DAO_SavedSearch();
@@ -95,7 +95,6 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
    *
    * @return array
    *   the values of the posted saved search
-   * @static
    */
   public static function &getFormValues($id) {
     $fv = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $id, 'form_values');
@@ -151,7 +150,7 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
   }
 
   /**
-   * Get the where clause for a saved search
+   * Get the where clause for a saved search.
    *
    * @param int $id
    *   Saved search id.
@@ -162,7 +161,6 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
    *
    * @return string
    *   the where clause for this saved search
-   * @static
    */
   public static function whereClause($id, &$tables, &$whereTables) {
     $params = self::getSearchParams($id);
@@ -171,8 +169,8 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
         // this has not yet been implemented
       }
       else {
-      return CRM_Contact_BAO_Query::getWhereClause($params, NULL, $tables, $whereTables);
-    }
+        return CRM_Contact_BAO_Query::getWhereClause($params, NULL, $tables, $whereTables);
+      }
     }
     return NULL;
   }
@@ -215,8 +213,8 @@ WHERE  $where";
       }
       else {
         $tables = $whereTables = array('civicrm_contact' => 1, 'civicrm_email' => 1);
-        $where  = CRM_Contact_BAO_SavedSearch::whereClause($id, $tables, $whereTables);
-        $from   = CRM_Contact_BAO_Query::fromClause($whereTables);
+        $where = CRM_Contact_BAO_SavedSearch::whereClause($id, $tables, $whereTables);
+        $from = CRM_Contact_BAO_Query::fromClause($whereTables);
         return array($from, $where);
       }
     }
@@ -257,8 +255,6 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
         $this->where_tables = serialize($whereTables);
       }
     }
-
-    return;
   }
 
   public function save() {
@@ -278,7 +274,6 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
    *
    * @return string
    *   the name of the saved search
-   * @static
    */
   public static function getName($id, $value = 'name') {
     $group = new CRM_Contact_DAO_Group();
@@ -301,7 +296,7 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
       $savedSearch->form_values = serialize($params['formValues']);
     }
     else {
-      $savedSearch->form_values = 'null';
+      $savedSearch->form_values = NULL;
     }
 
     $savedSearch->is_active = CRM_Utils_Array::value('is_active', $params, 1);
@@ -313,4 +308,16 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
 
     return $savedSearch;
   }
+
+  protected function assignTestValue($fieldName, &$fieldDef, $counter) {
+    if ($fieldName == 'form_values') {
+      // A dummy value for form_values.
+      $this->{$fieldName} = serialize(
+          array('sort_name' => "SortName{$counter}"));
+    }
+    else {
+      parent::assignTestValues($fieldName, $fieldDef, $counter);
+    }
+  }
+
 }