Commit | Line | Data |
---|---|---|
2045389a TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
2045389a | 6 | | | |
bc77d7c0 TO |
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 | | |
2045389a TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * Class CRM_Contribute_Tokens | |
15 | * | |
16 | * Generate "contribution.*" tokens. | |
17 | * | |
18 | * At time of writing, we don't have any particularly special tokens -- we just | |
19 | * do some basic formatting based on the corresponding DB field. | |
20 | */ | |
17b6f179 | 21 | class CRM_Contribute_Tokens extends CRM_Core_EntityTokens { |
2045389a | 22 | |
9b3cb77d EM |
23 | /** |
24 | * @return string | |
25 | */ | |
e4f3e4ce | 26 | protected function getEntityName(): string { |
9b3cb77d EM |
27 | return 'contribution'; |
28 | } | |
29 | ||
30 | /** | |
29f2b53e EM |
31 | * @return string |
32 | */ | |
33 | protected function getEntityAlias(): string { | |
34 | return 'contrib_'; | |
35 | } | |
36 | ||
37 | /** | |
38 | * Get the entity name for api v4 calls. | |
39 | * | |
40 | * In practice this IS just ucfirst($this->GetEntityName) | |
41 | * but declaring it seems more legible. | |
42 | * | |
43 | * @return string | |
9b3cb77d | 44 | */ |
29f2b53e EM |
45 | protected function getApiEntityName(): string { |
46 | return 'Contribution'; | |
9b3cb77d EM |
47 | } |
48 | ||
2045389a | 49 | /** |
4a526c1b EM |
50 | * Get a list of tokens for the entity for which access is permitted to. |
51 | * | |
52 | * This list is historical and we need to question whether we | |
53 | * should filter out any fields (other than those fields, like api_key | |
54 | * on the contact entity) with permissions defined. | |
55 | * | |
2045389a TO |
56 | * @return array |
57 | */ | |
4a526c1b | 58 | protected function getExposedFields(): array { |
b5e0905c | 59 | $fields = [ |
2045389a | 60 | 'contribution_page_id', |
e4f3e4ce EM |
61 | 'source', |
62 | 'id', | |
2045389a TO |
63 | 'receive_date', |
64 | 'total_amount', | |
65 | 'fee_amount', | |
66 | 'net_amount', | |
17b6f179 | 67 | 'non_deductible_amount', |
2045389a TO |
68 | 'trxn_id', |
69 | 'invoice_id', | |
70 | 'currency', | |
e4f3e4ce | 71 | 'cancel_date', |
2045389a TO |
72 | 'receipt_date', |
73 | 'thankyou_date', | |
74 | 'tax_amount', | |
cb31dd27 | 75 | 'contribution_status_id', |
7ddd4af7 EM |
76 | 'financial_type_id', |
77 | 'payment_instrument_id', | |
b5e0905c EM |
78 | 'cancel_reason', |
79 | 'amount_level', | |
80 | 'check_number', | |
be2fb01f | 81 | ]; |
b5e0905c EM |
82 | if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { |
83 | $fields[] = 'campaign_id'; | |
84 | } | |
85 | return $fields; | |
2045389a TO |
86 | } |
87 | ||
cb31dd27 EM |
88 | /** |
89 | * Get tokens supporting the syntax we are migrating to. | |
90 | * | |
91 | * In general these are tokens that were not previously supported | |
92 | * so we can add them in the preferred way or that we have | |
93 | * undertaken some, as yet to be written, db update. | |
94 | * | |
95 | * See https://lab.civicrm.org/dev/core/-/issues/2650 | |
96 | * | |
97 | * @return string[] | |
98 | */ | |
7ddd4af7 EM |
99 | public function getBasicTokens(): array { |
100 | $return = []; | |
4a526c1b | 101 | foreach ($this->getExposedFields() as $fieldName) { |
7ddd4af7 EM |
102 | $return[$fieldName] = $this->getFieldMetadata()[$fieldName]['title']; |
103 | } | |
104 | return $return; | |
cb31dd27 EM |
105 | } |
106 | ||
2045389a | 107 | } |