server/src/app/Models/Document.php
changeset 3 2b3247d02769
parent 2 00e2916104fe
child 4 f55970e41793
equal deleted inserted replaced
2:00e2916104fe 3:2b3247d02769
     1 <?php
     1 <?php
     2 namespace CorpusParole\Models;
     2 namespace CorpusParole\Models;
     3 
     3 
     4 use Config;
     4 use Config;
     5 use CorpusParole\Libraries\Utils;
     5 use CorpusParole\Libraries\Utils;
       
     6 use CorpusParole\Libraries\RdfModel\RdfModelResource;
     6 use Log;
     7 use Log;
     7 
     8 
     8 /**
     9 /**
     9  * Model class for Document. Inherit from EasyRdf_Resource
    10  * Model class for Document. Inherit from EasyRdf_Resource
       
    11  * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}
    10  */
    12  */
    11 class Document extends \EasyRdf_Resource {
    13 class Document extends RdfModelResource {
    12 
    14 
    13     public function __construct($uri, $graph = null) {
    15     public function __construct($uri, $graph = null) {
    14         parent::__construct($uri, $graph);
    16         parent::__construct($uri, $graph, 'foaf:primaryTopic');
    15         $this->innerDocument = $this->getResource('foaf:primaryTopic');
       
    16     }
    17     }
    17 
    18 
    18     private $id = null;
    19     private $id = null;
    19     private $innerDocument = null;
       
    20 
    20 
    21     public function getId() {
    21     public function getId() {
    22         if(is_null($this->id)) {
    22         if(is_null($this->id)) {
    23             $this->id = substr($this->uri, strlen(Config::get('corpusparole.cocoon_doc_id_base_uri')));
    23             $this->id = substr($this->uri, strlen(Config::get('corpusparole.cocoon_doc_id_base_uri')));
    24         }
    24         }
    63         }));
    63         }));
    64         return $res;
    64         return $res;
    65     }
    65     }
    66 
    66 
    67     public function updateDiscourseTypes(array $discoursesTypes) {
    67     public function updateDiscourseTypes(array $discoursesTypes) {
       
    68 
       
    69         $this->startDelta();
       
    70 
    68         foreach($this->getDiscourseTypes() as $discourseType) {
    71         foreach($this->getDiscourseTypes() as $discourseType) {
    69             $this->innerDocument->delete('dc11:type', $discourseType);
    72             $this->innerDocument->delete('dc11:type', $discourseType);
       
    73             $this->currentDelta->deletedGraph->add($this->innerDocument, 'dc11:type', $discourseType);
    70         }
    74         }
    71         // re-add them
    75         // re-add them
    72 
    76 
    73         foreach($discoursesTypes as $dType) {
    77         foreach($discoursesTypes as $dType) {
    74             $this->innerDocument->add('dc11:type', new \EasyRdf_Literal($dType, null, Config::get('constants.OLAC_DISCOURSE_TYPE')['uri']));
    78             $this->innerDocument->add('dc11:type', new \EasyRdf_Literal($dType, null, Config::get('constants.OLAC_DISCOURSE_TYPE')['uri']));
       
    79             $this->currentDelta->addedGraph->add($this->innerDocument, 'dc11:type', $discourseType);
    75         }
    80         }
    76     }
    81     }
    77 
    82 
    78     public function isIsomorphic($doc) {
    83     public function isIsomorphic($doc) {
    79         return \EasyRdf_Isomorphic::isomorphic($this->graph, $doc->graph);
    84         return \EasyRdf_Isomorphic::isomorphic($this->graph, $doc->graph);