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
{
22 public static function getSubscribedEvents() {
23 $events = parent
::getSubscribedEvents();
24 // Set the weight so it runs before event tokens.
25 $events['civi.token.eval'] = ['evaluateTokens', 400];
30 * Get the entity name for api v4 calls.
34 protected function getApiEntityName(): string {
41 public function getCurrencyFieldName(): array {
42 return ['fee_currency'];
46 * Get any tokens with custom calculation.
48 public function getBespokeTokens(): array {
49 return ['balance' => ts('Event Balance')];
54 * @throws \CiviCRM_API3_Exception
56 public function evaluateToken(TokenRow
$row, $entity, $field, $prefetch = NULL) {
57 $this->prefetch
= (array) $prefetch;
58 if (empty($row->context
['eventId'])) {
59 $row->context
['eventId'] = $this->getFieldValue($row, 'event_id');
61 if ($field === 'balance') {
62 // @todo - is this really a good idea to call this & potentially get the
63 // balance of the contribution attached to 'registered_by_id'
64 $info = \CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->getFieldValue($row, 'id'), 'event');
65 $balancePay = $info['balance'] ??
NULL;
66 $balancePay = \CRM_Utils_Money
::format($balancePay);
67 $row->tokens($entity, $field, $balancePay);
70 parent
::evaluateToken($row, $entity, $field, $prefetch);
74 * Do not show event id in the UI as event.id will also be available.
76 * Discount id is probably a bit esoteric.
80 protected function getHiddenTokens(): array {
81 return ['event_id', 'discount_id'];
85 * Get entity fields that should not be exposed as tokens.
89 public function getSkippedFields(): array {
90 $fields = parent
::getSkippedFields();
91 // Never add these 2 fields - may not be a stable part of the schema.
92 // This field is on it's way out of core.
93 $fields[] = 'cart_id';
94 // this will probably get schema changed out of the table at some point.
95 $fields[] = 'is_pay_later';