vendor/roothirsch/pim-bundle/Entity/Attribute.php line 22

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\PimBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeOption\AttributeOptionAwareTrait;
  5. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueAwareTrait;
  6. use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttribute;
  7. use Roothirsch\CoreBundle\Behaviors\Translatable\TranslatableFieldInterface;
  8. use Roothirsch\PimBundle\Entity\AttributeOption;
  9. use Roothirsch\PimBundle\Repository\AttributeRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use \Roothirsch\PimBundle\Entity\AttributeGroup;
  14. /**
  15. * @ApiResource(shortName="Pim/Attribute")
  16. * @ORM\Entity(repositoryClass=AttributeRepository::class)
  17. * @ORM\Table(name="pim_attribute")
  18. */
  19. class Attribute extends AbstractAttribute implements TranslatableFieldInterface
  20. {
  21. use AttributeOptionAwareTrait;
  22. use AttributeValueAwareTrait;
  23. /**
  24. * @ORM\OneToMany(targetEntity=AttributeValue::class, mappedBy="attribute", orphanRemoval=true)
  25. */
  26. private $attributeValues;
  27. /**
  28. * @ORM\OneToMany(targetEntity=AttributeOption::class, mappedBy="attribute", orphanRemoval=true, cascade={"persist"})
  29. */
  30. private $attributeOptions;
  31. /**
  32. * @ORM\ManyToOne(targetEntity=AttributeGroup::class, inversedBy="attributes")
  33. * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  34. */
  35. private $attributeGroup;
  36. /**
  37. * @ORM\Column(type="boolean")
  38. */
  39. private $valuePerChannel = false;
  40. /**
  41. * @ORM\Column(type="boolean")
  42. */
  43. private $valuePerLanguage = false;
  44. public function __toString()
  45. {
  46. return $this->title;
  47. }
  48. public function getValuePerChannel(): ?bool
  49. {
  50. return $this->valuePerChannel;
  51. }
  52. public function setValuePerChannel(bool $valuePerChannel): self
  53. {
  54. $this->valuePerChannel = $valuePerChannel;
  55. return $this;
  56. }
  57. public function getValuePerLanguage(): ?bool
  58. {
  59. return $this->valuePerLanguage;
  60. }
  61. public function setValuePerLanguage(bool $valuePerLanguage): self
  62. {
  63. $this->valuePerLanguage = $valuePerLanguage;
  64. return $this;
  65. }
  66. public function getAttributeGroup(): ?AttributeGroup
  67. {
  68. return $this->attributeGroup;
  69. }
  70. public function setAttributeGroup(?AttributeGroup $attributeGroup): self
  71. {
  72. $this->attributeGroup = $attributeGroup;
  73. return $this;
  74. }
  75. public function isTranslatable(): bool
  76. {
  77. return $this->getValuePerLanguage();
  78. }
  79. public function getTranslatableKey(): string
  80. {
  81. return $this->getName();
  82. }
  83. }