partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

MetaPartParameterCriteria.php (5051B)


      1 <?php
      2 
      3 namespace PartKeepr\PartBundle\Entity;
      4 
      5 use Doctrine\ORM\Mapping as ORM;
      6 use PartKeepr\CoreBundle\Entity\BaseEntity;
      7 use PartKeepr\SiPrefixBundle\Entity\SiPrefix;
      8 use Symfony\Component\Serializer\Annotation\Groups;
      9 
     10 /**
     11  * @ORM\Entity()
     12  */
     13 class MetaPartParameterCriteria extends BaseEntity
     14 {
     15     /**
     16      * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="metaPartParameterCriterias")
     17      *
     18      * @var Part
     19      */
     20     private $part;
     21 
     22     /**
     23      * @ORM\Column(type="string")
     24      * @Groups({"default"})
     25      *
     26      * @var string
     27      */
     28     private $partParameterName;
     29 
     30     /**
     31      * @ORM\Column(type="string")
     32      * @Groups({"default"})
     33      *
     34      * @var string
     35      */
     36     private $operator;
     37 
     38     /**
     39      * @ORM\Column(type="float",nullable=true)
     40      * @Groups({"default"})
     41      *
     42      * @var float
     43      */
     44     private $value;
     45 
     46     /**
     47      * @ORM\Column(type="float",nullable=true)
     48      *
     49      * @var float
     50      */
     51     private $normalizedValue;
     52 
     53     /**
     54      * The SiPrefix of the unit.
     55      *
     56      * @ORM\ManyToOne(targetEntity="PartKeepr\SiPrefixBundle\Entity\SiPrefix")
     57      * @Groups({"default"})
     58      *
     59      * @var SiPrefix
     60      */
     61     private $siPrefix;
     62 
     63     /**
     64      * @ORM\Column(type="string")
     65      * @Groups({"default"})
     66      *
     67      * @var string
     68      */
     69     private $stringValue;
     70 
     71     /**
     72      * The type of the value.
     73      *
     74      * @ORM\Column(type="string")
     75      * @Groups({"default"})
     76      *
     77      * @var string
     78      */
     79     private $valueType;
     80 
     81     /**
     82      * The unit for this type. May be null.
     83      *
     84      * @ORM\ManyToOne(targetEntity="PartKeepr\UnitBundle\Entity\Unit")
     85      * @Groups({"default"})
     86      *
     87      * @var \PartKeepr\UnitBundle\Entity\Unit
     88      */
     89     private $unit;
     90 
     91     public function __construct()
     92     {
     93         $this->setValueType(PartParameter::VALUE_TYPE_STRING);
     94         $this->setStringValue("");
     95     }
     96 
     97     /**
     98      * @return float
     99      */
    100     public function getNormalizedValue()
    101     {
    102         return $this->normalizedValue;
    103     }
    104 
    105     /**
    106      * @param float $normalizedValue
    107      */
    108     public function setNormalizedValue($normalizedValue)
    109     {
    110         $this->normalizedValue = $normalizedValue;
    111     }
    112 
    113     protected function recalculateNormalizedValue()
    114     {
    115         if ($this->getSiPrefix() === null) {
    116             $this->setNormalizedValue($this->getValue());
    117         } else {
    118             $this->setNormalizedValue($this->getSiPrefix()->calculateProduct($this->getValue()));
    119         }
    120     }
    121 
    122     /**
    123      * @return \PartKeepr\UnitBundle\Entity\Unit
    124      */
    125     public function getUnit()
    126     {
    127         return $this->unit;
    128     }
    129 
    130     /**
    131      * @param \PartKeepr\UnitBundle\Entity\Unit $unit
    132      */
    133     public function setUnit($unit = null)
    134     {
    135         $this->unit = $unit;
    136     }
    137 
    138     /**
    139      * @return string
    140      */
    141     public function getValueType()
    142     {
    143         // Fallback to numeric if legacy parameter
    144         if (!in_array($this->valueType, PartParameter::VALUE_TYPES)) {
    145             return PartParameter::VALUE_TYPE_NUMERIC;
    146         }
    147 
    148         return $this->valueType;
    149     }
    150 
    151     /**
    152      * @param string $valueType
    153      */
    154     public function setValueType($valueType)
    155     {
    156         if (!in_array($valueType, PartParameter::VALUE_TYPES)) {
    157             throw new \Exception("Invalid value type given:".$valueType);
    158         }
    159 
    160         $this->valueType = $valueType;
    161     }
    162 
    163     /**
    164      * @return SiPrefix
    165      */
    166     public function getSiPrefix()
    167     {
    168         return $this->siPrefix;
    169     }
    170 
    171     /**
    172      * @param SiPrefix $siPrefix
    173      */
    174     public function setSiPrefix($siPrefix)
    175     {
    176         $this->siPrefix = $siPrefix;
    177         $this->recalculateNormalizedValue();
    178     }
    179 
    180     /**
    181      * @return Part
    182      */
    183     public function getPart()
    184     {
    185         return $this->part;
    186     }
    187 
    188     /**
    189      * @param Part $part
    190      */
    191     public function setPart($part = null)
    192     {
    193         $this->part = $part;
    194     }
    195 
    196     /**
    197      * @return string
    198      */
    199     public function getPartParameterName()
    200     {
    201         return $this->partParameterName;
    202     }
    203 
    204     /**
    205      * @param string $partParameterName
    206      */
    207     public function setPartParameterName($partParameterName)
    208     {
    209         $this->partParameterName = $partParameterName;
    210     }
    211 
    212     /**
    213      * @return string
    214      */
    215     public function getOperator()
    216     {
    217         return $this->operator;
    218     }
    219 
    220     /**
    221      * @param string $operator
    222      */
    223     public function setOperator($operator)
    224     {
    225         $this->operator = $operator;
    226     }
    227 
    228     /**
    229      * @return float
    230      */
    231     public function getValue()
    232     {
    233         return $this->value;
    234     }
    235 
    236     /**
    237      * @param float $value
    238      */
    239     public function setValue($value)
    240     {
    241         $this->value = $value;
    242         $this->recalculateNormalizedValue();
    243     }
    244 
    245     /**
    246      * @return string
    247      */
    248     public function getStringValue()
    249     {
    250         return $this->stringValue;
    251     }
    252 
    253     /**
    254      * @param string $stringValue
    255      */
    256     public function setStringValue($stringValue)
    257     {
    258         $this->stringValue = $stringValue;
    259     }
    260 }