<?php
namespace App\Entity;
use App\_Interface\LocaleInterface;
use App\Repository\ProductCategoryRepository;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\Session\Session;
#[ORM\Entity(repositoryClass: ProductCategoryRepository::class)]
class ProductCategory implements JsonSerializable, LocaleInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $description;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $image;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $image_en;
#[ORM\OneToMany(targetEntity: 'Product', mappedBy: 'productCategory')]
private $products;
#[ORM\Column(type: 'integer', nullable: true)]
private $status;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name_english = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $description_english = null;
public function __construct() {
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getImageByLocal($local = 'fr'): ?string
{
$image = $this->image;
switch ($local)
{
case 'en' : $image = $this->image_en; break;
}
return $image;
}
/**
* @return mixed
*/
public function getImageEn()
{
return $this->image_en;
}
/**
* @param mixed $image_en
* @return ProductCategory
*/
public function setImageEn($image_en)
{
$this->image_en = $image_en;
return $this;
}
public function jsonSerialize()
{
$vars = get_object_vars($this);
return $vars;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(?int $status): self
{
$this->status = $status;
return $this;
}
public function getImagePathDefaultLocale()
{
$image = '';
if ($GLOBALS['app_default_locale'] === 'fr' ) {
$image = $this->image;
}else if($GLOBALS['app_default_locale'] === 'en'){
$image = ($this->image_en === '' or is_null($this->image_en)) ? $this->image : $this->image_en ;
}
return $image;
}
public function getNameEnglish(): ?string
{
return $this->name_english;
}
public function setNameEnglish(?string $name_english): self
{
$this->name_english = $name_english;
return $this;
}
public function getNameByDefaultLocale()
{
$name = '';
if ($GLOBALS['app_default_locale'] === 'fr' ) {
$name = $this->name;
}else if($GLOBALS['app_default_locale'] === 'en'){
$name = ($this->name_english === '' or is_null($this->name_english)) ? $this->name : $this->name_english ;
}
return $name;
}
public function getDescriptionEnglish(): ?string
{
return $this->description_english;
}
public function setDescriptionEnglish(?string $description_english): self
{
$this->description_english = $description_english;
return $this;
}
}