Вход Регистрация
Файл: mg-core/lib/int2str.php
Строк: 69
<?php
/**
 * Класс int2str - предназначен для подстановки правильного окончания к числительным.
 *
 * @author Авдеев Марк <mark-avdeev@mail.ru>
 * @package moguta.cms
 * @subpackage Libraries
 */
class int2str {

  private 
$rank = array(
    
=> array('рубль''рубля''рублей'),
    
=> array('тысяча''тысячи''тысяч'),
    
=> array('миллион''миллиона''миллионов'),
    
=> array('миллиард''миллиарда''миллиардов'),
    
=> array('триллион''триллиона''триллионов')
  );
  private 
$A0_9 = array(=> 'ноль'=> 'один'=> 'два'=> 'три'=> 'четыре'=> 'пять'=> 'шесть'=> 'семь'=> 'восемь'=> 'девять');
  private 
$A0_9_ = array(=> 'ноль'=> 'одна'=> 'две'=> 'три'=> 'четыре'=> 'пять'=> 'шесть'=> 'семь'=> 'восемь'=> 'девять');
  private 
$A10_19 = array(10 => 'десять'11 => 'одиннадцать'12 => 'двенадцать'13 => 'тринадцать'14 => 'четырнадцать'15 => 'пятнадцать',
    
16 => 'шестнадцать'17 => 'семнадцать'18 => 'восемнадцать'19 => 'девятнадцать');
  private 
$A20_90 = array(=> 'двадцать'=> 'тридцать'=> 'сорок'=> 'пятьдесят'=> 'шестьдесят'=> 'семьдесят'=> 'восемьдесят',
    
=> 'девяносто');
  private 
$A100_900 = array(=> 'сто'=> 'двести'=> 'триста'=> 'четыреста'=> 'пятьсот'=> 'шестьсот'=> 'семьсот'=> 'восемьсот',
    
=> 'девятьсот');
  public 
$num;
  public 
$triada;
  public 
$out;
  public 
$kop '';
  public 
$kopShort 'коп.';
  public 
$currencyString ' рублей';

  function 
__construct($x,$kop=true$currencyString =' рублей'$kopShort ='коп.') {
    
$this->kopShort $kopShort;
    
$this->currencyString $currencyString;
    
$propertyOrder MG::getOption('propertyOrder');
    
$propertyOrder stripslashes($propertyOrder);
    
$propertyOrder unserialize($propertyOrder);   
    
$rankUser explode(",",$propertyOrder["currency"]);   
    if(
count($rankUser)==3){      
      
$this->rank[1] = $rankUser;       
    }
    
$this->num $this->prepare($x);
    
$this->test();
    
$this->rub($kop);
  }

  function 
prepare($x) {
    
$search = array(',''/');
    
$x str_replace($search'.'$x);
    
$x explode('.'$x);
    if (empty(
$x[1])) {
      
$this->kop '00';
    } else {
      
$this->kop $x[1];
    }

    return 
$x[0];
  }

  function 
add_null($x) {
    switch (
$x) {
      case 
0;
        
$v "".$this->num;
        break;
      case 
1:$v "0".$this->num;
        break;
      case 
2:$v "00".$this->num;
        break;
    }
    
$this->num $v;
  }

  function 
test() {
    
$x mb_strlen($this->num);
    if (
$x<=3) {
      
$z 1;
      
$this->add_null(3-$x);
    } else {
      
$y $x%3;
      if (
$y==0) {
        
$z $x/3;
      } else {
        
$this->add_null(3-$y);
        
$z = ($x-$y)/3+1;
      }
    }
    return 
$this->triada $z;
  }

  private function 
lexem($x) {
    if (
$x==11||$x==12||$x==13||$x==14) {
      
$x 2;
    } else {
      
$x substr($x, -1);
      if (
$x==1):$x 0;
      elseif (
$x>1&&$x<=4):$x 1;
      else:
$x 2;
      endif;
    }
    return 
$x;
  }

  function 
parse($x$i) {
    
$a substr($x01);
    
$b substr($x12);
    
$c substr($x11);
    
$d substr($x21);

    if (
$i==2) {
      
$A $this->A0_9_[$d];
    } else {
      
$A $this->A0_9[$d];
    }
    if (
$x=='000'&&$i==1) {
      return 
$string $this->currencyString;
    } else {
      if (
$x=='000') {
        return 
$string '';
      }
    }
    if (
$a>=1) {
      
$string $this->A100_900[$a];
    }
    if (
$b<=9&&$b!=0) {
      
$string.=' '.$A;
    }
    if (
$b<=19) {
      
$string.=' '.$this->A10_19[$b];
    }
    if (
$b>=20&&$d==0) {
      
$string.=' '.$this->A20_90[$c];
    }
    if (
$b>=20&&$d!=0) {
      
$string.=' '.$this->A20_90[$c].' '.$A;
    }

    return 
$string.' '.$this->rank[$i][$this->lexem($b)].' ';
  }

  function 
rub($kop true) {
    for (
$i $this->triada$i>0$i--) {
      
$x.=$this->parse(substr($this->num, -$i*33), $i);
    }
    if(
$kop){
      
$this->rub ucfirst(trim($x)).' '.$this->kop.' '.$this->kopShort;    
    }else{
      
$this->rub ucfirst(trim($x));    
    }
  }

  function 
ucfirst($str) {
    
$tmp preg_split("//u"$str2PREG_SPLIT_NO_EMPTY);
    return 
mb_convert_case(
        
str_replace("i""İ"$tmp[0]), MB_CASE_TITLE"UTF-8").
        
$tmp[1];
 }

}
Онлайн: 0
Реклама