* CRM_Activity_Tokens constructor.
*/
public function __construct() {
- parent::__construct('activity', array(
- 'activity_id' => ts('Activity ID'),
- 'activity_type' => ts('Activity Type'),
- 'subject' => ts('Activity Subject'),
- 'details' => ts('Activity Details'),
- 'activity_date_time' => ts('Activity Date-Time'),
+ parent::__construct('activity', array_merge(
+ array(
+ 'activity_id' => ts('Activity ID'),
+ 'activity_type' => ts('Activity Type'),
+ 'subject' => ts('Activity Subject'),
+ 'details' => ts('Activity Details'),
+ 'activity_date_time' => ts('Activity Date-Time'),
+ ),
+ $this->getCustomTokens('Activity')
));
}
elseif (isset($actionSearchResult->$field)) {
$row->tokens($entity, $field, $actionSearchResult->$field);
}
+ elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
+ $row->customToken($entity, $field, $actionSearchResult->entity_id);
+ }
else {
$row->tokens($entity, $field, '');
}
$tokens['source'] = ts('Contribution Source');
$tokens['status'] = ts('Contribution Status');
$tokens['type'] = ts('Financial Type');
+ $tokens = array_merge($tokens, $this->getCustomTokens('Contribution'));
parent::__construct('contribution', $tokens);
}
elseif (isset($aliasTokens[$field])) {
$row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $aliasTokens[$field], $fieldValue);
}
+ elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
+ $row->customToken($entity, $field, $actionSearchResult->entity_id);
+ }
else {
$row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $field, $fieldValue);
}
* Class constructor.
*/
public function __construct() {
- parent::__construct('event', array(
- 'event_type' => ts('Event Type'),
- 'title' => ts('Event Title'),
- 'event_id' => ts('Event ID'),
- 'start_date' => ts('Event Start Date'),
- 'end_date' => ts('Event End Date'),
- 'summary' => ts('Event Summary'),
- 'description' => ts('Event Description'),
- 'location' => ts('Event Location'),
- 'info_url' => ts('Event Info URL'),
- 'registration_url' => ts('Event Registration URL'),
- 'fee_amount' => ts('Event Fee'),
- 'contact_email' => ts('Event Contact (Email)'),
- 'contact_phone' => ts('Event Contact (Phone)'),
- 'balance' => ts('Event Balance'),
+ parent::__construct('event', array_merge(
+ array(
+ 'event_type' => ts('Event Type'),
+ 'title' => ts('Event Title'),
+ 'event_id' => ts('Event ID'),
+ 'start_date' => ts('Event Start Date'),
+ 'end_date' => ts('Event End Date'),
+ 'summary' => ts('Event Summary'),
+ 'description' => ts('Event Description'),
+ 'location' => ts('Event Location'),
+ 'info_url' => ts('Event Info URL'),
+ 'registration_url' => ts('Event Registration URL'),
+ 'fee_amount' => ts('Event Fee'),
+ 'contact_email' => ts('Event Contact (Email)'),
+ 'contact_phone' => ts('Event Contact (Phone)'),
+ 'balance' => ts('Event Balance'),
+ ),
+ $this->getCustomTokens('Event')
));
}
elseif (isset($actionSearchResult->$field)) {
$row->tokens($entity, $field, $actionSearchResult->$field);
}
+ elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
+ $row->customToken($entity, $field, $actionSearchResult->entity_id);
+ }
else {
$row->tokens($entity, $field, '');
}
* Class constructor.
*/
public function __construct() {
- parent::__construct('membership', array(
- 'fee' => ts('Membership Fee'),
- 'id' => ts('Membership ID'),
- 'join_date' => ts('Membership Join Date'),
- 'start_date' => ts('Membership Start Date'),
- 'end_date' => ts('Membership End Date'),
- 'status' => ts('Membership Status'),
- 'type' => ts('Membership Type'),
+ parent::__construct('membership', array_merge(
+ array(
+ 'fee' => ts('Membership Fee'),
+ 'id' => ts('Membership ID'),
+ 'join_date' => ts('Membership Join Date'),
+ 'start_date' => ts('Membership Start Date'),
+ 'end_date' => ts('Membership End Date'),
+ 'status' => ts('Membership Status'),
+ 'type' => ts('Membership Type'),
+ ),
+ $this->getCustomTokens('Membership')
));
}
elseif (isset($actionSearchResult->$field)) {
$row->tokens($entity, $field, $actionSearchResult->$field);
}
+ elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
+ $row->customToken($entity, $field, $actionSearchResult->entity_id);
+ }
else {
$row->tokens($entity, $field, '');
}
}
}
+ /**
+ * Get all custom field tokens of $entity
+ *
+ * @param string $entity
+ * @return array $customTokens
+ * return custom field tokens in array('custom_N' => 'label') format
+ */
+ public function getCustomTokens($entity) {
+ $customTokens = array();
+ foreach (\CRM_Core_BAO_CustomField::getFields($entity) as $id => $info) {
+ $customTokens["custom_$id"] = $info['label'];
+ }
+
+ return $customTokens;
+ }
+
/**
* Alter the query which prepopulates mailing data
* for scheduled reminders.
}
$activeTokens = array_intersect($messageTokens[$this->entity], array_keys($this->tokenNames));
- $extraTokens = array_diff($messageTokens[$this->entity], array_keys($this->tokenNames));
$prefetch = $this->prefetch($e);
foreach ($e->getRows() as $row) {
- $this->evaluateExtraToken($row, $this->entity, $extraTokens);
foreach ((array) $activeTokens as $field) {
$this->evaluateToken($row, $this->entity, $field, $prefetch);
}
}
}
- /**
- * Populate the custom field and other remaining entity token data.
- *
- * @param TokenRow $row
- * The record for which we want token values.
- * @param string $entity
- * The entity for which we want the token values
- * @param array $tokens
- * The array of tokens whose data need to be fetched
- */
- public function evaluateExtraToken(TokenRow $row, $entity, $tokens) {
- if (empty($tokens)) {
- return;
- }
-
- $actionSearchResult = $row->context['actionSearchResult'];
-
- try {
- $result = civicrm_api3($entity, 'getsingle', array(
- 'id' => $actionSearchResult->entity_id,
- 'return' => $tokens,
- ));
- }
- catch (CiviCRM_API3_Exception $e) {
- return;
- }
-
- foreach ($tokens as $token) {
- $row->tokens($entity, $token, \CRM_Utils_Array::value($token, $result, ''));
- }
- }
-
/**
* To perform a bulk lookup before rendering tokens, override this
* function and return the prefetched data.
throw new TokenException("Failed to generate token data. Invalid contact ID: " . $row->context['contactId']);
}
- $contactTokens = \CRM_Utils_Array::value('contact', $messageTokens);
- if (!empty($contactTokens)) {
- try {
- $result = civicrm_api3('Contact', 'getsingle', array(
- 'id' => $contactId,
- 'return' => $contactTokens,
- ));
- $contact = array_merge($contact, $result);
- }
- catch (CiviCRM_API3_Exception $e) {
- //do nothing
+ //update value of custom field token
+ if (!empty($messageTokens['contact'])) {
+ foreach ($messageTokens['contact'] as $token) {
+ if (\CRM_Core_BAO_CustomField::getKeyID($token)) {
+ $row->customToken('Contact', $token, $contactId);
+ }
}
}
}
return $this;
}
+ /**
+ * Update the value of a custom field token.
+ *
+ * @param string $entity
+ * @param string $fieldName
+ * @param string $entityID
+ * @return TokenRow
+ */
+ public function customToken($entity, $fieldName, $entityID) {
+ $fieldValue = civicrm_api3($entity, 'getvalue', array(
+ 'return' => $fieldName,
+ 'id' => $entityID,
+ ));
+ return $this->tokens($entity, $fieldName, $fieldValue);
+ }
+
/**
* Update the value of a token. Apply formatting based on DB schema.
*