/** * Import Ort table into the FLOW domain_model tabel subugoe_germaniasacra_domain_model_ort * @return int */ public function importOrtAction() { if ($this->logger) { $start = microtime(true); } /** @var \Doctrine\DBAL\Connection $sqlConnection */ $sqlConnection = $this->entityManager->getConnection(); $tbl = 'subugoe_germaniasacra_domain_model_ort'; $sql = "ANALYZE LOCAL TABLE " . $tbl; $sqlConnection->executeUpdate($sql); $sqlConnection->close(); /** @var \Doctrine\DBAL\Connection $sqlConnection */ $sqlConnection = $this->entityManager->getConnection(); $tbl = 'subugoe_germaniasacra_domain_model_urltyp'; $sql = 'SELECT * FROM ' . $tbl . ' WHERE name = "Geonames"'; $urltyp = $sqlConnection->fetchAll($sql); if (count($urltyp) > 0) { $urltypUUID = $urltyp[0]['persistence_object_identifier']; } if (!isset($urltypUUID)) { $urlTypeName = "Geonames"; $urltypObject = new Urltyp(); $urltypObject->setName($urlTypeName); $this->urltypRepository->add($urltypObject); $this->persistenceManager->persistAll(); $urltypUUID = $urltypObject->getUUID(); } $sql = 'SELECT * FROM Ort ORDER BY ID ASC'; $orts = $sqlConnection->fetchAll($sql); if (isset($orts) and is_array($orts)) { $nOrt = 0; foreach ($orts as $ortvalue) { $uid = $ortvalue['ID']; $ort = $ortvalue['Ort']; $laenge = round($ortvalue['Laenge'], 5); $breite = round($ortvalue['Breite'], 5); $wuestung = $ortvalue['Wuestung']; $gemeinde = $ortvalue['Gemeinde']; $kreis = $ortvalue['Kreis']; $land = $ortvalue['Land']; $url = $ortvalue['GeoNameId']; $ortObject = new Ort(); $ortObject->setUid($uid); $ortObject->setOrt($ort); $ortObject->setLaenge($laenge); $ortObject->setBreite($breite); $ortObject->setWuestung($wuestung); $ortObject->setGemeinde($gemeinde); $ortObject->setKreis($kreis); $landObject = $this->landRepository->findOneByUid($land); if (is_object($landObject)) { $ortObject->setLand($landObject); } $this->ortRepository->add($ortObject); $this->persistenceManager->persistAll(); $ortUUID = $ortObject->getUUID(); if (isset($url) && !empty($url)) { $url = 'http://geonames.org/' . $url; $urlbemerkung = $ort . " " . $url; $urlObject = new Url(); $urlObject->setUrl($url); $urlObject->setBemerkung($urlbemerkung); $urltypObject = $this->urltypRepository->findByIdentifier($urltypUUID); $urlObject->setUrltyp($urltypObject); $this->urlRepository->add($urlObject); $this->persistenceManager->persistAll(); $urlUUID = $urlObject->getUUID(); $orthasurlObject = new Orthasurl(); $ortObject = $this->ortRepository->findByIdentifier($ortUUID); $orthasurlObject->setOrt($ortObject); $urlObject = $this->urlRepository->findByIdentifier($urlUUID); $orthasurlObject->setUrl($urlObject); $this->ortHasUrlRepository->add($orthasurlObject); $this->persistenceManager->persistAll(); } $nOrt++; } if ($this->logger) { $end = microtime(true); $time = number_format($end - $start, 2); $this->logger->log('Ort import completed in ' . round($time / 60, 2) . ' minutes.'); } return $nOrt; } }
/** * Create a new Ort entity */ public function createAction() { $ortObj = new Ort(); if (is_object($ortObj)) { $ortObj->setOrt($this->request->getArgument('ort')); $ortObj->setGemeinde($this->request->getArgument('gemeinde')); $ortObj->setKreis($this->request->getArgument('kreis')); $ortObj->setWuestung($this->request->hasArgument('wuestung')); $ortObj->setBreite($this->request->getArgument('breite')); $ortObj->setLaenge($this->request->getArgument('laenge')); if ($this->request->hasArgument('bistum')) { $bistumUUID = $this->request->getArgument('bistum'); $bistumObj = $this->bistumRepository->findByIdentifier($bistumUUID); if (is_object($bistumObj)) { $ortObj->setBistum($bistumObj); } } if ($this->request->hasArgument('land')) { $landUUID = $this->request->getArgument('land'); $landObj = $this->landRepository->findByIdentifier($landUUID); if (is_object($landObj)) { $ortObj->setLand($landObj); } } $this->ortRepository->add($ortObj); // Add GND if set if ($this->request->hasArgument('gnd')) { $gnd = $this->request->getArgument('gnd'); if ($this->request->hasArgument('gnd_label')) { $gnd_label = $this->request->getArgument('gnd_label'); } if (empty($gnd_label)) { $gndid = str_replace('http://d-nb.info/gnd/', '', trim($gnd)); $gnd_label = $this->request->getArgument('ort') . ' [' . $gndid . ']'; } if (isset($gnd) && !empty($gnd)) { $url = new Url(); $url->setUrl($gnd); if (!empty($gnd_label)) { $url->setBemerkung($gnd_label); } $urlTypObj = $this->urltypRepository->findOneByName('GND'); $url->setUrltyp($urlTypObj); $this->urlRepository->add($url); $urlUUID = $url->getUUID(); $urlObj = $this->urlRepository->findByIdentifier($urlUUID); $orthasurl = new OrtHasUrl(); $orthasurl->setOrt($ortObj); $orthasurl->setUrl($urlObj); $this->ortHasUrlRepository->add($orthasurl); } } //Add Wikipedia if set if ($this->request->hasArgument('wikipedia')) { $wikipedia = $this->request->getArgument('wikipedia'); if ($this->request->hasArgument('wikipedia_label')) { $wikipedia_label = $this->request->getArgument('wikipedia_label'); } if (empty($wikipedia_label)) { $wikipedia_label = str_replace('http://de.wikipedia.org/wiki/', '', trim($wikipedia)); $wikipedia_label = str_replace('_', ' ', $wikipedia_label); $wikipedia_label = rawurldecode($wikipedia_label); } if (isset($wikipedia) && !empty($wikipedia)) { $url = new Url(); $url->setUrl($wikipedia); if (!empty($wikipedia_label)) { $url->setBemerkung($wikipedia_label); } $urlTypObj = $this->urltypRepository->findOneByName('Wikipedia'); $url->setUrltyp($urlTypObj); $this->urlRepository->add($url); $urlUUID = $url->getUUID(); $urlObj = $this->urlRepository->findByIdentifier($urlUUID); $orthasurl = new OrtHasUrl(); $orthasurl->setOrt($ortObj); $orthasurl->setUrl($urlObj); $this->ortHasUrlRepository->add($orthasurl); } } // Add Url if set if ($this->request->hasArgument('url')) { $urlArr = $this->request->getArgument('url'); if (isset($urlArr) && !empty($urlArr)) { if ($this->request->hasArgument('url_typ')) { $urlTypArr = $this->request->getArgument('url_typ'); } if ($this->request->hasArgument('links_label')) { $linksLabelArr = $this->request->getArgument('links_label'); } if (isset($urlArr) && !empty($urlArr) && (isset($urlTypArr) && !empty($urlTypArr))) { foreach ($urlArr as $k => $url) { if (!empty($url)) { $urlObj = new Url(); $urlObj->setUrl($url); $urlTypObj = $this->urltypRepository->findByIdentifier($urlTypArr[$k]); $urlTyp = $urlTypObj->getName(); $urlObj->setUrltyp($urlTypObj); if (isset($linksLabelArr[$k]) && !empty($linksLabelArr[$k])) { $urlObj->setBemerkung($linksLabelArr[$k]); } else { $urlObj->setBemerkung($urlTyp); } $this->urlRepository->add($urlObj); $orthasurl = new OrtHasUrl(); $orthasurl->setOrt($ortObj); $orthasurl->setUrl($urlObj); $this->ortHasUrlRepository->add($orthasurl); } } } } } $this->persistenceManager->persistAll(); $this->throwStatus(200, null, null); } else { $this->throwStatus(400, 'Entity Ort not available', null); } }