resources
4 years ago
Assets.php
4 years ago
ServiceProvider.php
4 years ago
SummaryView.php
4 years ago
SummaryView.php
142 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationSummary; |
| 4 | |
| 5 | use Give\Helpers\Form\Template; |
| 6 | |
| 7 | /** |
| 8 | * @since 2.17.0 |
| 9 | */ |
| 10 | class SummaryView |
| 11 | { |
| 12 | |
| 13 | /** |
| 14 | * @since 2.17.0 |
| 15 | * @var int |
| 16 | */ |
| 17 | protected $formID; |
| 18 | |
| 19 | /** |
| 20 | * @since 2.18.0 |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $template; |
| 24 | |
| 25 | /** |
| 26 | * @since 2.17.0 |
| 27 | * @var array |
| 28 | */ |
| 29 | protected $templateOptions; |
| 30 | |
| 31 | /** |
| 32 | * @since 2.17.0 |
| 33 | * |
| 34 | * @param int $formID |
| 35 | */ |
| 36 | public function __invoke($formID) |
| 37 | { |
| 38 | $this->formID = $formID; |
| 39 | $this->template = Template::getActiveID($formID); |
| 40 | $this->templateOptions = Template::getOptions($formID); |
| 41 | |
| 42 | /** |
| 43 | * @hook give_donation_form_user_info |
| 44 | * @hook give_donation_form_before_submit |
| 45 | */ |
| 46 | add_action($this->getFormTemplateLocation(), [$this, 'maybeRender']); |
| 47 | } |
| 48 | |
| 49 | public function maybeRender() |
| 50 | { |
| 51 | if ($this->isDonationSummaryEnabled()) { |
| 52 | if (in_array(Template::getActiveID($this->formID), [ 'sequoia', 'classic'])) { |
| 53 | $this->render(); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @since 2.17.0 |
| 60 | */ |
| 61 | public function render() |
| 62 | { |
| 63 | do_action( 'give_donation_summary_top' ); |
| 64 | include 'resources/views/summary.php'; |
| 65 | do_action( 'give_donation_summary_bottom' ); |
| 66 | } |
| 67 | |
| 68 | public function getPrimaryColor() |
| 69 | { |
| 70 | return $this->templateOptions['visual_appearance']['primary_color']; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @since 2.17.0 |
| 75 | * @return string |
| 76 | */ |
| 77 | public function getFormTemplateLocation() |
| 78 | { |
| 79 | if (isset($this->templateOptions['payment_information']) && isset($this->templateOptions['payment_information']['donation_summary_location'])) { |
| 80 | return $this->templateOptions['payment_information']['donation_summary_location']; |
| 81 | } |
| 82 | |
| 83 | return 'give_donation_form_before_submit'; // Default location. |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @since 2.17.0 |
| 88 | * @return string |
| 89 | */ |
| 90 | public function getSummaryHeading() |
| 91 | { |
| 92 | if (isset($this->templateOptions['payment_information']) && isset($this->templateOptions['payment_information']['donation_summary_heading'])) { |
| 93 | return $this->templateOptions['payment_information']['donation_summary_heading']; |
| 94 | } |
| 95 | |
| 96 | return ''; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @since 2.17.0 |
| 101 | * @return bool |
| 102 | */ |
| 103 | public function isDonationSummaryEnabled() |
| 104 | { |
| 105 | return isset($this->templateOptions['payment_information']) |
| 106 | && isset($this->templateOptions['payment_information']['donation_summary_enabled']) |
| 107 | && give_is_setting_enabled($this->templateOptions['payment_information']['donation_summary_enabled']); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @since 2.17.0 |
| 112 | * @return bool |
| 113 | */ |
| 114 | protected function isFeeRecoveryEnabled() |
| 115 | { |
| 116 | if (class_exists('\GiveFeeRecovery\Helpers\Form\Form')) { |
| 117 | return \GiveFeeRecovery\Helpers\Form\Form::canRecoverFee($this->formID); |
| 118 | } |
| 119 | |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @since 2.19.0 - remove check for Give_Recurring |
| 125 | * @return bool |
| 126 | * @since 2.17.0 |
| 127 | */ |
| 128 | protected function isRecurringEnabled() |
| 129 | { |
| 130 | return give_recurring_is_recurring($this->formID); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @since 2.18.0 |
| 135 | * @return bool |
| 136 | */ |
| 137 | protected function isMultiStep() |
| 138 | { |
| 139 | return $this->template === 'sequoia'; |
| 140 | } |
| 141 | } |
| 142 |