game/_incl_data/class/Model/EkrExchangeRates.php

38 lines
740 B
PHP
Raw Normal View History

<?php
namespace Model;
use Core\Db;
class EkrExchangeRates
{
/**
* @var array|false
*/
private $today;
public function __construct()
{
$this->today = Db::getRow('select RUB, USD, from_unixtime(id, ?) as date from ekr_exchange_rates order by id desc limit 1', ['%d.%m.%Y']);
if (empty($this->today)) {
$this->today = ['RUB' => 0, 'USD' => 0, 'date' => '00.00.0000'];
}
}
public function oneEkrInUSD(): float
{
return round($this->today['RUB'] / $this->today['USD'], 2);
}
public function oneEkrInRUB(): float
{
return $this->today['RUB'];
}
public function date(): string
{
return $this->today['date'];
}
}