180 lines
3.6 KiB
PHP
180 lines
3.6 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 $cust_vehicles;
|
|
|
|
// manufacturer
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="VehicleManufacturer", inversedBy="vehicles")
|
|
* @ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id")
|
|
* @Assert\NotBlank()
|
|
*/
|
|
protected $manufacturer;
|
|
|
|
// make
|
|
/**
|
|
* @ORM\Column(type="string", length=110)
|
|
* @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", indexBy="id", fetch="EXTRA_LAZY")
|
|
* @ORM\OrderBy({"sell_price" = "DESC"})
|
|
*/
|
|
protected $batteries;
|
|
|
|
// display in mobile app
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
protected $flag_mobile;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->cust_vehicles = new ArrayCollection();
|
|
$this->batteries = new ArrayCollection();
|
|
$this->flag_mobile = true;
|
|
}
|
|
|
|
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($has_dash = true)
|
|
{
|
|
if ($this->model_year_from == 0)
|
|
{
|
|
if ($this->model_year_to == 0)
|
|
{
|
|
if ($has_dash)
|
|
return '-';
|
|
|
|
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[$battery->getID()] = $battery;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function clearBatteries()
|
|
{
|
|
$this->batteries->clear();
|
|
return $this;
|
|
}
|
|
|
|
public function getBatteries()
|
|
{
|
|
return $this->batteries;
|
|
}
|
|
|
|
public function setDisplayMobile($bool = true)
|
|
{
|
|
$this->flag_mobile = $bool;
|
|
return $this;
|
|
}
|
|
|
|
public function shouldDisplayMobile()
|
|
{
|
|
return $this->flag_mobile;
|
|
}
|
|
|
|
public function getCustomerVehicles()
|
|
{
|
|
return $this->cust_vehicles;
|
|
}
|
|
}
|