/**
  * Update a Band 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);
     }
     $bandObj = $this->bandRepository->findByIdentifier($uuid);
     if (is_object($bandObj)) {
         $bandObj->setNummer($this->request->getArgument('nummer'));
         $bandObj->setTitel($this->request->getArgument('titel'));
         $bandObj->setKurztitel($this->request->getArgument('kurztitel'));
         $bandObj->setSortierung($this->request->getArgument('sortierung'));
         if ($this->request->hasArgument('bistum')) {
             $bistumUUID = $this->request->getArgument('bistum');
             $bistumObj = $this->bistumRepository->findByIdentifier($bistumUUID);
             if (is_object($bistumObj)) {
                 $bandObj->setBistum($bistumObj);
             }
         }
         $this->bandRepository->update($bandObj);
         // Fetch Band Urls
         $bandHasUrls = $bandObj->getBandHasUrls();
         $bandHasGND = 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('nummer') . ' [' . $gndid . ']';
             }
             if (isset($gnd) && !empty($gnd)) {
                 if (!empty($bandHasUrls)) {
                     foreach ($bandHasUrls as $i => $bandHasUrl) {
                         $urlObj = $bandHasUrl->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);
                             $bandHasGND = true;
                         }
                     }
                 }
                 if (!$bandHasGND) {
                     $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);
                     $bandhasurl = new BandHasUrl();
                     $bandhasurl->setBand($bandObj);
                     $bandhasurl->setUrl($urlObj);
                     $this->bandHasUrlRepository->add($bandhasurl);
                 }
             }
         }
         //Update Wikipedia if set
         $bandHasWiki = 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 ($bandHasUrls as $i => $bandHasUrl) {
                     $urlObj = $bandHasUrl->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);
                         $bandHasWiki = true;
                     }
                 }
                 if (!$bandHasWiki) {
                     $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);
                     $bandhasurl = new BandHasUrl();
                     $bandhasurl->setBand($bandObj);
                     $bandhasurl->setUrl($urlObj);
                     $this->bandHasUrlRepository->add($bandhasurl);
                 }
             }
         }
         // 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 ($bandHasUrls as $i => $bandHasUrl) {
                         $urlObj = $bandHasUrl->getUrl();
                         $urlTypObj = $urlObj->getUrltyp();
                         $urlTyp = $urlTypObj->getName();
                         if ($urlTyp != "Wikipedia" && $urlTyp != "GND") {
                             $this->bandHasUrlRepository->remove($bandHasUrl);
                             $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);
                             $bandhasurl = new BandHasUrl();
                             $bandhasurl->setBand($bandObj);
                             $bandhasurl->setUrl($urlObj);
                             $this->bandHasUrlRepository->add($bandhasurl);
                         }
                     }
                 }
             }
         }
         $this->persistenceManager->persistAll();
         $this->throwStatus(200, null, null);
     } else {
         $this->throwStatus(400, 'Entity Band not available', null);
     }
 }
 /**
  * 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;
     }
 }
 /** Updates the list of Kloster
  * @FLOW\SkipCsrfProtection
  * @return int $status http status
  */
 public function updateListAction()
 {
     if ($this->request->hasArgument('data')) {
         $klosterlist = $this->request->getArgument('data');
     }
     if (empty($klosterlist)) {
         $this->throwStatus(400, 'Required data arguemnts not provided', null);
     }
     $role = array_keys($this->securityContext->getAccount()->getRoles())[0];
     if (trim($role) == 'Flow.Login:Hiwi') {
         if (is_array($klosterlist) && !empty($klosterlist)) {
             $error = 0;
             foreach ($klosterlist as $k => $v) {
                 $bearbeitungsstatus = $this->bearbeitungsstatusRepository->findByIdentifier($v['bearbeitungsstatus']);
                 if (is_object($bearbeitungsstatus)) {
                     $bearbeitungsstatusName = $bearbeitungsstatus->getName();
                 }
                 if (isset($bearbeitungsstatusName) && !empty($bearbeitungsstatusName)) {
                     if (trim($bearbeitungsstatusName) == 'Online') {
                         $error++;
                     }
                 }
             }
         }
         if ($error > 0) {
             $this->throwStatus(400, 'You are not allowed to set a Kloster entry online', null);
         }
     }
     if (is_array($klosterlist) && !empty($klosterlist)) {
         foreach ($klosterlist as $k => $v) {
             $klosterObject = $this->klosterRepository->findByIdentifier((string) $k);
             $klosterObject->setKloster($v['kloster']);
             $bearbeitungsstatusObject = $this->bearbeitungsstatusRepository->findByIdentifier($v['bearbeitungsstatus']);
             $klosterObject->setBearbeitungsstatus($bearbeitungsstatusObject);
             $klosterObject->setBearbeitungsstand($v['bearbeitungsstand']);
             $this->klosterRepository->update($klosterObject);
             $gndAlreadyExists = false;
             $klosterHasUrls = $klosterObject->getKlosterHasUrls();
             if (is_object($klosterHasUrls) && count($klosterHasUrls) > 0) {
                 foreach ($klosterHasUrls as $klosterHasUrl) {
                     $urlObject = $klosterHasUrl->getUrl();
                     $urlTypObject = $urlObject->getUrltyp();
                     $urlTyp = $urlTypObject->getName();
                     if ($urlTyp == "GND") {
                         if (!empty($v['gnd'])) {
                             $urlObject->setUrl($v['gnd']);
                             $this->urlRepository->update($urlObject);
                         } elseif (isset($v['gnd']) && empty($v['gnd'])) {
                             $this->klosterHasUrlRepository->remove($klosterHasUrl);
                             $this->urlRepository->remove($urlObject);
                         }
                         $gndAlreadyExists = true;
                     }
                 }
             }
             if (!$gndAlreadyExists) {
                 $urlObject = new Url();
                 $urlObject->setUrl($v['gnd']);
                 $gndid = str_replace('http://d-nb.info/gnd/', '', $v['gnd']);
                 $gndbemerkung = $v['kloster'] . ' [' . $gndid . ']';
                 $urlObject->setBemerkung($gndbemerkung);
                 $urlTypObj = $this->urltypRepository->findOneByName('GND');
                 $urlObject->setUrltyp($urlTypObj);
                 $this->urlRepository->add($urlObject);
                 $klosterhasurl = new KlosterHasUrl();
                 $klosterhasurl->setKloster($klosterObject);
                 $klosterhasurl->setUrl($urlObject);
                 $this->klosterHasUrlRepository->add($klosterhasurl);
             }
         }
         $this->persistenceManager->persistAll();
     }
     $this->throwStatus(200, null, null);
 }