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 int
  38. *
  39. * @ORM\Column(name="attributes_order", type="integer", nullable=false)
  40. */
  41. private $sortOrder = 99999;
  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=true)
  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. /**
  65. * @var ?string
  66. *
  67. * @ORM\Column(name="attributes_suffix", type="string", length=255, nullable=true)
  68. */
  69. private $suffix;
  70. private $values = [];
  71. private ?object $entity = null;
  72. public function getId(): int {
  73. return $this->id;
  74. }
  75. public function getStatus(): bool {
  76. return $this->status;
  77. }
  78. public function getCode(): string {
  79. return $this->code;
  80. }
  81. public function getSortOrder(): int {
  82. return $this->sortOrder;
  83. }
  84. public function getDescriptions() {
  85. return $this->descriptions;
  86. }
  87. public function getTitle() {
  88. if(!empty($this->languageId)){
  89. $description = null;
  90. foreach($this->descriptions as $d){
  91. if($d->getLanguage()->getId()==$this->languageId){
  92. $description = $d;
  93. break;
  94. }
  95. }
  96. }
  97. if(empty($description) && count($this->descriptions)){
  98. $description = $this->descriptions[0];
  99. }
  100. return empty($description)?'':$description->getTitle();
  101. }
  102. public function setId(int $id): void {
  103. $this->id = $id;
  104. }
  105. public function setStatus(bool $status): void {
  106. $this->status = $status;
  107. }
  108. public function setCode(string $code): void {
  109. $this->code = $code;
  110. }
  111. public function setSortOrder(int $sortOrder): void {
  112. $this->sortOrder = $sortOrder;
  113. }
  114. public function setDescriptions($descriptions): void {
  115. $this->descriptions = $descriptions;
  116. }
  117. public function getAttributeDescription($lang='fr') : ?AttributeDescription {
  118. foreach($this->getDescriptions() as $desc){
  119. if($desc->getLanguage()->getCode() == $lang)
  120. return $desc;
  121. }
  122. return null;
  123. }
  124. public function getDisplay(): ?string {
  125. return $this->display;
  126. }
  127. public function setDisplay(?string $display): void {
  128. $this->display = $display;
  129. }
  130. public function getValues() {
  131. return $this->values;
  132. }
  133. public function setValues($values): void {
  134. $this->values = $values;
  135. }
  136. public function getShowInFilter(): bool {
  137. return $this->showInFilter;
  138. }
  139. public function getShowInCaracteristic(): bool {
  140. return $this->showInCaracteristic;
  141. }
  142. public function setShowInFilter(bool $showInFilter): void {
  143. $this->showInFilter = $showInFilter;
  144. }
  145. public function setShowInCaracteristic(bool $showInCaracteristic): void {
  146. $this->showInCaracteristic = $showInCaracteristic;
  147. }
  148. public function getSuffix(): ?string {
  149. return $this->suffix;
  150. }
  151. public function setSuffix(?string $suffix): void {
  152. $this->suffix = $suffix;
  153. }
  154. public function getEntity(): ?object {
  155. return $this->entity;
  156. }
  157. public function setEntity(?string $entity): void {
  158. $this->entity = $entity;
  159. }
  160. public function isVariant(): bool {
  161. return !empty($this->display);
  162. }
  163. public function toArray() : array{
  164. $output = [
  165. 'id' => $this->getId(),
  166. 'title' => $this->getTitle(),
  167. 'author' => $this->getAuthor(),
  168. 'dateAdded' => $this->getDateAdded(),
  169. 'dateModified' => $this->getDateModified(),
  170. 'image' => $this->getImage(),
  171. 'status' => $this->getStatus(),
  172. 'sort' => $this->getSortOrder()
  173. ];
  174. return $output;
  175. }
  176. }