Merged [47046]: Minor optimisation to BankAccountField and added methods to get specific parts of the account number.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60477 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Hayden Smith 2008-08-12 03:54:54 +00:00
parent e4654c4ab6
commit ea28c7b9cc

View File

@ -9,6 +9,12 @@ class BankAccountField extends FormField {
protected $bankCode;
protected $branchCode;
/**
* @var array $valueArr Stores value in associative array-format, with:
* BankCode, BranchCode, AccountNumber, AccountSuffix
*/
protected $valueArr = array();
/**
* HACK Proper requiring of compositefields would involve serious restructuring.
*/
@ -24,6 +30,9 @@ class BankAccountField extends FormField {
$this->bankCode = $bankCode;
$this->branchCode = $branchCode;
// needs to be passed through setValue() to populate $valueArr
if($value) $this->setValue($value);
parent::__construct($name, $title, $value, $form);
}
@ -31,13 +40,8 @@ class BankAccountField extends FormField {
$field = new FieldGroup($this->name);
$field->setID("{$this->name}_Holder");
$valueArr = array();
list(
$valueArr['BankCode'],
$valueArr['BranchCode'],
$valueArr['AccountNumber'],
$valueArr['AccountSuffix']
) = explode(" ",$this->value);
$valueArr = $this->valueArray;
$valueArr = self::convert_format_nz($valueArr);
$field->push($n1 = new NumericField($this->name.'[BankCode]', '', $valueArr['BankCode'], 2));
@ -56,8 +60,51 @@ class BankAccountField extends FormField {
public function setValue($value) {
$this->value = self::join_bank_number($value);
$this->valueArr = array();
list(
$this->valueArr['BankCode'],
$this->valueArr['BranchCode'],
$this->valueArr['AccountNumber'],
$this->valueArr['AccountSuffix']
) = explode(" ",$this->value);
}
/**
* @return string
*/
function getBankCode() {
return $this->valueArr['BankCode'];
}
/**
* @return string
*/
function getBranchCode() {
return $this->valueArr['BranchCode'];
}
/**
* @return string
*/
function getAccountNumber() {
return $this->valueArr['AccountNumber'];
}
/**
* @return string
*/
function getAccountSuffix() {
return $this->valueArr['AccountSuffix'];
}
/**
* Makes sure the number is a string with spaces instead of hyphens,
* and adjusts to new format (2-4-8-3) by using conver_format_nz().
*
* @param mixed $value String- or Array-representation of full bank-account-number.
* @return string
*/
public static function join_bank_number($value) {
if(is_array($value)) {
$value = self::convert_format_nz($value);