/**
  * Update a list of Land entities
  */
 public function updateListAction()
 {
     if ($this->request->hasArgument('data')) {
         $landlist = $this->request->getArgument('data');
     }
     if (empty($landlist)) {
         $this->throwStatus(400, 'Required data arguemnts not provided', null);
     }
     foreach ($landlist as $uuid => $land) {
         $landObj = $this->landRepository->findByIdentifier($uuid);
         $landObj->setLand($land['land']);
         if (isset($land['ist_in_deutschland']) && !empty($land['ist_in_deutschland'])) {
             $ist_in_deutschland = $land['ist_in_deutschland'];
         } else {
             $ist_in_deutschland = 0;
         }
         $landObj->setIst_in_deutschland($ist_in_deutschland);
         $this->landRepository->update($landObj);
     }
     $this->persistenceManager->persistAll();
     $this->throwStatus(200, null, null);
 }
 /**
  * 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;
     }
 }
 /**
  * Return the options to fill the select fields in Kloster edit form
  * @FLOW\SkipCsrfProtection
  * @return array $response select options as JSON
  */
 public function getOptionsAction()
 {
     // Bearbeitungsstatus data
     $bearbeitungsstatusArr = [];
     $this->bearbeitungsstatusRepository->setDefaultOrderings(['name' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bearbeitungsstatuses = $this->bearbeitungsstatusRepository->findAll();
     foreach ($bearbeitungsstatuses as $bearbeitungsstatus) {
         $bearbeitungsstatusArr[$bearbeitungsstatus->getUUID()] = $bearbeitungsstatus->getName();
     }
     // Personallistenstatus data
     $personallistenstatusArr = [];
     $personallistenstatuses = $this->personallistenstatusRepository->findAll();
     foreach ($personallistenstatuses as $personallistenstatus) {
         $personallistenstatusArr[$personallistenstatus->getUUID()] = $personallistenstatus->getName();
     }
     // Band data
     $bandArr = [];
     $this->bandRepository->setDefaultOrderings(['sortierung' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bands = $this->bandRepository->findAll();
     foreach ($bands as $band) {
         $bandNummerTitel = $band->getNummer() . '-' . $band->getTitel();
         $bandArr[$band->getUUID()] = $bandNummerTitel;
     }
     // Literature data for select box
     $literaturArr = $this->getLiteraturAction();
     // Bistum data for select box
     $bistumArr = [];
     $this->bistumRepository->setDefaultOrderings(['bistum' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bistums = $this->bistumRepository->findAll();
     foreach ($bistums as $bistum) {
         if ($bistum->getBistum() != 'keine Angabe') {
             $bistumArr[$bistum->getUUID()] = $bistum->getBistum();
         } else {
             $bistumArr[$bistum->getUUID()] = '––';
         }
     }
     // Orden data for select box
     $ordenArr = [];
     $this->ordenRepository->setDefaultOrderings(['orden' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $ordens = $this->ordenRepository->findAll();
     foreach ($ordens as $orden) {
         $ordenArr[$orden->getUUID()] = $orden->getOrden();
     }
     // Ordenstyp data for select box
     $ordenstypArr = [];
     $this->ordenstypRepository->setDefaultOrderings(['ordenstyp' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $ordenstyps = $this->ordenstypRepository->findAll();
     foreach ($ordenstyps as $ordenstyp) {
         $ordenstypArr[$ordenstyp->getUUID()] = $ordenstyp->getOrdenstyp();
     }
     // Klosterstatus data for select box
     $klosterstatusArr = [];
     $this->klosterstatusRepository->setDefaultOrderings(['status' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $klosterstatuses = $this->klosterstatusRepository->findAll();
     foreach ($klosterstatuses as $klosterstatus) {
         if ($klosterstatus->getStatus() != 'keine Angabe') {
             $klosterstatusArr[$klosterstatus->getUUID()] = $klosterstatus->getStatus();
         } else {
             $klosterstatusArr[$klosterstatus->getUUID()] = '––';
         }
     }
     // Bearbeiter data for select box
     $bearbeiterArr = [];
     $this->bearbeiterRepository->setDefaultOrderings(['bearbeiter' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bearbeiters = $this->bearbeiterRepository->findAll();
     foreach ($bearbeiters as $bearbeiter) {
         $bearbeiterArr[$bearbeiter->getUUID()] = $bearbeiter->getBearbeiter();
     }
     // URL-Typ data for select box
     $urltypArr = [];
     $this->urltypRepository->setDefaultOrderings(['name' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $urltyps = $this->urltypRepository->findAll();
     foreach ($urltyps as $urltyp) {
         if ($urltyp->getName() != 'GND' && $urltyp->getName() != 'Wikipedia') {
             $urltypArr[$urltyp->getUUID()] = $urltyp->getName();
         }
     }
     // Land data for select box
     $landArr = [];
     $this->landRepository->setDefaultOrderings(['land' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $lands = $this->landRepository->findAll();
     foreach ($lands as $land) {
         $landArr[$land->getUUID()] = $land->getLand();
     }
     // Bearbeiter roles
     $roleArr = [];
     foreach ($this->roleRepository->findAll()->toArray() as $role) {
         if (stristr($role->getIdentifier(), 'Flow.Login')) {
             $roleValues = explode(':', $role->getIdentifier());
             $roleArr[$role->getIdentifier()] = $roleValues[1];
         }
     }
     $response = [];
     $response['bearbeitungsstatus'] = $bearbeitungsstatusArr;
     $response['personallistenstatus'] = $personallistenstatusArr;
     $response['band'] = $bandArr;
     $response['literatur'] = $literaturArr;
     $response['bistum'] = $bistumArr;
     $response['orden'] = $ordenArr;
     $response['ordenstyp'] = $ordenstypArr;
     $response['klosterstatus'] = $klosterstatusArr;
     $response['bearbeiter'] = $bearbeiterArr;
     $response['url_typ'] = $urltypArr;
     $response['land'] = $landArr;
     $response['role'] = $roleArr;
     $getOptions = json_encode($response);
     return $getOptions;
 }
 /**
  * Update a Ort entity
  */
 public function updateAction()
 {
     if ($this->request->hasArgument('uUID')) {
         $uuid = $this->request->getArgument('uUID');
     }
     if (empty($uuid)) {
         $this->throwStatus(400, 'Required uUID not provided', null);
     }
     $ortObj = $this->ortRepository->findByIdentifier($uuid);
     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->update($ortObj);
         // Fetch Ort Urls
         $ortHasUrls = $ortObj->getOrtHasUrls();
         // Update GND if set
         $ortHasGND = false;
         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)) {
                 if (!empty($ortHasUrls)) {
                     foreach ($ortHasUrls as $i => $ortHasUrl) {
                         $urlObj = $ortHasUrl->getUrl();
                         $urlTypObj = $urlObj->getUrltyp();
                         if (is_object($urlTypObj)) {
                             $urlTyp = $urlTypObj->getName();
                             if ($urlTyp == "GND") {
                                 $urlObj->setUrl($gnd);
                                 if (!empty($gnd_label)) {
                                     $urlObj->setBemerkung($gnd_label);
                                 }
                                 $this->urlRepository->update($urlObj);
                                 $ortHasGND = true;
                             }
                         }
                     }
                 }
                 if (!$ortHasGND) {
                     $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);
                 }
             }
         }
         //Update Wikipedia if set
         $ortHasWiki = false;
         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)) {
                 foreach ($ortHasUrls as $i => $ortHasUrl) {
                     $urlObj = $ortHasUrl->getUrl();
                     $urlTypObj = $urlObj->getUrltyp();
                     if (is_object($urlTypObj)) {
                         $urlTyp = $urlTypObj->getName();
                         if ($urlTyp == "Wikipedia") {
                             $urlObj->setUrl($wikipedia);
                             if (!empty($wikipedia_label)) {
                                 $urlObj->setBemerkung($wikipedia_label);
                             }
                             $this->urlRepository->update($urlObj);
                             $ortHasWiki = true;
                         }
                     }
                 }
                 if (!$ortHasWiki) {
                     $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($ortHasUrls) && $ortHasUrls !== []) {
                     foreach ($ortHasUrls as $i => $ortHasUrl) {
                         $urlObj = $ortHasUrl->getUrl();
                         $urlTypObj = $urlObj->getUrltyp();
                         if (is_object($urlTypObj)) {
                             $urlTyp = $urlTypObj->getName();
                         }
                         if (isset($urlTyp) && ($urlTyp != "Wikipedia" && $urlTyp != "GND")) {
                             $this->ortHasUrlRepository->remove($ortHasUrl);
                             $this->urlRepository->remove($urlObj);
                         }
                     }
                 }
                 foreach ($urlArr as $k => $url) {
                     if (!empty($url)) {
                         $urlObj = new Url();
                         $urlObj->setUrl($url);
                         if (isset($urlTypArr[$k]) && !empty($urlTypArr[$k])) {
                             $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);
     }
 }