* Build an array of available membership types.
*
* @param CRM_Core_Form $form
- * @param int $membershipTypeID
+ * @param array $membershipTypeID
* @param bool $activeOnly
* Do we only want active ones?
* (probably this should default to TRUE but as a newly added parameter we are leaving default b
*
* @return array
*/
- public static function buildMembershipTypeValues(&$form, $membershipTypeID = NULL, $activeOnly = FALSE) {
+ public static function buildMembershipTypeValues(&$form, $membershipTypeID = array(), $activeOnly = FALSE) {
$whereClause = " WHERE domain_id = " . CRM_Core_Config::domainID();
+ $membershipTypeIDS = (array) $membershipTypeID;
if ($activeOnly) {
$whereClause .= " AND is_active = 1 ";
}
- if (is_array($membershipTypeID)) {
- $allIDs = implode(',', $membershipTypeID);
+ if (!empty($membershipTypeIDS)) {
+ $allIDs = implode(',', $membershipTypeIDS);
$whereClause .= " AND id IN ( $allIDs )";
}
- elseif (is_numeric($membershipTypeID) &&
- $membershipTypeID > 0
- ) {
- $whereClause .= " AND id = $membershipTypeID";
- }
$query = "
SELECT *
public function postProcess() {
// get the submitted form values.
$this->_params = $formValues = $this->controller->exportValues($this->_name);
+ $this->assignBillingName();
- $statusMsg = $this->submit($formValues);
+ try {
+ $statusMsg = $this->submit($formValues);
+ }
+ catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
+ CRM_Core_Error::displaySessionError($e->getMessage());
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership',
+ "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"
+ ));
+ }
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
}
$fields["email-{$this->_bltID}"] = 1;
- $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
-
$nameFields = array('first_name', 'middle_name', 'last_name');
foreach ($nameFields as $name) {
$formValues['preserveDBName'] = TRUE;
}
}
-
+dpm($fields);
//here we are setting up the billing contact - if different from the member they are already created
// but they will get billing details assigned
CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields,
- $this->_contributorContactID, NULL, NULL, $ctype
+ $this->_contributorContactID, NULL, NULL,
+ CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type')
);
// add all the additional payment params we need
$payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- if (!empty($paymentParams['auto_renew'])) {
+ if (!empty($formValues['auto_renew'])) {
$contributionRecurParams = $this->processRecurringContribution($paymentParams);
$paymentParams = array_merge($paymentParams, $contributionRecurParams);
}
- $result = $payment->doDirectPayment($paymentParams);
-
- if (is_a($result, 'CRM_Core_Error')) {
- CRM_Core_Error::displaySessionError($result);
- CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership',
- "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"
- ));
- }
+ $result = $payment->doPayment($paymentParams);
if ($result) {
$this->_params = array_merge($this->_params, $result);
));
$this->assign('customValues', $customValues);
if ($this->_mode) {
- if (!empty($this->_params['billing_first_name'])) {
- $name = $this->_params['billing_first_name'];
- }
-
- if (!empty($this->_params['billing_middle_name'])) {
- $name .= " {$this->_params['billing_middle_name']}";
- }
-
- if (!empty($this->_params['billing_last_name'])) {
- $name .= " {$this->_params['billing_last_name']}";
- }
- $this->assign('billingName', $name);
-
// assign the address formatted up for display
$addressParts = array(
"street_address-{$this->_bltID}",
$this->submit($formValues);
}
+ protected function assignBillingName() {
+ if (!empty($this->_params['billing_first_name'])) {
+ $name = $this->_params['billing_first_name'];
+ }
+
+ if (!empty($this->_params['billing_middle_name'])) {
+ $name .= " {$this->_params['billing_middle_name']}";
+ }
+
+ if (!empty($this->_params['billing_last_name'])) {
+ $name .= " {$this->_params['billing_last_name']}";
+ }
+ $this->assign('billingName', $name);
+ }
+
}
$this->callAPISuccess('relationship_type', 'delete', array('id' => 20));
}
- /**
- * Test CRM_Member_Form_Membership::buildQuickForm()
- */
- //function testCRMMemberFormMembershipBuildQuickForm()
- //{
- // throw new PHPUnit_Framework_IncompleteTestError( "not implemented" );
- //}
-
/**
* Test the submit function of the membership form.
*/
'num_terms' => '1',
'source' => '',
'total_amount' => '50.00',
- 'financial_type_id' => '2', //Member dues, see data.xml
+ //Member dues, see data.xml
+ 'financial_type_id' => '2',
'soft_credit_type_id' => '',
'soft_credit_contact_id' => '',
'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
$form->testSubmit($params);
$membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- //$this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
+ $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
$contribution = $this->callAPISuccess('Contribution', 'get', array(
'contact_id' => $this->_individualId,
'is_test' => TRUE,