partkeepr

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

Unit.php (3138B)


      1 <?php
      2 
      3 namespace PartKeepr\UnitBundle\Entity;
      4 
      5 use Doctrine\Common\Collections\ArrayCollection;
      6 use Doctrine\ORM\Mapping as ORM;
      7 use PartKeepr\CoreBundle\Entity\BaseEntity;
      8 use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
      9 use PartKeepr\SiPrefixBundle\Entity\SiPrefix;
     10 use Symfony\Component\Serializer\Annotation\Groups;
     11 use Symfony\Component\Validator\Constraints as Assert;
     12 
     13 /**
     14  * This object represents an unit. Units can be: Volt, Hertz etc.
     15  *
     16  * @ORM\Entity
     17  * @TargetService(uri="/api/units")
     18  **/
     19 class Unit extends BaseEntity
     20 {
     21     /**
     22      * The name of the unit (e.g. Volts, Ampere, Farad, Metres).
     23      *
     24      * @ORM\Column(type="string")
     25      * @Groups({"default"})
     26      * @Assert\Type(type="string")
     27      * @Assert\NotBlank(message="unit.name.not_blank")
     28      *
     29      * @var string
     30      */
     31     private $name;
     32 
     33     /**
     34      * The symbol of the unit (e.g. V, A, F, m).
     35      *
     36      * @ORM\Column(type="string")
     37      * @Groups({"default"})
     38      * @Assert\Type(type="string")
     39      * @Assert\NotBlank(message="unit.symbol.not_blank")
     40      *
     41      * @var string
     42      */
     43     private $symbol;
     44 
     45     /**
     46      * Defines the allowed SiPrefixes for this parameter unit.
     47      *
     48      * @ORM\ManyToMany(targetEntity="PartKeepr\SiPrefixBundle\Entity\SiPrefix")
     49      * @ORM\JoinTable(name="UnitSiPrefixes",
     50      *            joinColumns={@ORM\JoinColumn(name="unit_id", referencedColumnName="id")},
     51      *            inverseJoinColumns={@ORM\JoinColumn(name="siprefix_id", referencedColumnName="id")}
     52      *            )
     53      * @Groups({"default"})
     54      * @Assert\All({
     55      *      @Assert\Type(type="PartKeepr\SiPrefixBundle\Entity\SiPrefix")
     56      * })
     57      *
     58      * @var ArrayCollection
     59      */
     60     private $prefixes;
     61 
     62     /**
     63      * Creates a new Unit.
     64      */
     65     public function __construct()
     66     {
     67         $this->prefixes = new ArrayCollection();
     68     }
     69 
     70     /**
     71      * Sets the name for this unit.
     72      *
     73      * @param string $name the name for this unit
     74      */
     75     public function setName($name)
     76     {
     77         $this->name = $name;
     78     }
     79 
     80     /**
     81      * Returns the name for this unit.
     82      *
     83      * @return string The unit name
     84      */
     85     public function getName()
     86     {
     87         return $this->name;
     88     }
     89 
     90     /**
     91      * Sets the symbol for this unit.
     92      *
     93      * @param string $symbol The symbol
     94      */
     95     public function setSymbol($symbol)
     96     {
     97         $this->symbol = $symbol;
     98     }
     99 
    100     /**
    101      * Returns the symbol for this unit.
    102      *
    103      * @return string The symbol
    104      */
    105     public function getSymbol()
    106     {
    107         return $this->symbol;
    108     }
    109 
    110     /**
    111      * Returns the si-prefix list for this unit.
    112      *
    113      * @return ArrayCollection An array of SiPrefix objects
    114      */
    115     public function getPrefixes()
    116     {
    117         return $this->prefixes->getValues();
    118     }
    119 
    120     /**
    121      * Adds a prefix.
    122      *
    123      * @param SiPrefix
    124      */
    125     public function addPrefix($prefix)
    126     {
    127         $this->prefixes->add($prefix);
    128     }
    129 
    130     /**
    131      * Adds a prefix.
    132      *
    133      * @param SiPrefix
    134      */
    135     public function removePrefix($prefix)
    136     {
    137         $this->prefixes->removeElement($prefix);
    138     }
    139 }