Merge pull request #16008 from civicrm/5.20
[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 * $Id$
17 *
18 */
19
20/**
21 * Base class for offline membership / membership type / membership renewal and membership status forms
22 *
23 */
24class 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 /**
fe482240 34 * The name of the BAO object for this form.
fb3082b2
EM
35 *
36 * @var string
37 */
38 protected $_BAOName;
d5965a37 39
fb3082b2 40 /**
c490a46a 41 * Set default values for the form. MobileProvider that in edit/view mode
fb3082b2
EM
42 * the default values are retrieved from the database
43 *
a6c01b45
CW
44 * @return array
45 * defaults
fb3082b2 46 */
00be9182 47 public function setDefaultValues() {
be2fb01f 48 $defaults = [];
fb3082b2
EM
49
50 if (isset($this->_id)) {
be2fb01f 51 $params = ['id' => $this->_id];
fb3082b2
EM
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 /**
fe482240 79 * Build the form object.
fb3082b2
EM
80 *
81 * @return void
fb3082b2
EM
82 */
83 public function buildQuickForm() {
84 if ($this->_action & CRM_Core_Action::RENEW) {
be2fb01f
CW
85 $this->addButtons([
86 [
c5c263ca
AH
87 'type' => 'upload',
88 'name' => ts('Renew'),
89 'isDefault' => TRUE,
be2fb01f
CW
90 ],
91 [
c5c263ca
AH
92 'type' => 'cancel',
93 'name' => ts('Cancel'),
be2fb01f
CW
94 ],
95 ]);
fb3082b2
EM
96 }
97 elseif ($this->_action & CRM_Core_Action::DELETE) {
be2fb01f
CW
98 $this->addButtons([
99 [
c5c263ca
AH
100 'type' => 'next',
101 'name' => ts('Delete'),
102 'isDefault' => TRUE,
be2fb01f
CW
103 ],
104 [
c5c263ca
AH
105 'type' => 'cancel',
106 'name' => ts('Cancel'),
be2fb01f
CW
107 ],
108 ]);
fb3082b2
EM
109 }
110 else {
be2fb01f
CW
111 $this->addButtons([
112 [
c5c263ca
AH
113 'type' => 'upload',
114 'name' => ts('Save'),
115 'isDefault' => TRUE,
be2fb01f
CW
116 ],
117 [
c5c263ca
AH
118 'type' => 'upload',
119 'name' => ts('Save and New'),
120 'subName' => 'new',
be2fb01f
CW
121 ],
122 [
c5c263ca
AH
123 'type' => 'cancel',
124 'name' => ts('Cancel'),
be2fb01f
CW
125 ],
126 ]);
fb3082b2
EM
127 }
128 }
96025800 129
fb3082b2 130}