4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
13 use Civi\Token\TokenRow
;
16 * Class CRM_Event_ParticipantTokens
18 * Generate "participant.*" tokens.
20 class CRM_Event_ParticipantTokens
extends CRM_Core_EntityTokens
{
23 * Get the entity name for api v4 calls.
27 protected function getApiEntityName(): string {
34 public function getCurrencyFieldName(): array {
35 return ['fee_currency'];
39 * Get any tokens with custom calculation.
41 protected function getBespokeTokens(): array {
44 'title' => ts('Event Balance'),
46 'type' => 'calculated',
48 'data_type' => 'Money',
54 public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent
$e): void
{
55 // When targeting `civicrm_participant` records, we enable both `{participant.*}` (per usual) and the related `{event.*}`.
56 parent
::alterActionScheduleQuery($e);
57 if ($e->mapping
->getEntity() === $this->getExtendableTableName()) {
58 $e->query
->select('e.event_id AS tokenContext_eventId');
64 * @throws \CiviCRM_API3_Exception
66 public function evaluateToken(TokenRow
$row, $entity, $field, $prefetch = NULL) {
67 $this->prefetch
= (array) $prefetch;
68 if ($field === 'balance') {
69 // @todo - is this really a good idea to call this & potentially get the
70 // balance of the contribution attached to 'registered_by_id'
71 $info = \CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->getFieldValue($row, 'id'), 'event');
72 $balancePay = $info['balance'] ??
NULL;
73 $balancePay = \CRM_Utils_Money
::format($balancePay);
74 $row->tokens($entity, $field, $balancePay);
77 parent
::evaluateToken($row, $entity, $field, $prefetch);
81 * Do not show event id in the UI as event.id will also be available.
83 * Discount id is probably a bit esoteric.
87 protected function getHiddenTokens(): array {
88 return ['event_id', 'discount_id'];
92 * Get entity fields that should not be exposed as tokens.
96 protected function getSkippedFields(): array {
97 $fields = parent
::getSkippedFields();
98 // Never add these 2 fields - may not be a stable part of the schema.
99 // This field is on it's way out of core.
100 $fields[] = 'cart_id';
101 // this will probably get schema changed out of the table at some point.
102 $fields[] = 'is_pay_later';