Skip to content

Commit

Permalink
Merge pull request #19072 from eileenmcnaughton/url
Browse files Browse the repository at this point in the history
dev/financial#157 [REF] Extract functions
  • Loading branch information
seamuslee001 authored Dec 4, 2020
2 parents 901b4a0 + 9ae94cf commit 53bc1b8
Showing 1 changed file with 48 additions and 25 deletions.
73 changes: 48 additions & 25 deletions CRM/Admin/Form/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,18 @@ public function setDeleteMessage() {
$this->deleteMessage = ts('Deleting this Payment Processor may result in some transaction pages being rendered inactive.') . ' ' . ts('Do you want to continue?');
}

/**
* Preprocess the form.
*
* @throws \CRM_Core_Exception
*/
public function preProcess() {
parent::preProcess();

if ($this->_id) {
$this->_paymentProcessorType = CRM_Utils_Request::retrieve('pp', 'String', $this, FALSE, NULL);
if (!$this->_paymentProcessorType) {
$this->_paymentProcessorType = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'payment_processor_type_id'
);
}
$this->set('pp', $this->_paymentProcessorType);
}
else {
$this->_paymentProcessorType = CRM_Utils_Request::retrieve('pp', 'String', $this, TRUE, NULL);
}

$this->setPaymentProcessorTypeID();
$this->setPaymentProcessor();
$this->assign('ppType', $this->_paymentProcessorType);
$ppTypeName = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
$this->_paymentProcessorType,
'name'
);
$this->assign('ppTypeName', $ppTypeName);

$this->_paymentProcessorDAO = new CRM_Financial_DAO_PaymentProcessorType();
$this->_paymentProcessorDAO->id = $this->_paymentProcessorType;

$this->_paymentProcessorDAO->find(TRUE);
$this->assign('ppTypeName', $this->_paymentProcessorDAO->name);

if ($this->_id) {
$refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor',
Expand Down Expand Up @@ -317,7 +301,7 @@ public static function formRule($fields) {
*
* @return bool
*/
public static function checkSection(&$fields, &$errors, $section = NULL) {
public static function checkSection(&$fields, &$errors, $section = NULL): bool {
$names = ['user_name'];

$present = FALSE;
Expand Down Expand Up @@ -507,4 +491,43 @@ public function updatePaymentProcessor(&$values, $domainID, $test) {
civicrm_api3('PaymentProcessor', 'create', $params);
}

/**
* Set the payment processor type id as a form property
*
* @throws \CRM_Core_Exception
*/
protected function setPaymentProcessorTypeID(): void {
if ($this->_id) {
$this->_paymentProcessorType = CRM_Utils_Request::retrieve('pp', 'String', $this, FALSE, NULL);
if (!$this->_paymentProcessorType) {
$this->_paymentProcessorType = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'payment_processor_type_id'
);
}
$this->set('pp', $this->_paymentProcessorType);
}
else {
$this->_paymentProcessorType = CRM_Utils_Request::retrieve('pp', 'String', $this, TRUE, NULL);
}
}

/**
* Get the relevant payment processor type id.
*
* @return int
*/
protected function getPaymentProcessorTypeID(): int {
return (int) $this->_paymentProcessorType;
}

/**
* Set the payment processor as a form property.
*/
protected function setPaymentProcessor(): void {
$this->_paymentProcessorDAO = new CRM_Financial_DAO_PaymentProcessorType();
$this->_paymentProcessorDAO->id = $this->getPaymentProcessorTypeID();
$this->_paymentProcessorDAO->find(TRUE);
}

}

0 comments on commit 53bc1b8

Please sign in to comment.