Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * form to process actions on Premiums | |
38 | */ | |
39 | class CRM_Contribute_Form_ContributionPage_Premium extends CRM_Contribute_Form_ContributionPage { | |
40 | ||
41 | /** | |
c490a46a | 42 | * Set default values for the form. Note that in edit/view mode |
6a488035 TO |
43 | * the default values are retrieved from the database |
44 | * | |
6a488035 TO |
45 | * |
46 | * @return void | |
47 | */ | |
00be9182 | 48 | public function setDefaultValues() { |
6a488035 TO |
49 | $defaults = array(); |
50 | if (isset($this->_id)) { | |
51 | $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); | |
251668d9 | 52 | CRM_Utils_System::setTitle(ts('Premiums') . " ($title)"); |
6a488035 TO |
53 | $dao = new CRM_Contribute_DAO_Premium(); |
54 | $dao->entity_table = 'civicrm_contribution_page'; | |
55 | $dao->entity_id = $this->_id; | |
56 | $dao->find(TRUE); | |
57 | CRM_Core_DAO::storeValues($dao, $defaults); | |
58 | } | |
59 | return $defaults; | |
60 | } | |
61 | ||
62 | /** | |
c490a46a | 63 | * Build the form object |
6a488035 TO |
64 | * |
65 | * @return void | |
6a488035 TO |
66 | */ |
67 | public function buildQuickForm() { | |
68 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Premium'); | |
2560550d | 69 | $this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL); |
6a488035 TO |
70 | |
71 | $this->addElement('text', 'premiums_intro_title', ts('Title'), $attributes['premiums_intro_title']); | |
72 | ||
73 | $this->add('textarea', 'premiums_intro_text', ts('Introductory Message'), 'rows=5, cols=50'); | |
74 | ||
75 | $this->add('text', 'premiums_contact_email', ts('Contact Email') . ' ', $attributes['premiums_contact_email']); | |
76 | ||
f289559e | 77 | $this->addRule('premiums_contact_email', ts('Please enter a valid email address.') . ' ', 'email'); |
6a488035 TO |
78 | |
79 | $this->add('text', 'premiums_contact_phone', ts('Contact Phone'), $attributes['premiums_contact_phone']); | |
80 | ||
81 | $this->addRule('premiums_contact_phone', ts('Please enter a valid phone number.'), 'phone'); | |
82 | ||
83 | $this->addElement('checkbox', 'premiums_display_min_contribution', ts('Display Minimum Contribution Amount?')); | |
84 | ||
85 | // CRM-10999 Control label and position for No Thank-you radio button | |
2560550d | 86 | $this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label']); |
6a488035 TO |
87 | $positions = array(1 => ts('Before Premiums'), 2 => ts('After Premiums')); |
88 | $this->add('select','premiums_nothankyou_position', ts('No Thank-you Option'), $positions); | |
89 | $showForm = TRUE; | |
90 | ||
91 | if ($this->_single) { | |
92 | if ($this->_id) { | |
93 | $daoPremium = new CRM_Contribute_DAO_Premium(); | |
94 | $daoPremium->entity_id = $this->_id; | |
95 | $daoPremium->entity_table = 'civicrm_contribution_page'; | |
96 | $daoPremium->premiums_active = 1; | |
97 | if ($daoPremium->find(TRUE)) { | |
98 | $showForm = FALSE; | |
99 | } | |
100 | } | |
101 | } | |
102 | $this->assign('showForm', $showForm); | |
103 | ||
104 | parent::buildQuickForm(); | |
2560550d | 105 | $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Premium', 'formRule'), $this); |
6a488035 TO |
106 | |
107 | $premiumPage = new CRM_Contribute_Page_Premium(); | |
108 | $premiumPage->browse(); | |
109 | } | |
110 | ||
2560550d | 111 | /** |
100fef9d | 112 | * Validation |
2560550d | 113 | * |
014c4014 TO |
114 | * @param array $params |
115 | * (ref.) an assoc array of name/value pairs. | |
2560550d AW |
116 | * |
117 | * @return mixed true or array of errors | |
2560550d AW |
118 | * @static |
119 | */ | |
120 | public static function formRule($params) { | |
121 | $errors = array(); | |
a7488080 CW |
122 | if (!empty($params['premiums_active'])) { |
123 | if (empty($params['premiums_nothankyou_label'])) { | |
2560550d AW |
124 | $errors['premiums_nothankyou_label'] = ts('No Thank-you Label is a required field.'); |
125 | } | |
126 | } | |
127 | return empty($errors) ? TRUE : $errors; | |
128 | } | |
129 | ||
6a488035 TO |
130 | /** |
131 | * Process the form | |
132 | * | |
133 | * @return void | |
6a488035 TO |
134 | */ |
135 | public function postProcess() { | |
136 | // get the submitted form values. | |
137 | $params = $this->controller->exportValues($this->_name); | |
138 | ||
139 | // we do this in case the user has hit the forward/back button | |
140 | ||
141 | $dao = new CRM_Contribute_DAO_Premium(); | |
142 | $dao->entity_table = 'civicrm_contribution_page'; | |
143 | $dao->entity_id = $this->_id; | |
144 | $dao->find(TRUE); | |
145 | $premiumID = $dao->id; | |
146 | if ($premiumID) { | |
147 | $params['id'] = $premiumID; | |
148 | } | |
149 | ||
150 | $params['premiums_active'] = CRM_Utils_Array::value('premiums_active', $params, FALSE); | |
151 | $params['premiums_display_min_contribution'] = CRM_Utils_Array::value('premiums_display_min_contribution', $params, FALSE); | |
152 | $params['entity_table'] = 'civicrm_contribution_page'; | |
153 | $params['entity_id'] = $this->_id; | |
154 | ||
155 | $dao = new CRM_Contribute_DAO_Premium(); | |
156 | $dao->copyValues($params); | |
157 | $dao->save(); | |
158 | parent::endPostProcess(); | |
159 | } | |
160 | ||
161 | /** | |
162 | * Return a descriptive name for the page, used in wizard header | |
163 | * | |
164 | * @return string | |
6a488035 TO |
165 | */ |
166 | public function getTitle() { | |
167 | return ts('Premiums'); | |
168 | } | |
169 | } |