public $_action;
/**
- * Contribution mode e.g express for payment express, notify for off-site + notification back to CiviCRM
+ * Contribution mode.
+ *
+ * In general we are trying to deprecate this parameter but some templates and processors still
+ * require it to denote whether the processor redirects offsite (notify) or not.
+ *
+ * The intent is that this knowledge should not be required and all contributions should
+ * be created in a pending state and updated based on the payment result without needing to be
+ * aware of the processor workings.
+ *
* @var string
+ *
+ * @deprecated
*/
public $_contributeMode;
public $_emailExists = FALSE;
/**
- * Is this a backoffice form
- * (this will affect whether paypal express code is displayed)
+ * Is this a backoffice form.
+ *
+ * Processors may display different options to backoffice users.
+ *
* @var bool
*/
public $isBackOffice = FALSE;
* @param int $id
* @param CRM_Core_Form $form
*
+ * @throws \API_Exception
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function buildComponentForm($id, $form) {
+ public function buildComponentForm($id, $form): void {
if (empty($id)) {
return;
}
// radio button for Honor Type
foreach ($form->_values['soft_credit_types'] as $value) {
- $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
+ $honorTypes[$value] = $softCreditTypes[$value];
}
- $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
+ $form->addRadio('soft_credit_type_id', NULL, $honorTypes, ['allowClear' => TRUE]);
$honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields(
$this->_values['honoree_profile_id'], FALSE,
}
}
- $form->assign('fieldSetTitle', CRM_Core_BAO_UFGroup::getTitle($form->_values['onbehalf_profile_id']));
+ $form->assign('fieldSetTitle', CRM_Core_BAO_UFGroup::getFrontEndTitle($form->_values['onbehalf_profile_id']));
if (!empty($form->_values['is_for_organization'])) {
if ($form->_values['is_for_organization'] == 2) {
foreach ($profileFields as $name => $field) {
if (in_array($field['field_type'], $fieldTypes)) {
- list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
+ [$prefixName, $index] = CRM_Utils_System::explode('-', $name, 2);
if (in_array($prefixName, ['organization_name', 'email']) && empty($field['is_required'])) {
$field['is_required'] = 1;
}
}
}
- /**
- * Build Membership Block in Contribution Pages.
- *
- * @param int $cid
- * Contact checked for having a current membership for a particular membership.
- * @param bool $isContributionMainPage
- * Is this the main page? If so add form input fields.
- * (or better yet don't have this functionality in a function shared with forms that don't share it).
- * @param int|array $selectedMembershipTypeID
- * Selected membership id.
- * @param bool $thankPage
- * Thank you page.
- * @param null $isTest
- *
- * @return bool
- * Is this a separate membership payment
- *
- * @throws \CiviCRM_API3_Exception
- * @throws \CRM_Core_Exception
- */
- protected function buildMembershipBlock(
- $cid,
- $isContributionMainPage = FALSE,
- $selectedMembershipTypeID = NULL,
- $thankPage = FALSE,
- $isTest = NULL
- ) {
-
- $separateMembershipPayment = FALSE;
- if ($this->_membershipBlock) {
- $this->_currentMemberships = [];
-
- $membershipTypeIds = $membershipTypes = $radio = [];
- $membershipPriceset = (!empty($this->_priceSetId) && $this->_useForMember);
-
- $allowAutoRenewMembership = $autoRenewOption = FALSE;
- $autoRenewMembershipTypeOptions = [];
-
- $separateMembershipPayment = $this->_membershipBlock['is_separate_payment'] ?? NULL;
-
- if ($membershipPriceset) {
- foreach ($this->_priceSet['fields'] as $pField) {
- if (empty($pField['options'])) {
- continue;
- }
- foreach ($pField['options'] as $opId => $opValues) {
- if (empty($opValues['membership_type_id'])) {
- continue;
- }
- $membershipTypeIds[$opValues['membership_type_id']] = $opValues['membership_type_id'];
- }
- }
- }
- elseif (!empty($this->_membershipBlock['membership_types'])) {
- $membershipTypeIds = explode(',', $this->_membershipBlock['membership_types']);
- }
-
- if (!empty($membershipTypeIds)) {
- //set status message if wrong membershipType is included in membershipBlock
- if (isset($this->_mid) && !$membershipPriceset) {
- $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
- $this->_mid,
- 'membership_type_id'
- );
- if (!in_array($membershipTypeID, $membershipTypeIds)) {
- CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Invalid Membership'), 'error');
- }
- }
-
- $membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIds);
- $this->_membershipTypeValues = $membershipTypeValues;
- $endDate = NULL;
-
- // Check if we support auto-renew on this contribution page
- // FIXME: If any of the payment processors do NOT support recurring you cannot setup an
- // auto-renew payment even if that processor is not selected.
- $allowAutoRenewOpt = TRUE;
- if (is_array($this->_paymentProcessors)) {
- foreach ($this->_paymentProcessors as $id => $val) {
- if ($id && !$val['is_recur']) {
- $allowAutoRenewOpt = FALSE;
- }
- }
- }
- foreach ($membershipTypeIds as $value) {
- $memType = $membershipTypeValues[$value];
- if ($selectedMembershipTypeID != NULL) {
- if ($memType['id'] == $selectedMembershipTypeID) {
- $this->assign('minimum_fee',
- CRM_Utils_Array::value('minimum_fee', $memType)
- );
- $this->assign('membership_name', $memType['name']);
- if (!$thankPage && $cid) {
- $membership = new CRM_Member_DAO_Membership();
- $membership->contact_id = $cid;
- $membership->membership_type_id = $memType['id'];
- if ($membership->find(TRUE)) {
- $this->assign('renewal_mode', TRUE);
- $memType['current_membership'] = $membership->end_date;
- $this->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id;
- }
- }
- $membershipTypes[] = $memType;
- }
- }
- elseif ($memType['is_active']) {
-
- if ($allowAutoRenewOpt) {
- $javascriptMethod = ['onclick' => "return showHideAutoRenew( this.value );"];
- $isAvailableAutoRenew = $this->_membershipBlock['auto_renew'][$value] ?? 1;
- $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $memType['auto_renew'] * $isAvailableAutoRenew;
- $allowAutoRenewMembership = TRUE;
- }
- else {
- $javascriptMethod = NULL;
- $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = 0;
- }
-
- //add membership type.
- $radio[$memType['id']] = $this->createElement('radio', NULL, NULL, NULL,
- $memType['id'], $javascriptMethod
- );
- if ($cid) {
- $membership = new CRM_Member_DAO_Membership();
- $membership->contact_id = $cid;
- $membership->membership_type_id = $memType['id'];
-
- //show current membership, skip pending and cancelled membership records,
- //because we take first membership record id for renewal
- $membership->whereAdd('status_id != 5 AND status_id !=6');
-
- if (!is_null($isTest)) {
- $membership->is_test = $isTest;
- }
-
- //CRM-4297
- $membership->orderBy('end_date DESC');
-
- if ($membership->find(TRUE)) {
- if (!$membership->end_date) {
- unset($radio[$memType['id']]);
- $this->assign('islifetime', TRUE);
- continue;
- }
- $this->assign('renewal_mode', TRUE);
- $this->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id;
- $memType['current_membership'] = $membership->end_date;
- if (!$endDate) {
- $endDate = $memType['current_membership'];
- $this->_defaultMemTypeId = $memType['id'];
- }
- if ($memType['current_membership'] < $endDate) {
- $endDate = $memType['current_membership'];
- $this->_defaultMemTypeId = $memType['id'];
- }
- }
- }
- $membershipTypes[] = $memType;
- }
- }
- }
-
- $this->assign('membershipBlock', $this->_membershipBlock);
- $this->assign('showRadio', $isContributionMainPage);
- $this->assign('membershipTypes', $membershipTypes);
- $this->assign('allowAutoRenewMembership', $allowAutoRenewMembership);
- $this->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions));
- //give preference to user submitted auto_renew value.
- $takeUserSubmittedAutoRenew = (!empty($_POST) || $this->isSubmitted());
- $this->assign('takeUserSubmittedAutoRenew', $takeUserSubmittedAutoRenew);
-
- // Assign autorenew option (0:hide,1:optional,2:required) so we can use it in confirmation etc.
- $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId);
- //$selectedMembershipTypeID is retrieved as an array for membership priceset if multiple
- //options for different organisation is selected on the contribution page.
- if (is_numeric($selectedMembershipTypeID) && isset($membershipTypeValues[$selectedMembershipTypeID]['auto_renew'])) {
- $this->assign('autoRenewOption', $membershipTypeValues[$selectedMembershipTypeID]['auto_renew']);
- }
- else {
- $this->assign('autoRenewOption', $autoRenewOption);
- }
-
- if ($isContributionMainPage) {
- if (!$membershipPriceset) {
- if (!$this->_membershipBlock['is_required']) {
- $this->assign('showRadioNoThanks', TRUE);
- $radio[''] = $this->createElement('radio', NULL, NULL, NULL, 'no_thanks', NULL);
- $this->addGroup($radio, 'selectMembership', NULL);
- }
- elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) {
- $temp = array_keys($radio);
- $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']);
- $this->assign('singleMembership', TRUE);
- $this->assign('showRadio', FALSE);
- }
- else {
- $this->addGroup($radio, 'selectMembership', NULL);
- }
-
- $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required');
- }
-
- if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) {
- if ($autoRenewOption == 2) {
- $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.'));
- }
- else {
- $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.'));
- }
- }
-
- }
- }
-
- return $separateMembershipPayment;
- }
-
/**
* Determine if recurring parameters need to be added to the form parameters.
*