<?phpnamespace Roothirsch\PimBundle\Entity;use ApiPlatform\Core\Annotation\ApiResource;use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeOption\AttributeOptionAwareTrait;use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueAwareTrait;use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttribute;use Roothirsch\CoreBundle\Behaviors\Translatable\TranslatableFieldInterface;use Roothirsch\PimBundle\Entity\AttributeOption;use Roothirsch\PimBundle\Repository\AttributeRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Ignore;use \Roothirsch\PimBundle\Entity\AttributeGroup;/** * @ApiResource(shortName="Pim/Attribute") * @ORM\Entity(repositoryClass=AttributeRepository::class) * @ORM\Table(name="pim_attribute") */class Attribute extends AbstractAttribute implements TranslatableFieldInterface{ use AttributeOptionAwareTrait; use AttributeValueAwareTrait; /** * @ORM\OneToMany(targetEntity=AttributeValue::class, mappedBy="attribute", orphanRemoval=true) * @Ignore */ private $attributeValues; /** * @ORM\OneToMany(targetEntity=AttributeOption::class, mappedBy="attribute", orphanRemoval=true, cascade={"persist"}) */ private $attributeOptions; /** * @ORM\ManyToOne(targetEntity=AttributeGroup::class, inversedBy="attributes") * @ORM\JoinColumn(nullable=true, onDelete="CASCADE") */ private $attributeGroup; /** * @ORM\Column(type="boolean") */ private $valuePerChannel = false; /** * @ORM\Column(type="boolean") */ private $valuePerLanguage = false; /** * @ORM\ManyToMany(targetEntity=Product::class, mappedBy="individualAttributes") */ private $products; public function __construct() { parent::__construct(); $this->products = new ArrayCollection(); } public function __toString() { return $this->title ?? ''; } public function getValuePerChannel(): ?bool { return $this->valuePerChannel; } public function setValuePerChannel(bool $valuePerChannel): self { $this->valuePerChannel = $valuePerChannel; return $this; } public function getValuePerLanguage(): ?bool { return $this->valuePerLanguage; } public function setValuePerLanguage(bool $valuePerLanguage): self { $this->valuePerLanguage = $valuePerLanguage; return $this; } public function getAttributeGroup(): ?AttributeGroup { return $this->attributeGroup; } public function setAttributeGroup(?AttributeGroup $attributeGroup): self { $this->attributeGroup = $attributeGroup; return $this; } public function isTranslatable(): bool { return $this->getValuePerLanguage(); } public function getTranslatableKey(): string { return $this->getName(); } /** * @return Collection|Product[] */ public function getProducts(): Collection { return $this->products; }}