Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactors to support converting custom fields to datepicker fields #15711

Merged
merged 3 commits into from
Nov 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3646,6 +3649,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 @@ -4041,6 +4046,8 @@ public function modifiedDates($values) {

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