Skip to content

Commit

Permalink
Merge pull request #15711 from eileenmcnaughton/cust_ug
Browse files Browse the repository at this point in the history
Minor refactors to support converting custom fields to datepicker fields
  • Loading branch information
seamuslee001 authored Nov 3, 2019
2 parents 949af2c + e14c912 commit a78eeec
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ class CRM_Contact_BAO_Query {
* @param string $operator
* @param string $apiEntity
* @param bool|null $primaryLocationOnly
*
* @throws \CRM_Core_Exception
*/
public function __construct(
$params = NULL, $returnProperties = NULL, $fields = NULL,
Expand Down Expand Up @@ -548,6 +550,8 @@ public function __construct(
* @param string $apiEntity
* The api entity being called.
* This sort-of duplicates $mode in a confusing way. Probably not by design.
*
* @throws \CRM_Core_Exception
*/
public function initialize($apiEntity = NULL) {
$this->_select = [];
Expand Down Expand Up @@ -579,6 +583,17 @@ public function initialize($apiEntity = NULL) {
$this->_whereTables = $this->_tables;

$this->selectClause($apiEntity);
if (!empty($this->_cfIDs)) {
// @todo This function is the select function but instead of running 'select' it
// is running the whole query.
$this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE, $this->_locationSpecificCustomFields);
$this->_customQuery->query();
$this->_select = array_merge($this->_select, $this->_customQuery->_select);
$this->_element = array_merge($this->_element, $this->_customQuery->_element);
$this->_tables = array_merge($this->_tables, $this->_customQuery->_tables);
$this->_whereTables = array_merge($this->_whereTables, $this->_customQuery->_whereTables);
$this->_options = $this->_customQuery->_options;
}
$isForcePrimaryOnly = !empty($apiEntity);
$this->_whereClause = $this->whereClause($isForcePrimaryOnly);
if (array_key_exists('civicrm_contribution', $this->_whereTables)) {
Expand Down Expand Up @@ -651,7 +666,7 @@ public function buildParamsLookup() {
if (empty($value[0])) {
continue;
}
$cfID = CRM_Core_BAO_CustomField::getKeyID(str_replace('_relative', '', $value[0]));
$cfID = CRM_Core_BAO_CustomField::getKeyID(str_replace(['_relative', '_low', '_high', '_to', '_high'], '', $value[0]));
if ($cfID) {
if (!array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = [];
Expand Down Expand Up @@ -1029,18 +1044,6 @@ public function selectClause($apiEntity = NULL) {
CRM_Core_Component::alterQuery($this, 'select');

CRM_Contact_BAO_Query_Hook::singleton()->alterSearchQuery($this, 'select');

if (!empty($this->_cfIDs)) {
// @todo This function is the select function but instead of running 'select' it
// is running the whole query.
$this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE, $this->_locationSpecificCustomFields);
$this->_customQuery->query();
$this->_select = array_merge($this->_select, $this->_customQuery->_select);
$this->_element = array_merge($this->_element, $this->_customQuery->_element);
$this->_tables = array_merge($this->_tables, $this->_customQuery->_tables);
$this->_whereTables = array_merge($this->_whereTables, $this->_customQuery->_whereTables);
$this->_options = $this->_customQuery->_options;
}
}

/**
Expand Down Expand Up @@ -3604,6 +3607,8 @@ public function phone_numeric(&$values) {
* Where / qill clause for phone type/location
*
* @param array $values
*
* @throws \CRM_Core_Exception
*/
public function phone_option_group($values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
Expand Down Expand Up @@ -3992,6 +3997,8 @@ public function modifiedDates($values) {

/**
* @param $values
*
* @throws \CRM_Core_Exception
*/
public function demographics(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
Expand Down

0 comments on commit a78eeec

Please sign in to comment.