classes/XLite/Model/MoneyModificator.php line 11

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.  * Money modificator
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table  (name="money_modificators")
  13.  */
  14. class MoneyModificator extends \XLite\Model\AEntity
  15. {
  16.     /**
  17.      * ID
  18.      *
  19.      * @var integer
  20.      *
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue (strategy="AUTO")
  23.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  24.      */
  25.     protected $id;
  26.     /**
  27.      * Class name
  28.      *
  29.      * @var string
  30.      *
  31.      * @ORM\Column (type="string")
  32.      */
  33.     protected $class;
  34.     /**
  35.      * Method-modificator
  36.      *
  37.      * @var string
  38.      *
  39.      * @ORM\Column (type="string", length=64)
  40.      */
  41.     protected $modificator 'modifyMoney';
  42.     /**
  43.      * Method-validator
  44.      *
  45.      * @var string
  46.      *
  47.      * @ORM\Column (type="string", length=64)
  48.      */
  49.     protected $validator '';
  50.     /**
  51.      * Position
  52.      *
  53.      * @var integer
  54.      *
  55.      * @ORM\Column (type="integer")
  56.      */
  57.     protected $position 0;
  58.     /**
  59.      * Behavior limitation
  60.      *
  61.      * @var string
  62.      *
  63.      * @ORM\Column (type="string", length=64)
  64.      */
  65.     protected $behavior '';
  66.     /**
  67.      * Purpose limitation
  68.      *
  69.      * @var string
  70.      *
  71.      * @ORM\Column (type="string", length=64)
  72.      */
  73.     protected $purpose '';
  74.     /**
  75.      * Apply
  76.      *
  77.      * @param float                $value     Property value
  78.      * @param \XLite\Model\AEntity $model     Model
  79.      * @param string               $property  Model's property
  80.      * @param array                $behaviors Behaviors
  81.      * @param string               $purpose   Purpose
  82.      *
  83.      * @return float
  84.      */
  85.     public function apply($value\XLite\Model\AEntity $model$property, array $behaviors$purpose)
  86.     {
  87.         $class $this->getClass();
  88.         if (class_exists($class)) {
  89.             $validationMethod $this->getValidator();
  90.             $calculateMethod $this->getModificator();
  91.             if (!$validationMethod || $class::$validationMethod($model$property$behaviors$purpose)) {
  92.                 $value $class::$calculateMethod($value$model$property$behaviors$purpose);
  93.             }
  94.         }
  95.         return $value;
  96.     }
  97.     /**
  98.      * Get id
  99.      *
  100.      * @return integer
  101.      */
  102.     public function getId()
  103.     {
  104.         return $this->id;
  105.     }
  106.     /**
  107.      * Set class
  108.      *
  109.      * @param string $class
  110.      * @return MoneyModificator
  111.      */
  112.     public function setClass($class)
  113.     {
  114.         $this->class $class;
  115.         return $this;
  116.     }
  117.     /**
  118.      * Get class
  119.      *
  120.      * @return string
  121.      */
  122.     public function getClass()
  123.     {
  124.         return $this->class;
  125.     }
  126.     /**
  127.      * Set modificator
  128.      *
  129.      * @param string $modificator
  130.      * @return MoneyModificator
  131.      */
  132.     public function setModificator($modificator)
  133.     {
  134.         $this->modificator $modificator;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Get modificator
  139.      *
  140.      * @return string
  141.      */
  142.     public function getModificator()
  143.     {
  144.         return $this->modificator;
  145.     }
  146.     /**
  147.      * Set validator
  148.      *
  149.      * @param string $validator
  150.      * @return MoneyModificator
  151.      */
  152.     public function setValidator($validator)
  153.     {
  154.         $this->validator $validator;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get validator
  159.      *
  160.      * @return string
  161.      */
  162.     public function getValidator()
  163.     {
  164.         return $this->validator;
  165.     }
  166.     /**
  167.      * Set position
  168.      *
  169.      * @param integer $position
  170.      * @return MoneyModificator
  171.      */
  172.     public function setPosition($position)
  173.     {
  174.         $this->position $position;
  175.         return $this;
  176.     }
  177.     /**
  178.      * Get position
  179.      *
  180.      * @return integer
  181.      */
  182.     public function getPosition()
  183.     {
  184.         return $this->position;
  185.     }
  186.     /**
  187.      * Set behavior
  188.      *
  189.      * @param string $behavior
  190.      * @return MoneyModificator
  191.      */
  192.     public function setBehavior($behavior)
  193.     {
  194.         $this->behavior $behavior;
  195.         return $this;
  196.     }
  197.     /**
  198.      * Get behavior
  199.      *
  200.      * @return string
  201.      */
  202.     public function getBehavior()
  203.     {
  204.         return $this->behavior;
  205.     }
  206.     /**
  207.      * Set purpose
  208.      *
  209.      * @param string $purpose
  210.      * @return MoneyModificator
  211.      */
  212.     public function setPurpose($purpose)
  213.     {
  214.         $this->purpose $purpose;
  215.         return $this;
  216.     }
  217.     /**
  218.      * Get purpose
  219.      *
  220.      * @return string
  221.      */
  222.     public function getPurpose()
  223.     {
  224.         return $this->purpose;
  225.     }
  226. }