server/src/app/Models/GeoResource.php
author ymh <ymh.work@gmail.com>
Sun, 05 Jun 2016 00:28:45 +0200
changeset 169 8fddc113095e
child 171 f4f558f04f37
permissions -rw-r--r--
Correct proble on geo info merging + add geo resource

<?php
namespace CorpusParole\Models;

use CorpusParole\Libraries\RdfModel\RdfModelResource;
use CorpusParole\Libraries\Utils;
use JsonSerializable;
use Log;

/**
 */
class GeoResource extends RdfModelResource implements JsonSerializable {

    public function __construct($uri, $graph) {
        parent::__construct($uri, $graph);
    }

    private $refLoc = false;
    private $notes = null;

    public function clearMemoizationCache() {
        $this->refLoc = false;
        $this->notes = null;
    }

    public function getRefLoc() {
        if($this->refLoc === false) {
            $refLoc = $this->getResource("<http://www.w3.org/2002/07/owl#sameAs>");
            $this->refLoc = is_null($refLoc)?null:$refLoc->getUri();
        }
        return $this->refLoc;
    }

    public function getNotes() {
        if(is_null($this->notes)) {
            $this->notes = $this->all('<http://www.w3.org/2004/02/skos/core#note>');
        }
        return $this->notes;
    }

    public function jsonSerialize() {
        $notes = array_map(
            function($note) { return Utils::processLiteralResourceOrString($note); },
            $this->getNotes()
        );
        return [
            'ref-loc' => $this->getRefLoc(),
            'notes' => $notes
        ];
    }

}