Skip to content

Commit

Permalink
Merge pull request #16101 from jitendrapurohit/dev-1474
Browse files Browse the repository at this point in the history
dev/core#1474 - (On Hold) text missing from email column when custom …
  • Loading branch information
yashodha authored Dec 17, 2019
2 parents 1bc1920 + 7906396 commit aebf30b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public function __construct(
$this->_returnProperties['contact_type'] = 1;
$this->_returnProperties['contact_sub_type'] = 1;
$this->_returnProperties['sort_name'] = 1;
if (!empty($this->_returnProperties['location']) && is_array($this->_returnProperties['location'])) {
foreach ($this->_returnProperties['location'] as $key => $property) {
if (!empty($property['email'])) {
$this->_returnProperties['location'][$key]['on_hold'] = 1;
}
}
}
}

$displayRelationshipType = CRM_Utils_Array::value('display_relationship_type', $this->_formValues);
Expand Down Expand Up @@ -708,6 +715,15 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
}
$row[$property] = $websiteUrl;
}
elseif (strpos($property, '-email') !== FALSE) {
list($locType) = explode("-email", $property);
$onholdProperty = "{$locType}-on_hold";

$row[$property] = isset($result->$property) ? $result->$property : NULL;
if (!empty($row[$property]) && !empty($result->$onholdProperty)) {
$row[$property] .= " (On Hold)";
}
}
else {
$row[$property] = isset($result->$property) ? $result->$property : NULL;
}
Expand Down
66 changes: 66 additions & 0 deletions tests/phpunit/CRM/Contact/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,72 @@ public function testSelectorQuery($dataSet) {
}
}

/**
* Test advanced search results by uf_group_id.
*/
public function testSearchByProfile() {
//Create search profile for contacts.
$ufGroup = $this->callAPISuccess('uf_group', 'create', [
'group_type' => 'Contact',
'name' => 'test_search_profile',
'title' => 'Test Search Profile',
'api.uf_field.create' => [
[
'field_name' => 'email',
'visibility' => 'Public Pages and Listings',
'field_type' => 'Contact',
'label' => 'Email',
'in_selector' => 1,
],
],
]);
$contactID = $this->individualCreate(['email' => 'mickey@mouseville.com']);
//Put the email on hold.
$email = $this->callAPISuccess('Email', 'get', [
'sequential' => 1,
'contact_id' => $contactID,
]);
$this->callAPISuccess('Email', 'create', [
'id' => $email['id'],
'on_hold' => 1,
]);

$dataSet = [
'description' => 'Normal default behaviour',
'class' => 'CRM_Contact_Selector',
'settings' => [],
'form_values' => ['email' => 'mickey@mouseville.com', 'uf_group_id' => $ufGroup['id']],
'params' => [],
'return_properties' => NULL,
'context' => 'advanced',
'action' => CRM_Core_Action::ADVANCED,
'includeContactIds' => NULL,
'searchDescendentGroups' => FALSE,
];
$params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, []);
// create CRM_Contact_Selector instance and set desired query params
$selector = new CRM_Contact_Selector(
$dataSet['class'],
$dataSet['form_values'],
$params,
$dataSet['return_properties'],
$dataSet['action'],
$dataSet['includeContactIds'],
$dataSet['searchDescendentGroups'],
$dataSet['context']
);
$rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 50, '');
$this->assertEquals(1, count($rows));
$this->assertEquals($contactID, key($rows));

//Check if email column contains (On Hold) string.
foreach ($rows[$contactID] as $key => $value) {
if (strpos($key, 'email') !== FALSE) {
$this->assertContains("(On Hold)", (string) $value);
}
}
}

/**
* Test the civicrm_prevnext_cache entry if it correctly stores the search query result
*/
Expand Down

0 comments on commit aebf30b

Please sign in to comment.