Merge pull request #15865 from eileenmcnaughton/query
[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 * $Id$
17 *
18 */
19
20 /**
21 * Base class for offline membership / membership type / membership renewal and membership status forms
22 *
23 */
24 class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
25
26 /**
27 * The id of the object being edited / created
28 *
29 * @var int
30 */
31 public $_id;
32
33 /**
34 * The name of the BAO object for this form.
35 *
36 * @var string
37 */
38 protected $_BAOName;
39
40 /**
41 * Set default values for the form. MobileProvider that in edit/view mode
42 * the default values are retrieved from the database
43 *
44 * @return array
45 * defaults
46 */
47 public function setDefaultValues() {
48 $defaults = [];
49
50 if (isset($this->_id)) {
51 $params = ['id' => $this->_id];
52 $baoName = $this->_BAOName;
53 $baoName::retrieve($params, $defaults);
54 }
55
56 if (isset($defaults['minimum_fee'])) {
57 $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
58 }
59
60 if (isset($defaults['status'])) {
61 $this->assign('membershipStatus', $defaults['status']);
62 }
63
64 if ($this->_action & CRM_Core_Action::ADD) {
65 $defaults['is_active'] = 1;
66 }
67
68 if (isset($defaults['member_of_contact_id']) &&
69 $defaults['member_of_contact_id']
70 ) {
71 $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
72 $defaults['member_of_contact_id'], 'display_name'
73 );
74 }
75 return $defaults;
76 }
77
78 /**
79 * Build the form object.
80 *
81 * @return void
82 */
83 public function buildQuickForm() {
84 if ($this->_action & CRM_Core_Action::RENEW) {
85 $this->addButtons([
86 [
87 'type' => 'upload',
88 'name' => ts('Renew'),
89 'isDefault' => TRUE,
90 ],
91 [
92 'type' => 'cancel',
93 'name' => ts('Cancel'),
94 ],
95 ]);
96 }
97 elseif ($this->_action & CRM_Core_Action::DELETE) {
98 $this->addButtons([
99 [
100 'type' => 'next',
101 'name' => ts('Delete'),
102 'isDefault' => TRUE,
103 ],
104 [
105 'type' => 'cancel',
106 'name' => ts('Cancel'),
107 ],
108 ]);
109 }
110 else {
111 $this->addButtons([
112 [
113 'type' => 'upload',
114 'name' => ts('Save'),
115 'isDefault' => TRUE,
116 ],
117 [
118 'type' => 'upload',
119 'name' => ts('Save and New'),
120 'subName' => 'new',
121 ],
122 [
123 'type' => 'cancel',
124 'name' => ts('Cancel'),
125 ],
126 ]);
127 }
128 }
129
130 }