//sort by state
//CRM-15301
$query->_sort = $order;
- list($select, $from, $where, $having) = $query->query();
+ [$select, $from, $where, $having] = $query->query();
$this->setQueryFields($query->_fields);
$whereClauses = ['trash_clause' => "contact_a.is_deleted != 1"];
if ($this->getComponentClause()) {
$order .= ", contact_a.id";
}
- list($field, $dir) = explode(' ', $order, 2);
+ [$field, $dir] = explode(' ', $order, 2);
$field = trim($field);
if (!empty($this->getReturnProperties()[$field])) {
//CRM-15301
}
/**
- * @param int $contactId
+ * Replace contact greetings in merged contacts.
+ *
+ * @param int $contactID
*
* @return array
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
- public function replaceMergeTokens($contactId) {
- $greetings = [];
- $contact = NULL;
-
- $greetingFields = [
- 'postal_greeting' => $this->getPostalGreetingTemplate(),
- 'addressee' => $this->getAddresseeGreetingTemplate(),
+ public function replaceMergeTokens(int $contactID): array {
+ $messageTemplate = [
+ 'postal_greeting' => $this->getPostalGreetingTemplate() ?? '',
+ 'addressee' => $this->getAddresseeGreetingTemplate() ?? '',
];
- foreach ($greetingFields as $greeting => $greetingLabel) {
- $tokens = CRM_Utils_Token::getTokens($greetingLabel);
- if (!empty($tokens)) {
- if (empty($contact)) {
- $values = [
- 'id' => $contactId,
- 'version' => 3,
- ];
- $contact = civicrm_api('contact', 'get', $values);
-
- if (!empty($contact['is_error'])) {
- return $greetings;
- }
- $contact = $contact['values'][$contact['id']];
- }
-
- $tokens = ['contact' => $greetingLabel];
- $greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
- }
+ if (array_filter($messageTemplate)) {
+ return CRM_Core_TokenSmarty::render($messageTemplate, ['contactId' => $contactID]);
}
- return $greetings;
+ return $messageTemplate;
}
/**
*/
public function getPreview($limit) {
$rows = [];
- list($outputColumns) = $this->getExportStructureArrays();
+ [$outputColumns] = $this->getExportStructureArrays();
$query = $this->runQuery([], '');
CRM_Core_DAO::disableFullGroupByMode();
$result = CRM_Core_DAO::executeQuery($query[1] . ' LIMIT ' . (int) $limit);
*
* @return string
*/
- protected function getContactGreeting(int $contactID, string $type, string $default) {
- return CRM_Utils_Array::value($type,
- $this->contactGreetingFields[$contactID], $default
- );
+ protected function getContactGreeting(int $contactID, string $type, string $default): string {
+ return empty($this->contactGreetingFields[$contactID][$type]) ? $default : $this->contactGreetingFields[$contactID][$type];
}
/**