Commit | Line | Data |
---|---|---|
66c8a610 EM |
1 | <?php |
2 | ||
3 | /** | |
4 | * @method array getContribution() | |
2a402daa TO |
5 | * @method ?int getContributionID() |
6 | * @method $this setContributionID(?int $contributionId) | |
66c8a610 EM |
7 | */ |
8 | trait CRM_Contribute_WorkflowMessage_ContributionTrait { | |
9 | /** | |
10 | * The contribution. | |
11 | * | |
12 | * @var array|null | |
13 | * | |
14 | * @scope tokenContext as contribution | |
15 | */ | |
16 | public $contribution; | |
17 | ||
18 | /** | |
19 | * @var int | |
20 | * @scope tokenContext as contribution_id | |
21 | */ | |
22 | public $contributionId; | |
23 | ||
6b892bd2 EM |
24 | /** |
25 | * Is the site configured such that tax should be displayed. | |
26 | * | |
27 | * @var bool | |
28 | */ | |
29 | public $isShowTax; | |
30 | ||
132e4dea EM |
31 | /** |
32 | * @var CRM_Financial_BAO_Order | |
33 | */ | |
34 | private $order; | |
35 | ||
36 | /** | |
37 | * Get order, if available. | |
38 | * | |
39 | * The order is used within the class to calculate line items etc. | |
40 | * | |
41 | * @return \CRM_Financial_BAO_Order|null | |
42 | */ | |
43 | private function getOrder(): ?CRM_Financial_BAO_Order { | |
44 | if ($this->contributionId) { | |
45 | $this->order = new CRM_Financial_BAO_Order(); | |
46 | $this->order->setTemplateContributionID($this->contributionId); | |
47 | } | |
48 | return $this->order; | |
49 | } | |
50 | ||
51 | /** | |
52 | * Should line items be displayed for the contribution. | |
53 | * | |
54 | * This determination is based on whether the price set is quick config. | |
55 | * | |
56 | * @var bool | |
57 | * | |
58 | * @scope tplParams | |
59 | */ | |
60 | public $isShowLineItems; | |
61 | ||
62 | /** | |
63 | * Get bool for whether a line item breakdown be displayed. | |
64 | * | |
65 | * @return bool | |
66 | */ | |
67 | public function getIsShowLineItems(): bool { | |
68 | $order = $this->getOrder(); | |
69 | if (!$order) { | |
70 | // This would only be the case transitionally. | |
71 | // Since this is a trait it is used by templates which don't (yet) | |
72 | // always have the contribution ID available as well as migrated ones. | |
73 | return FALSE; | |
74 | } | |
75 | return $this->order->getPriceSetMetadata()['is_quick_config']; | |
76 | } | |
77 | ||
66c8a610 EM |
78 | /** |
79 | * Set contribution object. | |
80 | * | |
81 | * @param array $contribution | |
82 | * | |
83 | * @return $this | |
84 | */ | |
85 | public function setContribution(array $contribution): self { | |
86 | $this->contribution = $contribution; | |
87 | if (!empty($contribution['id'])) { | |
88 | $this->contributionId = $contribution['id']; | |
89 | } | |
90 | return $this; | |
91 | } | |
92 | ||
6b892bd2 EM |
93 | /** |
94 | * Extra variables to be exported to smarty based on being calculated. | |
95 | * | |
96 | * We export isShowTax to denote whether invoicing is enabled but | |
97 | * hopefully at some point we will separate the assumption that invoicing | |
98 | * and tax are a package. | |
99 | * | |
100 | * @param array $export | |
101 | */ | |
102 | protected function exportExtraTplParams(array &$export): void { | |
103 | $export['isShowTax'] = (bool) Civi::settings()->get('invoicing'); | |
104 | } | |
105 | ||
66c8a610 | 106 | } |