function sparql()
 {
     if ($this->hasMethod == 'sparql') {
         $tr = $this->hasSource[0];
         if ($this->model_uri == null) {
             $this->model_uri = $tr->getModel();
         }
         $this->hasParameter[] = '"model=' . $this->model_uri . '"';
         $prefixes[] = "@prefix : <http://liris.cnrs.fr/silex/2009/ktbs#> .";
         $statements[] = "<> :contains <" . $this->name . "> .";
         $statements[] = "<" . $this->name . "> a :ComputedTrace ;";
         $statements[] = ":hasMethod :sparql ;";
         $statements[] = ":hasSource " . $this->listSources() . " ;";
         $statements[] = ':hasParameter ' . implode(',', $this->hasParameter) . ' .';
         $this->script = implode("\n", $prefixes) . "\n" . implode("\n", $statements);
         $this->result = RestfulHelper::post($this->base_uri, $this->script);
         if ($this->model_uri != $tr->getModel()) {
             $model = new TraceModel($this->model_uri);
             $Gene = new GenerateModel($this->uri, $model->getName());
             $Gene->PutModel();
         }
     }
 }
 function getListOfTypes()
 {
     $res = RestfulHelper::getInfo($this->uri);
     $res = json_decode($res, true);
     $def = $res["@graph"];
     $j = 0;
     $supertypes = array();
     for ($i = 1; $i < sizeof($def); $i++) {
         $ty = $def[$i];
         if (in_array('hasSuperObselType', array_keys($ty))) {
             foreach ($ty['hasSuperObselType'] as $key => $value) {
                 if (!in_array($value, $supertypes)) {
                     $supertypes[] = $value;
                 }
             }
         }
     }
     for ($i = 1; $i < sizeof($def); $i++) {
         $ty = $def[$i];
         if (strripos($ty["@id"], "/") == false) {
             if (!in_array($ty["@id"], $supertypes)) {
                 $this->listOfTypes[$j] = str_replace('#', "", $ty["@id"]);
                 $j++;
             }
         }
     }
     return $this->listOfTypes;
 }
 function refresh($json, $after = null, $before = null)
 {
     $trace = $this->TraceOrigin[0];
     $this->name = $json["Name"];
     $formule = $json["formule"];
     $this->formule = $json["formule"];
     $input = $json["input"];
     $variable = array();
     $transformation = $json["Transformation"];
     // verification si la dernière transformation est faite ou non !!
     // si oui pas la peine de refaire toutes les transformation. avec KTBS les obsels se propagent !!!cool non ?
     // si non on fait les transformations.
     $s = sizeof($transformation) - 1;
     $tname = str_replace(' ', '_', $this->name . " {$s}");
     $b = $trace->getBaseUri();
     $trverif = new Trace($b . $tname);
     $c = $json["createdOn"];
     $encode = true;
     if (!$trverif->exist()) {
         $encode = false;
         $k = 0;
         $models = array();
         if ($transformation == null && $c == null) {
             $encode = false;
             goto notransformation;
         }
         if ($transformation == null && $c != null) {
             $encode = true;
             goto notransformation;
         }
     } else {
         $trace = $trverif;
     }
     notransformation:
     $this->ComputedTrace = $trace;
     $reponse = RestfulHelper::getInfo($trace->getUri());
     while ($reponse == null) {
         sleep(2);
         $reponse = RestfulHelper::getInfo($trace->getUri());
     }
     $values = array();
     // $cond = array();
     // 	if($after != null){
     // 		$time =  strtotime($after)*1000;
     // 		$cond[] = 'minb='.$time;
     // 	}
     // 	if($before != null){
     // 		$time =  strtotime($before)*1000;
     // 		$cond[] = 'maxb='.$time;
     // 	}
     // 	$times = implode('&', $cond);
     $Tcomp = new ComputedTrace($trace->getBaseUri(), 'time' . str_replace(' ', '_', $this->name));
     if ($Tcomp->exist()) {
         $Tcomp->Delete();
     }
     $Tcomp->config('filter', array($trace));
     $Tcomp->setFilterParameter($after, $before);
     $Tcomp->filter();
     $trace = new Trace($Tcomp->getUri());
     foreach ($input as $key => $value) {
         $sparql = $value["operation"];
         if ($encode == false) {
             $sparql = urlencode($sparql);
         }
         $URL = null;
         // if(strlen($times) == 0 ){
         $URL = $trace->getUri() . "@obsels?query=" . $sparql;
         // }
         // else{
         // 	$URL = $trace->getUri()."@obsels?".$times."&query=".$sparql;
         // }
         $r = RestfulHelper::httpInfo($URL);
         while ($r == "409") {
             sleep(1);
             $r = RestfulHelper::httpInfo($URL);
         }
         $reponse = RestfulHelper::getInfo($URL);
         $rep = json_decode($reponse, true);
         $res = $rep['results'];
         $resultat = $res['bindings'];
         $val = $resultat[0];
         $keys = array_keys($val);
         $a = $val[$keys[0]];
         $va = $a["value"];
         if (gettype(intval($va)) != "integer") {
             $va = 0;
         }
         $values[$value['name']] = $va;
     }
     $f = $formule;
     foreach ($values as $key => $value) {
         $f = str_replace($key, $value, $f);
     }
     $m = new EvalMath();
     $m->suppress_errors = true;
     $equation = explode("=", $f);
     $res = $m->evaluate($equation[1]);
     $Tcomp->Delete();
     if ($res == false) {
         return array("var" => $equation[0], "val" => "ERROR : Time intervale caused an error");
     } else {
         return array("var" => $equation[0], "val" => $res);
     }
 }
 public static function getEtagAndPut($url, $content)
 {
     $etag = RestfulHelper::getEtag($url, "ttl");
     $header = array("Content-type:text/turtle", 'If-match: ' . $etag . '');
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_USERPWD, "admin" . ":" . "admin");
     curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
     $reponse = curl_exec($curl);
     $infos = curl_getinfo($curl);
     curl_close($curl);
     $http_code = $infos["http_code"];
     if ($http_code == "200") {
         return true;
     } else {
         return $reponse;
     }
 }
 public function dump()
 {
     $prefixes[] = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .";
     $prefixes[] = "@prefix ktbs: <http://liris.cnrs.fr/silex/2009/ktbs#> .";
     $prefixes[] = "@prefix : <" . $this->type . "/> .";
     $statements[] = "<" . $this->name . "> a <" . $this->type . ">.";
     $statements[] = "<" . $this->name . "> ktbs:hasTrace <> .";
     $statements[] = "<" . $this->name . "> ktbs:hasSubject " . '"' . $this->Subject . '"' . " .";
     $statements[] = "<" . $this->name . "> :hasDate " . '"' . $this->hasDate . '"' . " .";
     //user information
     $statements[] = "<" . $this->name . "> :hasUser_UserID " . '"' . $this->UserID . '"' . " .";
     $statements[] = "<" . $this->name . "> :hasUser_UserName " . '"' . $this->UserName . '"' . " .";
     $statements[] = "<" . $this->name . "> :hasUser_FirstName " . '"' . $this->FirstName . '"' . " .";
     $statements[] = "<" . $this->name . "> :hasUser_LastName " . '"' . $this->LastName . '"' . " .";
     // tool information
     if ($this->WorkspaceName) {
         $statements[] = "<" . $this->name . "> :hasTool_WorkspaceName " . '"' . $this->WorkspaceName . '"' . " .";
     }
     if ($this->ResourceNode) {
         $statements[] = "<" . $this->name . "> :hasTool_ResourceName " . '"' . $this->ResourceNode . '"' . " .";
     }
     if ($this->ResourcePath) {
         $statements[] = "<" . $this->name . "> :hasTool_ResourcePath " . '"' . $this->ResourcePath . '"' . " .";
     }
     if ($this->ResourceType) {
         $statements[] = "<" . $this->name . "> :hasTool_ResourceType " . '"' . $this->ResourceType . '"' . " .";
     }
     if ($this->oldName) {
         $statements[] = "<" . $this->name . "> :hasTool_OldName " . '"' . $this->oldName . '"' . " .";
     }
     // forum
     if ($this->newName) {
         $statements[] = "<" . $this->name . "> :hasTool_NewName " . '"' . $this->newName . '"' . " .";
     }
     if ($this->CategoryId) {
         $statements[] = "<" . $this->name . "> :hasTool_CategoryId " . '"' . $this->CategoryId . '"' . " .";
     }
     if ($this->subjectId) {
         $statements[] = "<" . $this->name . "> :hasTool_subjectId " . '"' . $this->subjectId . '"' . " .";
     }
     if ($this->MessageId) {
         $statements[] = "<" . $this->name . "> :hasTool_MessageId " . '"' . $this->MessageId . '"' . " .";
     }
     if ($this->subjectold_title) {
         $statements[] = "<" . $this->name . "> :hasTool_subjectOldContent " . '"' . $this->subjectold_title . '"' . " .";
     }
     if ($this->subjectNew_title) {
         $statements[] = "<" . $this->name . "> :hasTool_subjectNew_title " . '"' . $this->subjectNew_title . '"' . " .";
     }
     if ($this->MessageOldContent) {
         $statements[] = "<" . $this->name . "> :hasTool_MessageOldContent " . '"' . $this->MessageOldContent . '"' . " .";
     }
     if ($this->Messagenew_content) {
         $statements[] = "<" . $this->name . "> :hasTool_Messagenew_content " . '"' . $this->Messagenew_content . '"' . " .";
     }
     //blog
     if ($this->postTitle) {
         $statements[] = "<" . $this->name . "> :hasTool_Post_Title " . '"' . $this->postTitle . '"' . " .";
     }
     //exercice
     if ($this->ExerciceId) {
         $statements[] = "<" . $this->name . "> :hasTool_Exercice_Id " . '"' . $this->ExerciceId . '"' . " .";
     }
     if ($this->Exercisetitle) {
         $statements[] = "<" . $this->name . "> :hasTool_Exercise_Title " . '"' . $this->Exercisetitle . '"' . " .";
     }
     if ($this->ExerciseResult) {
         $statements[] = "<" . $this->name . "> :hasTool_Exercise_Result " . '"' . $this->ExerciseResult . '"' . " .";
     }
     if ($this->BlogId) {
         $statements[] = "<" . $this->name . "> :hasTool_BlogId " . '"' . $this->BlogId . '"' . " .";
     }
     if ($this->postBlogId) {
         $statements[] = "<" . $this->name . "> :hasTool_postBlogId " . '"' . $this->postBlogId . '"' . " .";
     }
     if ($this->blog_authorizeComment !== null) {
         $statements[] = "<" . $this->name . "> :hasTool_blog_authorizeComment " . '"' . $this->blog_authorizeComment . '"' . " .";
     }
     if ($this->blog_authorizeAnonymousComment !== null) {
         $statements[] = "<" . $this->name . "> :hasTool_blog_authorizeAnonymousComment " . '"' . $this->blog_authorizeAnonymousComment . '"' . " .";
     }
     if ($this->blog_autoPublishPost !== null) {
         $statements[] = "<" . $this->name . "> :hasTool_blog_autoPublishPost " . '"' . $this->blog_autoPublishPost . '"' . " .";
     }
     if ($this->blog_autoPublishComment !== null) {
         $statements[] = "<" . $this->name . "> :hasTool_blog_autoPublishComment " . '"' . $this->blog_autoPublishComment . '"' . " .";
     }
     $this->script = implode("\n", $prefixes) . "\n" . implode("\n", $statements);
     $this->numAttr = count($statements);
     $this->result = RestfulHelper::post($this->trace_uri, $this->script);
 }
 function bringTrace($trace, $model_uri)
 {
     /*This method allow to bring one trace and change it's model
     		use : 
     		$Base->bringTrace(Trace_Object,uri_of_new_model);
     		if you don't want to change the model 
     		$Base->bringTrace(Trace_Object,Trace_Object->getModel);*/
     if (is_object($trace) && get_class($trace) == "Trace") {
         $Tr = new Trace($this->uri, $model_uri, "From_" . $trace->getBaseName() . "_" . $trace->getName());
         $Tr->dump();
         $t = $Tr->getUri();
         $obs = $trace->getObsel();
         RestfulHelper::json_post($t, json_encode($obs));
         $Tr->setNewOrigin($trace->getOrigin());
         $Tr->setNewModel($model_uri);
     }
 }
 function exist()
 {
     $this->exist = RestfulHelper::get($this->uri);
     return $this->exist;
 }
 function setNewOrigin($newOrigin)
 {
     /*  Verify the format of the time */
     $this->hasOrigin = $newOrigin;
     $reponse = RestfulHelper::getInfo($this->uri);
     $obj = json_decode($reponse, true);
     $obj['origin'] = $this->hasOrigin;
     $query = json_encode($obj);
     RestfulHelper::json_getEtagAndPut($this->uri, $query);
 }