'receive_date' => array('default' => 'now'),
);
+ /**
+ * Get selected membership type from the form values.
+ *
+ * @param int $priceSetID
+ * @param array $params
+ *
+ * @return array
+ */
+ public static function getSelectedMemberships($priceSetID, $params) {
+ $memTypeSelected = array();
+ $priceFieldIDS = self::getPriceFieldIDs($params);
+ if ($priceSetID && is_array($priceFieldIDS)) {
+ foreach ($priceFieldIDS as $priceFieldId) {
+ if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
+ $memTypeSelected[$id] = $id;
+ }
+ }
+ }
+ else {
+ $memTypeSelected = $params['membership_type_id'];
+ }
+ return $memTypeSelected;
+ }
+
+ /**
+ * Extract price set fields and values from $params.
+ *
+ * @param $params
+ * @return array
+ */
+ public static function getPriceFieldIDs($params) {
+ $priceFieldIDS = $priceSet = $fieldIds = array();
+ if (isset(self::$priceSet) && is_array(self::$priceSet)) {
+ $priceSet = self::$_priceSet;
+ if (isset($priceSet['fields']) && is_array($priceSet['fields'])) {
+ $fieldIds = array_keys($priceSet['fields']);
+ }
+ }
+ foreach ($fieldIds as $fieldId) {
+ if (!empty($params['price_' . $fieldId])) {
+ if (is_array($params['price_' . $fieldId])) {
+ foreach ($params['price_' . $fieldId] as $priceFldVal => $isSet) {
+ if ($isSet) {
+ $priceFieldIDS[] = $priceFldVal;
+ }
+ }
+ }
+ else {
+ $priceFieldIDS[] = $params['price_' . $fieldId];
+ }
+ }
+ }
+ return $priceFieldIDS;
+ }
+
public function preProcess() {
//custom data related code
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
$this->assign('cdType', TRUE);
return CRM_Custom_Form_CustomData::preProcess($this);
}
-
+ // This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
+ $this->assign('formClass', 'membership');
parent::preProcess();
// get price set id.
$this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
$this->set('priceSetId', $this->_priceSetId);
$this->assign('priceSetId', $this->_priceSetId);
- // check for edit permission
- if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
- CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
- }
-
if ($this->_action & CRM_Core_Action::DELETE) {
$contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id);
// check delete permission for contribution
/**
* Set default values for the form. MobileProvider that in edit/view mode
* the default values are retrieved from the database
- *
- *
- * @return void
*/
public function setDefaultValues() {
if ($this->_cdType) {
/**
* Build the form object.
- *
- * @return void
*/
public function buildQuickForm() {
if ($this->_cdType) {
}
$this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
- $config = CRM_Core_Config::singleton();
- $this->assign('currency', $config->defaultCurrencySymbol);
+
+ $this->assign('currency', CRM_Core_Config::singleton()->defaultCurrencySymbol);
$invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
if (isset($invoicing)) {
$memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value );");
//build the form for auto renew.
- $recurProcessor = $autoRenew = array();
+ $autoRenew = array();
if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) {
- $autoRenewElement = $this->addElement('checkbox',
+ $this->addElement('checkbox',
'auto_renew',
ts('Membership renewed automatically'),
NULL,
array('onclick' => "buildReceiptANDNotice( );")
);
+ $this->assignPaymentRelatedVariables();
+
if ($this->_mode) {
- //get the valid recurring processors.
- $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE;
- $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1');
- $recurProcessor = array_intersect_assoc($this->_processors, $recurring);
- $autoRenew = array();
- if (!empty($recurProcessor)) {
+ if (!empty($this->_recurPaymentProcessors)) {
if (!empty($membershipType)) {
$sql = '
SELECT id,
'onChange' =>
"CRM.buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );",
);
+ $this->assign('allowAutoRenew', TRUE);
}
}
}
- $allowAutoRenew = FALSE;
- if ($this->_mode && !empty($recurProcessor)) {
- $allowAutoRenew = TRUE;
- }
- $this->assign('allowAutoRenew', $allowAutoRenew);
+
$this->assign('autoRenewOptions', json_encode($autoRenew));
- $this->assign('recurProcessor', json_encode($recurProcessor));
// for max_related: a little JS to show/hide & set default value
$memTypeJs['onChange'] = "buildMaxRelated(this.value,true); " . $memTypeJs['onChange'];
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType()
);
- //CRM-10223 - allow contribution to be recorded against different contact
- // causes a conflict in standalone mode so skip in standalone for now
$this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
+
$this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
$this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
- $this->add('textarea', 'receipt_text_signup', ts('Receipt Message'));
+ $this->add('textarea', 'receipt_text', ts('Receipt Message'));
// Retrieve the name and email of the contact - this will be the TO for receipt email
if ($this->_contactID) {
$priceSetId = CRM_Utils_Array::value('price_set_id', $params);
+ $selectedMemberships = self::getSelectedMemberships($priceSetId, $params);
+
if ($priceSetId) {
CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $params, $errors);
- $priceFieldIDS = array();
- foreach ($self->_priceSet['fields'] as $priceIds => $dontCare) {
-
- if (!empty($params['price_' . $priceIds])) {
- if (is_array($params['price_' . $priceIds])) {
- foreach ($params['price_' . $priceIds] as $priceFldVal => $isSet) {
- if ($isSet) {
- $priceFieldIDS[] = $priceFldVal;
- }
- }
- }
- else {
- $priceFieldIDS[] = $params['price_' . $priceIds];
- }
- }
- }
+ $priceFieldIDS = self::getPriceFieldIDs($params, $self);
if (!empty($priceFieldIDS)) {
$ids = implode(',', $priceFieldIDS);
$errors['_qf_default'] = ts('Select at most one option associated with the same membership type.');
}
}
-
- foreach ($priceFieldIDS as $priceFieldId) {
- if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
- $self->_memTypeSelected[$id] = $id;
- }
- }
}
}
elseif (empty($params['membership_type_id'][1])) {
$errors['membership_type_id'] = ts('Please select a membership type.');
}
- else {
- $self->_memTypeSelected[] = $params['membership_type_id'][1];
- }
if (!$priceSetId) {
$numterms = CRM_Utils_Array::value('num_terms', $params);
}
// Return error if empty $self->_memTypeSelected
- if ($priceSetId && empty($errors) && empty($self->_memTypeSelected)) {
+ if ($priceSetId && empty($errors) && empty($selectedMemberships)) {
$errors['_qf_default'] = ts('Select at least one membership option.');
}
- if (!empty($errors) && (count($self->_memTypeSelected) > 1)) {
- $memberOfContacts = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($self->_memTypeSelected);
+ if (!empty($errors) && (count($selectedMemberships) > 1)) {
+ $memberOfContacts = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($selectedMemberships);
$duplicateMemberOfContacts = array_count_values($memberOfContacts);
foreach ($duplicateMemberOfContacts as $countDuplicate) {
if ($countDuplicate > 1) {
$joinDate = CRM_Utils_Date::processDate($params['join_date']);
- foreach ($self->_memTypeSelected as $memType) {
+ foreach ($selectedMemberships as $memType) {
$startDate = NULL;
if (!empty($params['start_date'])) {
$startDate = CRM_Utils_Date::processDate($params['start_date']);
/**
* Process the form submission.
- *
- *
- * @return void
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Member_BAO_Membership::del($this->_id);
return;
}
+ // get the submitted form values.
+ $this->_params = $this->controller->exportValues($this->_name);
- $allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
- $allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
+ $this->submit($this->_params);
+ $this->setUserContext();
+ }
+
+ /**
+ * Send email receipt.
+ *
+ * @param CRM_Core_Form $form
+ * Form object.
+ * @param array $formValues
+ * @param object $membership
+ * Object.
+ *
+ * @return bool
+ * true if mail was sent successfully
+ */
+ public static function emailReceipt(&$form, &$formValues, &$membership) {
+ // retrieve 'from email id' for acknowledgement
+ $receiptFrom = $formValues['from_email_address'];
+
+ if (!empty($formValues['payment_instrument_id'])) {
+ $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
+ $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
+ }
+
+ // retrieve custom data
+ $customFields = $customValues = array();
+ if (property_exists($form, '_groupTree')
+ && !empty($form->_groupTree)
+ ) {
+ foreach ($form->_groupTree as $groupID => $group) {
+ if ($groupID == 'info') {
+ continue;
+ }
+ foreach ($group['fields'] as $k => $field) {
+ $field['title'] = $field['label'];
+ $customFields["custom_{$k}"] = $field;
+ }
+ }
+ }
+
+ $members = array(array('member_id', '=', $membership->id, 0, 0));
+ // check whether its a test drive
+ if ($form->_mode == 'test') {
+ $members[] = array('member_test', '=', 1, 0, 0);
+ }
+
+ CRM_Core_BAO_UFGroup::getValues($formValues['contact_id'], $customFields, $customValues, FALSE, $members);
+
+ if ($form->_mode) {
+ $name = '';
+ if (!empty($form->_params['billing_first_name'])) {
+ $name = $form->_params['billing_first_name'];
+ }
+
+ if (!empty($form->_params['billing_middle_name'])) {
+ $name .= " {$form->_params['billing_middle_name']}";
+ }
+
+ if (!empty($form->_params['billing_last_name'])) {
+ $name .= " {$form->_params['billing_last_name']}";
+ }
+
+ $form->assign('billingName', $name);
+
+ // assign the address formatted up for display
+ $addressParts = array(
+ "street_address-{$form->_bltID}",
+ "city-{$form->_bltID}",
+ "postal_code-{$form->_bltID}",
+ "state_province-{$form->_bltID}",
+ "country-{$form->_bltID}",
+ );
+ $addressFields = array();
+ foreach ($addressParts as $part) {
+ list($n, $id) = explode('-', $part);
+ if (isset($form->_params['billing_' . $part])) {
+ $addressFields[$n] = $form->_params['billing_' . $part];
+ }
+ }
+ $form->assign('address', CRM_Utils_Address::format($addressFields));
+
+ $date = CRM_Utils_Date::format($form->_params['credit_card_exp_date']);
+ $date = CRM_Utils_Date::mysqlToIso($date);
+ $form->assign('credit_card_exp_date', $date);
+ $form->assign('credit_card_number',
+ CRM_Utils_System::mungeCreditCard($form->_params['credit_card_number'])
+ );
+ $form->assign('credit_card_type', $form->_params['credit_card_type']);
+ $form->assign('contributeMode', 'direct');
+ $form->assign('isAmountzero', 0);
+ $form->assign('is_pay_later', 0);
+ $form->assign('isPrimary', 1);
+ }
+
+ $form->assign('module', 'Membership');
+ $form->assign('contactID', $formValues['contact_id']);
+
+ $form->assign('membershipID', CRM_Utils_Array::value('membership_id', $form->_params, CRM_Utils_Array::value('membership_id', $form->_defaultValues)));
+
+ if (!empty($formValues['contribution_id'])) {
+ $form->assign('contributionID', $formValues['contribution_id']);
+ }
+ elseif (isset($form->_onlinePendingContributionId)) {
+ $form->assign('contributionID', $form->_onlinePendingContributionId);
+ }
+
+ if (!empty($formValues['contribution_status_id'])) {
+ $form->assign('contributionStatusID', $formValues['contribution_status_id']);
+ $form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name'));
+ }
+
+ if (!empty($formValues['is_renew'])) {
+ $form->assign('receiptType', 'membership renewal');
+ }
+ else {
+ $form->assign('receiptType', 'membership signup');
+ }
+ $form->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $formValues)));
+ $form->assign('formValues', $formValues);
+
+ if (empty($lineItem)) {
+ $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y'));
+ if (!CRM_Utils_System::isNull($membership->end_date)) {
+ $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y'));
+ }
+ $form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
+ }
+
+ $form->assign('customValues', $customValues);
+ $isBatchProcess = is_a($form, 'CRM_Batch_Form_Entry');
+ if ((empty($form->_contributorDisplayName) || empty($form->_contributorEmail)) || $isBatchProcess) {
+ // in this case the form is being called statically from the batch editing screen
+ // having one class in the form layer call another statically is not greate
+ // & we should aim to move this function to the BAO layer in future.
+ // however, we can assume that the contact_id passed in by the batch
+ // function will be the recipient
+ list($form->_contributorDisplayName, $form->_contributorEmail)
+ = CRM_Contact_BAO_Contact_Location::getEmailDetails($formValues['contact_id']);
+ if (empty($form->_receiptContactId) || $isBatchProcess) {
+ $form->_receiptContactId = $formValues['contact_id'];
+ }
+ }
+ $template = CRM_Core_Smarty::singleton();
+ $taxAmt = $template->get_template_vars('dataArray');
+ $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
+ $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
+ $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
+ if ((!empty($taxAmt) || isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
+ $isEmailPdf = TRUE;
+ }
+ else {
+ $isEmailPdf = FALSE;
+ }
+
+ list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
+ array(
+ 'groupName' => 'msg_tpl_workflow_membership',
+ 'valueName' => 'membership_offline_receipt',
+ 'contactId' => $form->_receiptContactId,
+ 'from' => $receiptFrom,
+ 'toName' => $form->_contributorDisplayName,
+ 'toEmail' => $form->_contributorEmail,
+ 'PDFFilename' => ts('receipt') . '.pdf',
+ 'isEmailPdf' => $isEmailPdf,
+ 'contributionId' => $formValues['contribution_id'],
+ 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW),
+ )
+ );
+
+ return TRUE;
+ }
+
+ /**
+ * @param array $formValues
+
+ * @return array
+ */
+ public function submit($formValues) {
$isTest = ($this->_mode == 'test') ? 1 : 0;
+ $joinDate = $startDate = $endDate = NULL;
+ $membershipTypes = $membership = $calcDate = array();
+ $membershipType = NULL;
+
+ $mailSend = FALSE;
+ $priceSetID = CRM_Utils_Array::value('price_set_id', $formValues);
+
+ $params = $softParams = $ids = array();
+
+ $allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
+ $allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
+
$lineItems = NULL;
if (!empty($this->_lineItem)) {
$lineItems = $this->_lineItem;
}
+ // Set variables that we normally get from context.
+ // In form mode these are set in preProcess.
+ //TODO: set memberships, fixme
+ $this->setContextVariables($formValues);
+ $this->_memTypeSelected = self::getSelectedMemberships($priceSetID, $formValues);
+
$config = CRM_Core_Config::singleton();
- // get the submitted form values.
- $this->_params = $formValues = $this->controller->exportValues($this->_name);
- $this->convertDateFieldsToMySQL($formValues);
- $params = $softParams = $ids = array();
+ $this->convertDateFieldsToMySQL($formValues);
$membershipTypeValues = array();
foreach ($this->_memTypeSelected as $memType) {
}
//take the required membership recur values.
- if ($this->_mode && !empty($this->_params['auto_renew'])) {
+ if ($this->_mode && !empty($formValues['auto_renew'])) {
$params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE;
$mapping = array(
'frequency_interval' => 'duration_interval',
// process price set and get total amount and line items.
$lineItem = array();
- $priceSetId = NULL;
- if (!$priceSetId = CRM_Utils_Array::value('price_set_id', $formValues)) {
- CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
+ if ($priceSetID) {
+ CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetID);
}
$isQuickConfig = 0;
- if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
+ if ($priceSetID && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'is_quick_config')) {
$isQuickConfig = 1;
}
$termsByType = array();
- if ($priceSetId) {
+ if ($priceSetID) {
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
- $this->_params, $lineItem[$priceSetId]);
+ $this->_params, $lineItem[$priceSetID]);
if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
$params['tax_amount'] = $this->_params['tax_amount'];
}
$params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
- if (!empty($lineItem[$priceSetId])) {
- foreach ($lineItem[$priceSetId] as &$li) {
+ if (!empty($lineItem[$priceSetID])) {
+ foreach ($lineItem[$priceSetID] as &$li) {
if (!empty($li['membership_type_id'])) {
if (!empty($li['membership_num_terms'])) {
$termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
// membership type custom data
foreach ($this->_memTypeSelected as $memType) {
- $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE,
- $memType
- );
-
- $customFields = CRM_Utils_Array::crmArrayMerge($customFields,
- CRM_Core_BAO_CustomField::getFields('Membership',
- FALSE, FALSE,
- NULL, NULL, TRUE
- )
- );
-
$membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues,
- $customFields,
$this->_id,
'Membership'
);
if (!$this->_onlinePendingContributionId) {
if (empty($formValues['source'])) {
$params['contribution_source'] = ts('%1 Membership: Offline signup (by %2)', array(
- 1 => $membershipType,
- 2 => $userName,
- ));
+ 1 => $membershipType,
+ 2 => $userName,
+ ));
}
else {
$params['contribution_source'] = $formValues['source'];
}
$createdMemberships = array();
if ($this->_mode) {
- if (empty($formValues['total_amount']) && !$priceSetId) {
+ if (empty($formValues['total_amount']) && !$priceSetID) {
// if total amount not provided minimum for membership type is used
$params['total_amount'] = $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
$formValues['membership_type_id'][1], 'minimum_fee'
$params['total_amount'] = CRM_Utils_Array::value('total_amount', $formValues, 0);
}
- if ($priceSetId && !$isQuickConfig) {
+ if ($priceSetID && !$isQuickConfig) {
$params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet',
- $priceSetId,
+ $priceSetID,
'financial_type_id'
);
}
CRM_Core_Error::fatal('Could not find a system table');
}
- $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this,
+ $contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this,
$paymentParams,
$result,
$this->_contributorContactID,
// suppress form values in template.
$this->assign('cancelled', $cancelled);
- // FIX ME: need to recheck this
- // here we might updated dates, so get from object.
- foreach ($calcDates[$membership->membership_type_id] as $date => & $val) {
- if ($membership->$date) {
- $val = $membership->$date;
- }
- }
-
$createdMemberships[] = $membership;
}
else {
}
}
- if (!empty($lineItem[$priceSetId])) {
+ if (!empty($lineItem[$priceSetID])) {
$invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$taxAmount = FALSE;
$totalTaxAmount = 0;
- foreach ($lineItem[$priceSetId] as & $priceFieldOp) {
+ foreach ($lineItem[$priceSetID] as & $priceFieldOp) {
if (!empty($priceFieldOp['membership_type_id'])) {
$priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'], '%B %E%f, %Y') : '-';
$priceFieldOp['end_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'], '%B %E%f, %Y') : '-';
}
if ($invoicing) {
$dataArray = array();
- foreach ($lineItem[$priceSetId] as $key => $value) {
+ foreach ($lineItem[$priceSetID] as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
if (!empty($formValues['send_receipt']) && $receiptSend) {
$formValues['contact_id'] = $this->_contactID;
$formValues['contribution_id'] = $contributionId;
-
+ // We really don't need a distinct receipt_text_signup vs receipt_text_renewal as they are
+ // handled in the receipt. But by setting one we avoid breaking templates for now
+ // although at some point we should switch in the templates.
+ $formValues['receipt_text_signup'] = $formValues['receipt_text'];
// send email receipt
$mailSend = self::emailReceipt($this, $formValues, $membership);
}
- $statusMsg = '';
- if (($this->_action & CRM_Core_Action::UPDATE)) {
- //end date can be modified by hooks, so if end date is set then use it.
- $endDate = ($membership->end_date) ? $membership->end_date : $endDate;
- $statusMsg = ts('Membership for %1 has been updated.', array(1 => $this->_memberDisplayName));
- if ($endDate && $endDate !== 'null') {
- $endDate = CRM_Utils_Date::customFormat($endDate);
- $statusMsg .= ' ' . ts('The membership End Date is %1.', array(1 => $endDate));
- }
- if ($receiptSend) {
- $statusMsg .= ' ' . ts('A confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
- }
+ // finally set membership id if already not set
+ if (!$this->_id) {
+ $this->_id = $membership->id;
}
- elseif (($this->_action & CRM_Core_Action::ADD)) {
- // FIX ME: fix status messages
-
- $statusMsg = array();
- foreach ($membershipTypes as $memType => $membershipType) {
- $statusMsg[$memType] = ts('%1 membership for %2 has been added.', array(
- 1 => $membershipType,
- 2 => $this->_memberDisplayName,
- ));
-
- $membership = $createdMemberships[$memType];
- $memEndDate = ($membership->end_date) ? $membership->end_date : $endDate;
- //get the end date from calculated dates.
- if (!$memEndDate && empty($params['is_recur'])) {
- $memEndDate = CRM_Utils_Array::value('end_date', $calcDates[$memType]);
- }
+ $statusMsg = '';
+ if (($this->_action & CRM_Core_Action::UPDATE)) {
+ $statusMsg = $this->getStatusMessageForUpdate($membership, $endDate, $receiptSend);
- if ($memEndDate && $memEndDate !== 'null') {
- $memEndDate = CRM_Utils_Date::customFormat($memEndDate);
- $statusMsg[$memType] .= ' ' . ts('The new membership End Date is %1.', array(1 => $memEndDate));
- }
- }
- $statusMsg = implode('<br/>', $statusMsg);
- if ($receiptSend && $mailSend) {
- $statusMsg .= ' ' . ts('A membership confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
- }
}
-
- // finally set membership id if already not set
- if (!$this->_id) {
- $this->_id = $membership->id;
+ elseif (($this->_action & CRM_Core_Action::ADD)) {
+ $statusMsg = $this->getStatusMessageForCreate($endDate, $receiptSend, $membershipTypes, $createdMemberships,
+ $params, $calcDates, $mailSend);
}
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
+ return $createdMemberships;
+ }
+
+ protected function setUserContext() {
$buttonName = $this->controller->getButtonName();
+ $session = CRM_Core_Session::singleton();
+
if ($this->_context == 'standalone') {
if ($buttonName == $this->getButtonName('upload', 'new')) {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/member/add',
}
/**
- * Send email receipt.
- *
- * @param CRM_Core_Form $form
- * Form object.
- * @param array $formValues
- * @param object $membership
- * Object.
- *
- * @return bool
- * true if mail was sent successfully
+ * @param $membership
+ * @param $endDate
+ * @param $receiptSend
+ * @return string
*/
- public static function emailReceipt(&$form, &$formValues, &$membership) {
- // retrieve 'from email id' for acknowledgement
- $receiptFrom = $formValues['from_email_address'];
-
- if (!empty($formValues['payment_instrument_id'])) {
- $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
- $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
- }
-
- // retrieve custom data
- $customFields = $customValues = array();
- if (property_exists($form, '_groupTree')
- && !empty($form->_groupTree)
- ) {
- foreach ($form->_groupTree as $groupID => $group) {
- if ($groupID == 'info') {
- continue;
- }
- foreach ($group['fields'] as $k => $field) {
- $field['title'] = $field['label'];
- $customFields["custom_{$k}"] = $field;
- }
- }
- }
-
- $members = array(array('member_id', '=', $membership->id, 0, 0));
- // check whether its a test drive
- if ($form->_mode == 'test') {
- $members[] = array('member_test', '=', 1, 0, 0);
- }
-
- CRM_Core_BAO_UFGroup::getValues($formValues['contact_id'], $customFields, $customValues, FALSE, $members);
-
- if ($form->_mode) {
- $name = '';
- if (!empty($form->_params['billing_first_name'])) {
- $name = $form->_params['billing_first_name'];
- }
+ protected function getStatusMessageForUpdate($membership, $endDate, $receiptSend) {
+ //end date can be modified by hooks, so if end date is set then use it.
+ $endDate = ($membership->end_date) ? $membership->end_date : $endDate;
- if (!empty($form->_params['billing_middle_name'])) {
- $name .= " {$form->_params['billing_middle_name']}";
- }
-
- if (!empty($form->_params['billing_last_name'])) {
- $name .= " {$form->_params['billing_last_name']}";
- }
-
- $form->assign('billingName', $name);
-
- // assign the address formatted up for display
- $addressParts = array(
- "street_address-{$form->_bltID}",
- "city-{$form->_bltID}",
- "postal_code-{$form->_bltID}",
- "state_province-{$form->_bltID}",
- "country-{$form->_bltID}",
- );
- $addressFields = array();
- foreach ($addressParts as $part) {
- list($n, $id) = explode('-', $part);
- if (isset($form->_params['billing_' . $part])) {
- $addressFields[$n] = $form->_params['billing_' . $part];
- }
- }
- $form->assign('address', CRM_Utils_Address::format($addressFields));
-
- $date = CRM_Utils_Date::format($form->_params['credit_card_exp_date']);
- $date = CRM_Utils_Date::mysqlToIso($date);
- $form->assign('credit_card_exp_date', $date);
- $form->assign('credit_card_number',
- CRM_Utils_System::mungeCreditCard($form->_params['credit_card_number'])
- );
- $form->assign('credit_card_type', $form->_params['credit_card_type']);
- $form->assign('contributeMode', 'direct');
- $form->assign('isAmountzero', 0);
- $form->assign('is_pay_later', 0);
- $form->assign('isPrimary', 1);
+ $statusMsg = ts('Membership for %1 has been updated.', array(1 => $this->_memberDisplayName));
+ if ($endDate && $endDate !== 'null') {
+ $endDate = CRM_Utils_Date::customFormat($endDate);
+ $statusMsg .= ' ' . ts('The membership End Date is %1.', array(1 => $endDate));
}
- $form->assign('module', 'Membership');
- $form->assign('contactID', $formValues['contact_id']);
-
- $form->assign('membershipID', CRM_Utils_Array::value('membership_id', $form->_params, CRM_Utils_Array::value('membership_id', $form->_defaultValues)));
-
- if (!empty($formValues['contribution_id'])) {
- $form->assign('contributionID', $formValues['contribution_id']);
- }
- elseif (isset($form->_onlinePendingContributionId)) {
- $form->assign('contributionID', $form->_onlinePendingContributionId);
+ if ($receiptSend) {
+ $statusMsg .= ' ' . ts('A confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
}
+ return $statusMsg;
+ }
- if (!empty($formValues['contribution_status_id'])) {
- $form->assign('contributionStatusID', $formValues['contribution_status_id']);
- $form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name'));
- }
+ /**
+ * @param $endDate
+ * @param $receiptSend
+ * @param $membershipTypes
+ * @param $createdMemberships
+ * @param $params
+ * @param $calcDates
+ * @param $mailSent
+ * @internal param $membership
+ * @return array|string
+ */
+ protected function getStatusMessageForCreate($endDate, $receiptSend, $membershipTypes, $createdMemberships,
+ $params, $calcDates, $mailSent) {
+ // FIX ME: fix status messages
+
+ $statusMsg = array();
+ foreach ($membershipTypes as $memType => $membershipType) {
+ $statusMsg[$memType] = ts('%1 membership for %2 has been added.', array(
+ 1 => $membershipType,
+ 2 => $this->_memberDisplayName,
+ ));
- if (!empty($formValues['is_renew'])) {
- $form->assign('receiptType', 'membership renewal');
- }
- else {
- $form->assign('receiptType', 'membership signup');
- }
- $form->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $formValues)));
- $form->assign('formValues', $formValues);
+ $membership = $createdMemberships[$memType];
+ $memEndDate = ($membership->end_date) ? $membership->end_date : $endDate;
- if (empty($lineItem)) {
- $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y'));
- if (!CRM_Utils_System::isNull($membership->end_date)) {
- $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y'));
+ //get the end date from calculated dates.
+ if (!$memEndDate && empty($params['is_recur'])) {
+ $memEndDate = CRM_Utils_Array::value('end_date', $calcDates[$memType]);
}
- $form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
- }
- $form->assign('customValues', $customValues);
- $isBatchProcess = is_a($form, 'CRM_Batch_Form_Entry');
- if ((empty($form->_contributorDisplayName) || empty($form->_contributorEmail)) || $isBatchProcess) {
- // in this case the form is being called statically from the batch editing screen
- // having one class in the form layer call another statically is not greate
- // & we should aim to move this function to the BAO layer in future.
- // however, we can assume that the contact_id passed in by the batch
- // function will be the recipient
- list($form->_contributorDisplayName, $form->_contributorEmail)
- = CRM_Contact_BAO_Contact_Location::getEmailDetails($formValues['contact_id']);
- if (empty($form->_receiptContactId) || $isBatchProcess) {
- $form->_receiptContactId = $formValues['contact_id'];
+ if ($memEndDate && $memEndDate !== 'null') {
+ $memEndDate = CRM_Utils_Date::customFormat($memEndDate);
+ $statusMsg[$memType] .= ' ' . ts('The new membership End Date is %1.', array(1 => $memEndDate));
}
}
- $template = CRM_Core_Smarty::singleton();
- $taxAmt = $template->get_template_vars('dataArray');
- $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
- $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
- $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
- if ((!empty($taxAmt) || isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
- $isEmailPdf = TRUE;
+ $statusMsg = implode('<br/>', $statusMsg);
+ if ($receiptSend && $mailSent) {
+ $statusMsg .= ' ' . ts('A membership confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
}
- else {
- $isEmailPdf = FALSE;
- }
-
- list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
- array(
- 'groupName' => 'msg_tpl_workflow_membership',
- 'valueName' => 'membership_offline_receipt',
- 'contactId' => $form->_receiptContactId,
- 'from' => $receiptFrom,
- 'toName' => $form->_contributorDisplayName,
- 'toEmail' => $form->_contributorEmail,
- 'PDFFilename' => ts('receipt') . '.pdf',
- 'isEmailPdf' => $isEmailPdf,
- 'contributionId' => $formValues['contribution_id'],
- 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW),
- )
- );
-
- return TRUE;
+ return $statusMsg;
}
}