Merge pull request #23893 from eileenmcnaughton/user_two
[civicrm-core.git] / CRM / Member / Form / MembershipConfig.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Base class for offline membership / membership type / membership renewal and membership status forms
20 *
21 */
22 class 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 /**
32 * The name of the BAO object for this form.
33 *
34 * @var string
35 */
36 protected $_BAOName;
37
38 /**
39 * Set default values for the form. MobileProvider that in edit/view mode
40 * the default values are retrieved from the database
41 *
42 * @return array
43 * defaults
44 */
45 public function setDefaultValues() {
46 $defaults = [];
47
48 if (isset($this->_id)) {
49 $params = ['id' => $this->_id];
50 $baoName = $this->_BAOName;
51 $baoName::retrieve($params, $defaults);
52 }
53
54 if (isset($defaults['minimum_fee'])) {
55 $defaults['minimum_fee'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($defaults['minimum_fee']);
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 /**
77 * Build the form object.
78 *
79 * @return void
80 */
81 public function buildQuickForm() {
82 if ($this->_action & CRM_Core_Action::RENEW) {
83 $this->addButtons([
84 [
85 'type' => 'upload',
86 'name' => ts('Renew'),
87 'isDefault' => TRUE,
88 ],
89 [
90 'type' => 'cancel',
91 'name' => ts('Cancel'),
92 ],
93 ]);
94 }
95 elseif ($this->_action & CRM_Core_Action::DELETE) {
96 $this->addButtons([
97 [
98 'type' => 'next',
99 'name' => ts('Delete'),
100 'isDefault' => TRUE,
101 ],
102 [
103 'type' => 'cancel',
104 'name' => ts('Cancel'),
105 ],
106 ]);
107 }
108 else {
109 $this->addButtons([
110 [
111 'type' => 'upload',
112 'name' => ts('Save'),
113 'isDefault' => TRUE,
114 ],
115 [
116 'type' => 'upload',
117 'name' => ts('Save and New'),
118 'subName' => 'new',
119 ],
120 [
121 'type' => 'cancel',
122 'name' => ts('Cancel'),
123 ],
124 ]);
125 }
126 }
127
128 }