Skip to content

Commit

Permalink
Set, don't pass queryOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 17, 2018
1 parent adabfa4 commit 71464b7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public static function exportComponents(
$queryOperator = 'AND'
) {

$processor = new CRM_Export_BAO_ExportProcessor($exportMode);
$processor = new CRM_Export_BAO_ExportProcessor($exportMode, $queryOperator);
$returnProperties = array();
$paymentFields = $selectedPaymentFields = FALSE;

Expand Down Expand Up @@ -556,7 +556,7 @@ public static function exportComponents(
CRM_Contact_BAO_ProximityQuery::fixInputParams($params);
}

list($query, $select, $from, $where, $having) = $processor->runQuery($params, $order, $queryOperator, $returnProperties);
list($query, $select, $from, $where, $having) = $processor->runQuery($params, $order, $returnProperties);

if ($mergeSameHousehold == 1) {
if (empty($returnProperties['id'])) {
Expand Down
48 changes: 35 additions & 13 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ class CRM_Export_BAO_ExportProcessor {
*/
protected $queryFields = [];

/**
* Either AND or OR.
*
* @var string
*/
protected $queryOperator;

/**
* CRM_Export_BAO_ExportProcessor constructor.
*
* @param int $exportMode
* @param string $queryOperator
*/
public function __construct($exportMode, $queryOperator) {
$this->setExportMode($exportMode);
$this->setQueryMode();
$this->setQueryOperator($queryOperator);
}

/**
* @return string
*/
public function getQueryOperator() {
return $this->queryOperator;
}

/**
* @param string $queryOperator
*/
public function setQueryOperator($queryOperator) {
$this->queryOperator = $queryOperator;
}

/**
* @return array
*/
Expand All @@ -69,16 +102,6 @@ public function setQueryFields($queryFields) {
$this->queryFields = $queryFields;
}

/**
* CRM_Export_BAO_ExportProcessor constructor.
*
* @param int $exportMode
*/
public function __construct($exportMode) {
$this->setExportMode($exportMode);
$this->setQueryMode();
}

/**
* @return int
*/
Expand Down Expand Up @@ -142,14 +165,13 @@ public function setExportMode($exportMode) {
/**
* @param $params
* @param $order
* @param $queryOperator
* @param $returnProperties
* @return array
*/
public function runQuery($params, $order, $queryOperator, $returnProperties) {
public function runQuery($params, $order, $returnProperties) {
$query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL,
FALSE, FALSE, $this->getQueryMode(),
FALSE, TRUE, TRUE, NULL, $queryOperator
FALSE, TRUE, TRUE, NULL, $this->getQueryOperator()
);

//sort by state
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function tearDown() {
* Basic test to ensure the exportComponents function completes without error.
*/
public function testExportComponentsNull() {
list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
list($tableName) = CRM_Export_BAO_Export::exportComponents(
TRUE,
array(),
array(),
Expand Down Expand Up @@ -192,10 +192,10 @@ public function testGetExportStructureArrays() {
$pattern = '/as `?([^`,]*)/';
$queryFieldAliases = array();
preg_match_all($pattern, $select, $queryFieldAliases, PREG_PATTERN_ORDER);
$processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
$processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, 'AND');
$processor->setQueryFields($query->_fields);

list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $processor, $contactRelationshipTypes, '', array());
list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $processor, $contactRelationshipTypes, '');
foreach (array_keys($outputFields) as $fieldAlias) {
if ($fieldAlias == 'Home-country') {
$this->assertTrue(in_array($fieldAlias . '_id', $queryFieldAliases[1]), 'Country is subject to some funky translate so we make sure country id is present');
Expand Down Expand Up @@ -502,7 +502,7 @@ public function testExportDeceasedDoNotMail() {
));

//create address for contact A
$result = $this->callAPISuccess('address', 'create', array(
$this->callAPISuccess('address', 'create', array(
'contact_id' => $contactA['id'],
'location_type_id' => 'Home',
'street_address' => 'ABC 12',
Expand All @@ -513,7 +513,7 @@ public function testExportDeceasedDoNotMail() {
));

//create address for contact B
$result = $this->callAPISuccess('address', 'create', array(
$this->callAPISuccess('address', 'create', array(
'contact_id' => $contactB['id'],
'location_type_id' => 'Home',
'street_address' => 'ABC 12',
Expand Down

0 comments on commit 71464b7

Please sign in to comment.