<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Attribute
*
* @ORM\Table(name="attributes")
* @ORM\Entity
*/
class Attribute extends TranslatedEntity
{
public const DISPLAY_TYPE_COMBOBOX = 'combobox';
public const DISPLAY_TYPE_BOX = 'box';
public const DISPLAY_TYPE_COLOR = 'color';
protected $tranlatedEntity = 'AttributeDescription';
/**
* @var bool
*
* @ORM\Column(name="attributes_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var bool
*
* @ORM\Column(name="attributes_status", type="boolean", nullable=false, options={"default"="1"})
*/
private $status = '1';
/**
* @var string
*
* @ORM\Column(name="attributes_code", type="string", length=32, nullable=false)
*/
private $code = '';
/**
* @var bool
*
* @ORM\Column(name="attributes_order", type="boolean", nullable=false)
*/
private $sortOrder = '0';
/**
* @ORM\OneToMany(targetEntity="App\Entity\AttributeDescription", mappedBy="attribute")
*/
private $descriptions = [];
/**
* @var ?string
*
* @ORM\Column(name="attributes_display", type="string", length=32, nullable=false)
*/
private $display;
/**
* @var bool
*
* @ORM\Column(name="attributes_filter", type="boolean", nullable=false)
*/
private $showInFilter = false;
/**
* @var bool
*
* @ORM\Column(name="attributes_caracteristic", type="boolean", nullable=false)
*/
private $showInCaracteristic = false;
private $values = [];
private ?object $entity = null;
public function getId(): int {
return $this->id;
}
public function getStatus(): bool {
return $this->status;
}
public function getCode(): string {
return $this->code;
}
public function getSortOrder(): int {
return $this->sortOrder;
}
public function getDescriptions() {
return $this->descriptions;
}
public function setId(int $id): void {
$this->id = $id;
}
public function setStatus(bool $status): void {
$this->status = $status;
}
public function setCode(string $code): void {
$this->code = $code;
}
public function setSortOrder(int $sortOrder): void {
$this->sortOrder = $sortOrder;
}
public function setDescriptions($descriptions): void {
$this->descriptions = $descriptions;
}
public function getAttributeDescription($lang='fr') : ?AttributeDescription {
foreach($this->getDescriptions() as $desc){
if($desc->getLanguage()->getCode() == $lang)
return $desc;
}
return null;
}
public function getDisplay(): ?string {
return $this->display;
}
public function setDisplay(?string $display): void {
$this->display = $display;
}
public function getValues() {
return $this->values;
}
public function setValues($values): void {
$this->values = $values;
}
public function getShowInFilter(): bool {
return $this->showInFilter;
}
public function getShowInCaracteristic(): bool {
return $this->showInCaracteristic;
}
public function setShowInFilter(bool $showInFilter): void {
$this->showInFilter = $showInFilter;
}
public function setShowInCaracteristic(bool $showInCaracteristic): void {
$this->showInCaracteristic = $showInCaracteristic;
}
public function getEntity(): ?object {
return $this->entity;
}
public function setEntity(?string $entity): void {
$this->entity = $entity;
}
public function isVariant(): bool {
return !empty($this->display);
}
public function toArray() : array{
$output = [
'id' => $this->getId(),
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'dateAdded' => $this->getDateAdded(),
'dateModified' => $this->getDateModified(),
'image' => $this->getImage(),
'status' => $this->getStatus(),
'sort' => $this->getSortOrder()
];
return $output;
}
}