resq/src/Entity/Vehicle.php

149 lines
3 KiB
PHP

<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="vehicle")
*/
class Vehicle
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// customer vehicles
/**
* @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="vehicle")
*/
protected $customers;
// manufacturer
/**
* @ORM\ManyToOne(targetEntity="VehicleManufacturer", inversedBy="vehicles")
* @ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $manufacturer;
// make
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $make;
// model year from
/**
* @ORM\Column(type="smallint")
*/
protected $model_year_from;
// model year to
/**
* @ORM\Column(type="smallint")
*/
protected $model_year_to;
// link to batteries compatible with this vehicle
/**
* @ORM\ManyToMany(targetEntity="Battery", mappedBy="vehicles", fetch="EXTRA_LAZY")
*/
protected $batteries;
public function __construct()
{
$this->customers = new ArrayCollection();
$this->batteries = new ArrayCollection();
}
public function getID()
{
return $this->id;
}
public function setManufacturer($manufacturer)
{
$this->manufacturer = $manufacturer;
return $this;
}
public function getManufacturer()
{
return $this->manufacturer;
}
public function setMake($make)
{
$this->make = $make;
return $this;
}
public function getMake()
{
return $this->make;
}
public function setModelYearFrom($model_year_from)
{
$this->model_year_from = $model_year_from;
return $this;
}
public function getModelYearFrom()
{
return $this->model_year_from;
}
public function setModelYearTo($model_year_to)
{
$this->model_year_to = $model_year_to;
return $this;
}
public function getModelYearTo()
{
return $this->model_year_to;
}
public function getModelYearFormatted()
{
if ($this->model_year_from == 0)
{
if ($this->model_year_to == 0)
return '-';
return $this->model_year_to;
}
if ($this->model_year_to == 0)
return $this->model_year_from;
return $this->model_year_from . ' - ' . $this->model_year_to;
}
public function addBattery(Battery $battery)
{
$this->batteries->add($battery);
return $this;
}
public function clearBatteries()
{
$this->batteries->clear();
return $this;
}
public function getBatteries()
{
return $this->batteries;
}
}