File: /www/exchange0old/exchange/admin/validator/Valid.php
<?php
class Valid {
public static function getOwnAccounts(){
$accountCurrency = array();
$accountCurrency['44513401'] = 'EUR';
$accountCurrency['44513402'] = 'EUR';
$accountCurrency['44513403'] = 'EUR';
$accountCurrency['44513404'] = 'EUR';
$accountCurrency['33049957'] = 'GBP';
$accountCurrency['73119157'] = 'GBP';
$accountCurrency['73796558'] = 'GBP';
$accountCurrency['44513405'] = 'USD';
$accountCurrency['44513406'] = 'USD';
$accountCurrency['IE86BARC99021244513401'] = 'EUR';
$accountCurrency['IE59BARC99021244513402'] = 'EUR';
$accountCurrency['GB17BARC20060544067333'] = 'EUR';
$accountCurrency['GB66BARC20035373119157'] = 'GBP';
return $accountCurrency;
}
public static function getLDC()
{
$accountCurrency = array();
$accountCurrency['IE59BARC99021244513402'] = 'EUR';
$accountCurrency['IE86BARC99021244513401'] = 'EUR';
return $accountCurrency;
}
public static function not_empty($value)
{
if (is_object($value) AND $value instanceof ArrayObject)
{
// Get the array from the ArrayObject
$value = $value->getArrayCopy();
}
// Value cannot be NULL, FALSE, '', or an empty array
return ! in_array($value, array(NULL, FALSE, '', array()), TRUE);
}
public static function min_length($value, $length)
{
return mb_strlen($value) >= $length;
}
public static function max_length($value, $length)
{
return mb_strlen($value) <= $length;
}
public static function equals($value, $required)
{
return ($value === $required);
}
public static function in_values($value, array $required)
{
return in_array($value,$required);
}
public static function digit($str, $utf8 = FALSE)
{
if ($utf8 === TRUE)
{
return (bool) preg_match('/^\pN++$/uD', $str);
}
else
{
return (is_int($str) AND $str >= 0) OR ctype_digit($str);
}
}
public static function numeric($str)
{
// Get the decimal point for the current locale
list($decimal) = array_values(localeconv());
// A lookahead is used to make sure the string contains at least one digit (before or after the decimal point)
return (bool) preg_match('/^-?+(?=.*[0-9])[0-9]*+'.preg_quote($decimal).'?+[0-9]*+$/D', (string) $str);
}
public static function range($number, $min, $max, $step = NULL)
{
if ($number <= $min OR $number >= $max)
{
// Number is outside of range
return FALSE;
}
if ( ! $step)
{
// Default to steps of 1
$step = 1;
}
// Check step requirements
return (($number - $min) % $step === 0);
}
public static function decimal($str, $places = 2, $digits = NULL)
{
if ($digits > 0)
{
// Specific number of digits
$digits = '{'.( (int) $digits).'}';
}
else
{
// Any number of digits
$digits = '+';
}
// Get the decimal point for the current locale
list($decimal) = array_values(localeconv());
return (bool) preg_match('/^[+-]?[0-9]'.$digits.preg_quote($decimal).'[0-9]{'.( (int) $places).'}$/D', $str);
}
public static function exact_length($value, $length)
{
if (is_array($length))
{
foreach ($length as $strlen)
{
if (mb_strlen($value) === $strlen)
return TRUE;
}
return FALSE;
}
return mb_strlen($value) === $length;
}
public static function check_account_currency($account,Transaction $object){
$account = trim($account);
$accountCurrency = self::getOwnAccounts();
$ldc = self::getLDC();
if(array_key_exists($account, $ldc))
{
return true;
}
if(array_key_exists($account,$accountCurrency)){
return $accountCurrency[$account]==$object->getData('32A.currency');
}
}
public static function check_account($account){
return array_key_exists(trim($account),self::getOwnAccounts());
}
public static function check_account_if_not_iban($account){
$account = trim($account);
if(strlen($account)>8){
return true;
}
return array_key_exists($account,self::getOwnAccounts());
}
public static function batch_transactions_count(array $transactions, $count){
if(count($transactions)>$count){
return false;
}
}
public static function transaction_sequence(array $transactions){
for($i=0;$i<count($transactions);$i++){
if($transactions[$i]->getTransactionId()!=($i+1)){
return 'Incorrect '. ($i+1).' transaction';
}
}
return true;
}
public static function batch_sequence(array $batches){
$prevBatchNumber = null;
foreach($batches as $batch){
$batchNumber = $batch->getId();
if($prevBatchNumber==null){
$prevBatchNumber = $batchNumber;
continue;
}
$neededBtachNumber = $batchNumber-1;
if($neededBtachNumber!=$prevBatchNumber){
return 'Incorrect '. $neededBtachNumber.' batch';
}
$prevBatchNumber = $batchNumber;
}
return true;
}
public static function positive_value($value){
return ($value>0);
}
public static function avoid_same_account($value, $field, Transaction $object){
return ($value != $object->getData($field));
}
} // End Valid