server/src/app/Models/Document.php
changeset 138 3079cbf80006
parent 130 fac22d8c2df8
child 141 c0e8626a271c
equal deleted inserted replaced
137:1baa7c6bd370 138:3079cbf80006
   175     public function getModifiedValue() {
   175     public function getModifiedValue() {
   176         $modified = $this->getModified();
   176         $modified = $this->getModified();
   177         return is_null($modified)?null:$modified->getValue();
   177         return is_null($modified)?null:$modified->getValue();
   178     }
   178     }
   179 
   179 
   180     public function setModified($value) {
   180     public function setModified($value = null) {
       
   181         if(is_null($value)) {
       
   182             $value = gmdate(\DateTime::ATOM);
       
   183         } elseif ($value instanceof \DateTime) {
       
   184             $value = $value->format(\DateTime::ATOM);
       
   185         }
       
   186         $value = preg_replace('/[\+\-]00(\:?)00$/', 'Z', $value);
       
   187 
   181         $modified = $this->getModified();
   188         $modified = $this->getModified();
   182         if($value && (!$modified || $modified->getValue() != $value) ) {
   189         if($value && (!$modified || $modified->getValue() !== $value) ) {
   183 
   190 
   184             $newModified = new Literal($value, "http://purl.org/dc/terms/W3CDTF");
   191             $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
   185             $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified);
   192             $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified);
   186 
   193 
   187             $this->modified = null;
   194             $this->modified = null;
   188         }
   195         }
   189     }
   196     }
   326             $this->subjects = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/subject>');
   333             $this->subjects = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/subject>');
   327         }
   334         }
   328         return $this->subjects;
   335         return $this->subjects;
   329     }
   336     }
   330 
   337 
       
   338     /**
       
   339      * change subjecs list
       
   340      */
       
   341     public function setSubjects($subjects) {
       
   342         $delta = $this->startDelta();
       
   343         //remove old,
       
   344         foreach ($this->getSubjects() as $subject) {
       
   345             $this->getProvidedCHO()->delete('<http://purl.org/dc/elements/1.1/subject>', $subject);
       
   346             $delta->getDeletedGraph()->add($this->getProvidedCHO(), 'http://purl.org/dc/elements/1.1/subject', $subject);
       
   347         }
       
   348 
       
   349         //put new
       
   350         foreach ($subjects as $newSubject) {
       
   351             $value = null;
       
   352             if(filter_var($newSubject, FILTER_VALIDATE_URL)) {
       
   353                 $value = new Resource($newSubject);
       
   354             }
       
   355             else {
       
   356                 $value = new Literal($newSubject, "fr", null);
       
   357             }
       
   358 
       
   359             $this->getProvidedCHO()->add('http://purl.org/dc/elements/1.1/subject', $value);
       
   360             $delta->getAddedGraph()->add($this->getProvidedCHO(), 'http://purl.org/dc/elements/1.1/subject', $value);
       
   361         }
       
   362 
       
   363         $this->subjects = null;
       
   364 
       
   365     }
       
   366 
   331     public function isIsomorphic($doc) {
   367     public function isIsomorphic($doc) {
   332         return Isomorphic::isomorphic($this->graph, $doc->graph);
   368         return Isomorphic::isomorphic($this->graph, $doc->graph);
   333     }
   369     }
   334 
   370 
   335     /*
   371     /*