API - add field options to getoptions metadata
[civicrm-core.git] / CRM / Member / Form.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Base class for offline membership / membership type / membership renewal and membership status forms
38 *
39 */
cc984198 40class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
6a488035
TO
41
42 /**
43 * The id of the object being edited / created
44 *
45 * @var int
46 */
cc984198 47 public $_id;
6a488035 48
a6513ad5
EM
49 /**
50 * Membership Type ID
51 * @var
52 */
53 protected $_memType;
54
55 /**
56 * Array of from email ids
57 * @var array
58 */
59 protected $_fromEmails = array();
60
00be9182 61 public function preProcess() {
b09fe5ed 62 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
a6513ad5
EM
63 $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
64 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
65 $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
66 $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
67
68 $this->assign('context', $this->_context);
69 $this->assign('membershipMode', $this->_mode);
70 $this->assign('contactID', $this->_contactID);
fb3082b2 71
a6513ad5
EM
72 if ($this->_mode) {
73 $this->assignPaymentRelatedVariables();
74 }
75
76 if ($this->_id) {
77 $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
78 $this->_membershipIDs[] = $this->_id;
79 }
80 $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
6a488035
TO
81 }
82
83 /**
c490a46a 84 * Set default values for the form. MobileProvider that in edit/view mode
6a488035
TO
85 * the default values are retrieved from the database
86 *
6a488035 87 *
a6c01b45
CW
88 * @return array
89 * defaults
6a488035 90 */
00be9182 91 public function setDefaultValues() {
6a488035 92 $defaults = array();
a6513ad5
EM
93 if (isset($this->_id)) {
94 $params = array('id' => $this->_id);
95 CRM_Member_BAO_Membership::retrieve($params, $defaults);
96 }
6a488035 97
6a488035
TO
98 if (isset($defaults['minimum_fee'])) {
99 $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
100 }
101
102 if (isset($defaults['status'])) {
103 $this->assign('membershipStatus', $defaults['status']);
104 }
105
106 if ($this->_action & CRM_Core_Action::ADD) {
107 $defaults['is_active'] = 1;
108 }
109
110 if (isset($defaults['member_of_contact_id']) &&
111 $defaults['member_of_contact_id']
112 ) {
113 $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
114 $defaults['member_of_contact_id'], 'display_name'
115 );
116 }
117 return $defaults;
118 }
119
120 /**
fe482240 121 * Build the form object.
6a488035 122 *
355ba699 123 * @return void
6a488035
TO
124 */
125 public function buildQuickForm() {
a6513ad5
EM
126 if ($this->_mode) {
127 $this->add('select', 'payment_processor_id',
128 ts('Payment Processor'),
129 $this->_processors, TRUE,
130 array('onChange' => "buildAutoRenew( null, this.value );")
131 );
4d1fd569 132 CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE);
a6513ad5 133 }
6a488035
TO
134 if ($this->_action & CRM_Core_Action::RENEW) {
135 $this->addButtons(array(
136 array(
137 'type' => 'upload',
138 'name' => ts('Renew'),
21dfd5f5 139 'isDefault' => TRUE,
6a488035
TO
140 ),
141 array(
142 'type' => 'cancel',
21dfd5f5
TO
143 'name' => ts('Cancel'),
144 ),
6a488035
TO
145 )
146 );
147 }
148 elseif ($this->_action & CRM_Core_Action::DELETE) {
149 $this->addButtons(array(
150 array(
151 'type' => 'next',
152 'name' => ts('Delete'),
21dfd5f5 153 'isDefault' => TRUE,
6a488035
TO
154 ),
155 array(
156 'type' => 'cancel',
21dfd5f5
TO
157 'name' => ts('Cancel'),
158 ),
6a488035
TO
159 )
160 );
161 }
162 else {
163 $this->addButtons(array(
164 array(
165 'type' => 'upload',
166 'name' => ts('Save'),
21dfd5f5 167 'isDefault' => TRUE,
6a488035
TO
168 ),
169 array(
170 'type' => 'upload',
171 'name' => ts('Save and New'),
21dfd5f5 172 'subName' => 'new',
6a488035
TO
173 ),
174 array(
175 'type' => 'cancel',
21dfd5f5
TO
176 'name' => ts('Cancel'),
177 ),
6a488035
TO
178 )
179 );
180 }
181 }
182
fb3082b2 183 /**
100fef9d 184 * Extract values from the contact create boxes on the form and assign appropriately to
6a488035
TO
185 *
186 * - $this->_contributorEmail,
187 * - $this->_memberEmail &
fb3082b2 188 * - $this->_contributionName
6a488035
TO
189 * - $this->_memberName
190 * - $this->_contactID (effectively memberContactId but changing might have spin-off effects)
191 * - $this->_contributorContactId - id of the contributor
192 * - $this->_receiptContactId
193 *
194 * If the member & contributor are the same then the values will be the same. But if different people paid
195 * then they weill differ
196 *
5a4f6742
CW
197 * @param array $formValues
198 * values from form. The important values we are looking for are.
4c7aa1f7
CW
199 * - contact_id
200 * - soft_credit_contact_id
6a488035 201 */
9b873358 202 public function storeContactFields($formValues) {
6a488035 203 // in a 'standalone form' (contact id not in the url) the contact will be in the form values
4c7aa1f7
CW
204 if (!empty($formValues['contact_id'])) {
205 $this->_contactID = $formValues['contact_id'];
6a488035
TO
206 }
207
208 list($this->_memberDisplayName,
353ffa53
TO
209 $this->_memberEmail
210 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
6a488035
TO
211
212 //CRM-10375 Where the payer differs to the member the payer should get the email.
213 // here we store details in order to do that
4c7aa1f7
CW
214 if (!empty($formValues['soft_credit_contact_id'])) {
215 $this->_receiptContactId = $this->_contributorContactID = $formValues['soft_credit_contact_id'];
481a74f4 216 list($this->_contributorDisplayName,
353ffa53 217 $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contributorContactID);
6a488035
TO
218 }
219 else {
220 $this->_receiptContactId = $this->_contributorContactID = $this->_contactID;
221 $this->_contributorDisplayName = $this->_memberDisplayName;
222 $this->_contributorEmail = $this->_memberEmail;
223 }
224 }
96025800 225
6a488035 226}