PartMeasurementUnit.php (3434B)
1 <?php 2 3 namespace PartKeepr\PartBundle\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 Symfony\Component\Serializer\Annotation\Groups; 10 use Symfony\Component\Validator\Constraints as Assert; 11 12 /** 13 * This entity represents a part measurement unit. Typical measurement units are pieces, centimeters etc. 14 * 15 * @ORM\Entity 16 * @ORM\Table(name="PartUnit") 17 * @TargetService(uri="/api/part_measurement_units") 18 **/ 19 class PartMeasurementUnit extends BaseEntity 20 { 21 /** 22 * Defines the name of the unit. 23 * 24 * @ORM\Column(type="string") 25 * @Groups({"default"}) 26 * 27 * @Assert\Type(type="string") 28 * @Assert\NotBlank(message="partMeasurementUnit.name.not_blank") 29 * 30 * @var string 31 */ 32 private $name; 33 34 /** 35 * Defines the short name of the unit. 36 * 37 * @ORM\Column(type="string") 38 * @Groups({"default"}) 39 * 40 * @Assert\Type(type="string") 41 * @Assert\NotBlank(message="partMeasurementUnit.shortName.not_blank") 42 * 43 * @var string 44 */ 45 private $shortName; 46 47 /** 48 * Defines if the unit is default or not. Note that this property may not be set directly. 49 * 50 * @ORM\Column(type="boolean", name="is_default") 51 * @Groups({"default"}) 52 * 53 * @var bool 54 */ 55 private $default; 56 57 /** 58 * The parts used by this PartMeasurementUnit. 59 * 60 * @ORM\OneToMany(targetEntity="PartKeepr\PartBundle\Entity\Part",mappedBy="partUnit") 61 */ 62 private $parts; 63 64 /** 65 * Creates a new part unit. 66 * 67 * Sets the default to false. 68 */ 69 public function __construct() 70 { 71 $this->parts = new ArrayCollection(); 72 $this->setDefault(false); 73 } 74 75 /** 76 * Sets the name for this unit. 77 * 78 * @param string $name The name for this unit 79 */ 80 public function setName($name) 81 { 82 $this->name = $name; 83 } 84 85 /** 86 * Returns the name for this unit. 87 * 88 * @param none 89 * 90 * @return string The name for this unit 91 */ 92 public function getName() 93 { 94 return $this->name; 95 } 96 97 /** 98 * Sets the short name for this unit. 99 * 100 * Short names are used for list views (e.g. if your unit name is "metres", your short name could be "m") 101 * 102 * @param string $shortName The short name 103 */ 104 public function setShortName($shortName) 105 { 106 $this->shortName = $shortName; 107 } 108 109 /** 110 * Returns the short name for this unit. 111 * 112 * @param none 113 * 114 * @return string The short name for this unit 115 */ 116 public function getShortName() 117 { 118 return $this->shortName; 119 } 120 121 /** 122 * Defines if the unit is default or not. 123 * 124 * @param bool $default True if the unit is default, false otherwise 125 */ 126 public function setDefault($default) 127 { 128 $this->default = (bool) $default; 129 } 130 131 /** 132 * Returns if the unit is default or not. 133 * 134 * @param none 135 * 136 * @return bool True if the unit is default, false for not 137 */ 138 public function isDefault() 139 { 140 return $this->default; 141 } 142 143 /** 144 * Returns the parts for this PartUnit. 145 * 146 * @return ArrayCollection 147 */ 148 public function getParts() 149 { 150 return $this->parts->getValues(); 151 } 152 }