acl_gen = $acl_gen; } public function getCompatibleBatteries(Request $req, $vid, EntityManagerInterface $em) { $this->denyAccessUnlessGranted('tapi_battery_compatible.list', null, 'No access.'); // check required parameters and api key $required_params = []; $msg = $this->checkRequiredParameters($req, $required_params); if ($msg) return new APIResponse(false, $msg); // get vehicle $vehicle = $em->getRepository(Vehicle::class)->find($vid); if ($vehicle == null) { $message = 'Invalid vehicle id.'; return new APIResponse(false, $message); } // batteries $batt_list = []; // $batts = $vehicle->getBatteries(); $batts = $vehicle->getActiveBatteries(); foreach ($batts as $batt) { // TODO: Add warranty_tnv to battery information $batt_list[] = [ 'id' => $batt->getID(), 'mfg_id' => $batt->getManufacturer()->getID(), 'mfg_name' => $batt->getManufacturer()->getName(), 'model_id' => $batt->getModel()->getID(), 'model_name' => $batt->getModel()->getName(), 'size_id' => $batt->getSize()->getID(), 'size_name' => $batt->getSize()->getName(), 'price' => $batt->getSellingPrice(), 'wty_private' => $batt->getWarrantyPrivate(), 'wty_commercial' => $batt->getWarrantyCommercial(), 'image_url' => $this->getBatteryImageURL($req, $batt), ]; } // data $data = [ 'vehicle' => [ 'id' => $vehicle->getID(), 'mfg_id' => $vehicle->getManufacturer()->getID(), 'mfg_name' => $vehicle->getManufacturer()->getName(), 'make' => $vehicle->getMake(), 'model_year_from' => $vehicle->getModelYearFrom(), 'model_year_to' => $vehicle->getModelYearTo(), ], 'batteries' => $batt_list, ]; $message = 'Compatible batteries found.'; return new APIResponse(true, $message, $data); } // TODO: might have to put this in a common service since JobOrderController also calls this protected function getBatteryImageURL($req, $batt) { // TODO: workaround for now, we get static image of battery based on model name $filename = trim(strtolower($batt->getModel()->getName())) . '_mobile.jpg'; $file_path = $req->getSchemeAndHttpHost() . $this->generateUrl('static_battery_image') . '/' . $filename; return $file_path; } }