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 getTitle() {
  82. if(!empty($this->languageId)){
  83. $description = null;
  84. foreach($this->descriptions as $d){
  85. if($d->getLanguage()->getId()==$this->languageId){
  86. $description = $d;
  87. break;
  88. }
  89. }
  90. }
  91. if(empty($description) && count($this->descriptions)){
  92. $description = $this->descriptions[0];
  93. }
  94. return empty($description)?'':$description->getTitle();
  95. }
  96. public function setId(int $id): void {
  97. $this->id = $id;
  98. }
  99. public function setStatus(bool $status): void {
  100. $this->status = $status;
  101. }
  102. public function setCode(string $code): void {
  103. $this->code = $code;
  104. }
  105. public function setSortOrder(int $sortOrder): void {
  106. $this->sortOrder = $sortOrder;
  107. }
  108. public function setDescriptions($descriptions): void {
  109. $this->descriptions = $descriptions;
  110. }
  111. public function getAttributeDescription($lang='fr') : ?AttributeDescription {
  112. foreach($this->getDescriptions() as $desc){
  113. if($desc->getLanguage()->getCode() == $lang)
  114. return $desc;
  115. }
  116. return null;
  117. }
  118. public function getDisplay(): ?string {
  119. return $this->display;
  120. }
  121. public function setDisplay(?string $display): void {
  122. $this->display = $display;
  123. }
  124. public function getValues() {
  125. return $this->values;
  126. }
  127. public function setValues($values): void {
  128. $this->values = $values;
  129. }
  130. public function getShowInFilter(): bool {
  131. return $this->showInFilter;
  132. }
  133. public function getShowInCaracteristic(): bool {
  134. return $this->showInCaracteristic;
  135. }
  136. public function setShowInFilter(bool $showInFilter): void {
  137. $this->showInFilter = $showInFilter;
  138. }
  139. public function setShowInCaracteristic(bool $showInCaracteristic): void {
  140. $this->showInCaracteristic = $showInCaracteristic;
  141. }
  142. public function getEntity(): ?object {
  143. return $this->entity;
  144. }
  145. public function setEntity(?string $entity): void {
  146. $this->entity = $entity;
  147. }
  148. public function isVariant(): bool {
  149. return !empty($this->display);
  150. }
  151. public function toArray() : array{
  152. $output = [
  153. 'id' => $this->getId(),
  154. 'title' => $this->getTitle(),
  155. 'author' => $this->getAuthor(),
  156. 'dateAdded' => $this->getDateAdded(),
  157. 'dateModified' => $this->getDateModified(),
  158. 'image' => $this->getImage(),
  159. 'status' => $this->getStatus(),
  160. 'sort' => $this->getSortOrder()
  161. ];
  162. return $output;
  163. }
  164. }