Add deletion of battery from vehicle when vehicle has more than one compatible battery. #317

This commit is contained in:
Korina Cordero 2020-01-29 11:16:07 +00:00
parent 234d993d8f
commit 33fdc857f2

View file

@ -282,15 +282,25 @@ class VehicleController extends Controller
// need to check if a battery has been removed
if (count($current_batteries) > count($batteries))
{
error_log('A battery has been removed');
}
foreach ($batteries as $battery_id)
{
$battery = $em->getRepository(Battery::class)->find($battery_id);
if (!empty($battery))
// battery/batteries have been removed
foreach ($current_batteries as $cbatt)
{
error_log('battery id ' . $battery->getID());
$cbatt_id = $cbatt->getID();
if (in_array($cbatt_id, $batteries))
{
// do nothing, move to next element
continue;
}
else
{
// cbatt_id has been deleted
$battery = $em->getRepository(Battery::class)->find($cbatt_id);
if (!empty($battery))
{
$battery->removeVehicle($row);
}
}
}
}
}