vendor/roothirsch/pim-bundle/Entity/AttributeValue.php line 27

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\PimBundle\Entity;
  3. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableAwareInterface;
  4. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableInterface;
  5. use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeAwareTrait;
  6. use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeInterface;
  7. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeOption\AttributeOptionAwareTrait;
  8. use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttributeValue;
  9. use Roothirsch\PimBundle\Entity\AttributeOption;
  10. use Roothirsch\PimBundle\Repository\AttributeValueRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use \Roothirsch\PimBundle\Entity\Attribute;
  15. use \Roothirsch\PimBundle\Entity\Article;
  16. use \Roothirsch\CoreBundle\Translation\Entity\Language;
  17. use \Roothirsch\PimBundle\Entity\Channel;
  18. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Serializer\Annotation\Ignore;
  21. /**
  22. * @ORM\Entity(repositoryClass=AttributeValueRepository::class)
  23. * @ORM\Table(name="pim_attribute_value")
  24. */
  25. class AttributeValue extends AbstractAttributeValue
  26. {
  27. use AttributeAwareTrait;
  28. use AttributeOptionAwareTrait;
  29. /**
  30. * @ORM\ManyToOne(targetEntity=Attribute::class, inversedBy="attributeValues")
  31. * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  32. * @Ignore
  33. */
  34. private $attribute;
  35. /**
  36. * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="attributeValues")
  37. * @ORM\JoinColumn(nullable=false)
  38. * @Ignore
  39. */
  40. private $product;
  41. /**
  42. * @ORM\ManyToOne(targetEntity=Language::class)
  43. * @Groups({"list"})
  44. */
  45. private $language;
  46. /**
  47. * @ORM\ManyToOne(targetEntity=Channel::class)
  48. * @Groups({"list"})
  49. */
  50. private $channel;
  51. /**
  52. * @ORM\ManyToMany(targetEntity=AttributeOption::class, cascade={"persist"})
  53. * @ORM\JoinTable(name="pim_attribute_value_attribute_option")
  54. * @Groups({"list"})
  55. */
  56. private $attributeOptions;
  57. public function __construct(AttributeInterface $attribute)
  58. {
  59. $this->attributeOptions = new ArrayCollection();
  60. $this->attribute = $attribute;
  61. }
  62. function resolveExpression(): array
  63. {
  64. return [
  65. "product" => $this->getAttributable(),
  66. // 'owner' => $this->declaration->getOwner()
  67. ];
  68. }
  69. public function getAttributable(): AttributableInterface
  70. {
  71. return $this->product;
  72. }
  73. public function setAttributable(AttributableInterface $attributable): AttributableAwareInterface
  74. {
  75. $this->product = $attributable;
  76. return $this;
  77. }
  78. public function getLanguage(): ?Language
  79. {
  80. return $this->language;
  81. }
  82. public function setLanguage(?Language $language): self
  83. {
  84. $this->language = $language;
  85. return $this;
  86. }
  87. public function getChannel(): ?Channel
  88. {
  89. return $this->channel;
  90. }
  91. public function setChannel(?Channel $channel): self
  92. {
  93. $this->channel = $channel;
  94. return $this;
  95. }
  96. }