Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Tell A Friend | |
38 | * | |
39 | */ | |
40 | class CRM_Friend_Form_Event extends CRM_Event_Form_ManageEvent { | |
41 | ||
42 | /** | |
fe482240 | 43 | * Tell a friend id in db. |
6a488035 TO |
44 | * |
45 | * @var int | |
46 | */ | |
00f9643d | 47 | public $_friendId; |
6a488035 TO |
48 | |
49 | public function preProcess() { | |
50 | parent::preProcess(); | |
e4b857f8 | 51 | $this->setSelectedChild('friend'); |
6a488035 TO |
52 | } |
53 | ||
54 | /** | |
c490a46a | 55 | * Set default values for the form. |
6a488035 | 56 | * |
6a488035 | 57 | * |
355ba699 | 58 | * @return void |
6a488035 TO |
59 | */ |
60 | public function setDefaultValues() { | |
be2fb01f | 61 | $defaults = []; |
6a488035 TO |
62 | |
63 | if (isset($this->_id)) { | |
64 | $defaults['entity_table'] = 'civicrm_event'; | |
65 | $defaults['entity_id'] = $this->_id; | |
66 | CRM_Friend_BAO_Friend::getValues($defaults); | |
a7488080 | 67 | if (!empty($defaults['id'])) { |
f6060879 DL |
68 | $defaults['tf_id'] = CRM_Utils_Array::value('id', $defaults); |
69 | $this->_friendId = $defaults['tf_id']; | |
fd937866 | 70 | // lets unset the 'id' since it conflicts with eventID (or contribID) |
f6060879 DL |
71 | // CRM-12667 |
72 | unset($defaults['id']); | |
73 | } | |
6a488035 TO |
74 | $defaults['tf_title'] = CRM_Utils_Array::value('title', $defaults); |
75 | $defaults['tf_is_active'] = CRM_Utils_Array::value('is_active', $defaults); | |
76 | $defaults['tf_thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults); | |
77 | $defaults['tf_thankyou_text'] = CRM_Utils_Array::value('thankyou_text', $defaults); | |
78 | } | |
79 | ||
80 | if (!$this->_friendId) { | |
81 | $defaults['intro'] = ts('Help us spread the word about this event. Use the space below to personalize your email message - let your friends know why you\'re attending. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.'); | |
82 | $defaults['suggested_message'] = ts('Thought you might be interested in checking out this event. I\'m planning on attending.'); | |
83 | $defaults['tf_thankyou_text'] = ts('Thanks for spreading the word about this event to your friends.'); | |
84 | $defaults['tf_title'] = ts('Tell a Friend'); | |
85 | $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word'); | |
86 | } | |
87 | ||
88 | return $defaults; | |
89 | } | |
90 | ||
91 | /** | |
fe482240 | 92 | * Build the form object. |
6a488035 | 93 | * |
355ba699 | 94 | * @return void |
6a488035 TO |
95 | */ |
96 | public function buildQuickForm() { | |
00f9643d ML |
97 | if (isset($this->_id)) { |
98 | $defaults['entity_table'] = 'civicrm_event'; | |
99 | $defaults['entity_id'] = $this->_id; | |
100 | CRM_Friend_BAO_Friend::getValues($defaults); | |
101 | $this->_friendId = CRM_Utils_Array::value('id', $defaults); | |
102 | } | |
103 | ||
6a488035 TO |
104 | CRM_Friend_BAO_Friend::buildFriendForm($this); |
105 | parent::buildQuickForm(); | |
106 | } | |
107 | ||
108 | /** | |
fe482240 | 109 | * Process the form submission. |
6a488035 | 110 | * |
6a488035 | 111 | * |
355ba699 | 112 | * @return void |
6a488035 TO |
113 | */ |
114 | public function postProcess() { | |
115 | // get the submitted form values. | |
116 | $formValues = $this->controller->exportValues($this->_name); | |
117 | ||
118 | // let's unset event id | |
119 | unset($formValues['id']); | |
120 | ||
121 | $formValues['entity_table'] = 'civicrm_event'; | |
122 | $formValues['entity_id'] = $this->_id; | |
123 | $formValues['title'] = $formValues['tf_title']; | |
124 | $formValues['is_active'] = CRM_Utils_Array::value('tf_is_active', $formValues, FALSE); | |
125 | $formValues['thankyou_title'] = CRM_Utils_Array::value('tf_thankyou_title', $formValues); | |
126 | $formValues['thankyou_text'] = CRM_Utils_Array::value('tf_thankyou_text', $formValues); | |
127 | ||
128 | if (($this->_action & CRM_Core_Action::UPDATE) && $this->_friendId) { | |
129 | $formValues['id'] = $this->_friendId; | |
130 | } | |
131 | ||
132 | CRM_Friend_BAO_Friend::addTellAFriend($formValues); | |
133 | ||
5d92a7e7 CW |
134 | // Update tab "disabled" css class |
135 | $this->ajaxResponse['tabValid'] = !empty($formValues['tf_is_active']); | |
136 | ||
6a488035 TO |
137 | parent::endPostProcess(); |
138 | } | |
139 | ||
140 | /** | |
141 | * Return a descriptive name for the page, used in wizard header | |
142 | * | |
143 | * @return string | |
6a488035 TO |
144 | */ |
145 | public function getTitle() { | |
146 | return ts('Tell a Friend'); | |
147 | } | |
96025800 | 148 | |
6a488035 | 149 | } |