src/ProductBundle/Entity/SubAttribute.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\ProductBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\ProductBundle\Entity\Translation\SubAttributeTranslation;
  7. use PN\LocaleBundle\Model\LocaleTrait;
  8. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  9. use PN\ServiceBundle\Model\DateTimeTrait;
  10. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  11. use PN\LocaleBundle\Model\Translatable;
  12. /**
  13. * @ORM\HasLifecycleCallbacks
  14. * @ORM\Table(name="product_sub_attribute")
  15. * @ORM\Entity(repositoryClass="App\ProductBundle\Repository\SubAttributeRepository")
  16. */
  17. class SubAttribute implements Translatable,DateTimeInterface
  18. {
  19. use VirtualDeleteTrait,
  20. DateTimeTrait,
  21. LocaleTrait;
  22. /**
  23. * @var int
  24. *
  25. * @ORM\Column(name="id", type="integer")
  26. * @ORM\Id
  27. * @ORM\GeneratedValue(strategy="AUTO")
  28. */
  29. private $id;
  30. /**
  31. * @ORM\ManyToOne(targetEntity="Attribute", inversedBy="subAttributes")
  32. */
  33. private $attribute;
  34. /**
  35. * @var string
  36. *
  37. * @ORM\Column(name="title", type="string", length=100)
  38. */
  39. private $title;
  40. /**
  41. * @ORM\OneToMany(targetEntity="ProductHasAttribute", mappedBy="subAttribute", cascade={"persist"})
  42. */
  43. private $productHasAttributes;
  44. /**
  45. * @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\Translation\SubAttributeTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  46. */
  47. private $translations;
  48. public function __construct()
  49. {
  50. $this->productHasAttributes = new ArrayCollection();
  51. $this->translations = new ArrayCollection();
  52. }
  53. public function getId(): ?int
  54. {
  55. return $this->id;
  56. }
  57. public function getTitle(): ?string
  58. {
  59. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  60. }
  61. public function setTitle(string $title): self
  62. {
  63. $this->title = $title;
  64. return $this;
  65. }
  66. public function getAttribute(): ?Attribute
  67. {
  68. return $this->attribute;
  69. }
  70. public function setAttribute(?Attribute $attribute): self
  71. {
  72. $this->attribute = $attribute;
  73. return $this;
  74. }
  75. /**
  76. * @return Collection|ProductHasAttribute[]
  77. */
  78. public function getProductHasAttributes(): Collection
  79. {
  80. return $this->productHasAttributes;
  81. }
  82. public function addProductHasAttribute(ProductHasAttribute $productHasAttribute): self
  83. {
  84. if (!$this->productHasAttributes->contains($productHasAttribute)) {
  85. $this->productHasAttributes[] = $productHasAttribute;
  86. $productHasAttribute->setSubAttribute($this);
  87. }
  88. return $this;
  89. }
  90. public function removeProductHasAttribute(ProductHasAttribute $productHasAttribute): self
  91. {
  92. if ($this->productHasAttributes->removeElement($productHasAttribute)) {
  93. // set the owning side to null (unless already changed)
  94. if ($productHasAttribute->getSubAttribute() === $this) {
  95. $productHasAttribute->setSubAttribute(null);
  96. }
  97. }
  98. return $this;
  99. }
  100. /**
  101. * @return Collection|SubAttributeTranslation[]
  102. */
  103. public function getTranslations(): Collection
  104. {
  105. return $this->translations;
  106. }
  107. public function addTranslation(SubAttributeTranslation $translation): self
  108. {
  109. if (!$this->translations->contains($translation)) {
  110. $this->translations[] = $translation;
  111. $translation->setTranslatable($this);
  112. }
  113. return $this;
  114. }
  115. public function removeTranslation(SubAttributeTranslation $translation): self
  116. {
  117. if ($this->translations->removeElement($translation)) {
  118. // set the owning side to null (unless already changed)
  119. if ($translation->getTranslatable() === $this) {
  120. $translation->setTranslatable(null);
  121. }
  122. }
  123. return $this;
  124. }
  125. }