Merge pull request #12828 from seamuslee001/lab_core_357
[civicrm-core.git] / CRM / Member / Form / MembershipConfig.php
CommitLineData
fb3082b2
EM
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
fb3082b2 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
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() {
fb3082b2
EM
64 $defaults = array();
65
66 if (isset($this->_id)) {
67 $params = array('id' => $this->_id);
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) {
101 $this->addButtons(array(
c5c263ca
AH
102 array(
103 'type' => 'upload',
104 'name' => ts('Renew'),
105 'isDefault' => TRUE,
106 ),
107 array(
108 'type' => 'cancel',
109 'name' => ts('Cancel'),
110 ),
111 ));
fb3082b2
EM
112 }
113 elseif ($this->_action & CRM_Core_Action::DELETE) {
114 $this->addButtons(array(
c5c263ca
AH
115 array(
116 'type' => 'next',
117 'name' => ts('Delete'),
118 'isDefault' => TRUE,
119 ),
120 array(
121 'type' => 'cancel',
122 'name' => ts('Cancel'),
123 ),
124 ));
fb3082b2
EM
125 }
126 else {
127 $this->addButtons(array(
c5c263ca
AH
128 array(
129 'type' => 'upload',
130 'name' => ts('Save'),
131 'isDefault' => TRUE,
132 ),
133 array(
134 'type' => 'upload',
135 'name' => ts('Save and New'),
136 'subName' => 'new',
137 ),
138 array(
139 'type' => 'cancel',
140 'name' => ts('Cancel'),
141 ),
142 ));
fb3082b2
EM
143 }
144 }
96025800 145
fb3082b2 146}