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 \Civi\Token\AbstractTokenSubscriber
{
30 public function __construct() {
31 parent
::__construct('membership', array_merge(
33 'fee' => ts('Membership Fee'),
34 'id' => ts('Membership ID'),
35 'join_date' => ts('Membership Join Date'),
36 'start_date' => ts('Membership Start Date'),
37 'end_date' => ts('Membership End Date'),
38 'status' => ts('Membership Status'),
39 'type' => ts('Membership Type'),
41 CRM_Utils_Token
::getCustomFieldTokens('Membership')
48 public function checkActive(\Civi\Token\TokenProcessor
$processor) {
49 // Extracted from scheduled-reminders code. See the class description.
50 return !empty($processor->context
['actionMapping'])
51 && $processor->context
['actionMapping']->getEntity() === 'civicrm_membership';
55 * Alter action schedule query.
57 * @param \Civi\ActionSchedule\Event\MailingQueryEvent $e
59 public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent
$e) {
60 if ($e->mapping
->getEntity() !== 'civicrm_membership') {
64 // FIXME: `select('e.*')` seems too broad.
67 ->select('mt.minimum_fee as fee, e.id as id , e.join_date, e.start_date, e.end_date, ms.name as status, mt.name as type')
68 ->join('mt', "!casMailingJoinType civicrm_membership_type mt ON e.membership_type_id = mt.id")
69 ->join('ms', "!casMailingJoinType civicrm_membership_status ms ON e.status_id = ms.id");
75 public function evaluateToken(\Civi\Token\TokenRow
$row, $entity, $field, $prefetch = NULL) {
76 $actionSearchResult = $row->context
['actionSearchResult'];
78 if (in_array($field, ['start_date', 'end_date', 'join_date'])) {
79 $row->tokens($entity, $field, \CRM_Utils_Date
::customFormat($actionSearchResult->$field));
81 elseif ($field == 'fee') {
82 $row->tokens($entity, $field, \CRM_Utils_Money
::format($actionSearchResult->$field, NULL, NULL, TRUE));
84 elseif (isset($actionSearchResult->$field)) {
85 $row->tokens($entity, $field, $actionSearchResult->$field);
87 elseif ($cfID = \CRM_Core_BAO_CustomField
::getKeyID($field)) {
88 $row->customToken($entity, $cfID, $actionSearchResult->entity_id
);
91 $row->tokens($entity, $field, '');