src/Entity/Attribute.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Attribute
  6. *
  7. * @ORM\Table(name="attributes")
  8. * @ORM\Entity
  9. */
  10. class Attribute extends TranslatedEntity
  11. {
  12. public const DISPLAY_TYPE_COMBOBOX = 'combobox';
  13. public const DISPLAY_TYPE_BOX = 'box';
  14. public const DISPLAY_TYPE_COLOR = 'color';
  15. protected $tranlatedEntity = 'AttributeDescription';
  16. /**
  17. * @var bool
  18. *
  19. * @ORM\Column(name="attributes_id", type="integer", nullable=false)
  20. * @ORM\Id
  21. * @ORM\GeneratedValue(strategy="IDENTITY")
  22. */
  23. private $id;
  24. /**
  25. * @var bool
  26. *
  27. * @ORM\Column(name="attributes_status", type="boolean", nullable=false, options={"default"="1"})
  28. */
  29. private $status = '1';
  30. /**
  31. * @var string
  32. *
  33. * @ORM\Column(name="attributes_code", type="string", length=32, nullable=false)
  34. */
  35. private $code = '';
  36. /**
  37. * @var bool
  38. *
  39. * @ORM\Column(name="attributes_order", type="boolean", nullable=false)
  40. */
  41. private $sortOrder = '0';
  42. /**
  43. * @ORM\OneToMany(targetEntity="App\Entity\AttributeDescription", mappedBy="attribute")
  44. */
  45. private $descriptions = [];
  46. /**
  47. * @var ?string
  48. *
  49. * @ORM\Column(name="attributes_display", type="string", length=32, nullable=false)
  50. */
  51. private $display;
  52. /**
  53. * @var bool
  54. *
  55. * @ORM\Column(name="attributes_filter", type="boolean", nullable=false)
  56. */
  57. private $showInFilter = false;
  58. /**
  59. * @var bool
  60. *
  61. * @ORM\Column(name="attributes_caracteristic", type="boolean", nullable=false)
  62. */
  63. private $showInCaracteristic = false;
  64. private $values = [];
  65. private ?object $entity = null;
  66. public function getId(): int {
  67. return $this->id;
  68. }
  69. public function getStatus(): bool {
  70. return $this->status;
  71. }
  72. public function getCode(): string {
  73. return $this->code;
  74. }
  75. public function getSortOrder(): int {
  76. return $this->sortOrder;
  77. }
  78. public function getDescriptions() {
  79. return $this->descriptions;
  80. }
  81. public function setId(int $id): void {
  82. $this->id = $id;
  83. }
  84. public function setStatus(bool $status): void {
  85. $this->status = $status;
  86. }
  87. public function setCode(string $code): void {
  88. $this->code = $code;
  89. }
  90. public function setSortOrder(int $sortOrder): void {
  91. $this->sortOrder = $sortOrder;
  92. }
  93. public function setDescriptions($descriptions): void {
  94. $this->descriptions = $descriptions;
  95. }
  96. public function getAttributeDescription($lang='fr') : ?AttributeDescription {
  97. foreach($this->getDescriptions() as $desc){
  98. if($desc->getLanguage()->getCode() == $lang)
  99. return $desc;
  100. }
  101. return null;
  102. }
  103. public function getDisplay(): ?string {
  104. return $this->display;
  105. }
  106. public function setDisplay(?string $display): void {
  107. $this->display = $display;
  108. }
  109. public function getValues() {
  110. return $this->values;
  111. }
  112. public function setValues($values): void {
  113. $this->values = $values;
  114. }
  115. public function getShowInFilter(): bool {
  116. return $this->showInFilter;
  117. }
  118. public function getShowInCaracteristic(): bool {
  119. return $this->showInCaracteristic;
  120. }
  121. public function setShowInFilter(bool $showInFilter): void {
  122. $this->showInFilter = $showInFilter;
  123. }
  124. public function setShowInCaracteristic(bool $showInCaracteristic): void {
  125. $this->showInCaracteristic = $showInCaracteristic;
  126. }
  127. public function getEntity(): ?object {
  128. return $this->entity;
  129. }
  130. public function setEntity(?string $entity): void {
  131. $this->entity = $entity;
  132. }
  133. public function isVariant(): bool {
  134. return !empty($this->display);
  135. }
  136. public function toArray() : array{
  137. $output = [
  138. 'id' => $this->getId(),
  139. 'title' => $this->getTitle(),
  140. 'author' => $this->getAuthor(),
  141. 'dateAdded' => $this->getDateAdded(),
  142. 'dateModified' => $this->getDateModified(),
  143. 'image' => $this->getImage(),
  144. 'status' => $this->getStatus(),
  145. 'sort' => $this->getSortOrder()
  146. ];
  147. return $output;
  148. }
  149. }