Commit | Line | Data |
---|---|---|
fb3082b2 EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
fb3082b2 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
fb3082b2 EM |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Base class for offline membership / membership type / membership renewal and membership status forms | |
38 | * | |
39 | */ | |
40 | class 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 TM |
55 | |
56 | /** | |
6e62b28c TM |
57 | * Explicitly declare the entity api name. |
58 | */ | |
59 | public function getDefaultEntity() { | |
60 | return 'MembershipType'; | |
61 | } | |
fb3082b2 | 62 | |
00be9182 | 63 | public function preProcess() { |
fb3082b2 EM |
64 | $this->_id = $this->get('id'); |
65 | $this->_BAOName = $this->get('BAOName'); | |
66 | } | |
67 | ||
68 | /** | |
c490a46a | 69 | * Set default values for the form. MobileProvider that in edit/view mode |
fb3082b2 EM |
70 | * the default values are retrieved from the database |
71 | * | |
fb3082b2 | 72 | * |
a6c01b45 CW |
73 | * @return array |
74 | * defaults | |
fb3082b2 | 75 | */ |
00be9182 | 76 | public function setDefaultValues() { |
fb3082b2 EM |
77 | $defaults = array(); |
78 | ||
79 | if (isset($this->_id)) { | |
80 | $params = array('id' => $this->_id); | |
81 | $baoName = $this->_BAOName; | |
82 | $baoName::retrieve($params, $defaults); | |
83 | } | |
84 | ||
85 | if (isset($defaults['minimum_fee'])) { | |
86 | $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a'); | |
87 | } | |
88 | ||
89 | if (isset($defaults['status'])) { | |
90 | $this->assign('membershipStatus', $defaults['status']); | |
91 | } | |
92 | ||
93 | if ($this->_action & CRM_Core_Action::ADD) { | |
94 | $defaults['is_active'] = 1; | |
95 | } | |
96 | ||
97 | if (isset($defaults['member_of_contact_id']) && | |
98 | $defaults['member_of_contact_id'] | |
99 | ) { | |
100 | $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', | |
101 | $defaults['member_of_contact_id'], 'display_name' | |
102 | ); | |
103 | } | |
104 | return $defaults; | |
105 | } | |
106 | ||
107 | /** | |
fe482240 | 108 | * Build the form object. |
fb3082b2 EM |
109 | * |
110 | * @return void | |
fb3082b2 EM |
111 | */ |
112 | public function buildQuickForm() { | |
113 | if ($this->_action & CRM_Core_Action::RENEW) { | |
114 | $this->addButtons(array( | |
115 | array( | |
116 | 'type' => 'upload', | |
117 | 'name' => ts('Renew'), | |
21dfd5f5 | 118 | 'isDefault' => TRUE, |
fb3082b2 EM |
119 | ), |
120 | array( | |
121 | 'type' => 'cancel', | |
21dfd5f5 TO |
122 | 'name' => ts('Cancel'), |
123 | ), | |
fb3082b2 EM |
124 | ) |
125 | ); | |
126 | } | |
127 | elseif ($this->_action & CRM_Core_Action::DELETE) { | |
128 | $this->addButtons(array( | |
129 | array( | |
130 | 'type' => 'next', | |
131 | 'name' => ts('Delete'), | |
21dfd5f5 | 132 | 'isDefault' => TRUE, |
fb3082b2 EM |
133 | ), |
134 | array( | |
135 | 'type' => 'cancel', | |
21dfd5f5 TO |
136 | 'name' => ts('Cancel'), |
137 | ), | |
fb3082b2 EM |
138 | ) |
139 | ); | |
140 | } | |
141 | else { | |
142 | $this->addButtons(array( | |
143 | array( | |
144 | 'type' => 'upload', | |
145 | 'name' => ts('Save'), | |
21dfd5f5 | 146 | 'isDefault' => TRUE, |
fb3082b2 EM |
147 | ), |
148 | array( | |
149 | 'type' => 'upload', | |
150 | 'name' => ts('Save and New'), | |
21dfd5f5 | 151 | 'subName' => 'new', |
fb3082b2 EM |
152 | ), |
153 | array( | |
154 | 'type' => 'cancel', | |
21dfd5f5 TO |
155 | 'name' => ts('Cancel'), |
156 | ), | |
fb3082b2 EM |
157 | ) |
158 | ); | |
159 | } | |
160 | } | |
96025800 | 161 | |
fb3082b2 | 162 | } |