| 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 4.14.0 load frontend assets |
| 60 |
* @since 2.17.0 |
| 61 |
*/ |
| 62 |
public function render() |
| 63 |
{ |
| 64 |
give(Assets::class)->loadFrontendAssets(); |
| 65 |
|
| 66 |
do_action( 'give_donation_summary_top' ); |
| 67 |
include 'resources/views/summary.php'; |
| 68 |
do_action( 'give_donation_summary_bottom' ); |
| 69 |
} |
| 70 |
|
| 71 |
public function getPrimaryColor() |
| 72 |
{ |
| 73 |
return $this->templateOptions['visual_appearance']['primary_color']; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* @since 2.17.0 |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
public function getFormTemplateLocation() |
| 81 |
{ |
| 82 |
if (isset($this->templateOptions['payment_information']) && isset($this->templateOptions['payment_information']['donation_summary_location'])) { |
| 83 |
return $this->templateOptions['payment_information']['donation_summary_location']; |
| 84 |
} |
| 85 |
|
| 86 |
return 'give_donation_form_before_submit'; // Default location. |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* @since 2.17.0 |
| 91 |
* @return string |
| 92 |
*/ |
| 93 |
public function getSummaryHeading() |
| 94 |
{ |
| 95 |
if (isset($this->templateOptions['payment_information']) && isset($this->templateOptions['payment_information']['donation_summary_heading'])) { |
| 96 |
return $this->templateOptions['payment_information']['donation_summary_heading']; |
| 97 |
} |
| 98 |
|
| 99 |
return ''; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* @since 2.17.0 |
| 104 |
* @return bool |
| 105 |
*/ |
| 106 |
public function isDonationSummaryEnabled() |
| 107 |
{ |
| 108 |
return isset($this->templateOptions['payment_information']) |
| 109 |
&& isset($this->templateOptions['payment_information']['donation_summary_enabled']) |
| 110 |
&& give_is_setting_enabled($this->templateOptions['payment_information']['donation_summary_enabled']); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* @since 2.17.0 |
| 115 |
* @return bool |
| 116 |
*/ |
| 117 |
protected function isFeeRecoveryEnabled() |
| 118 |
{ |
| 119 |
if (class_exists('\GiveFeeRecovery\Helpers\Form\Form')) { |
| 120 |
return \GiveFeeRecovery\Helpers\Form\Form::canRecoverFee($this->formID); |
| 121 |
} |
| 122 |
|
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* @since 2.19.0 - remove check for Give_Recurring |
| 128 |
* @return bool |
| 129 |
* @since 2.17.0 |
| 130 |
*/ |
| 131 |
protected function isRecurringEnabled() |
| 132 |
{ |
| 133 |
return give_recurring_is_recurring($this->formID); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* @since 2.18.0 |
| 138 |
* @return bool |
| 139 |
*/ |
| 140 |
protected function isMultiStep() |
| 141 |
{ |
| 142 |
return $this->template === 'sequoia'; |
| 143 |
} |
| 144 |
} |
| 145 |
|