X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FMember%2FForm%2FMembershipRenewal.php;h=096e45e65254bc327427cad20afe14df65d3f8c2;hb=971e129ba60ff4699184047a1df9aa5daf678098;hp=138576eb2f9ca9a299e627e84a7c4d5cb62181d7;hpb=24704c73fe5f5ee2ca19a9fc98101841ee7c854a;p=civicrm-core.git diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 138576eb2f..096e45e652 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -45,6 +45,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { /** * email of the person paying for the membership (used for receipts) + * @var string */ protected $_memberEmail = NULL; @@ -65,6 +66,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { /** * email of the person paying for the membership (used for receipts) + * @var string */ protected $_contributorEmail = NULL; @@ -85,6 +87,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { /** * context would be set to standalone if the contact is use is being selected from * the form rather than in the URL + * @var string */ public $_context; @@ -109,16 +112,6 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { */ protected $membershipTypeName = ''; - /** - * An array to hold a list of datefields on the form - * so that they can be converted to ISO in a consistent manner - * - * @var array - */ - protected $_dateFields = array( - 'receive_date' => array('default' => 'now'), - ); - /** * Set entity fields to be assigned to the form. */ @@ -190,10 +183,9 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $defaults = parent::setDefaultValues(); // set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed) - list($now, $currentTime) = CRM_Utils_Date::setDateDefaults(); + $now = date('Y-m-d'); $defaults['renewal_date'] = $now; - $defaults['receive_date'] = $now; - $defaults['receive_date_time'] = $currentTime; + $defaults['receive_date'] = $now . ' ' . date('H:i:s'); if ($defaults['id']) { $defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', @@ -223,9 +215,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $scTypes = CRM_Core_OptionGroup::values("soft_credit_type"); $defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes)); - $renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults), - NULL, NULL, 'Y-m-d' - ); + $renewalDate = CRM_Utils_Array::value('renewal_date', $defaults); $this->assign('renewalDate', $renewalDate); $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults)); @@ -248,7 +238,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->assign('entityID', $this->_id); $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -'); - $allMembershipInfo = array(); + $allMembershipInfo = []; // CRM-21485 if (is_array($defaults['membership_type_id'])) { @@ -293,12 +283,12 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { // build membership info array, which is used to set the payment information block when // membership type is selected. - $allMembershipInfo[$key] = array( + $allMembershipInfo[$key] = [ 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, - 'tax_message' => $taxAmount ? ts("Includes %1 amount of %2", array(1 => $this->getSalesTaxTerm(), 2 => CRM_Utils_Money::format($taxAmount))) : $taxAmount, - ); + 'tax_message' => $taxAmount ? ts("Includes %1 amount of %2", [1 => $this->getSalesTaxTerm(), 2 => CRM_Utils_Money::format($taxAmount)]) : $taxAmount, + ]; if (!empty($values['auto_renew'])) { $allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']]; @@ -325,45 +315,45 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $selOrgMemType[$index] = $orgMembershipType; } - $js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData('Membership', this.value);"); + $js = ['onChange' => "setPaymentBlock(); CRM.buildCustomData('Membership', this.value);"]; $sel = &$this->addElement('hierselect', 'membership_type_id', ts('Renewal Membership Organization and Type'), $js ); - $sel->setOptions(array($selMemTypeOrg, $selOrgMemType)); - $elements = array(); + $sel->setOptions([$selMemTypeOrg, $selOrgMemType]); + $elements = []; if ($sel) { $elements[] = $sel; } $this->applyFilter('__ALL__', 'trim'); - $this->addDate('renewal_date', ts('Date Renewal Entered'), FALSE, array('formatType' => 'activityDate')); + $this->add('datepicker', 'renewal_date', ts('Date Renewal Entered'), [], FALSE, ['time' => FALSE]); $this->add('select', 'financial_type_id', ts('Financial Type'), - array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType() + ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::financialType() ); - $this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE); + $this->add('number', 'num_terms', ts('Extend Membership by'), ['onchange' => "setPaymentBlock();"], TRUE); $this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer'); if (CRM_Core_Permission::access('CiviContribute') && !$this->_mode) { - $this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, array('onclick' => "checkPayment();")); + $this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, ['onclick' => "checkPayment();"]); $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); - $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime')); + $this->add('datepicker', 'receive_date', ts('Received'), [], FALSE, ['time' => TRUE]); $this->add('select', 'payment_instrument_id', ts('Payment Method'), - array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), - FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);") + ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::paymentInstrument(), + FALSE, ['onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"] ); $this->add('text', 'trxn_id', ts('Transaction ID')); $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), - 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id') + 'objectExists', ['CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'] ); $this->add('select', 'contribution_status_id', ts('Payment Status'), @@ -379,7 +369,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); } $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, - array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false ); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio',false);") + ['onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false ); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio',false);"] ); $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails); @@ -404,10 +394,10 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { ); } } - $this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule'), $this); + $this->addFormRule(['CRM_Member_Form_MembershipRenewal', 'formRule'], $this); $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->addSelect('soft_credit_type_id', ['entity' => 'contribution_soft']); + $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), ['create' => TRUE]); } /** @@ -415,12 +405,14 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { * * @param array $params * (ref.) an assoc array of name/value pairs. + * @param $files + * @param $self * * @return bool|array * mixed true or array of errors */ public static function formRule($params, $files, $self) { - $errors = array(); + $errors = []; if ($params['membership_type_id'][0] == 0) { $errors['membership_type_id'] = ts('Oops. It looks like you are trying to change the membership type while renewing the membership. Please click the "change membership type" link, and select a Membership Organization.'); } @@ -436,7 +428,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { // The fields in Renewal form come into this routine in $params array. 'renewal_date' is in the form // We process both the dates before comparison using CRM utils so that they are in same date format if (isset($params['renewal_date'])) { - if (CRM_Utils_Date::processDate($params['renewal_date']) < CRM_Utils_Date::processDate($joinDate)) { + if ($params['renewal_date'] < $joinDate) { $errors['renewal_date'] = ts('Renewal date must be the same or later than Member since (Join Date).'); } } @@ -467,18 +459,18 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { try { $this->submit(); - $statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $this->membershipTypeName, 2 => $this->_memberDisplayName)); + $statusMsg = ts('%1 membership for %2 has been renewed.', [1 => $this->membershipTypeName, 2 => $this->_memberDisplayName]); if ($this->endDate) { - $statusMsg .= ' ' . ts('The new membership End Date is %1.', array( + $statusMsg .= ' ' . ts('The new membership End Date is %1.', [ 1 => CRM_Utils_Date::customFormat(substr($this->endDate, 0, 8)), - )); + ]); } if ($this->isMailSent) { - $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array( + $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', [ 1 => $this->_contributorEmail, - )); + ]); return $statusMsg; } return $statusMsg; @@ -502,8 +494,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->storeContactFields($this->_params); $this->beginPostProcess(); $now = CRM_Utils_Date::getToday(NULL, 'YmdHis'); - $this->convertDateFieldsToMySQL($this->_params); - $this->assign('receive_date', $this->_params['receive_date']); + $this->assign('receive_date', CRM_Utils_Array::value('receive_date', $this->_params, date('Y-m-d H:i:s'))); $this->processBillingAddress(); list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID')); $this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, @@ -570,7 +561,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->assign('trxn_id', $result['trxn_id']); } - $renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = CRM_Utils_Date::processDate($this->_params['renewal_date']) : NULL; + $renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = $this->_params['renewal_date'] : NULL; // check for test membership. $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test'); @@ -614,7 +605,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})"; //create line items - $lineItem = array(); + $lineItem = []; $this->_params = $this->setPriceSetParameters($this->_params); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$this->_priceSetId], NULL, $this->_priceSetId @@ -637,10 +628,10 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { if ($this->_contributorContactID != $this->_contactID) { $this->_params['contribution_contact_id'] = $this->_contributorContactID; if (!empty($this->_params['soft_credit_type_id'])) { - $this->_params['soft_credit'] = array( + $this->_params['soft_credit'] = [ 'soft_credit_type_id' => $this->_params['soft_credit_type_id'], 'contact_id' => $this->_contactID, - ); + ]; } } $this->_params['contact_id'] = $this->_contactID; @@ -648,10 +639,10 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { // not a great pattern & ideally it would not receive as a reference. We assign our params as a // temporary variable to avoid e-notice & to make it clear to future refactorer that // this function is NOT reliant on that var being set - $temporaryParams = array_merge($this->_params, array( + $temporaryParams = array_merge($this->_params, [ 'membership_id' => $membership->id, 'contribution_recur_id' => $contributionRecurID, - )); + ]); //Remove `tax_amount` if it is not calculated. if (CRM_Utils_Array::value('tax_amount', $temporaryParams) === 0) { unset($temporaryParams['tax_amount']); @@ -671,7 +662,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $this->_id, FALSE, $this->_memType); // retrieve custom data - $customFields = $customValues = $fo = array(); + $customFields = $customValues = $fo = []; foreach ($this->_groupTree as $groupID => $group) { if ($groupID == 'info') { continue; @@ -681,10 +672,10 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $customFields["custom_{$k}"] = $field; } } - $members = array(array('member_id', '=', $this->_membershipId, 0, 0)); + $members = [['member_id', '=', $this->_membershipId, 0, 0]]; // check whether its a test drive if ($this->_mode == 'test') { - $members[] = array('member_test', '=', 1, 0, 0); + $members[] = ['member_test', '=', 1, 0, 0]; } CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members); @@ -715,7 +706,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { } list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate( - array( + [ 'groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_receiptContactId, @@ -723,7 +714,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test', - ) + ] ); } }