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 +--------------------------------------------------------------------+
14 * Class CRM_Member_Tokens
16 * Generate "member.*" tokens.
18 * This TokenSubscriber was produced by refactoring the code from the
19 * scheduled-reminder system with the goal of making that system
20 * more flexible. The current implementation is still coupled to
21 * scheduled-reminders. It would be good to figure out a more generic
22 * implementation which is not tied to scheduled reminders, although
23 * that is outside the current scope.
25 class CRM_Member_Tokens
extends CRM_Core_EntityTokens
{
28 * Get the entity name for api v4 calls.
32 protected function getApiEntityName(): string {
39 * This function will be removed once the parent class can determine it.
41 public function getAllTokens(): array {
44 'fee' => ts('Membership Fee'),
45 'id' => ts('Membership ID'),
46 'join_date' => ts('Membership Join Date'),
47 'start_date' => ts('Membership Start Date'),
48 'end_date' => ts('Membership End Date'),
49 'status_id:label' => ts('Membership Status'),
50 'membership_type_id:label' => ts('Membership Type'),
52 CRM_Utils_Token
::getCustomFieldTokens('Membership')
59 public function checkActive(\Civi\Token\TokenProcessor
$processor) {
60 // Extracted from scheduled-reminders code. See the class description.
61 return !empty($processor->context
['actionMapping'])
62 && $processor->context
['actionMapping']->getEntity() === 'civicrm_membership';
66 * Alter action schedule query.
68 * @param \Civi\ActionSchedule\Event\MailingQueryEvent $e
70 public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent
$e): void
{
71 if ($e->mapping
->getEntity() !== 'civicrm_membership') {
74 parent
::alterActionScheduleQuery($e);
76 ->select('mt.minimum_fee as ' . $this->getEntityAlias() . 'fee')
77 ->join('mt', '!casMailingJoinType civicrm_membership_type mt ON e.membership_type_id = mt.id');
83 public function evaluateToken(\Civi\Token\TokenRow
$row, $entity, $field, $prefetch = NULL) {
84 if ($field === 'fee') {
85 $row->tokens($entity, $field, \CRM_Utils_Money
::formatLocaleNumericRoundedForDefaultCurrency($this->getFieldValue($row, $field)));
88 parent
::evaluateToken($row, $entity, $field, $prefetch);