src/Entity/Tires/TireSize.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Tires;
  3. use App\Entity\MiniAbstractBase;
  4. use App\Repository\Tires\TireSizeRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @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"})})
  8.  * @ORM\Entity(repositoryClass=TireSizeRepository::class)
  9.  */
  10. class TireSize
  11. {
  12.     /**
  13.      * @ORM\Column(name="id", type="integer")
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue(strategy="AUTO")
  16.      */
  17.     private int $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=64, nullable=true)
  20.      */
  21.     private ?string $width null;
  22.     /**
  23.      * @ORM\Column(type="string", length=64, nullable=true)
  24.      */
  25.     private ?string $ratio null;
  26.     /**
  27.      * @ORM\Column(type="string", length=64, nullable=true)
  28.      */
  29.     private ?string $diameter null;
  30.     /**
  31.      * @ORM\Column(type="string", length=64, nullable=true)
  32.      */
  33.     private ?string $loadIndex null;
  34.     /**
  35.      * @ORM\Column(type="string", length=64, nullable=true)
  36.      */
  37.     private ?string $speedIndex null;
  38.     public function __construct()
  39.     {
  40.     }
  41.     public function getId(): int
  42.     {
  43.         return $this->id;
  44.     }
  45.     /**
  46.      * Get tyre model short format "{WIDHT}/{RATIO} R{DIAMETER} {LOAD}{SPEED}".
  47.      */
  48.     public function getName(): string
  49.     {
  50.         // Al importar los neumáticos del csv ponemos el valor '-' cuando tiene valor vacío ''
  51.         // para no tratar con campos de texto vacío o null en los selects del buscador
  52.         $width = ('-' === $this->getWidth()) ? '' $this->getWidth();
  53.         $ratio = ('-' === $this->getRatio()) ? '' $this->getRatio();
  54.         $diameter = ('-' === $this->getDiameter()) ? '' $this->getDiameter();
  55.         $loadIndex = ('-' === $this->getLoadIndex()) ? '' $this->getLoadIndex();
  56.         $speedIndex = ('-' === $this->getSpeedIndex()) ? '' $this->getSpeedIndex();
  57.         $size = !empty($width) ? $width '';
  58.         $size .= !empty($ratio) ? '/'.$ratio '';
  59.         $size .= !empty($diameter) ? ' R'.$diameter '';
  60.         $size .= !empty($loadIndex) ? ' '.$loadIndex '';
  61.         $size .= !empty($speedIndex) ? (empty($loadIndex) ? ' ' '').$speedIndex '';
  62.         return $size;
  63.     }
  64.     /**
  65.      * Get tyre model short format "{WIDHT}/{RATIO} R{DIAMETER} {LOAD}{SPEED}" for given tire size arguments.
  66.      */
  67.     public static function getNameFor(string $tireWidthstring $tireRatiostring $tireDiameterstring $tireLoadIndexstring $tireSpeedIndex): string
  68.     {
  69.         // Al importar los neumáticos del csv ponemos el valor '-' cuando tiene valor vacío ''
  70.         // para no tratar con campos de texto vacío o null en los selects del buscador
  71.         $width = ('-' === $tireWidth) ? '' $tireWidth;
  72.         $ratio = ('-' === $tireRatio) ? '' $tireRatio;
  73.         $diameter = ('-' === $tireDiameter) ? '' $tireDiameter;
  74.         $loadIndex = ('-' === $tireLoadIndex) ? '' $tireLoadIndex;
  75.         $speedIndex = ('-' === $tireSpeedIndex) ? '' $tireSpeedIndex;
  76.         $size = !empty($width) ? $width '';
  77.         $size .= !empty($ratio) ? '/'.$ratio '';
  78.         $size .= !empty($diameter) ? ' R'.$diameter '';
  79.         $size .= !empty($loadIndex) ? ' '.$loadIndex '';
  80.         $size .= !empty($speedIndex) ? (empty($loadIndex) ? ' ' '').$speedIndex '';
  81.         return $size;
  82.     }
  83.     public function getWidth(): ?string
  84.     {
  85.         return $this->width;
  86.     }
  87.     public function setWidth(string $width): self
  88.     {
  89.         $this->width $width;
  90.         return $this;
  91.     }
  92.     public function getRatio(): ?string
  93.     {
  94.         return $this->ratio;
  95.     }
  96.     public function setRatio(string $ratio): self
  97.     {
  98.         $this->ratio $ratio;
  99.         return $this;
  100.     }
  101.     public function getDiameter(): ?string
  102.     {
  103.         return $this->diameter;
  104.     }
  105.     public function setDiameter(string $diameter): self
  106.     {
  107.         $this->diameter $diameter;
  108.         return $this;
  109.     }
  110.     public function getLoadIndex(): ?string
  111.     {
  112.         return $this->loadIndex;
  113.     }
  114.     public function setLoadIndex(string $loadIndex): self
  115.     {
  116.         $this->loadIndex $loadIndex;
  117.         return $this;
  118.     }
  119.     public function getSpeedIndex(): ?string
  120.     {
  121.         return $this->speedIndex;
  122.     }
  123.     public function setSpeedIndex(string $speedIndex): self
  124.     {
  125.         $this->speedIndex $speedIndex;
  126.         return $this;
  127.     }
  128.     public static function getDefaultSizeArray(): array
  129.     {
  130.         return [
  131.             'tireWidth' => '225',
  132.             'tireRatio' => '50',
  133.             'tireDiameter' => '17',
  134.             'tireLoadIndex' => '98',
  135.             'tireSpeedIndex' => 'W',
  136.         ];
  137.     }
  138.     public function isEmpty(): bool
  139.     {
  140.         if (empty($this->width)
  141.             && empty($this->ratio)
  142.             && empty($this->diameter)
  143.             && empty($this->loadIndex)
  144.             && empty($this->speedIndex)) {
  145.             return true;
  146.         }
  147.         return false;
  148.     }
  149.     public function __toString(): string
  150.     {
  151.         return $this->id $this->getName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
  152.     }
  153. }