Add saving of battery to vehicle. #323

This commit is contained in:
Korina Cordero 2020-02-03 11:23:57 +00:00
parent 6bcdf70902
commit ac908e9bcd

View file

@ -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
{