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