Add deletion of battery from vehicle when vehicle has more than one compatible battery. #317
This commit is contained in:
parent
234d993d8f
commit
33fdc857f2
1 changed files with 18 additions and 8 deletions
|
|
@ -282,15 +282,25 @@ class VehicleController extends Controller
|
||||||
// need to check if a battery has been removed
|
// need to check if a battery has been removed
|
||||||
if (count($current_batteries) > count($batteries))
|
if (count($current_batteries) > count($batteries))
|
||||||
{
|
{
|
||||||
error_log('A battery has been removed');
|
// battery/batteries have been removed
|
||||||
}
|
foreach ($current_batteries as $cbatt)
|
||||||
foreach ($batteries as $battery_id)
|
|
||||||
{
|
|
||||||
$battery = $em->getRepository(Battery::class)->find($battery_id);
|
|
||||||
|
|
||||||
if (!empty($battery))
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue