3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * Base class for offline membership / membership type / membership renewal and membership status forms
40 class CRM_Member_Form
extends CRM_Contribute_Form_AbstractEditPayment
{
43 * The id of the object being edited / created
56 * Array of from email ids
59 protected $_fromEmails = array();
61 public function preProcess() {
63 $params['action'] = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
64 $params['context'] = CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'membership');
65 $params['id'] = CRM_Utils_Request
::retrieve('id', 'Positive', $this);
66 $params['mode'] = CRM_Utils_Request
::retrieve('mode', 'String', $this);
68 $this->setContextVariables($params);
70 $this->assign('context', $this->_context
);
71 $this->assign('membershipMode', $this->_mode
);
72 $this->assign('contactID', $this->_contactID
);
76 * Set default values for the form. MobileProvider that in edit/view mode
77 * the default values are retrieved from the database
83 public function setDefaultValues() {
85 if (isset($this->_id
)) {
86 $params = array('id' => $this->_id
);
87 CRM_Member_BAO_Membership
::retrieve($params, $defaults);
90 if (isset($defaults['minimum_fee'])) {
91 $defaults['minimum_fee'] = CRM_Utils_Money
::format($defaults['minimum_fee'], NULL, '%a');
94 if (isset($defaults['status'])) {
95 $this->assign('membershipStatus', $defaults['status']);
98 if ($this->_action
& CRM_Core_Action
::ADD
) {
99 $defaults['is_active'] = 1;
102 if (isset($defaults['member_of_contact_id']) &&
103 $defaults['member_of_contact_id']
105 $defaults['member_org'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
106 $defaults['member_of_contact_id'], 'display_name'
113 * Build the form object.
117 public function buildQuickForm() {
119 $this->add('select', 'payment_processor_id',
120 ts('Payment Processor'),
121 $this->_processors
, TRUE,
122 array('onChange' => "buildAutoRenew( null, this.value );")
124 CRM_Core_Payment_Form
::buildPaymentForm($this, $this->_paymentProcessor
, FALSE);
126 if ($this->_action
& CRM_Core_Action
::RENEW
) {
127 $this->addButtons(array(
130 'name' => ts('Renew'),
135 'name' => ts('Cancel'),
140 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
141 $this->addButtons(array(
144 'name' => ts('Delete'),
149 'name' => ts('Cancel'),
155 $this->addButtons(array(
158 'name' => ts('Save'),
163 'name' => ts('Save and New'),
168 'name' => ts('Cancel'),
176 * Extract values from the contact create boxes on the form and assign appropriately to
178 * - $this->_contributorEmail,
179 * - $this->_memberEmail &
180 * - $this->_contributionName
181 * - $this->_memberName
182 * - $this->_contactID (effectively memberContactId but changing might have spin-off effects)
183 * - $this->_contributorContactId - id of the contributor
184 * - $this->_receiptContactId
186 * If the member & contributor are the same then the values will be the same. But if different people paid
187 * then they weill differ
189 * @param array $formValues
190 * values from form. The important values we are looking for are.
192 * - soft_credit_contact_id
194 public function storeContactFields($formValues) {
195 // in a 'standalone form' (contact id not in the url) the contact will be in the form values
196 if (!empty($formValues['contact_id'])) {
197 $this->_contactID
= $formValues['contact_id'];
200 list($this->_memberDisplayName
,
202 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactID
);
204 //CRM-10375 Where the payer differs to the member the payer should get the email.
205 // here we store details in order to do that
206 if (!empty($formValues['soft_credit_contact_id'])) {
207 $this->_receiptContactId
= $this->_contributorContactID
= $formValues['soft_credit_contact_id'];
208 list($this->_contributorDisplayName
,
209 $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contributorContactID
);
212 $this->_receiptContactId
= $this->_contributorContactID
= $this->_contactID
;
213 $this->_contributorDisplayName
= $this->_memberDisplayName
;
214 $this->_contributorEmail
= $this->_memberEmail
;
218 protected function setContextVariables($params) {
220 'action' => '_action',
221 'context' => '_context',
223 'cid' => '_contactID',
226 foreach ($variables as $paramKey => $classVar) {
227 if (isset($params[$paramKey]) && !isset($this->$classVar)) {
228 $this->$classVar = $params[$paramKey];
233 $this->assignPaymentRelatedVariables();
237 $this->_memType
= CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_Membership', $this->_id
, 'membership_type_id');
238 $this->_membershipIDs
[] = $this->_id
;
240 $this->_fromEmails
= CRM_Core_BAO_Email
::getFromEmail();