core/lib/Thelia/Model/Currency.php line 19

  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Thelia\Model;
  12. use Propel\Runtime\Connection\ConnectionInterface;
  13. use Propel\Runtime\Exception\PropelException;
  14. use Thelia\Model\Base\Currency as BaseCurrency;
  15. class Currency extends BaseCurrency
  16. {
  17.     use \Thelia\Model\Tools\PositionManagementTrait;
  18.     protected static $defaultCurrency null;
  19.     public static function getDefaultCurrency()
  20.     {
  21.         if (null === self::$defaultCurrency) {
  22.             self::$defaultCurrency CurrencyQuery::create()->findOneByByDefault(1);
  23.             if (null === self::$defaultCurrency) {
  24.                 throw new \RuntimeException('No default currency is defined. Please define one.');
  25.             }
  26.         }
  27.         return self::$defaultCurrency;
  28.     }
  29.     /**
  30.      * {@inheritDoc}
  31.      */
  32.     public function preInsert(ConnectionInterface $con null)
  33.     {
  34.         parent::preInsert($con);
  35.         // Set the current position for the new object
  36.         $this->setPosition($this->getNextPosition());
  37.         return true;
  38.     }
  39.     /**
  40.      * Get the [rate] column value.
  41.      *
  42.      * @throws PropelException
  43.      *
  44.      * @return float
  45.      */
  46.     public function getRate()
  47.     {
  48.         if (false === filter_var($this->rate\FILTER_VALIDATE_FLOAT)) {
  49.             throw new PropelException('Currency::rate is not float value');
  50.         }
  51.         return $this->rate;
  52.     }
  53. }