Merge branch 4.6 into master
[civicrm-core.git] / CRM / Core / BAO / CustomQuery.php
index bb656e8b1adf154536e86e47cc2de6a13fffa010..512b7595c4d85899d70025da6a330e9981648dce 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$
  *
  */
@@ -37,21 +37,21 @@ class CRM_Core_BAO_CustomQuery {
   const PREFIX = 'custom_value_';
 
   /**
-   * The set of custom field ids
+   * The set of custom field ids.
    *
    * @var array
    */
   protected $_ids;
 
   /**
-   * The select clause
+   * The select clause.
    *
    * @var array
    */
   public $_select;
 
   /**
-   * The name of the elements that are in the select clause
+   * The name of the elements that are in the select clause.
    * used to extract the values
    *
    * @var array
@@ -59,7 +59,7 @@ class CRM_Core_BAO_CustomQuery {
   public $_element;
 
   /**
-   * The tables involved in the query
+   * The tables involved in the query.
    *
    * @var array
    */
@@ -67,28 +67,28 @@ class CRM_Core_BAO_CustomQuery {
   public $_whereTables;
 
   /**
-   * The where clause
+   * The where clause.
    *
    * @var array
    */
   public $_where;
 
   /**
-   * The english language version of the query
+   * The english language version of the query.
    *
    * @var array
    */
   public $_qill;
 
   /**
-   * The cache to translate the option values into labels
+   * The cache to translate the option values into labels.
    *
    * @var array
    */
   public $_options;
 
   /**
-   * The custom fields information
+   * The custom fields information.
    *
    * @var array
    */
@@ -104,10 +104,9 @@ class CRM_Core_BAO_CustomQuery {
   protected $_locationSpecificCustomFields;
 
   /**
-   * This stores custom data group types and tables that it extends
+   * This stores custom data group types and tables that it extends.
    *
    * @var array
-   * @static
    */
   static $extendsMap = array(
     'Contact' => 'civicrm_contact',
@@ -130,7 +129,7 @@ class CRM_Core_BAO_CustomQuery {
   );
 
   /**
-   * Class constructor
+   * Class constructor.
    *
    * Takes in a set of custom field ids andsets up the data structures to
    * generate a query
@@ -254,11 +253,9 @@ SELECT label, value
   }
 
   /**
-   * Generate the select clause and the associated tables
+   * Generate the select clause and the associated tables.
    * for the from clause
    *
-   * @param NULL
-   *
    * @return void
    */
   public function select() {
@@ -321,11 +318,9 @@ SELECT label, value
   }
 
   /**
-   * Generate the where clause and also the english language
+   * Generate the where clause and also the english language.
    * equivalent
    *
-   * @param NULL
-   *
    * @return void
    */
   public function where() {
@@ -358,7 +353,7 @@ SELECT label, value
           $wildcard = $isSerialized ? $wildcard : TRUE;
           $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array(
                 'field' => $name,
-                'context' => 'search'
+                'context' => 'search',
               ), array()));
           $qillValue = '';
           $sqlOP = $wildcard ? ' OR ' : ' AND ';
@@ -487,7 +482,7 @@ SELECT label, value
             $toValue = CRM_Utils_Array::value('to', $value);
 
             if (!$fromValue && !$toValue) {
-              if (!CRM_Utils_Date::processDate($value) && $op != 'IS NULL' && $op != 'IS NOT NULL') {
+              if (!CRM_Utils_Date::processDate($value) && !in_array($op, array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) {
                 continue;
               }
 
@@ -553,11 +548,9 @@ SELECT label, value
   }
 
   /**
-   * Function that does the actual query generation
+   * Function that does the actual query generation.
    * basically ties all the above functions together
    *
-   * @param NULL
-   *
    * @return array
    *   array of strings
    */
@@ -624,4 +617,5 @@ SELECT label, value
       $this->_qill[$grouping][] = $label . ' - ' . implode(' ' . ts('and') . ' ', $qill);
     }
   }
+
 }