Add saving of battery to vehicle. #323
This commit is contained in:
parent
6bcdf70902
commit
ac908e9bcd
1 changed files with 35 additions and 0 deletions
|
|
@ -310,6 +310,41 @@ class VehicleController extends Controller
|
|||
}
|
||||
}
|
||||
}
|
||||
// need to check if a battery has been added
|
||||
if (count($current_batteries) < count($batteries))
|
||||
{
|
||||
// get the ids of current batteries
|
||||
$cbatt_ids = [];
|
||||
foreach ($current_batteries as $cbatt)
|
||||
{
|
||||
$cbatt_ids = [
|
||||
$cbatt->getID(),
|
||||
];
|
||||
}
|
||||
|
||||
// find the battery to add
|
||||
foreach ($batteries as $batt)
|
||||
{
|
||||
$batt_id = $batt;
|
||||
if (in_array($batt_id, $cbatt_ids))
|
||||
{
|
||||
// do nothing since battery already there
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// batt is the new battery
|
||||
$battery = $em->getRepository(Battery::class)->find($batt_id);
|
||||
|
||||
if (!empty($battery))
|
||||
{
|
||||
$battery->addVehicle($row);
|
||||
|
||||
$em->persist($battery);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue