Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * form to process actions on Membership | |
38 | */ | |
39 | class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPage { | |
40 | ||
41 | /** | |
100fef9d | 42 | * Store membership price set id |
6a488035 TO |
43 | */ |
44 | protected $_memPriceSetId = NULL; | |
45 | ||
46 | /** | |
c490a46a | 47 | * Set default values for the form. Note that in edit/view mode |
6a488035 TO |
48 | * the default values are retrieved from the database |
49 | * | |
6a488035 TO |
50 | * |
51 | * @return void | |
fd726496 | 52 | */ |
00be9182 | 53 | public function setDefaultValues() { |
6a488035 TO |
54 | //parent::setDefaultValues(); |
55 | $defaults = array(); | |
56 | if (isset($this->_id)) { | |
57 | $defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); | |
58 | } | |
59 | $defaults['member_is_active'] = $defaults['is_active']; | |
60 | ||
61 | // Set Display Minimum Fee default to true if we are adding a new membership block | |
62 | if (!isset($defaults['id'])) { | |
63 | $defaults['display_min_fee'] = 1; | |
64 | } | |
65 | else { | |
66 | $this->assign('membershipBlockId', $defaults['id']); | |
67 | } | |
68 | if ($this->_id && | |
9da8dc8c | 69 | ($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3, 1)) |
6a488035 TO |
70 | ) { |
71 | $defaults['member_price_set_id'] = $priceSetId; | |
72 | $this->_memPriceSetId = $priceSetId; | |
73 | } | |
74 | else { | |
75 | // for membership_types | |
76 | // if ( isset( $defaults['membership_types'] ) ) { | |
9da8dc8c | 77 | $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3); |
6a488035 TO |
78 | $this->assign('isQuick', 1); |
79 | $this->_memPriceSetId = $priceSetId; | |
80 | $pFIDs = array(); | |
81 | if ($priceSetId) { | |
353ffa53 TO |
82 | CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array( |
83 | 'html_type', | |
84 | 'name', | |
87a890cc | 85 | 'label', |
353ffa53 | 86 | )); |
6a488035 TO |
87 | foreach ($pFIDs as $pid => $pValue) { |
88 | if ($pValue['html_type'] == 'Radio' && $pValue['name'] == 'membership_amount') { | |
89 | $defaults['mem_price_field_id'] = $pValue['id']; | |
21f4797a | 90 | $defaults['membership_type_label'] = $pValue['label']; |
6a488035 TO |
91 | } |
92 | } | |
93 | ||
a7488080 | 94 | if (!empty($defaults['mem_price_field_id'])) { |
6a488035 | 95 | $options = array(); |
9da8dc8c | 96 | $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1); |
6a488035 TO |
97 | foreach ($options as $k => $v) { |
98 | $newMembershipType[$v['membership_type_id']] = 1; | |
3476772a | 99 | if (!empty($defaults['auto_renew'])) { |
92fcb95f | 100 | $defaults["auto_renew_" . $v['membership_type_id']] = $defaults['auto_renew'][$v['membership_type_id']]; |
6a488035 TO |
101 | } |
102 | } | |
103 | $defaults['membership_type'] = $newMembershipType; | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | return $defaults; | |
109 | } | |
110 | ||
111 | /** | |
fe482240 | 112 | * Build the form object. |
6a488035 TO |
113 | * |
114 | * @return void | |
6a488035 TO |
115 | */ |
116 | public function buildQuickForm() { | |
117 | $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(); | |
118 | ||
119 | if (!empty($membershipTypes)) { | |
120 | $this->addElement('checkbox', 'member_is_active', ts('Membership Section Enabled?')); | |
121 | ||
122 | $this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title')); | |
123 | ||
5d51a2f9 | 124 | $this->add('wysiwyg', 'new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text')); |
6a488035 TO |
125 | |
126 | $this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title')); | |
127 | ||
5d51a2f9 | 128 | $this->add('wysiwyg', 'renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text')); |
6a488035 TO |
129 | |
130 | $this->addElement('checkbox', 'is_required', ts('Require Membership Signup')); | |
131 | $this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee')); | |
132 | $this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment')); | |
21f4797a | 133 | $this->addElement('text', 'membership_type_label', ts('Membership Types Label'), array('placeholder' => ts('Membership'))); |
6a488035 TO |
134 | |
135 | $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); | |
136 | $paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', | |
137 | $this->_id, 'payment_processor' | |
138 | ); | |
139 | $paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds); | |
140 | $isRecur = TRUE; | |
141 | foreach ($paymentProcessorId as $dontCare => $id) { | |
142 | if (!array_key_exists($id, $paymentProcessor)) { | |
143 | $isRecur = FALSE; | |
144 | continue; | |
145 | } | |
146 | } | |
147 | ||
3476772a | 148 | $membership = $membershipDefault = $params = array(); |
6a488035 TO |
149 | foreach ($membershipTypes as $k => $v) { |
150 | $membership[] = $this->createElement('advcheckbox', $k, NULL, $v); | |
151 | $membershipDefault[] = $this->createElement('radio', NULL, NULL, NULL, $k); | |
3476772a | 152 | $membershipRequired[$k] = NULL; |
6a488035 | 153 | if ($isRecur) { |
353ffa53 | 154 | $autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew'); |
3476772a | 155 | $membershipRequired[$k] = $autoRenew; |
6a488035 TO |
156 | $autoRenewOptions = array(); |
157 | if ($autoRenew) { | |
158 | $autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required')); | |
159 | $this->addElement('select', "auto_renew_$k", ts('Auto-renew'), $autoRenewOptions); | |
3476772a | 160 | //CRM-15573 |
22e263ad | 161 | if ($autoRenew == 2) { |
3476772a | 162 | $this->freeze("auto_renew_$k"); |
b09fe5ed | 163 | $params['id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipBlock', $this->_id, 'id', 'entity_id'); |
3476772a | 164 | } |
6a488035 TO |
165 | $this->_renewOption[$k] = $autoRenew; |
166 | } | |
167 | } | |
168 | } | |
169 | ||
3476772a | 170 | //CRM-15573 |
171 | if (!empty($params['id'])) { | |
172 | $params['membership_types'] = serialize($membershipRequired); | |
173 | CRM_Member_BAO_MembershipBlock::create($params); | |
174 | } | |
6a488035 TO |
175 | $this->add('hidden', "mem_price_field_id", '', array('id' => "mem_price_field_id")); |
176 | $this->assign('is_recur', $isRecur); | |
177 | if (isset($this->_renewOption)) { | |
178 | $this->assign('auto_renew', $this->_renewOption); | |
179 | } | |
180 | $this->addGroup($membership, 'membership_type', ts('Membership Types')); | |
353ffa53 TO |
181 | $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default')) |
182 | ->setAttribute('allowClear', TRUE); | |
6a488035 TO |
183 | |
184 | $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id); | |
185 | } | |
9da8dc8c | 186 | $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember'); |
6a488035 TO |
187 | if (CRM_Utils_System::isNull($price)) { |
188 | $this->assign('price', FALSE); | |
189 | } | |
190 | else { | |
191 | $this->assign('price', TRUE); | |
192 | } | |
193 | $this->add('select', 'member_price_set_id', ts('Membership Price Set'), (array('' => ts('- none -')) + $price)); | |
194 | ||
195 | $session = CRM_Core_Session::singleton(); | |
196 | $single = $session->get('singleForm'); | |
197 | if ($single) { | |
198 | $this->addButtons(array( | |
199 | array( | |
200 | 'type' => 'next', | |
201 | 'name' => ts('Save'), | |
202 | 'spacing' => ' ', | |
203 | 'isDefault' => TRUE, | |
204 | ), | |
205 | array( | |
206 | 'type' => 'cancel', | |
207 | 'name' => ts('Cancel'), | |
208 | ), | |
209 | ) | |
210 | ); | |
211 | } | |
212 | else { | |
213 | parent::buildQuickForm(); | |
214 | } | |
215 | } | |
216 | ||
217 | /** | |
fe482240 | 218 | * Validation. |
6a488035 | 219 | * |
b2363ea8 TO |
220 | * @param array $params |
221 | * (ref.) an assoc array of name/value pairs. | |
6a488035 | 222 | * |
da6b46f4 | 223 | * @param $files |
100fef9d | 224 | * @param int $contributionPageId |
da6b46f4 | 225 | * |
72b3a70c CW |
226 | * @return bool|array |
227 | * mixed true or array of errors | |
6a488035 | 228 | */ |
00be9182 | 229 | public static function formRule($params, $files, $contributionPageId = NULL) { |
6a488035 TO |
230 | $errors = array(); |
231 | ||
a7488080 | 232 | if (!empty($params['member_price_set_id'])) { |
fd726496 | 233 | //check if this price set has membership type both auto-renew and non-auto-renew memberships. |
f72e6e2c | 234 | $bothTypes = CRM_Price_BAO_PriceSet::isMembershipPriceSetContainsMixOfRenewNonRenew($params['member_price_set_id']); |
6a488035 TO |
235 | |
236 | //check for supporting payment processors | |
237 | //if both auto-renew and non-auto-renew memberships | |
238 | if ($bothTypes) { | |
b09fe5ed | 239 | $paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', |
353ffa53 TO |
240 | $contributionPageId, 'payment_processor' |
241 | ); | |
6a488035 | 242 | |
b09fe5ed | 243 | $paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds); |
6a488035 TO |
244 | |
245 | if (!empty($paymentProcessorId)) { | |
22e263ad | 246 | foreach ($paymentProcessorId as $pid) { |
6a488035 | 247 | if ($pid) { |
b6ffdf22 EM |
248 | $processor = Civi\Payment\System::singleton()->getById($pid); |
249 | if (!$processor->supports('MultipleConcurrentPayments')) { | |
250 | $errors['member_price_set_id'] = ts('The membership price set associated with this online contribution allows a user to select BOTH an auto-renew AND a non-auto-renew membership. This requires submitting multiple processor transactions, and is not supported for one or more of the payment processors enabled under the Amounts tab.'); | |
251 | } | |
6a488035 | 252 | } |
6a488035 TO |
253 | } |
254 | } | |
fd726496 | 255 | } |
6a488035 | 256 | } |
a7488080 | 257 | if (!empty($params['member_is_active'])) { |
6a488035 TO |
258 | |
259 | // don't allow price set w/ membership signup, CRM-5095 | |
9da8dc8c | 260 | if ($contributionPageId && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $contributionPageId, NULL, 1))) { |
6a488035 | 261 | |
9da8dc8c | 262 | $extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends'); |
6a488035 TO |
263 | if ($extends != CRM_Core_Component::getComponentID('CiviMember')) { |
264 | $errors['member_is_active'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page.'); | |
265 | return $errors; | |
266 | } | |
267 | } | |
268 | ||
a7488080 | 269 | if (!empty($params['member_price_set_id'])) { |
6a488035 TO |
270 | return $errors; |
271 | } | |
272 | ||
273 | if (!isset($params['membership_type']) || | |
274 | (!is_array($params['membership_type'])) | |
275 | ) { | |
276 | $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.'); | |
277 | } | |
278 | else { | |
279 | $membershipType = array_values($params['membership_type']); | |
9cc96227 | 280 | $isRecur = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_recur'); |
6a488035 TO |
281 | if (array_sum($membershipType) == 0) { |
282 | $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.'); | |
283 | } | |
0c165e1c DG |
284 | elseif (array_sum($membershipType) > CRM_Price_Form_Field::NUM_OPTION) { |
285 | // for CRM-13079 | |
286 | $errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION)); | |
287 | } | |
9cc96227 | 288 | elseif ($isRecur) { |
289 | if (empty($params['is_separate_payment']) && array_sum($membershipType) != 0) { | |
290 | $errors['is_separate_payment'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution'); | |
291 | } | |
292 | elseif (!empty($params['is_separate_payment'])) { | |
293 | foreach ($params['membership_type'] as $mt => $dontCare) { | |
294 | if (!empty($params["auto_renew_$mt"])) { | |
295 | $errors["auto_renew_$mt"] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page'); | |
296 | break; | |
297 | } | |
298 | } | |
299 | } | |
300 | } | |
6a488035 TO |
301 | } |
302 | ||
303 | //for CRM-1302 | |
304 | //if Membership status is not present, then display an error message | |
305 | $dao = new CRM_Member_BAO_MembershipStatus(); | |
306 | if (!$dao->find()) { | |
307 | $errors['_qf_default'] = ts('Add status rules, before configuring membership'); | |
308 | } | |
309 | ||
310 | //give error if default is selected for an unchecked membership type | |
0c165e1c | 311 | if (!empty($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) { |
6a488035 TO |
312 | $errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.'); |
313 | } | |
314 | ||
315 | if ($contributionPageId) { | |
316 | $amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active'); | |
317 | ||
8cc574cf | 318 | if (!$amountBlock && !empty($params['is_separate_payment'])) { |
6a488035 TO |
319 | $errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.'); |
320 | } | |
321 | } | |
fd726496 | 322 | |
6a488035 TO |
323 | } |
324 | ||
325 | return empty($errors) ? TRUE : $errors; | |
326 | } | |
327 | ||
328 | /** | |
fe482240 | 329 | * Process the form. |
6a488035 TO |
330 | * |
331 | * @return void | |
6a488035 TO |
332 | */ |
333 | public function postProcess() { | |
334 | // get the submitted form values. | |
335 | $params = $this->controller->exportValues($this->_name); | |
336 | $deletePriceSet = 0; | |
337 | if ($params['membership_type']) { | |
338 | // we do this in case the user has hit the forward/back button | |
353ffa53 | 339 | $dao = new CRM_Member_DAO_MembershipBlock(); |
6a488035 | 340 | $dao->entity_table = 'civicrm_contribution_page'; |
353ffa53 | 341 | $dao->entity_id = $this->_id; |
6a488035 TO |
342 | $dao->find(TRUE); |
343 | $membershipID = $dao->id; | |
344 | if ($membershipID) { | |
345 | $params['id'] = $membershipID; | |
346 | } | |
347 | ||
348 | $membershipTypes = array(); | |
349 | if (is_array($params['membership_type'])) { | |
350 | foreach ($params['membership_type'] as $k => $v) { | |
351 | if ($v) { | |
352 | $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_$k", $params); | |
353 | } | |
354 | } | |
355 | } | |
356 | ||
2d8ae2ae CW |
357 | if ($this->_id && !empty($params['member_price_set_id'])) { |
358 | CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0); | |
359 | } | |
360 | ||
6a488035 TO |
361 | // check for price set. |
362 | $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params); | |
a7488080 | 363 | if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) { |
9da8dc8c | 364 | $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2); |
a7488080 | 365 | if (empty($params['mem_price_field_id']) && !$usedPriceSetId) { |
6a488035 TO |
366 | $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245)); |
367 | $setParams['title'] = $this->_values['title']; | |
9da8dc8c | 368 | if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) { |
6a488035 TO |
369 | $setParams['name'] = $pageTitle; |
370 | } | |
9da8dc8c | 371 | elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) { |
6a488035 TO |
372 | $setParams['name'] = $pageTitle . '_' . $this->_id; |
373 | } | |
374 | else { | |
b09fe5ed | 375 | $timeSec = explode(".", microtime(TRUE)); |
6a488035 TO |
376 | $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; |
377 | } | |
378 | $setParams['is_quick_config'] = 1; | |
379 | $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember'); | |
481a74f4 | 380 | $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values); |
9da8dc8c | 381 | $priceSet = CRM_Price_BAO_PriceSet::create($setParams); |
6a488035 TO |
382 | $priceSetID = $priceSet->id; |
383 | $fieldParams['price_set_id'] = $priceSet->id; | |
384 | } | |
385 | elseif ($usedPriceSetId) { | |
386 | $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember'); | |
481a74f4 | 387 | $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values); |
6a488035 | 388 | $setParams['id'] = $usedPriceSetId; |
9da8dc8c | 389 | $priceSet = CRM_Price_BAO_PriceSet::create($setParams); |
6a488035 TO |
390 | $priceSetID = $priceSet->id; |
391 | $fieldParams['price_set_id'] = $priceSet->id; | |
392 | } | |
393 | else { | |
394 | $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params); | |
9da8dc8c | 395 | $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id'); |
6a488035 TO |
396 | } |
397 | $editedFieldParams = array( | |
398 | 'price_set_id' => $priceSetID, | |
399 | 'name' => 'membership_amount', | |
400 | ); | |
401 | $editedResults = array(); | |
9da8dc8c | 402 | CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults); |
a7488080 | 403 | if (empty($editedResults['id'])) { |
6a488035 | 404 | $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245)); |
a7488080 | 405 | if (empty($params['mem_price_field_id'])) { |
9da8dc8c | 406 | CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID)); |
6a488035 TO |
407 | } |
408 | $fieldParams['weight'] = 1; | |
409 | } | |
410 | else { | |
411 | $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults); | |
412 | } | |
413 | ||
21f4797a | 414 | $fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership'); |
6a488035 TO |
415 | $fieldParams['is_active'] = 1; |
416 | $fieldParams['html_type'] = 'Radio'; | |
0d8afee2 CW |
417 | $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0; |
418 | $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0; | |
6a488035 TO |
419 | $rowCount = 1; |
420 | $options = array(); | |
a7488080 | 421 | if (!empty($fieldParams['id'])) { |
9da8dc8c | 422 | CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} "); |
6a488035 TO |
423 | } |
424 | ||
425 | foreach ($membershipTypes as $memType => $memAutoRenew) { | |
426 | if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) { | |
427 | $fieldParams['option_id'][$rowCount] = $priceFieldID; | |
428 | unset($options[$priceFieldID]); | |
429 | } | |
430 | $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType); | |
353ffa53 TO |
431 | $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype); |
432 | $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0); | |
433 | $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype); | |
6a488035 | 434 | $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype); |
353ffa53 | 435 | $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params); |
b09fe5ed | 436 | $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype); |
6a488035 TO |
437 | |
438 | $fieldParams['membership_type_id'][$rowCount] = $memType; | |
439 | // [$rowCount] = $membetype['']; | |
440 | $rowCount++; | |
441 | } | |
442 | foreach ($options as $priceFieldID => $memType) { | |
9da8dc8c | 443 | CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0'); |
6a488035 | 444 | } |
9da8dc8c | 445 | $priceField = CRM_Price_BAO_PriceField::create($fieldParams); |
6a488035 | 446 | } |
9b873358 | 447 | elseif (!$priceSetID) { |
6a488035 TO |
448 | $deletePriceSet = 1; |
449 | } | |
450 | ||
451 | $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE); | |
452 | $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE); | |
453 | ||
454 | if ($priceSetID) { | |
455 | $params['membership_types'] = 'null'; | |
456 | $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null'); | |
353ffa53 TO |
457 | $params['membership_types'] = serialize($membershipTypes); |
458 | $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE); | |
459 | $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE); | |
6a488035 TO |
460 | } |
461 | $params['entity_table'] = 'civicrm_contribution_page'; | |
462 | $params['entity_id'] = $this->_id; | |
463 | ||
464 | $dao = new CRM_Member_DAO_MembershipBlock(); | |
465 | $dao->copyValues($params); | |
466 | $dao->save(); | |
467 | ||
468 | if ($priceSetID && $params['is_active']) { | |
9da8dc8c | 469 | CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID); |
6a488035 TO |
470 | } |
471 | ||
472 | if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) { | |
473 | ||
474 | if ($this->_memPriceSetId) { | |
475 | $pFIDs = array(); | |
476 | $conditionParams = array( | |
477 | 'price_set_id' => $this->_memPriceSetId, | |
478 | 'html_type' => 'radio', | |
479 | 'name' => 'contribution_amount', | |
480 | ); | |
481 | ||
9da8dc8c | 482 | CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs); |
a7488080 | 483 | if (empty($pFIDs['id'])) { |
9da8dc8c | 484 | CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id); |
485 | CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0'); | |
6a488035 TO |
486 | } |
487 | else { | |
488 | ||
9da8dc8c | 489 | CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0'); |
6a488035 TO |
490 | } |
491 | } | |
492 | } | |
493 | } | |
494 | parent::endPostProcess(); | |
495 | } | |
496 | ||
497 | /** | |
498 | * Return a descriptive name for the page, used in wizard header | |
499 | * | |
500 | * @return string | |
6a488035 TO |
501 | */ |
502 | public function getTitle() { | |
503 | return ts('Memberships'); | |
504 | } | |
96025800 | 505 | |
6a488035 | 506 | } |