'netzgebiet_id', 'text' => 'Netzgebiet', 'required' => true, 'modal' => ['type' => 'select', 'items' => []], 'table' => ['filter' => 'select']], ['key' => 'name', 'text' => 'Name', 'required' => true], ['key' => 'rimo_id', 'text' => 'Rimo ID', 'required' => true], ['key' => 'label', 'text' => 'Label', 'required' => false], ['key' => 'building_type', 'text' => 'Gebäudetyp', 'required' => false], ['key' => 'rimo_ex_state', 'text' => 'Rimo Ex State', 'required' => false], ['key' => 'rimo_op_state', 'text' => 'Rimo Op State', 'required' => false], ['key' => 'gps_lat', 'text' => 'GPS Lat', 'required' => false], ['key' => 'gps_long', 'text' => 'GPS Long', 'required' => false], ['key' => 'create', 'text' => 'Erstellt', 'required' => true, 'modal' => false], ['key' => 'edit', 'text' => 'Bearbeitet', 'required' => true, 'modal' => false, 'table' => false], ['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center', 'priority' => 10]], ]; public function prepareCrudConfig() { $netzgebiete = array_map(function ($netzgebiet) { return ['value' => $netzgebiet->id, 'text' => $netzgebiet->name]; }, ADBNetzgebietModel::getAll()); $this->columns[0]['modal']['items'] = $netzgebiete; } public function ImportFCPsAction() { $input = json_decode(file_get_contents('php://input'), true); $fcpList = $input['data'] ?? []; $networkAreaId = $input['networkAreaId']; $counts = ['new' => 0, 'upd' => 0]; $now = date('U'); foreach ($fcpList as $fcpIn) { $rimoId = $fcpIn['ExternalID'] ?? null; if ($rimoId === null) $rimoId = $fcpIn['External ID'] ?? null; if ($rimoId === null) continue; $data = [ 'netzgebiet_id' => $networkAreaId, 'name' => $fcpIn['Name'] ?? null, 'rimo_id' => $rimoId, 'label' => $fcpIn['User label'] ?? null, 'building_type' => $fcpIn['Building type'] ?? null, 'rimo_ex_state' => $fcpIn['Execution state'] ?? null, 'rimo_op_state' => $fcpIn['Operational state'] ?? null, 'gps_lat' => floatval(str_replace(',', '.', $fcpIn['Latitude'] ?? '0')), 'gps_long' => floatval(str_replace(',', '.', $fcpIn['Longitude'] ?? '0')), 'edit' => $now ]; $existing = ADBRimoFcp::getAll(['rimo_id' => $rimoId]); if (count($existing) > 0 && $existing = $existing[0]) { $data['id'] = $existing->id; $data['create'] = $existing->create; ADBRimoFcp::update($data); $counts['upd']++; } else { $data['create'] = $now; ADBRimoFcp::create($data); $counts['new']++; } } $msg = sprintf('%d new, %d updated FCPs.', $counts['new'], $counts['upd']); self::returnJson(['success' => true, 'message' => $msg]); } public function ImportLocationsAction() { $input = json_decode(file_get_contents('php://input'), true); $fcpsByName = array_column(ADBRimoFcp::getAll(['netzgebiet_id' => $input['networkAreaId']]), null, 'name'); $counts = ['upd' => 0, 'fcpNF' => 0, 'noFCP' => 0, 'noExtId' => 0]; foreach ($input['data'] as $loc) { $fcpName = trim($loc['FCP cluster name'] ?? ''); $extId = $loc['ExternalID'] ?? null; if ($extId === null) $extId = $loc['External ID'] ?? null; if ($fcpName === '') { $counts['noFCP']++; continue; } if (!isset($fcpsByName[$fcpName])) { $counts['fcpNF']++; continue; } if ($extId === null) { $counts['noExtId']++; continue; } $fcp = $fcpsByName[$fcpName]; if ($hn = ADBHausnummerModel::getFirst(['rimo_id' => $extId])) { $hn->fcp_id = $fcp->id; $hn->rimo_fcp_name = $fcp->name; $hn->save(); $counts['upd']++; } } $msg = sprintf('Updated: %d, FCP not Found: %d, No FCP in the CSV: %d, No Rimo ID: %d', $counts['upd'], $counts['fcpNF'], $counts['noFCP'], $counts['noExtId']); self::returnJson(['success' => true, 'message' => $msg]); } public function MapAction() { Helper::renderVue($this, "ADBRimoFcpMap", "ADBRimoFcpMap", [ "MAPBOX_KEY" => TT_MAPBOX_TILE_API_TOKEN, ]); } public function getAllFCPsAction() { $input = json_decode(file_get_contents('php://input'), true); $fcpList = ADBRimoFcp::getAll(); $fcpData = array_map(function ($fcp) { return [ 'id' => $fcp->id, // 'rimo_ex_state' => $fcp->rimo_ex_state, // 'rimo_op_state' => $fcp->rimo_op_state, 'gps_lat' => $fcp->gps_lat, 'gps_long' => $fcp->gps_long ]; }, $fcpList); self::returnJson(['success' => true, 'data' => $fcpData]); } }