X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FCustomQuery.php;h=512b7595c4d85899d70025da6a330e9981648dce;hb=c15fb38374462a40d704d83fac983412df8a16a1;hp=b36e4daf0a7a322ec097c26e35e0fe5a71b3af33;hpb=2aa397bc9ba4608d4146278d55dedd4080c53aec;p=civicrm-core.git diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index b36e4daf0a..512b7595c4 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -1,10 +1,9 @@ 'civicrm_contact', @@ -131,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 @@ -141,19 +139,18 @@ class CRM_Core_BAO_CustomQuery { * * @param bool $contactSearch * @param array $locationSpecificFields - * */ 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; @@ -165,7 +162,7 @@ class CRM_Core_BAO_CustomQuery { // 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, @@ -256,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() { @@ -323,13 +318,10 @@ 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() { foreach ($this->_ids as $id => $values) { @@ -359,7 +351,10 @@ SELECT label, value 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(); @@ -408,7 +403,7 @@ SELECT label, value 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) @@ -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; } @@ -533,7 +528,7 @@ SELECT label, value 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'; @@ -553,12 +548,11 @@ 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 + * @return array + * array of strings */ public function query() { $this->select(); @@ -578,7 +572,8 @@ SELECT label, value } } - return array(implode(' , ', $this->_select), + return array( + implode(' , ', $this->_select), implode(' ', $this->_tables), $whereStr, ); @@ -622,4 +617,5 @@ SELECT label, value $this->_qill[$grouping][] = $label . ' - ' . implode(' ' . ts('and') . ' ', $qill); } } + }