src/Entity/Color.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Colors
  6. *
  7. * @ORM\Table(name="colors")
  8. * @ORM\Entity
  9. */
  10. class Color extends TranslatedEntity
  11. {
  12. const PATH = 'public/assets/colors';
  13. protected $tranlatedEntity = 'ColorDescription';
  14. /**
  15. * @var int
  16. *
  17. * @ORM\Column(name="colors_id", type="integer", nullable=false)
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="IDENTITY")
  20. */
  21. private $id;
  22. /**
  23. * @var string
  24. *
  25. * @ORM\Column(name="manufacturers_code", type="string", length=32, nullable=false)
  26. */
  27. private $code;
  28. /**
  29. * @var string
  30. *
  31. * @ORM\Column(name="colors_type", type="string", length=20, nullable=false)
  32. */
  33. private $type;
  34. /**
  35. * @var string|null
  36. *
  37. * @ORM\Column(name="colors_image", type="string", length=255, nullable=true)
  38. */
  39. private $image;
  40. /**
  41. * @ORM\OneToMany(targetEntity="App\Entity\ColorDescription", mappedBy="color")
  42. */
  43. private $descriptions = [];
  44. public function getId(): int
  45. {
  46. return $this->id;
  47. }
  48. public function getCode(): string {
  49. return $this->code;
  50. }
  51. public function getType(): string
  52. {
  53. return $this->type;
  54. }
  55. public function getImage(): ?string
  56. {
  57. return $this->image;
  58. }
  59. public function getDescriptions()
  60. {
  61. return $this->descriptions;
  62. }
  63. public function getColorDescription($lang = 'fr'): ?ColorDescription
  64. {
  65. foreach ($this->getDescriptions() as $desc) {
  66. if ($desc->getLanguage()->getCode() == $lang) {
  67. return $desc;
  68. }
  69. }
  70. return null;
  71. }
  72. public function setCode(string $code): void {
  73. $this->code = $code;
  74. }
  75. public function setType(string $type): void
  76. {
  77. $this->type = $type;
  78. }
  79. public function setImage(?string $image): void
  80. {
  81. $this->image = $image;
  82. }
  83. public function setDescriptions($descriptions): void
  84. {
  85. $this->descriptions = $descriptions;
  86. }
  87. public function toArray(): array
  88. {
  89. return [
  90. 'id' => $this->getId(),
  91. 'type' => $this->getType(),
  92. 'image' => $this->getImage(),
  93. ];
  94. }
  95. public function getWebPath() {
  96. return 'assets/colors/'.$this->getImage();
  97. }
  98. }