StorageLocation.php (3385B)
1 <?php 2 3 namespace PartKeepr\StorageLocationBundle\Entity; 4 5 use Doctrine\ORM\Mapping as ORM; 6 use PartKeepr\CoreBundle\Entity\BaseEntity; 7 use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; 8 use PartKeepr\UploadedFileBundle\Annotation\UploadedFile; 9 use Symfony\Component\Serializer\Annotation\Groups; 10 11 /** @ORM\Entity 12 * @TargetService(uri="/api/storage_locations") 13 */ 14 class StorageLocation extends BaseEntity 15 { 16 /** 17 * Holds the name for our storage location. 18 * 19 * @ORM\Column(type="string",unique=true) 20 * @Groups({"default"}) 21 * 22 * @var string 23 */ 24 private $name; 25 26 /** 27 * Holds the storage location image. 28 * 29 * @ORM\OneToOne(targetEntity="PartKeepr\StorageLocationBundle\Entity\StorageLocationImage", 30 * mappedBy="storageLocation",cascade={"persist", "remove"}, orphanRemoval=true) 31 * @Groups({"default"}) 32 * @UploadedFile() 33 * 34 * @var StorageLocationImage 35 */ 36 private $image; 37 38 /** 39 * The category of the storage location. 40 * 41 * @ORM\ManyToOne(targetEntity="PartKeepr\StorageLocationBundle\Entity\StorageLocationCategory", 42 * inversedBy="storageLocations") 43 * @Groups({"default"}) 44 * 45 * @var StorageLocationCategory 46 */ 47 private $category; 48 49 /** 50 * Returns the category path. 51 * 52 * @Groups({"default"}) 53 * 54 * @return string 55 */ 56 public function getCategoryPath() 57 { 58 if ($this->category !== null) { 59 return $this->category->getCategoryPath(); 60 } else { 61 return ''; 62 } 63 } 64 65 /** 66 * Sets the category for this storage location. 67 * 68 * @param StorageLocationCategory $category The category 69 * 70 * @return void 71 */ 72 public function setCategory(StorageLocationCategory $category) 73 { 74 $this->category = $category; 75 } 76 77 /** 78 * Returns the category of this storage location. 79 * 80 * @return StorageLocationCategory The storage location category 81 */ 82 public function getCategory() 83 { 84 return $this->category; 85 } 86 87 /** 88 * Sets the name for the storage location. 89 * 90 * @param string $name the name to set 91 */ 92 public function setName($name) 93 { 94 $this->name = $name; 95 } 96 97 /** 98 * Returns the name of the storage location. 99 * 100 * @return string The name 101 */ 102 public function getName() 103 { 104 return $this->name; 105 } 106 107 /** 108 * Sets the storage location image. 109 * 110 * @param StorageLocationImage $image The storage location image 111 * 112 * @return void 113 */ 114 public function setImage($image) 115 { 116 if ($image instanceof StorageLocationImage) { 117 $image->setStorageLocation($this); 118 $this->image = $image; 119 } else { 120 // Because this is a 1:1 relationship. only allow the temporary image to be set when no image exists. 121 // If an image exists, the frontend needs to deliver the old file ID with the replacement property set. 122 if ($this->getImage() === null) { 123 $this->image = $image; 124 } 125 } 126 } 127 128 /** 129 * Returns the storage location image. 130 * 131 * @return StorageLocationImage The storage location image 132 */ 133 public function getImage() 134 { 135 return $this->image; 136 } 137 }