diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index f7f8c625..d09d3752 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -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 {