Merge pull request #22662 from colemanw/softDeleteEntity
[civicrm-core.git] / CRM / Member / Form / MembershipConfig.php
CommitLineData
fb3082b2
EM
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
fb3082b2 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
fb3082b2 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
fb3082b2
EM
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
fb3082b2
EM
16 */
17
18/**
19 * Base class for offline membership / membership type / membership renewal and membership status forms
20 *
21 */
22class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
23
24 /**
25 * The id of the object being edited / created
26 *
27 * @var int
28 */
29 public $_id;
30
31 /**
fe482240 32 * The name of the BAO object for this form.
fb3082b2
EM
33 *
34 * @var string
35 */
36 protected $_BAOName;
d5965a37 37
fb3082b2 38 /**
c490a46a 39 * Set default values for the form. MobileProvider that in edit/view mode
fb3082b2
EM
40 * the default values are retrieved from the database
41 *
a6c01b45
CW
42 * @return array
43 * defaults
fb3082b2 44 */
00be9182 45 public function setDefaultValues() {
be2fb01f 46 $defaults = [];
fb3082b2
EM
47
48 if (isset($this->_id)) {
be2fb01f 49 $params = ['id' => $this->_id];
fb3082b2
EM
50 $baoName = $this->_BAOName;
51 $baoName::retrieve($params, $defaults);
52 }
53
54 if (isset($defaults['minimum_fee'])) {
476a47e9 55 $defaults['minimum_fee'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($defaults['minimum_fee']);
fb3082b2
EM
56 }
57
58 if (isset($defaults['status'])) {
59 $this->assign('membershipStatus', $defaults['status']);
60 }
61
62 if ($this->_action & CRM_Core_Action::ADD) {
63 $defaults['is_active'] = 1;
64 }
65
66 if (isset($defaults['member_of_contact_id']) &&
67 $defaults['member_of_contact_id']
68 ) {
69 $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
70 $defaults['member_of_contact_id'], 'display_name'
71 );
72 }
73 return $defaults;
74 }
75
76 /**
fe482240 77 * Build the form object.
fb3082b2
EM
78 *
79 * @return void
fb3082b2
EM
80 */
81 public function buildQuickForm() {
82 if ($this->_action & CRM_Core_Action::RENEW) {
be2fb01f
CW
83 $this->addButtons([
84 [
c5c263ca
AH
85 'type' => 'upload',
86 'name' => ts('Renew'),
87 'isDefault' => TRUE,
be2fb01f
CW
88 ],
89 [
c5c263ca
AH
90 'type' => 'cancel',
91 'name' => ts('Cancel'),
be2fb01f
CW
92 ],
93 ]);
fb3082b2
EM
94 }
95 elseif ($this->_action & CRM_Core_Action::DELETE) {
be2fb01f
CW
96 $this->addButtons([
97 [
c5c263ca
AH
98 'type' => 'next',
99 'name' => ts('Delete'),
100 'isDefault' => TRUE,
be2fb01f
CW
101 ],
102 [
c5c263ca
AH
103 'type' => 'cancel',
104 'name' => ts('Cancel'),
be2fb01f
CW
105 ],
106 ]);
fb3082b2
EM
107 }
108 else {
be2fb01f
CW
109 $this->addButtons([
110 [
c5c263ca
AH
111 'type' => 'upload',
112 'name' => ts('Save'),
113 'isDefault' => TRUE,
be2fb01f
CW
114 ],
115 [
c5c263ca
AH
116 'type' => 'upload',
117 'name' => ts('Save and New'),
118 'subName' => 'new',
be2fb01f
CW
119 ],
120 [
c5c263ca
AH
121 'type' => 'cancel',
122 'name' => ts('Cancel'),
be2fb01f
CW
123 ],
124 ]);
fb3082b2
EM
125 }
126 }
96025800 127
fb3082b2 128}