classes/XLite/Model/Currency.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Currency
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table (name="currencies",
  13.  *      indexes = {
  14.  *          @ORM\Index (name="code", columns={"code"})
  15.  *      }
  16.  * )
  17.  */
  18. class Currency extends \XLite\Model\Base\I18n
  19. {
  20.     public const ROUNDUP_NONE 'N';
  21.     /**
  22.      * Currency unique id (ISO 4217 number)
  23.      *
  24.      * @var integer
  25.      *
  26.      * @ORM\Id
  27.      * @ORM\Column (type="integer", options={ "unsigned": true })
  28.      */
  29.     protected $currency_id;
  30.     /**
  31.      * Currency code (ISO 4217 alpha-3)
  32.      *
  33.      * @var string
  34.      *
  35.      * @ORM\Column (type="string", options={ "fixed": true }, length=3, unique=true)
  36.      */
  37.     protected $code;
  38.     /**
  39.      * Symbol
  40.      *
  41.      * @var string
  42.      *
  43.      * @ORM\Column (type="string", length=16)
  44.      */
  45.     protected $symbol;
  46.     /**
  47.      * Prefix
  48.      *
  49.      * @var string
  50.      *
  51.      * @ORM\Column (type="string", length=32)
  52.      */
  53.     protected $prefix '';
  54.     /**
  55.      * Suffix
  56.      *
  57.      * @var string
  58.      *
  59.      * @ORM\Column (type="string", length=32)
  60.      */
  61.     protected $suffix '';
  62.     /**
  63.      * Number of digits after the decimal separator.
  64.      *
  65.      * @var integer
  66.      *
  67.      * @ORM\Column (type="smallint")
  68.      */
  69.     protected $e 0;
  70.     /**
  71.      * Decimal part delimiter
  72.      * @var string
  73.      *
  74.      * @ORM\Column (type="string", length=8)
  75.      */
  76.     protected $decimalDelimiter '.';
  77.     /**
  78.      * Thousand delimier
  79.      *
  80.      * @var string
  81.      *
  82.      * @ORM\Column (type="string", length=8)
  83.      */
  84.     protected $thousandDelimiter '';
  85.     /**
  86.      * Orders
  87.      *
  88.      * @var \Doctrine\Common\Collections\Collection
  89.      *
  90.      * @ORM\OneToMany (targetEntity="XLite\Model\Order", mappedBy="currency")
  91.      */
  92.     protected $orders;
  93.     /**
  94.      * Countries
  95.      *
  96.      * @var \Doctrine\Common\Collections\Collection
  97.      *
  98.      * @ORM\OneToMany (targetEntity="XLite\Model\Country", mappedBy="currency", cascade={"all"})
  99.      */
  100.     protected $countries;
  101.     /**
  102.      * RoundUp
  103.      *
  104.      * @var string
  105.      *
  106.      * @ORM\Column (type="string", options={"default" : "N"})
  107.      */
  108.     protected $roundUp self::ROUNDUP_NONE;
  109.     /**
  110.      * @var \Doctrine\Common\Collections\Collection
  111.      *
  112.      * @ORM\OneToMany (targetEntity="XLite\Model\CurrencyTranslation", mappedBy="owner", cascade={"all"})
  113.      */
  114.     protected $translations;
  115.     /**
  116.      * Set currency Id
  117.      *
  118.      * @param integer $value Currency id
  119.      * TODO - Doctrine is not generate setter for identifier. We must reworkt it
  120.      *
  121.      * @return void
  122.      */
  123.     public function setCurrencyId($value)
  124.     {
  125.         $this->currency_id $value;
  126.     }
  127.     /**
  128.      * Get urrency symbol to display in interface
  129.      *
  130.      * @param boolean $strict Flag: true - return only prefix or suffix, false - return code if prefix and suffix isn't specified for currency
  131.      *
  132.      * @return string
  133.      */
  134.     public function getCurrencySymbol($strict true)
  135.     {
  136.         return $this->getPrefix() ?: ($this->getSuffix() ?: (!$strict $this->getCode() : ''));
  137.     }
  138.     /**
  139.      * Round value
  140.      *
  141.      * @param float $value Value
  142.      *
  143.      * @return float
  144.      */
  145.     public function roundValue($value)
  146.     {
  147.         return \XLite\Logic\Math::getInstance()->roundByCurrency($value$this);
  148.     }
  149.     /**
  150.      * Round value as integer
  151.      *
  152.      * @param float $value Value
  153.      *
  154.      * @return integer
  155.      */
  156.     public function roundValueAsInteger($value)
  157.     {
  158.         return intval(round($this->roundValue($value) * pow(10$this->getE()), 0));
  159.     }
  160.     /**
  161.      * Convert integer to float
  162.      *
  163.      * @param integer $value Value
  164.      *
  165.      * @return float
  166.      */
  167.     public function convertIntegerToFloat($value)
  168.     {
  169.         return $value pow(10$this->getE());
  170.     }
  171.     /**
  172.      * Format value
  173.      *
  174.      * @param float $value Value
  175.      *
  176.      * @return string
  177.      */
  178.     public function formatValue($value)
  179.     {
  180.         return \XLite\Logic\Math::getInstance()->formatValue($value$this);
  181.     }
  182.     /**
  183.      * Get minimum value
  184.      *
  185.      * @return float
  186.      */
  187.     public function getMinimumValue()
  188.     {
  189.         return $this->convertIntegerToFloat(1);
  190.     }
  191.     /**
  192.      * Constructor
  193.      *
  194.      * @param array $data Entity properties OPTIONAL
  195.      *
  196.      * @return void
  197.      */
  198.     public function __construct(array $data = [])
  199.     {
  200.         $this->orders    = new \Doctrine\Common\Collections\ArrayCollection();
  201.         $this->countries = new \Doctrine\Common\Collections\ArrayCollection();
  202.         parent::__construct($data);
  203.     }
  204.     /**
  205.      * Format value as parts list
  206.      *
  207.      * @param float $value Value
  208.      *
  209.      * @return array
  210.      */
  211.     public function formatParts($value)
  212.     {
  213.         return \XLite\Logic\Math::getInstance()->formatParts($value$this);
  214.     }
  215.     /**
  216.      * Get currency_id
  217.      *
  218.      * @return integer
  219.      */
  220.     public function getCurrencyId()
  221.     {
  222.         return $this->currency_id;
  223.     }
  224.     /**
  225.      * Set code
  226.      *
  227.      * @param string $code
  228.      * @return Currency
  229.      */
  230.     public function setCode($code)
  231.     {
  232.         $this->code $code;
  233.         return $this;
  234.     }
  235.     /**
  236.      * Get code
  237.      *
  238.      * @return string
  239.      */
  240.     public function getCode()
  241.     {
  242.         return $this->code;
  243.     }
  244.     /**
  245.      * Set symbol
  246.      *
  247.      * @param string $symbol
  248.      * @return Currency
  249.      */
  250.     public function setSymbol($symbol)
  251.     {
  252.         $this->symbol $symbol;
  253.         return $this;
  254.     }
  255.     /**
  256.      * Get symbol
  257.      *
  258.      * @return string
  259.      */
  260.     public function getSymbol()
  261.     {
  262.         return $this->symbol;
  263.     }
  264.     /**
  265.      * Set prefix
  266.      *
  267.      * @param string $prefix
  268.      * @return Currency
  269.      */
  270.     public function setPrefix($prefix)
  271.     {
  272.         $this->prefix $prefix;
  273.         return $this;
  274.     }
  275.     /**
  276.      * Get prefix
  277.      *
  278.      * @return string
  279.      */
  280.     public function getPrefix()
  281.     {
  282.         return $this->prefix;
  283.     }
  284.     /**
  285.      * Set suffix
  286.      *
  287.      * @param string $suffix
  288.      * @return Currency
  289.      */
  290.     public function setSuffix($suffix)
  291.     {
  292.         $this->suffix $suffix;
  293.         return $this;
  294.     }
  295.     /**
  296.      * Get suffix
  297.      *
  298.      * @return string
  299.      */
  300.     public function getSuffix()
  301.     {
  302.         return $this->suffix;
  303.     }
  304.     /**
  305.      * Set e
  306.      *
  307.      * @param smallint $e
  308.      * @return Currency
  309.      */
  310.     public function setE($e)
  311.     {
  312.         $this->$e;
  313.         return $this;
  314.     }
  315.     /**
  316.      * Get e
  317.      *
  318.      * @return smallint
  319.      */
  320.     public function getE()
  321.     {
  322.         return $this->e;
  323.     }
  324.     /**
  325.      * Set decimalDelimiter
  326.      *
  327.      * @param string $decimalDelimiter
  328.      * @return Currency
  329.      */
  330.     public function setDecimalDelimiter($decimalDelimiter)
  331.     {
  332.         $this->decimalDelimiter $decimalDelimiter;
  333.         return $this;
  334.     }
  335.     /**
  336.      * Get decimalDelimiter
  337.      *
  338.      * @return string
  339.      */
  340.     public function getDecimalDelimiter()
  341.     {
  342.         return $this->decimalDelimiter;
  343.     }
  344.     /**
  345.      * Set thousandDelimiter
  346.      *
  347.      * @param string $thousandDelimiter
  348.      * @return Currency
  349.      */
  350.     public function setThousandDelimiter($thousandDelimiter)
  351.     {
  352.         $this->thousandDelimiter $thousandDelimiter;
  353.         return $this;
  354.     }
  355.     /**
  356.      * Get thousandDelimiter
  357.      *
  358.      * @return string
  359.      */
  360.     public function getThousandDelimiter()
  361.     {
  362.         return $this->thousandDelimiter;
  363.     }
  364.     /**
  365.      * Add orders
  366.      *
  367.      * @param \XLite\Model\Order $orders
  368.      * @return Currency
  369.      */
  370.     public function addOrders(\XLite\Model\Order $orders)
  371.     {
  372.         $this->orders[] = $orders;
  373.         return $this;
  374.     }
  375.     /**
  376.      * Get orders
  377.      *
  378.      * @return \Doctrine\Common\Collections\Collection
  379.      */
  380.     public function getOrders()
  381.     {
  382.         return $this->orders;
  383.     }
  384.     /**
  385.      * Add countries
  386.      *
  387.      * @param \XLite\Model\Country $countries
  388.      * @return Currency
  389.      */
  390.     public function addCountries(\XLite\Model\Country $countries)
  391.     {
  392.         $this->countries[] = $countries;
  393.         return $this;
  394.     }
  395.     /**
  396.      * Get countries
  397.      *
  398.      * @return \Doctrine\Common\Collections\Collection
  399.      */
  400.     public function getCountries()
  401.     {
  402.         return $this->countries;
  403.     }
  404.     /**
  405.      * Return RoundUp
  406.      *
  407.      * @return string
  408.      */
  409.     public function getRoundUp()
  410.     {
  411.         return $this->roundUp;
  412.     }
  413.     /**
  414.      * Set RoundUp
  415.      *
  416.      * @param string $roundUp
  417.      *
  418.      * @return $this
  419.      */
  420.     public function setRoundUp($roundUp)
  421.     {
  422.         $this->roundUp $roundUp;
  423.         return $this;
  424.     }
  425. }