/**
  * Import Orden table into the FLOW domain_model tabel subugoe_germaniasacra_domain_model_orden
  * @return int
  */
 public function importOrdenAction()
 {
     if ($this->logger) {
         $start = microtime(true);
     }
     /** @var \Doctrine\DBAL\Connection $sqlConnection */
     $sqlConnection = $this->entityManager->getConnection();
     $sql = 'SELECT * FROM Orden';
     $ordens = $sqlConnection->fetchAll($sql);
     $ordenstypArr = [];
     if (isset($ordens) and is_array($ordens)) {
         $nOrden = 0;
         foreach ($ordens as $ordenvalue) {
             $uid = $ordenvalue['ID_Ordo'];
             $orden = $ordenvalue['Ordensbezeichnung'];
             $ordo = $ordenvalue['Ordo'];
             $symbol = $ordenvalue['Symbol'];
             $graphik = null;
             if (isset($ordenvalue['Grafikdatei']) && !empty($ordenvalue['Grafikdatei'])) {
                 $graphik = $ordenvalue['Grafikdatei'];
             }
             $ordenstyp = $ordenvalue['Geschlecht'];
             $gnd = $ordenvalue['GND_Orden'];
             $wikipedia = $ordenvalue['Wikipedia_Orden'];
             if (empty($ordenstyp)) {
                 $ordenstyp = 'unbekannt';
             }
             if (!in_array($ordenstyp, $ordenstypArr)) {
                 $ordenstypObject = new Ordenstyp();
                 $ordenstypObject->setOrdenstyp($ordenstyp);
                 $this->ordenstypRepository->add($ordenstypObject);
                 $this->persistenceManager->persistAll();
                 $ordenstypUUID = $ordenstypObject->getUUID();
             }
             array_push($ordenstypArr, $ordenstyp);
             if (isset($ordenstypUUID) && !empty($ordenstypUUID)) {
                 $ordenstypObject = $this->ordenstypRepository->findByIdentifier($ordenstypUUID);
             } else {
                 $ordenstypObject = $this->ordenstypRepository->findOneByOrdenstyp($ordenstyp);
             }
             $ordenObject = new Orden();
             $ordenObject->setUid($uid);
             $ordenObject->setOrden($orden);
             $ordenObject->setOrdo($ordo);
             $ordenObject->setSymbol($symbol);
             $ordenObject->setGraphik($graphik);
             $ordenObject->setOrdenstyp($ordenstypObject);
             $this->ordenRepository->add($ordenObject);
             $this->persistenceManager->persistAll();
             unset($ordenstypUUID);
             $ordenUUID = $ordenObject->getUUID();
             if (isset($gnd) && !empty($gnd)) {
                 $gnd = str_replace("\t", " ", $gnd);
                 $gnd = str_replace("http:// ", " ", $gnd);
                 $gnd = str_replace(" http", ";http", $gnd);
                 $gnd = str_replace(";", "#", $gnd);
                 $gnds = explode("#", $gnd);
                 if (isset($gnds) && is_array($gnds)) {
                     $oldgnd = "";
                     foreach ($gnds as $gnd) {
                         if (isset($gnd) && !empty($gnd)) {
                             if ($gnd != $oldgnd) {
                                 $gnd = str_replace(" ", "", $gnd);
                                 $gnd = str_replace("# ", "", $gnd);
                                 $gndid = str_replace("http://d-nb.info/gnd/", "", $gnd);
                                 $gndbemerkung = $orden . " [" . $gndid . "]";
                                 $urlObject = new Url();
                                 $urlObject->setUrl($gnd);
                                 $urlObject->setBemerkung($gndbemerkung);
                                 $gndurltypObject = $this->urltypRepository->findOneByName('GND');
                                 $urlObject->setUrltyp($gndurltypObject);
                                 $this->urlRepository->add($urlObject);
                                 $this->persistenceManager->persistAll();
                                 $gndurlUUID = $urlObject->getUUID();
                                 $oldgnd = $gnd;
                                 $ordenhasurlObject = new Ordenhasurl();
                                 $ordenObject = $this->ordenRepository->findByIdentifier($ordenUUID);
                                 $ordenhasurlObject->setOrden($ordenObject);
                                 $gndurlObject = $this->urlRepository->findByIdentifier($gndurlUUID);
                                 $ordenhasurlObject->setUrl($gndurlObject);
                                 $this->ordenHasUrlRepository->add($ordenhasurlObject);
                                 $this->persistenceManager->persistAll();
                             }
                         }
                     }
                 }
             }
             if (isset($wikipedia) && !empty($wikipedia)) {
                 $wikipedia = str_replace("http:// ", " ", $wikipedia);
                 $wikipedia = str_replace(";", "#", $wikipedia);
                 $wikipedias = explode("#", $wikipedia);
                 if (isset($wikipedias) && is_array($wikipedias)) {
                     $oldwikipedia = "";
                     foreach ($wikipedias as $wikipedia) {
                         if (isset($wikipedia) && !empty($wikipedia)) {
                             if ($wikipedia != $oldwikipedia) {
                                 $wikipediabemerkung = str_replace("http://de.wikipedia.org/wiki/", "", $wikipedia);
                                 $wikipediabemerkung = str_replace("_", " ", $wikipediabemerkung);
                                 $wikipediabemerkung = rawurldecode($wikipediabemerkung);
                                 $urlObject = new Url();
                                 $urlObject->setUrl($wikipedia);
                                 $urlObject->setBemerkung($wikipediabemerkung);
                                 $wikiurltypObject = $this->urltypRepository->findOneByName('Wikipedia');
                                 $urlObject->setUrltyp($wikiurltypObject);
                                 $this->urlRepository->add($urlObject);
                                 $this->persistenceManager->persistAll();
                                 $wikiurlUUID = $urlObject->getUUID();
                                 $oldwikipedia = $wikipedia;
                                 $ordenhasurlObject = new Ordenhasurl();
                                 $ordenObject = $this->ordenRepository->findByIdentifier($ordenUUID);
                                 $ordenhasurlObject->setOrden($ordenObject);
                                 $wikiurlObject = $this->urlRepository->findByIdentifier($wikiurlUUID);
                                 $ordenhasurlObject->setUrl($wikiurlObject);
                                 $this->ordenHasUrlRepository->add($ordenhasurlObject);
                                 $this->persistenceManager->persistAll();
                             }
                         }
                     }
                 }
             }
             $nOrden++;
         }
         if ($this->logger) {
             $end = microtime(true);
             $time = number_format($end - $start, 2);
             $this->logger->log('Orden import completed in ' . round($time / 60, 2) . ' minutes.');
         }
         return $nOrden;
     }
 }
 /**
  * Update an Orden 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);
     }
     $ordenObj = $this->ordenRepository->findByIdentifier($uuid);
     if (is_object($ordenObj)) {
         $ordenObj->setOrden($this->request->getArgument('orden'));
         $ordenObj->setOrdo($this->request->getArgument('ordo'));
         $ordenObj->setSymbol($this->request->getArgument('symbol'));
         $ordenObj->setGraphik($this->request->getArgument('graphik'));
         if ($this->request->hasArgument('ordenstyp')) {
             $ordenstypUUID = $this->request->getArgument('ordenstyp');
             $ordenstypObj = $this->ordenstypRepository->findByIdentifier($ordenstypUUID);
             $ordenObj->setOrdenstyp($ordenstypObj);
         }
         $this->ordenRepository->update($ordenObj);
         // Fetch Orden Urls
         $ordenHasUrls = $ordenObj->getOrdenHasUrls();
         $ordenHasGND = false;
         // Update 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('orden') . ' [' . $gndid . ']';
             }
             if (isset($gnd) && !empty($gnd)) {
                 if (!empty($ordenHasUrls)) {
                     foreach ($ordenHasUrls as $i => $ordenHasUrl) {
                         $urlObj = $ordenHasUrl->getUrl();
                         $urlTypObj = $urlObj->getUrltyp();
                         $urlTyp = $urlTypObj->getName();
                         if ($urlTyp == "GND") {
                             $urlObj->setUrl($gnd);
                             if (!empty($gnd_label)) {
                                 $urlObj->setBemerkung($gnd_label);
                             }
                             $this->urlRepository->update($urlObj);
                             $ordenHasGND = true;
                         }
                     }
                 }
                 if (!$ordenHasGND) {
                     $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);
                     $ordenhasurl = new OrdenHasUrl();
                     $ordenhasurl->setOrden($ordenObj);
                     $ordenhasurl->setUrl($urlObj);
                     $this->ordenHasUrlRepository->add($ordenhasurl);
                 }
             }
         }
         //Update Wikipedia if set
         $ordenHasWiki = 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 ($ordenHasUrls as $i => $ordenHasUrl) {
                     $urlObj = $ordenHasUrl->getUrl();
                     $url = $urlObj->getUrl();
                     $urlTypObj = $urlObj->getUrltyp();
                     $urlTyp = $urlTypObj->getName();
                     if ($urlTyp == "Wikipedia") {
                         $urlObj->setUrl($wikipedia);
                         if (!empty($wikipedia_label)) {
                             $urlObj->setBemerkung($wikipedia_label);
                         }
                         $this->urlRepository->update($urlObj);
                         $ordenHasWiki = true;
                     }
                 }
                 if (!$ordenHasWiki) {
                     $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);
                     $ordenhasurl = new OrdenHasUrl();
                     $ordenhasurl->setOrden($ordenObj);
                     $ordenhasurl->setUrl($urlObj);
                     $this->ordenHasUrlRepository->add($ordenhasurl);
                 }
             }
         }
         // 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 ($ordenHasUrls as $i => $ordenHasUrl) {
                         $urlObj = $ordenHasUrl->getUrl();
                         $url = $urlObj->getUrl();
                         $urlTypObj = $urlObj->getUrltyp();
                         $urlTyp = $urlTypObj->getName();
                         if ($urlTyp != "Wikipedia" && $urlTyp != "GND") {
                             $this->ordenHasUrlRepository->remove($ordenHasUrl);
                             $this->urlRepository->remove($urlObj);
                         }
                     }
                     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);
                             $ordenhasurlObj = new OrdenHasUrl();
                             $ordenhasurlObj->setOrden($ordenObj);
                             $ordenhasurlObj->setUrl($urlObj);
                             $this->ordenHasUrlRepository->add($ordenhasurlObj);
                         }
                     }
                 }
             }
         }
         $this->persistenceManager->persistAll();
         $this->throwStatus(200, null, null);
     } else {
         $this->throwStatus(400, 'Entity Orden not available', null);
     }
 }