diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Models/GeoResource.php --- a/server/src/app/Models/GeoResource.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Models/GeoResource.php Thu Sep 22 15:42:12 2016 +0200 @@ -1,6 +1,7 @@ providedCHO = $providedCHO; + $this->readOnly = true; + $this->changePending = false; + $this->needDelete = false; } + private $providedCHO = null; + private $readOnly = true; + private $changePending = false; + private $needDelete = false; + private $refLocs = null; private $notes = null; + private $latitude = false; + private $longitude = false; + + public function getDeltaList() { + if($this->changePending) { + throw new CorpusParoleException('GetDeltaList called when changes are pending'); + } + return parent::getDeltaList(); + } public function clearMemoizationCache() { $this->refLocs = null; $this->notes = null; + $this->latitude = false; + $this->longitude = false; } public function getRefLocs() { @@ -30,6 +51,21 @@ return $this->refLocs; } + public function setRefLocs($refLocs) { + if(!$this->changePending) { + throw new CorpusParoleException('Can call setRefLocs only when changes are pending'); + } + + $this->delete(""); + + foreach($refLocs as $refLocUri) { + $this->addResource("http://www.w3.org/2002/07/owl#sameAs", $refLocUri); + } + + $this->clearMemoizationCache(); + + } + public function getNotes() { if(is_null($this->notes)) { $this->notes = $this->all(''); @@ -37,6 +73,40 @@ return $this->notes; } + public function getLatitude() { + if($this->latitude === false) { + try { + $this->latitude = $this->getLiteral(''); + } catch(\Exception $e) { + $this->latitude = null; + } + } + return $this->latitude; + } + + public function getLatitudeValue() { + $lat = $this->getLatitude(); + return is_null($lat)?null:$lat->getValue(); + } + + public function getLongitude() { + if($this->longitude === false) { + try { + $this->longitude = $this->getLiteral(''); + } catch(\Exception $e) { + $this->longitude = null; + } + } + return $this->longitude; + } + + public function getLongitudeValue() { + $long = $this->getLongitude(); + return is_null($long)?null:$long->getValue(); + } + + + public function jsonSerialize() { $notes = array_map( function($note) { return Utils::processLiteralResourceOrString($note); }, @@ -44,8 +114,65 @@ ); return [ 'ref-locs' => $this->getRefLocs(), - 'notes' => $notes + 'notes' => $notes, + 'latitude' => $this->getLatitudeValue(), + 'longitude' => $this->getLongitudeValue(), ]; } + public function setReadOnly($ro) { + if($this->readOnly and !$ro) { + $this->changePending = true; + } + $this->readOnly = $ro; + } + + public function setNeedDelete($nd) { + $this->needDelete = $nd; + } + + public function rollback() { + $this->changePending = false; + } + + public function commit() { + + // Do nothing if there is no change pending + if(!$this->changePending) { + return; + } + + $delta = $this->startDelta(); + + //delete the previous blank node + if($this->needDelete) { + $delta->addDeleteWhere( + "?s ?p ?o. ". + "{ ". + " ?_ ?s. ". + "} ". + "UNION { ". + " ?s ?o ". + "}" + ); + } + + // add the node + $geoinfoNodeAdded = $delta->getAddedGraph()->newBNode("http://www.europeana.eu/schemas/edm/Place"); + $delta->getAddedGraph()->add($this->providedCHO, "http://purl.org/dc/terms/spatial", $geoinfoNodeAdded); + + foreach($this->propertyUris() as $prop) { + if($prop == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { + continue; + } + foreach($this->all("<$prop>") as $propVal) { + $delta->getAddedGraph()->add($geoinfoNodeAdded, $prop, $propVal); + } + } + + $this->changePending = false; + + } + + } \ No newline at end of file