src/Entity/ProductCategory.php line 119

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\_Interface\LocaleInterface;
  4. use App\Repository\ProductCategoryRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JsonSerializable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. #[ORM\Entity(repositoryClass: ProductCategoryRepository::class)]
  10. class ProductCategory implements JsonSerializable, LocaleInterface
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column(type: 'integer')]
  15. private $id;
  16. #[ORM\Column(type: 'string', length: 255)]
  17. private $name;
  18. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  19. private $description;
  20. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  21. private $image;
  22. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  23. private $image_en;
  24. #[ORM\OneToMany(targetEntity: 'Product', mappedBy: 'productCategory')]
  25. private $products;
  26. #[ORM\Column(type: 'integer', nullable: true)]
  27. private $status;
  28. #[ORM\Column(length: 255, nullable: true)]
  29. private ?string $name_english = null;
  30. #[ORM\Column(length: 255, nullable: true)]
  31. private ?string $description_english = null;
  32. public function __construct() {
  33. $this->products = new ArrayCollection();
  34. }
  35. public function getId(): ?int
  36. {
  37. return $this->id;
  38. }
  39. public function getName(): ?string
  40. {
  41. return $this->name;
  42. }
  43. public function setName(string $name): self
  44. {
  45. $this->name = $name;
  46. return $this;
  47. }
  48. public function getDescription(): ?string
  49. {
  50. return $this->description;
  51. }
  52. public function setDescription(?string $description): self
  53. {
  54. $this->description = $description;
  55. return $this;
  56. }
  57. public function getImage(): ?string
  58. {
  59. return $this->image;
  60. }
  61. public function setImage(?string $image): self
  62. {
  63. $this->image = $image;
  64. return $this;
  65. }
  66. public function getImageByLocal($local = 'fr'): ?string
  67. {
  68. $image = $this->image;
  69. switch ($local)
  70. {
  71. case 'en' : $image = $this->image_en; break;
  72. }
  73. return $image;
  74. }
  75. /**
  76. * @return mixed
  77. */
  78. public function getImageEn()
  79. {
  80. return $this->image_en;
  81. }
  82. /**
  83. * @param mixed $image_en
  84. * @return ProductCategory
  85. */
  86. public function setImageEn($image_en)
  87. {
  88. $this->image_en = $image_en;
  89. return $this;
  90. }
  91. public function jsonSerialize()
  92. {
  93. $vars = get_object_vars($this);
  94. return $vars;
  95. }
  96. public function getStatus(): ?int
  97. {
  98. return $this->status;
  99. }
  100. public function setStatus(?int $status): self
  101. {
  102. $this->status = $status;
  103. return $this;
  104. }
  105. public function getImagePathDefaultLocale()
  106. {
  107. $image = '';
  108. if ($GLOBALS['app_default_locale'] === 'fr' ) {
  109. $image = $this->image;
  110. }else if($GLOBALS['app_default_locale'] === 'en'){
  111. $image = ($this->image_en === '' or is_null($this->image_en)) ? $this->image : $this->image_en ;
  112. }
  113. return $image;
  114. }
  115. public function getNameEnglish(): ?string
  116. {
  117. return $this->name_english;
  118. }
  119. public function setNameEnglish(?string $name_english): self
  120. {
  121. $this->name_english = $name_english;
  122. return $this;
  123. }
  124. public function getNameByDefaultLocale()
  125. {
  126. $name = '';
  127. if ($GLOBALS['app_default_locale'] === 'fr' ) {
  128. $name = $this->name;
  129. }else if($GLOBALS['app_default_locale'] === 'en'){
  130. $name = ($this->name_english === '' or is_null($this->name_english)) ? $this->name : $this->name_english ;
  131. }
  132. return $name;
  133. }
  134. public function getDescriptionEnglish(): ?string
  135. {
  136. return $this->description_english;
  137. }
  138. public function setDescriptionEnglish(?string $description_english): self
  139. {
  140. $this->description_english = $description_english;
  141. return $this;
  142. }
  143. }