Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class generates form components for Tell A Friend | |
22 | * | |
23 | */ | |
24 | class CRM_Friend_Form_Contribute extends CRM_Contribute_Form_ContributionPage { | |
25 | ||
26 | /** | |
fe482240 | 27 | * Tell a friend id in db. |
6a488035 TO |
28 | * |
29 | * @var int | |
30 | */ | |
00f9643d | 31 | public $_friendId; |
6a488035 TO |
32 | |
33 | public function preProcess() { | |
34 | parent::preProcess(); | |
7885e669 | 35 | $this->setSelectedChild('friend'); |
6a488035 TO |
36 | } |
37 | ||
38 | /** | |
c490a46a | 39 | * Set default values for the form. Note that in edit/view mode |
6a488035 TO |
40 | * the default values are retrieved from the database |
41 | * | |
6a488035 | 42 | * |
355ba699 | 43 | * @return void |
6a488035 TO |
44 | */ |
45 | public function setDefaultValues() { | |
be2fb01f | 46 | $defaults = []; |
6a488035 TO |
47 | |
48 | if (isset($this->_id)) { | |
49 | $defaults['entity_table'] = 'civicrm_contribution_page'; | |
50 | $defaults['entity_id'] = $this->_id; | |
51 | CRM_Friend_BAO_Friend::getValues($defaults); | |
9c1bc317 CW |
52 | $this->_friendId = $defaults['id'] ?? NULL; |
53 | $defaults['tf_title'] = $defaults['title'] ?? NULL; | |
54 | $defaults['tf_is_active'] = $defaults['is_active'] ?? NULL; | |
55 | $defaults['tf_thankyou_title'] = $defaults['thankyou_title'] ?? NULL; | |
56 | $defaults['tf_thankyou_text'] = $defaults['thankyou_text'] ?? NULL; | |
6a488035 TO |
57 | } |
58 | ||
59 | if (!$this->_friendId) { | |
60 | $defaults['intro'] = ts('Help us spread the word and leverage the power of your contribution by telling your friends. Use the space below to personalize your email message - let your friends know why you support us. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.'); | |
61 | $defaults['suggested_message'] = ts('Thought you might be interested in learning about and helping this organization. I think they do important work.'); | |
62 | $defaults['tf_thankyou_text'] = ts('Thanks for telling your friends about us and supporting our efforts. Together we can make a difference.'); | |
63 | $defaults['tf_title'] = ts('Tell a Friend'); | |
64 | $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word'); | |
65 | } | |
66 | ||
67 | return $defaults; | |
68 | } | |
69 | ||
70 | /** | |
fe482240 | 71 | * Build the form object. |
6a488035 | 72 | * |
355ba699 | 73 | * @return void |
6a488035 TO |
74 | */ |
75 | public function buildQuickForm() { | |
00f9643d ML |
76 | if (isset($this->_id)) { |
77 | $defaults['entity_table'] = 'civicrm_contribution_page'; | |
78 | $defaults['entity_id'] = $this->_id; | |
79 | CRM_Friend_BAO_Friend::getValues($defaults); | |
9c1bc317 | 80 | $this->_friendId = $defaults['id'] ?? NULL; |
00f9643d ML |
81 | } |
82 | ||
6a488035 TO |
83 | CRM_Friend_BAO_Friend::buildFriendForm($this); |
84 | parent::buildQuickForm(); | |
85 | } | |
86 | ||
87 | /** | |
fe482240 | 88 | * Process the form submission. |
6a488035 | 89 | * |
6a488035 | 90 | * |
355ba699 | 91 | * @return void |
6a488035 TO |
92 | */ |
93 | public function postProcess() { | |
94 | // get the submitted form values. | |
95 | $formValues = $this->controller->exportValues($this->_name); | |
96 | ||
97 | $formValues['entity_table'] = 'civicrm_contribution_page'; | |
98 | $formValues['entity_id'] = $this->_id; | |
99 | $formValues['title'] = $formValues['tf_title']; | |
100 | $formValues['is_active'] = CRM_Utils_Array::value('tf_is_active', $formValues, FALSE); | |
9c1bc317 CW |
101 | $formValues['thankyou_title'] = $formValues['tf_thankyou_title'] ?? NULL; |
102 | $formValues['thankyou_text'] = $formValues['tf_thankyou_text'] ?? NULL; | |
6a488035 TO |
103 | |
104 | if (($this->_action & CRM_Core_Action::UPDATE) && $this->_friendId) { | |
105 | $formValues['id'] = $this->_friendId; | |
106 | } | |
107 | ||
108 | CRM_Friend_BAO_Friend::addTellAFriend($formValues); | |
109 | parent::endPostProcess(); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Return a descriptive name for the page, used in wizard header | |
114 | * | |
115 | * @return string | |
6a488035 TO |
116 | */ |
117 | public function getTitle() { | |
118 | return ts('Tell a Friend'); | |
119 | } | |
96025800 | 120 | |
6a488035 | 121 | } |