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