<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Colors
*
* @ORM\Table(name="colors")
* @ORM\Entity
*/
class Color extends TranslatedEntity
{
const PATH = 'public/assets/colors';
protected $tranlatedEntity = 'ColorDescription';
/**
* @var int
*
* @ORM\Column(name="colors_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="manufacturers_code", type="string", length=32, nullable=false)
*/
private $code;
/**
* @var string
*
* @ORM\Column(name="colors_type", type="string", length=20, nullable=false)
*/
private $type;
/**
* @var string|null
*
* @ORM\Column(name="colors_image", type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ColorDescription", mappedBy="color")
*/
private $descriptions = [];
public function getId(): int
{
return $this->id;
}
public function getCode(): string {
return $this->code;
}
public function getType(): string
{
return $this->type;
}
public function getImage(): ?string
{
return $this->image;
}
public function getDescriptions()
{
return $this->descriptions;
}
public function getColorDescription($lang = 'fr'): ?ColorDescription
{
foreach ($this->getDescriptions() as $desc) {
if ($desc->getLanguage()->getCode() == $lang) {
return $desc;
}
}
return null;
}
public function setCode(string $code): void {
$this->code = $code;
}
public function setType(string $type): void
{
$this->type = $type;
}
public function setImage(?string $image): void
{
$this->image = $image;
}
public function setDescriptions($descriptions): void
{
$this->descriptions = $descriptions;
}
public function toArray(): array
{
return [
'id' => $this->getId(),
'type' => $this->getType(),
'image' => $this->getImage(),
];
}
public function getWebPath() {
return 'assets/colors/'.$this->getImage();
}
}