<?php
namespace App\Entity\Tires;
use App\Entity\MiniAbstractBase;
use App\Repository\Tires\TireSizeRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="vulco_tire_size", indexes={@ORM\Index(name="width_idx", columns={"width"}), @ORM\Index(name="ratio_idx", columns={"ratio"}), @ORM\Index(name="diameter_idx", columns={"diameter"}), @ORM\Index(name="load_index_idx", columns={"load_index"}), @ORM\Index(name="speed_index_idx", columns={"speed_index"})}, uniqueConstraints={@ORM\UniqueConstraint(name="tire_size_unique_idx", columns={"width", "ratio", "diameter", "load_index", "speed_index"})})
* @ORM\Entity(repositoryClass=TireSizeRepository::class)
*/
class TireSize
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private int $id;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private ?string $width = null;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private ?string $ratio = null;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private ?string $diameter = null;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private ?string $loadIndex = null;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private ?string $speedIndex = null;
public function __construct()
{
}
public function getId(): int
{
return $this->id;
}
/**
* Get tyre model short format "{WIDHT}/{RATIO} R{DIAMETER} {LOAD}{SPEED}".
*/
public function getName(): string
{
// Al importar los neumáticos del csv ponemos el valor '-' cuando tiene valor vacío ''
// para no tratar con campos de texto vacío o null en los selects del buscador
$width = ('-' === $this->getWidth()) ? '' : $this->getWidth();
$ratio = ('-' === $this->getRatio()) ? '' : $this->getRatio();
$diameter = ('-' === $this->getDiameter()) ? '' : $this->getDiameter();
$loadIndex = ('-' === $this->getLoadIndex()) ? '' : $this->getLoadIndex();
$speedIndex = ('-' === $this->getSpeedIndex()) ? '' : $this->getSpeedIndex();
$size = !empty($width) ? $width : '';
$size .= !empty($ratio) ? '/'.$ratio : '';
$size .= !empty($diameter) ? ' R'.$diameter : '';
$size .= !empty($loadIndex) ? ' '.$loadIndex : '';
$size .= !empty($speedIndex) ? (empty($loadIndex) ? ' ' : '').$speedIndex : '';
return $size;
}
/**
* Get tyre model short format "{WIDHT}/{RATIO} R{DIAMETER} {LOAD}{SPEED}" for given tire size arguments.
*/
public static function getNameFor(string $tireWidth, string $tireRatio, string $tireDiameter, string $tireLoadIndex, string $tireSpeedIndex): string
{
// Al importar los neumáticos del csv ponemos el valor '-' cuando tiene valor vacío ''
// para no tratar con campos de texto vacío o null en los selects del buscador
$width = ('-' === $tireWidth) ? '' : $tireWidth;
$ratio = ('-' === $tireRatio) ? '' : $tireRatio;
$diameter = ('-' === $tireDiameter) ? '' : $tireDiameter;
$loadIndex = ('-' === $tireLoadIndex) ? '' : $tireLoadIndex;
$speedIndex = ('-' === $tireSpeedIndex) ? '' : $tireSpeedIndex;
$size = !empty($width) ? $width : '';
$size .= !empty($ratio) ? '/'.$ratio : '';
$size .= !empty($diameter) ? ' R'.$diameter : '';
$size .= !empty($loadIndex) ? ' '.$loadIndex : '';
$size .= !empty($speedIndex) ? (empty($loadIndex) ? ' ' : '').$speedIndex : '';
return $size;
}
public function getWidth(): ?string
{
return $this->width;
}
public function setWidth(string $width): self
{
$this->width = $width;
return $this;
}
public function getRatio(): ?string
{
return $this->ratio;
}
public function setRatio(string $ratio): self
{
$this->ratio = $ratio;
return $this;
}
public function getDiameter(): ?string
{
return $this->diameter;
}
public function setDiameter(string $diameter): self
{
$this->diameter = $diameter;
return $this;
}
public function getLoadIndex(): ?string
{
return $this->loadIndex;
}
public function setLoadIndex(string $loadIndex): self
{
$this->loadIndex = $loadIndex;
return $this;
}
public function getSpeedIndex(): ?string
{
return $this->speedIndex;
}
public function setSpeedIndex(string $speedIndex): self
{
$this->speedIndex = $speedIndex;
return $this;
}
public static function getDefaultSizeArray(): array
{
return [
'tireWidth' => '225',
'tireRatio' => '50',
'tireDiameter' => '17',
'tireLoadIndex' => '98',
'tireSpeedIndex' => 'W',
];
}
public function isEmpty(): bool
{
if (empty($this->width)
&& empty($this->ratio)
&& empty($this->diameter)
&& empty($this->loadIndex)
&& empty($this->speedIndex)) {
return true;
}
return false;
}
public function __toString(): string
{
return $this->id ? $this->getName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
}
}