partkeepr

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

SiPrefix.php (3120B)


      1 <?php
      2 
      3 namespace PartKeepr\SiPrefixBundle\Entity;
      4 
      5 use Doctrine\ORM\Mapping as ORM;
      6 use PartKeepr\CoreBundle\Entity\BaseEntity;
      7 use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
      8 use Symfony\Component\Serializer\Annotation\Groups;
      9 use Symfony\Component\Validator\Constraints as Assert;
     10 
     11 /**
     12  * Represents an SI Prefix.
     13  *
     14  * @link http://en.wikipedia.org/wiki/Metric_prefix
     15  *
     16  * @ORM\Entity
     17  * @TargetService(uri="/api/si_prefixes")
     18  */
     19 class SiPrefix extends BaseEntity
     20 {
     21     /**
     22      * The prefix name of the Si-Prefix (e.g. yotta, deca, deci, centi).
     23      *
     24      * @ORM\Column(type="string")
     25      *
     26      * @Assert\Type(type="string")
     27      * @Assert\NotBlank(message="siprefix.prefix.not_blank")
     28      *
     29      * @var string
     30      * @Groups({"default"})
     31      */
     32     private $prefix;
     33 
     34     /**
     35      * The symbol of the Si-Prefix (e.g. m, M, G).
     36      *
     37      * @ORM\Column(type="string",length=2)
     38      *
     39      * @Assert\Type(type="string")
     40      * @Groups({"default"})
     41      *
     42      * @var string
     43      */
     44     private $symbol;
     45 
     46     /**
     47      * The exponent of the Si-Prefix (e.g. milli = 10^-3).
     48      *
     49      * @ORM\Column(type="integer")
     50      * @Assert\Type(type="integer")
     51      * @Groups({"default"})
     52      *
     53      * @var int
     54      */
     55     private $exponent;
     56 
     57     /**
     58      * The base of the Si-Prefix (e.g. 2^-3).
     59      *
     60      * @ORM\Column(type="integer")
     61      * @Assert\Type(type="integer")
     62      * @Groups({"default"})
     63      *
     64      * @var int
     65      */
     66     private $base;
     67 
     68     /**
     69      * Sets the prefix name.
     70      *
     71      * @param string $prefix
     72      */
     73     public function setPrefix($prefix)
     74     {
     75         $this->prefix = $prefix;
     76     }
     77 
     78     /**
     79      * Returns the prefix name.
     80      *
     81      *
     82      * @return string The prefix name
     83      */
     84     public function getPrefix()
     85     {
     86         return $this->prefix;
     87     }
     88 
     89     /**
     90      * Sets the symbol for the prefix.
     91      *
     92      * @param string $symbol The symbol
     93      */
     94     public function setSymbol($symbol)
     95     {
     96         $this->symbol = $symbol;
     97     }
     98 
     99     /**
    100      * Returns the symbol for the prefix.
    101      *
    102      * @return string The symbol
    103      */
    104     public function getSymbol()
    105     {
    106         return $this->symbol;
    107     }
    108 
    109     /**
    110      * Sets the exponent.
    111      *
    112      * @param int $exponent The exponent
    113      */
    114     public function setExponent($exponent)
    115     {
    116         $this->exponent = $exponent;
    117     }
    118 
    119     /**
    120      * Returns the exponent.
    121      *
    122      * @return int The exponent
    123      */
    124     public function getExponent()
    125     {
    126         return $this->exponent;
    127     }
    128 
    129     /**
    130      * Sets the base.
    131      *
    132      * @param int $base The base
    133      */
    134     public function setBase($base)
    135     {
    136         $this->base = $base;
    137     }
    138 
    139     /**
    140      * Returns the base.
    141      *
    142      * @return int The base
    143      */
    144     public function getBase()
    145     {
    146         return $this->base;
    147     }
    148 
    149     /**
    150      * Calculates the product for a given value.
    151      *
    152      * @param $value float The value to calculate the product
    153      *
    154      * @return float The resulting value
    155      */
    156     public function calculateProduct($value)
    157     {
    158         return $value * pow($this->base, $this->exponent);
    159     }
    160 }