resq/src/Entity/BatteryModel.php

79 lines
1.5 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="battery_model")
*/
class BatteryModel
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// name
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $name;
// battery
/**
* @ORM\OneToMany(targetEntity="Battery", mappedBy="model")
*/
protected $batteries;
public function __construct()
{
$this->batteries = new ArrayCollection();
}
public function getID()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function addBattery(Battery $battery)
{
$this->batteries->add($battery);
return $this;
}
public function clearBatteries()
{
$this->batteries->clear();
return $this;
}
public function getBatteries()
{
// TODO: fix this to be a proper getter function
// has to return set of strings because symfony is trying to move away from role objects
$str_batteries = [];
foreach ($this->batteries as $battery)
$str_batteries[] = $this->getProductCode();
return $str_batteries;
}
}