Update copyright date for 2020
[civicrm-core.git] / CRM / Member / Form / MembershipConfig.php
CommitLineData
fb3082b2
EM
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
fb3082b2 5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
fb3082b2
EM
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 */
fb3082b2
EM
27
28/**
29 *
30 * @package CRM
f299f7db 31 * @copyright CiviCRM LLC (c) 2004-2020
fb3082b2
EM
32 * $Id$
33 *
34 */
35
36/**
37 * Base class for offline membership / membership type / membership renewal and membership status forms
38 *
39 */
40class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
41
42 /**
43 * The id of the object being edited / created
44 *
45 * @var int
46 */
47 public $_id;
48
49 /**
fe482240 50 * The name of the BAO object for this form.
fb3082b2
EM
51 *
52 * @var string
53 */
54 protected $_BAOName;
d5965a37 55
fb3082b2 56 /**
c490a46a 57 * Set default values for the form. MobileProvider that in edit/view mode
fb3082b2
EM
58 * the default values are retrieved from the database
59 *
a6c01b45
CW
60 * @return array
61 * defaults
fb3082b2 62 */
00be9182 63 public function setDefaultValues() {
be2fb01f 64 $defaults = [];
fb3082b2
EM
65
66 if (isset($this->_id)) {
be2fb01f 67 $params = ['id' => $this->_id];
fb3082b2
EM
68 $baoName = $this->_BAOName;
69 $baoName::retrieve($params, $defaults);
70 }
71
72 if (isset($defaults['minimum_fee'])) {
73 $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
74 }
75
76 if (isset($defaults['status'])) {
77 $this->assign('membershipStatus', $defaults['status']);
78 }
79
80 if ($this->_action & CRM_Core_Action::ADD) {
81 $defaults['is_active'] = 1;
82 }
83
84 if (isset($defaults['member_of_contact_id']) &&
85 $defaults['member_of_contact_id']
86 ) {
87 $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
88 $defaults['member_of_contact_id'], 'display_name'
89 );
90 }
91 return $defaults;
92 }
93
94 /**
fe482240 95 * Build the form object.
fb3082b2
EM
96 *
97 * @return void
fb3082b2
EM
98 */
99 public function buildQuickForm() {
100 if ($this->_action & CRM_Core_Action::RENEW) {
be2fb01f
CW
101 $this->addButtons([
102 [
c5c263ca
AH
103 'type' => 'upload',
104 'name' => ts('Renew'),
105 'isDefault' => TRUE,
be2fb01f
CW
106 ],
107 [
c5c263ca
AH
108 'type' => 'cancel',
109 'name' => ts('Cancel'),
be2fb01f
CW
110 ],
111 ]);
fb3082b2
EM
112 }
113 elseif ($this->_action & CRM_Core_Action::DELETE) {
be2fb01f
CW
114 $this->addButtons([
115 [
c5c263ca
AH
116 'type' => 'next',
117 'name' => ts('Delete'),
118 'isDefault' => TRUE,
be2fb01f
CW
119 ],
120 [
c5c263ca
AH
121 'type' => 'cancel',
122 'name' => ts('Cancel'),
be2fb01f
CW
123 ],
124 ]);
fb3082b2
EM
125 }
126 else {
be2fb01f
CW
127 $this->addButtons([
128 [
c5c263ca
AH
129 'type' => 'upload',
130 'name' => ts('Save'),
131 'isDefault' => TRUE,
be2fb01f
CW
132 ],
133 [
c5c263ca
AH
134 'type' => 'upload',
135 'name' => ts('Save and New'),
136 'subName' => 'new',
be2fb01f
CW
137 ],
138 [
c5c263ca
AH
139 'type' => 'cancel',
140 'name' => ts('Cancel'),
be2fb01f
CW
141 ],
142 ]);
fb3082b2
EM
143 }
144 }
96025800 145
fb3082b2 146}