Skip to content

Commit

Permalink
dev/core#2079 [REF] clean up call to apiQuery
Browse files Browse the repository at this point in the history
    This fixes
    1) fixes apiQuery to be called statically as it is a static function
    2) casts results directly to detail

This is the copy & paste source of #18664 I guess....
  • Loading branch information
eileenmcnaughton committed Oct 3, 2020
1 parent 08642a5 commit 64c57b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
19 changes: 7 additions & 12 deletions CRM/Contact/Form/Task/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function setDefaultValues() {
*/
public function postProcess($params = NULL) {
$fv = $params ?: $this->controller->exportValues($this->_name);
$config = CRM_Core_Config::singleton();
$locName = NULL;
//get the address format sequence from the config file
$mailingFormat = Civi::settings()->get('mailing_format');
Expand Down Expand Up @@ -146,15 +145,12 @@ public function postProcess($params = NULL) {
$returnProperties['last_name'] = 1;
}

$individualFormat = FALSE;

/*
* CRM-8338: replace ids of household members with the id of their household
* so we can merge labels by household.
*/
if (isset($fv['merge_same_household'])) {
$this->mergeContactIdsByHousehold();
$individualFormat = TRUE;
}

//get the contacts information
Expand Down Expand Up @@ -200,13 +196,12 @@ public function postProcess($params = NULL) {

//get the total number of contacts to fetch from database.
$numberofContacts = count($this->_contactIds);
$query = new CRM_Contact_BAO_Query($params, $returnProperties);
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, FALSE, TRUE, CRM_Contact_BAO_Query::MODE_CONTACTS, NULL, $primaryLocationOnly);
[$details] = CRM_Contact_BAO_Query::apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, FALSE, TRUE, CRM_Contact_BAO_Query::MODE_CONTACTS, NULL, $primaryLocationOnly);
$messageToken = CRM_Utils_Token::getTokens($mailingFormat);

// $details[0] is an array of [ contactID => contactDetails ]
// $details is an array of [ contactID => contactDetails ]
// also get all token values
CRM_Utils_Hook::tokenValues($details[0],
CRM_Utils_Hook::tokenValues($details,
$this->_contactIds,
NULL,
$messageToken,
Expand All @@ -224,11 +219,11 @@ public function postProcess($params = NULL) {

foreach ($this->_contactIds as $value) {
foreach ($custom as $cfID) {
if (isset($details[0][$value]["custom_{$cfID}"])) {
$details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($details[0][$value]["custom_{$cfID}"], $cfID);
if (isset($details[$value]["custom_{$cfID}"])) {
$details[$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($details[$value]["custom_{$cfID}"], $cfID);
}
}
$contact = $details['0'][$value] ?? NULL;
$contact = $details[$value] ?? NULL;

if (is_a($contact, 'CRM_Core_Error')) {
return NULL;
Expand Down Expand Up @@ -271,7 +266,7 @@ public function postProcess($params = NULL) {
'im',
'openid',
])) {
if ($k == 'im') {
if ($k === 'im') {
$rows[$value][$k] = $v['1']['name'];
}
else {
Expand Down
14 changes: 11 additions & 3 deletions tests/phpunit/CRM/Contact/Form/Task/PrintMailingLabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class CRM_Contact_Form_Task_PrintMailingLabelTest extends CiviUnitTestCase {

protected $_contactIds = NULL;
protected $_contactIds;

protected function setUp() {
parent::setUp();
Expand All @@ -25,6 +25,14 @@ protected function setUp() {
];
}

/**
* Clean up after test.
*/
protected function tearDown() {
unset($this->_contactIds);
parent::tearDown();
}

/**
* core/issue-1158: Test the mailing label rows contain the primary addresses when location_type_id = none (as primary) is chosen in form
*/
Expand All @@ -38,7 +46,7 @@ public function testMailingLabel() {
// create the non-primary address first
foreach (['non-primary', 'primary'] as $flag) {
// @TODO: bug - this doesn't affect as if its the first and only address created for a contact then it always consider it as primary
$isPrimary = ($flag == 'primary');
$isPrimary = ($flag === 'primary');
$streetName = substr(sha1(rand()), 0, 7);
$addresses[$contactID][$flag] = $this->callAPISuccess('Address', 'create', [
'street_name' => $streetName,
Expand All @@ -53,7 +61,7 @@ public function testMailingLabel() {
'sequential' => 1,
])['values'][0];

if ($flag == 'non-primary') {
if ($flag === 'non-primary') {
$addresses[$contactID][$flag] = $this->callAPISuccess('Address', 'create', [
'is_primary' => $isPrimary,
'id' => $addresses[$contactID][$flag]['id'],
Expand Down

0 comments on commit 64c57b7

Please sign in to comment.