partkeepr

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

commit b97e1e5ae8c9216bd1c133f225ad6a76b5563612
parent 6cb8470937fc0a5cb5474774ba26041f71f69c2e
Author: Felicitus <felicitus@felicitus.org>
Date:   Tue, 22 Sep 2015 19:50:29 +0200

Added property accessors for adding/removing attachments

Diffstat:
Msrc/PartKeepr/PartBundle/Entity/Part.php | 30++++++++++++++++++++++++++++--
Msrc/PartKeepr/PartBundle/Entity/PartAttachment.php | 3++-
2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php @@ -13,6 +13,7 @@ use PartKeepr\StorageLocationBundle\Entity\StorageLocation; use PartKeepr\Util\BaseEntity; use PartKeepr\Util\Exceptions\OutOfRangeException; use Symfony\Component\Serializer\Annotation\Groups; +use PartKeepr\UploadedFileBundle\Annotation\UploadedFileCollection; /** * Represents a part in the database. The heart of our project. Handle with care! @@ -110,6 +111,7 @@ class Part extends BaseEntity * @ORM\OneToMany(targetEntity="PartKeepr\PartBundle\Entity\PartAttachment", * mappedBy="part",cascade={"persist", "remove"}) * @Groups({"default"}) + * @UploadedFileCollection() * * @var PartAttachment */ @@ -677,11 +679,35 @@ class Part extends BaseEntity } /** + * Adds a Part Attachment + * + * @param PartAttachment $partAttachment An attachment to add + */ + public function addAttachment($partAttachment) + { + if ($partAttachment instanceof PartAttachment) { + $partAttachment->setPart($this); + } + $this->attachments->add($partAttachment); + } + + /** + * Adds a Part Attachment + * + * @param PartAttachment $partAttachment An attachment to add + */ + public function removeAttachment($partAttachment) + { + $partAttachment->setPart(null); + $this->attachments->removeElement($partAttachment); + } + + /** * Adds a Part Manufacturer * * @param PartManufacturer $partManufacturer A part manufacturer to add */ - public function addManufacturer (PartManufacturer $partManufacturer) + public function addManufacturer(PartManufacturer $partManufacturer) { $partManufacturer->setPart($this); $this->manufacturers->add($partManufacturer); @@ -703,7 +729,7 @@ class Part extends BaseEntity * * @param PartDistributor $partDistributor A part distributor to add */ - public function addDistributor (PartDistributor $partDistributor) + public function addDistributor(PartDistributor $partDistributor) { $partDistributor->setPart($this); $this->distributors->add($partDistributor); diff --git a/src/PartKeepr/PartBundle/Entity/PartAttachment.php b/src/PartKeepr/PartBundle/Entity/PartAttachment.php @@ -16,6 +16,7 @@ class PartAttachment extends UploadedFile * Defines if the attachment is an image. * @ORM\Column(type="boolean",nullable=true) * @Groups({"default"}) + * * @var boolean */ private $isImage; @@ -43,7 +44,7 @@ class PartAttachment extends UploadedFile * * @param Part $part The part to set */ - public function setPart(Part $part) + public function setPart(Part $part = null) { $this->part = $part; }