Commit | Line | Data |
---|---|---|
fb3082b2 EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
fb3082b2 EM |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2014 | |
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 | /** | |
50 | * The name of the BAO object for this form | |
51 | * | |
52 | * @var string | |
53 | */ | |
54 | protected $_BAOName; | |
55 | ||
00be9182 | 56 | public function preProcess() { |
fb3082b2 EM |
57 | $this->_id = $this->get('id'); |
58 | $this->_BAOName = $this->get('BAOName'); | |
59 | } | |
60 | ||
61 | /** | |
c490a46a | 62 | * Set default values for the form. MobileProvider that in edit/view mode |
fb3082b2 EM |
63 | * the default values are retrieved from the database |
64 | * | |
fb3082b2 EM |
65 | * |
66 | * @return array defaults | |
67 | */ | |
00be9182 | 68 | public function setDefaultValues() { |
fb3082b2 EM |
69 | $defaults = array(); |
70 | ||
71 | if (isset($this->_id)) { | |
72 | $params = array('id' => $this->_id); | |
73 | $baoName = $this->_BAOName; | |
74 | $baoName::retrieve($params, $defaults); | |
75 | } | |
76 | ||
77 | if (isset($defaults['minimum_fee'])) { | |
78 | $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a'); | |
79 | } | |
80 | ||
81 | if (isset($defaults['status'])) { | |
82 | $this->assign('membershipStatus', $defaults['status']); | |
83 | } | |
84 | ||
85 | if ($this->_action & CRM_Core_Action::ADD) { | |
86 | $defaults['is_active'] = 1; | |
87 | } | |
88 | ||
89 | if (isset($defaults['member_of_contact_id']) && | |
90 | $defaults['member_of_contact_id'] | |
91 | ) { | |
92 | $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', | |
93 | $defaults['member_of_contact_id'], 'display_name' | |
94 | ); | |
95 | } | |
96 | return $defaults; | |
97 | } | |
98 | ||
99 | /** | |
c490a46a | 100 | * Build the form object |
fb3082b2 EM |
101 | * |
102 | * @return void | |
fb3082b2 EM |
103 | */ |
104 | public function buildQuickForm() { | |
105 | if ($this->_action & CRM_Core_Action::RENEW) { | |
106 | $this->addButtons(array( | |
107 | array( | |
108 | 'type' => 'upload', | |
109 | 'name' => ts('Renew'), | |
110 | 'isDefault' => TRUE | |
111 | ), | |
112 | array( | |
113 | 'type' => 'cancel', | |
114 | 'name' => ts('Cancel') | |
115 | ) | |
116 | ) | |
117 | ); | |
118 | } | |
119 | elseif ($this->_action & CRM_Core_Action::DELETE) { | |
120 | $this->addButtons(array( | |
121 | array( | |
122 | 'type' => 'next', | |
123 | 'name' => ts('Delete'), | |
124 | 'isDefault' => TRUE | |
125 | ), | |
126 | array( | |
127 | 'type' => 'cancel', | |
128 | 'name' => ts('Cancel') | |
129 | ) | |
130 | ) | |
131 | ); | |
132 | } | |
133 | else { | |
134 | $this->addButtons(array( | |
135 | array( | |
136 | 'type' => 'upload', | |
137 | 'name' => ts('Save'), | |
138 | 'isDefault' => TRUE | |
139 | ), | |
140 | array( | |
141 | 'type' => 'upload', | |
142 | 'name' => ts('Save and New'), | |
143 | 'subName' => 'new' | |
144 | ), | |
145 | array( | |
146 | 'type' => 'cancel', | |
147 | 'name' => ts('Cancel') | |
148 | ) | |
149 | ) | |
150 | ); | |
151 | } | |
152 | } | |
153 | } |