예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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);
     }
 }