<?php

namespace App\System\Model;
use App\System\Basic\beModel;

class CurrencyModel extends beModel {
    public $table = "be_currencies";
    public $primary_key = "cid";
    public static $beCurrencies = [];
    //@ioncube.dk beEncrypt("be_diyocp","beGetCurrencies") -> "d08469124454c8a6bcc63d0b95280652" RANDOM
    public static function beGetCurrencies($select,$cid = 0,$key = "cid"){
        $currencies = [];
        if($cid > 0){
            $currencies = self::beSelect($select)->beWhere("cid",$cid)->beGet();
        }
        else{
            $currencieslist = self::beSelect($select)->beGetAll();
            foreach($currencieslist as $currencie){
                $currencies[$currencie[$key]] = $currencie;
            }
        }
        return $currencies;
    }
    //@ioncube.dk beEncrypt("be_diyocp","beConvertCurrencie") -> "ffd211cc8aa1bbcf99ad3c01c6226712" RANDOM
    public static function beConvertCurrencie($price,$cur1,$cur2){
        if(!self::$beCurrencies){
            self::$beCurrencies = self::beGetCurrencies("cid,crate");
            $currencies = self::$beCurrencies;
        }
        else{
            $currencies = self::$beCurrencies;
        }
        return round(($price*$currencies[$cur1]["crate"])/$currencies[$cur2]["crate"],2);
    }
}

?>