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. /**
  21. * @ORM\Entity(repositoryClass=AttributeValueRepository::class)
  22. * @ORM\Table(name="pim_attribute_value")
  23. */
  24. class AttributeValue extends AbstractAttributeValue
  25. {
  26. use AttributeAwareTrait;
  27. use AttributeOptionAwareTrait;
  28. /**
  29. * @ORM\ManyToOne(targetEntity=Attribute::class, inversedBy="attributeValues")
  30. * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  31. */
  32. private $attribute;
  33. /**
  34. * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="attributeValues")
  35. * @ORM\JoinColumn(nullable=false)
  36. */
  37. private $product;
  38. /**
  39. * @ORM\ManyToOne(targetEntity=Language::class)
  40. * @Groups({"list"})
  41. */
  42. private $language;
  43. /**
  44. * @ORM\ManyToOne(targetEntity=Channel::class)
  45. * @Groups({"list"})
  46. */
  47. private $channel;
  48. /**
  49. * @ORM\ManyToMany(targetEntity=AttributeOption::class, cascade={"persist"})
  50. * @ORM\JoinTable(name="pim_attribute_value_attribute_option")
  51. * @Groups({"list"})
  52. */
  53. private $attributeOptions;
  54. public function __construct(AttributeInterface $attribute)
  55. {
  56. $this->attributeOptions = new ArrayCollection();
  57. $this->attribute = $attribute;
  58. }
  59. function resolveExpression(): array
  60. {
  61. return [
  62. "product" => $this->getAttributable(),
  63. // 'owner' => $this->declaration->getOwner()
  64. ];
  65. }
  66. public function getAttributable(): AttributableInterface
  67. {
  68. return $this->product;
  69. }
  70. public function setAttributable(AttributableInterface $attributable): AttributableAwareInterface
  71. {
  72. $this->product = $attributable;
  73. return $this;
  74. }
  75. public function getLanguage(): ?Language
  76. {
  77. return $this->language;
  78. }
  79. public function setLanguage(?Language $language): self
  80. {
  81. $this->language = $language;
  82. return $this;
  83. }
  84. public function getChannel(): ?Channel
  85. {
  86. return $this->channel;
  87. }
  88. public function setChannel(?Channel $channel): self
  89. {
  90. $this->channel = $channel;
  91. return $this;
  92. }
  93. }