Merge pull request #18400 from aydun/class_api_tweak_2
[civicrm-core.git] / CRM / Friend / Form / Contribute.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for Tell A Friend
20 *
21 */
22 class CRM_Friend_Form_Contribute extends CRM_Contribute_Form_ContributionPage {
23
24 /**
25 * Tell a friend id in db.
26 *
27 * @var int
28 */
29 public $_friendId;
30
31 public function preProcess() {
32 parent::preProcess();
33 $this->setSelectedChild('friend');
34 }
35
36 /**
37 * Set default values for the form. Note that in edit/view mode
38 * the default values are retrieved from the database
39 *
40 *
41 * @return void
42 */
43 public function setDefaultValues() {
44 $defaults = [];
45
46 if (isset($this->_id)) {
47 $defaults['entity_table'] = 'civicrm_contribution_page';
48 $defaults['entity_id'] = $this->_id;
49 CRM_Friend_BAO_Friend::getValues($defaults);
50 $this->_friendId = $defaults['id'] ?? NULL;
51 $defaults['tf_title'] = $defaults['title'] ?? NULL;
52 $defaults['tf_is_active'] = $defaults['is_active'] ?? NULL;
53 $defaults['tf_thankyou_title'] = $defaults['thankyou_title'] ?? NULL;
54 $defaults['tf_thankyou_text'] = $defaults['thankyou_text'] ?? NULL;
55 }
56
57 if (!$this->_friendId) {
58 $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\'.');
59 $defaults['suggested_message'] = ts('Thought you might be interested in learning about and helping this organization. I think they do important work.');
60 $defaults['tf_thankyou_text'] = ts('Thanks for telling your friends about us and supporting our efforts. Together we can make a difference.');
61 $defaults['tf_title'] = ts('Tell a Friend');
62 $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word');
63 }
64
65 return $defaults;
66 }
67
68 /**
69 * Build the form object.
70 *
71 * @return void
72 */
73 public function buildQuickForm() {
74 if (isset($this->_id)) {
75 $defaults['entity_table'] = 'civicrm_contribution_page';
76 $defaults['entity_id'] = $this->_id;
77 CRM_Friend_BAO_Friend::getValues($defaults);
78 $this->_friendId = $defaults['id'] ?? NULL;
79 }
80
81 CRM_Friend_BAO_Friend::buildFriendForm($this);
82 parent::buildQuickForm();
83 }
84
85 /**
86 * Process the form submission.
87 *
88 *
89 * @return void
90 */
91 public function postProcess() {
92 // get the submitted form values.
93 $formValues = $this->controller->exportValues($this->_name);
94
95 $formValues['entity_table'] = 'civicrm_contribution_page';
96 $formValues['entity_id'] = $this->_id;
97 $formValues['title'] = $formValues['tf_title'];
98 $formValues['is_active'] = CRM_Utils_Array::value('tf_is_active', $formValues, FALSE);
99 $formValues['thankyou_title'] = $formValues['tf_thankyou_title'] ?? NULL;
100 $formValues['thankyou_text'] = $formValues['tf_thankyou_text'] ?? NULL;
101
102 if (($this->_action & CRM_Core_Action::UPDATE) && $this->_friendId) {
103 $formValues['id'] = $this->_friendId;
104 }
105
106 CRM_Friend_BAO_Friend::addTellAFriend($formValues);
107 parent::endPostProcess();
108 }
109
110 /**
111 * Return a descriptive name for the page, used in wizard header
112 *
113 * @return string
114 */
115 public function getTitle() {
116 return ts('Tell a Friend');
117 }
118
119 }