Mercurial > hg > extraction-interface
diff develop/models/extractapp.php @ 28:e6e9bdc4f256
update the saving response from LGService between different file version
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 03 Mar 2015 18:13:20 +0100 |
parents | 4a29bccb6c59 |
children | fc7342914cdf |
line wrap: on
line diff
--- a/develop/models/extractapp.php Tue Mar 03 11:47:41 2015 +0100 +++ b/develop/models/extractapp.php Tue Mar 03 18:13:20 2015 +0100 @@ -8,7 +8,7 @@ return array("Index Value 1", "Value 2", "Value 3"); } - protected $section_id = 0, $data_path, $file_id = 0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0; + protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0; public $messages = ""; private function Initialize($_urlvalues) { @@ -17,24 +17,28 @@ } public function GetTextFromFileId($_postdata) { - $file_id = $_postdata['fileId']; + + if ($this->current_fileId != 0) { + $this->file_id = $this->current_fileId; + } else { + $this->file_id = $_postdata['fileId']; + } + $branch_id = $_postdata['branchId']; $section_id = $_postdata['sectionId']; $this->branch_id = $branch_id; - $this->file_id = $file_id; $this->user_id = $_postdata['userId']; $this->section_id = $section_id; - // TODO: get info from LGService $this->section_name = $_postdata['sectionName']; $this->book_id = $_postdata['bookId']; $this->book_name = $_postdata['bookName']; // get from URL with file_id - $lg_text_url = $this->get_text_from_fileId_url.$file_id; + $lg_text_url = $this->get_text_from_fileId_url.$this->file_id; $lg_text = file_get_contents($lg_text_url); $stringInput = $lg_text; @@ -112,13 +116,11 @@ if ($_postdata['bookId']) { $this->book_id = $_postdata['bookId']; } + if ($_postdata['currentFileId']) { + $this->current_fileId = $_postdata['currentFileId']; + } - $this->messages .= "Info: "; - $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; - $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; - $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name."<br>"; - - + } public function InitData($_postdata) { @@ -192,10 +194,19 @@ $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); $data['topic_name'] = $this->GetTopicName($this->GetTopic()); + $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, 'current_fileId'=>$this->current_fileId); + //'current_fileId'=>$this->file_id); + //'current_fileId'=>'123'); + + $this->messages .= "Info: "; + $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; + $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; + $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; + $this->messages .= ", current_fileId=".$this->current_fileId."<br>"; $data['messages'] = $this->messages; @@ -228,26 +239,44 @@ } public function UpdateInfoByResponseFromLGService($response) { + + + $status = $response["status"]; + if ($response["status"] == "error") { + $response_currentFile = $response["currentFile"]; + + $this->current_fileId = (string)$response_currentFile['id']; + $this->messages .= "saving does not success! ".(string)$response["message"]; + + } else { + + $response_file = $response["file"]; + $response_branch = $response["branch"]; + + $this->messages .= "saving success."; + $this->file_id = (string)$response_file["id"]; + $this->branch_id = (string)$response_branch["id"]; + + } + + + /* $response_file = $response["file"]; $response_branch = $response["branch"]; - $this->file_id = (string)$response_file["id"]; - $this->branch_id = (string)$response_branch["id"]; - - - $status = (string)$response["status"]; if ($status == "ok") { $this->messages .= "saving success."; + $this->file_id = (string)$response_file["id"]; + $this->branch_id = (string)$response_branch["id"]; } else if ($status == "error") { // saving not success $this->messages .= "saving does not success! ".(string)$response["message"]; - $this->current_fileId = (string)$response['currentFileId']; - // ask to "force save" or "reload" - + $this->current_fileId = $response["currentFileId"]; } + */ } @@ -282,7 +311,7 @@ if ($_postdata['branchId'] != 0) { - // exiting branch case + // -- exiting branch case $postfields = array( "text" => $require, "branchId" => $_postdata['branchId'], @@ -292,7 +321,7 @@ $save_url = $this->save_to_LGService_url; } else { - // new branch case + // -- new branch case echo "saveNew!"; if ($_postdata['userId']) { $user_id = $_postdata['userId']; @@ -323,10 +352,11 @@ // execute the request - $output = curl_exec($ch); + //$output = curl_exec($ch); + // output the profile information - includes the header - //echo($output) . PHP_EOL; + echo($output) . PHP_EOL; // close curl resource to free up system resources curl_close($ch);