Esempio n. 1
0
 /**
  * Supprime et recrée les déclarations de l'instance passée en paramètre
  *
  * @param onto_common_item $item Instance à sauvegarder
  * 
  * @return bool
  * 
  * @access public
  */
 public function save($item)
 {
     if ($item->check_values()) {
         if (onto_common_uri::is_temp_uri($item->get_uri())) {
             $item->replace_temp_uri();
         }
         $assertions = $item->get_assertions();
         $nb_assertions = count($assertions);
         $i = 0;
         // On commence par supprimer ce qui existe
         $query = "delete {\n\t\t\t\t<" . $item->get_uri() . "> ?prop ?obj\n\t\t\t\t}";
         $this->data_store->query($query);
         if ($errs = $this->data_store->get_errors()) {
             print "<br>Erreurs: <br>";
             print "<pre>";
             print_r($errs);
             print "</pre><br>";
         }
         // On peut y aller
         $query = "insert into <pmb> {\n\t\t\t\t";
         foreach ($assertions as $assertion) {
             if ($assertion->offset_get_object_property("type") == "literal") {
                 $object = "'" . addslashes($assertion->get_object()) . "'";
                 $object_properties = $assertion->get_object_properties();
                 if ($object_properties['lang']) {
                     $object .= "@" . $object_properties['lang'];
                 }
             } else {
                 $object = "<" . addslashes($assertion->get_object()) . ">";
             }
             $query .= "<" . addslashes($assertion->get_subject()) . "> <" . addslashes($assertion->get_predicate()) . "> " . $object;
             $i++;
             if ($i < $nb_assertions) {
                 $query .= " .";
             }
             $query .= "\n";
         }
         $query .= "}";
         $this->data_store->query($query);
         if ($errs = $this->data_store->get_errors()) {
             print "<br>Erreurs: <br>";
             print "<pre>";
             print_r($errs);
             print "</pre><br>";
         } else {
             $index = new onto_index();
             $index->set_handler($this);
             $index->maj(0, $item->get_uri());
         }
     } else {
         return $item->get_checking_errors();
     }
     return true;
 }