* automatically from contactId.)
* - actionSchedule: DAO, the rule which triggered the mailing
* [for CRM_Core_BAO_ActionScheduler].
+ * - schema: array, a list of fields that will be provided for each row.
+ * This is automatically populated with any general context
+ * keys, but you may need to add extra keys for token-row data.
+ * ex: ['contactId', 'activityId'].
*/
public $context;
*/
protected $tokens = NULL;
+ /**
+ * A list of available tokens formatted for display
+ * @var array
+ * Array('{' . $dottedName . '}' => 'labelString')
+ */
+ protected $listTokens = NULL;
+
protected $next = 0;
/**
* @param array $context
*/
public function __construct($dispatcher, $context) {
+ $context['schema'] = isset($context['schema'])
+ ? array_unique(array_merge($context['schema'], array_keys($context)))
+ : array_keys($context);
$this->dispatcher = $dispatcher;
$this->context = $context;
}
return new TokenRowIterator($this, new \ArrayIterator($this->rowContexts));
}
+ /**
+ * Get a list of all unique values for a given context field,
+ * whether defined at the processor or row level.
+ *
+ * @param string $field
+ * Ex: 'contactId'.
+ * @return array
+ * Ex: [12, 34, 56].
+ */
+ public function getContextValues($field, $subfield = NULL) {
+ $values = [];
+ if (isset($this->context[$field])) {
+ if ($subfield) {
+ if (isset($this->context[$field]->$subfield)) {
+ $values[] = $this->context[$field]->$subfield;
+ }
+ }
+ else {
+ $values[] = $this->context[$field];
+ }
+ }
+ foreach ($this->getRows() as $row) {
+ if (isset($row->context[$field])) {
+ if ($subfield) {
+ if (isset($row->context[$field]->$subfield)) {
+ $values[] = $row->context[$field]->$subfield;
+ }
+ }
+ else {
+ $values[] = $row->context[$field];
+ }
+ }
+ }
+ $values = array_unique($values);
+ return $values;
+ }
+
/**
* Get the list of available tokens.
*
return $this->tokens;
}
+ /**
+ * Get the list of available tokens, formatted for display
+ *
+ * @return array
+ * Ex: $tokens[ '{token.name}' ] = "Token label"
+ */
+ public function listTokens() {
+ if ($this->listTokens === NULL) {
+ $this->listTokens = array();
+ foreach ($this->getTokens() as $token => $values) {
+ $this->listTokens['{' . $token . '}'] = $values['label'];
+ }
+ }
+ return $this->listTokens;
+ }
+
/**
* Compute and store token values.
*/