<?php
-
/*
+--------------------------------------------------------------------+
| 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_Core_BAO_CustomQuery {
- CONST PREFIX = 'custom_value_';
+ 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
public $_element;
/**
- * The tables involved in the query
+ * The tables involved in the query.
*
* @var array
*/
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
*/
protected $_locationSpecificCustomFields;
/**
- * This stores custom data group types and tables that it extends
+ * This stores custom data group types and tables that it extends.
*
- * @todo add comments explaining why survey & campaign are missing from this
* @var array
- * @static
*/
static $extendsMap = array(
'Contact' => 'civicrm_contact',
'Pledge' => 'civicrm_pledge',
'Grant' => 'civicrm_grant',
'Address' => 'civicrm_address',
+ 'Campaign' => 'civicrm_campaign',
+ 'Survey' => 'civicrm_survey',
);
/**
- * Class constructor
+ * Class constructor.
*
* Takes in a set of custom field ids andsets up the data structures to
* generate a query
*
- * @param array $ids the set of custom field ids
+ * @param array $ids
+ * The set of custom field ids.
*
* @param bool $contactSearch
* @param array $locationSpecificFields
- *
- * @access public
*/
- function __construct($ids, $contactSearch = FALSE, $locationSpecificFields = array()) {
+ public function __construct($ids, $contactSearch = FALSE, $locationSpecificFields = array()) {
$this->_ids = &$ids;
$this->_locationSpecificCustomFields = $locationSpecificFields;
- $this->_select = array();
- $this->_element = array();
- $this->_tables = array();
+ $this->_select = array();
+ $this->_element = array();
+ $this->_tables = array();
$this->_whereTables = array();
- $this->_where = array();
- $this->_qill = array();
- $this->_options = array();
+ $this->_where = array();
+ $this->_qill = array();
+ $this->_options = array();
$this->_fields = array();
$this->_contactSearch = $contactSearch;
// initialize the field array
$tmpArray = array_keys($this->_ids);
$idString = implode(',', $tmpArray);
- $query = "
+ $query = "
SELECT f.id, f.label, f.data_type,
f.html_type, f.is_search_range,
f.option_group_id, f.custom_group_id,
}
/**
- * Generate the select clause and the associated tables
+ * Generate the select clause and the associated tables.
* for the from clause
*
- * @param NULL
- *
* @return void
- * @access public
*/
- function select() {
+ public function select() {
if (empty($this->_fields)) {
return;
}
}
/**
- * Generate the where clause and also the english language
+ * Generate the where clause and also the english language.
* equivalent
*
- * @param NULL
- *
* @return void
- *
- * @access public
*/
- function where() {
+ public function where() {
foreach ($this->_ids as $id => $values) {
// Fixed for Isuue CRM 607
if (is_array($value) && !$field['is_search_range']) {
$isSerialized = CRM_Core_BAO_CustomField::isSerialized($field);
$wildcard = $isSerialized ? $wildcard : TRUE;
- $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => $name, 'context' => 'search'), array()));
+ $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array(
+ 'field' => $name,
+ 'context' => 'search',
+ ), array()));
$qillValue = '';
$sqlOP = $wildcard ? ' OR ' : ' AND ';
$sqlValue = array();
if ($wildcard) {
$val = $strtolower(CRM_Core_DAO::escapeString($val));
$val = "%$val%";
- $op = 'LIKE';
+ $op = 'LIKE';
}
//FIX for custom data query fired against no value(NULL/NOT NULL)
$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;
}
break;
case 'File':
- if ( $op == 'IS NULL' || $op == 'IS NOT NULL' || $op == 'IS EMPTY' || $op == 'IS NOT EMPTY' ) {
+ if ($op == 'IS NULL' || $op == 'IS NOT NULL' || $op == 'IS EMPTY' || $op == 'IS NOT EMPTY') {
switch ($op) {
case 'IS EMPTY':
$op = 'IS NULL';
break;
+
case 'IS NOT EMPTY':
$op = 'IS NOT NULL';
break;
}
/**
- * 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
- * @access public
+ * @return array
+ * array of strings
*/
- function query() {
+ public function query() {
$this->select();
$this->where();
}
}
- return array(implode(' , ', $this->_select),
+ return array(
+ implode(' , ', $this->_select),
implode(' ', $this->_tables),
$whereStr,
);
* @param $value
* @param $grouping
*/
- function searchRange(&$id, &$label, $type, $fieldName, &$value, &$grouping) {
+ public function searchRange(&$id, &$label, $type, $fieldName, &$value, &$grouping) {
$qill = array();
if (isset($value['from'])) {
$this->_qill[$grouping][] = $label . ' - ' . implode(' ' . ts('and') . ' ', $qill);
}
}
+
}