Mercurial > hg > extraction-interface
diff models/extractapp.php @ 58:a11f9103b8db extractapp
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 31 Mar 2015 10:59:52 +0200 |
parents | 5cf9720a2e25 |
children | 6e44605eb4f6 |
line wrap: on
line diff
--- a/models/extractapp.php Mon Mar 30 17:23:47 2015 +0200 +++ b/models/extractapp.php Tue Mar 31 10:59:52 2015 +0200 @@ -10,7 +10,7 @@ protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = ""; - public $messages = ""; + public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); private function Initialize($_urlvalues) { $this->SetSectionId($_urlvalues); @@ -89,7 +89,8 @@ public function GetTextFromLocal($_id){ $this->section_id = $_id; $this->branch_id = 1; // local test sets branch_id to 1 - $this->messages .= "DEBUG: from my local"."<br>"; + // $this->messages .= "DEBUG: from my local"."<br>"; + $this->messages['debug'] .= "[Debug] from my local"."<br>"; $this->lg_text = $this->GetSectionContent(); } @@ -279,11 +280,24 @@ //'current_fileId'=>$this->file_id); //'current_fileId'=>'123'); + $this->messages['debug'] .= "[Debug] "; + $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id; + $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; + $this->messages['debug'] .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; + $this->messages['debug'] .= ", current_fileId=".$this->current_fileId."<br>"; + + $this->messages['info'] .= "[Info] book name: ".$this->book_name; + $this->messages['info'] .= ", section id: ". $this->section_id; + $this->messages['info'] .= ", branch id: ".$this->branch_id; + $this->messages['info'] .= "<br>"; + + /* $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; @@ -348,15 +362,20 @@ $status = (string)$response["status"]; if ($status == "ok") { - $this->messages .= "Saving success."; + $this->messages['info'] .= "[Info] Saving success. <br>"; + //$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['warning'] .= "[Warning] Saving Failed! ".(string)$response["message"]."<br>"; + $this->messages['warning'] .= "[Warning] Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>"; + + /* $this->messages .= "Saving Failed! ".(string)$response["message"]."<br>"; $this->messages .= "Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>"; - + */ $response_currentFile = $response["currentFile"]; //$this->current_fileId = $response["currentFileId"]; $this->current_fileId = (string)$response_currentFile["id"]; @@ -409,12 +428,16 @@ public function SaveFullTextToLGService($_postdata) { // save tagged text (full text) by Jorge's API to lg service // -------- + global $AT_LOCAL; + if ($_postdata['text']){ $date = date('Y_m_d_H_i_s', time()); if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); //saving in my local machine in developing phrase - //file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); + if ($AT_LOCAL) { + file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); + } } if (get_magic_quotes_gpc()) { @@ -437,7 +460,9 @@ $require = $this->AppendMetaData($require); //saving in my local machine in developing phrase - //file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); + if ($AT_LOCAL) { + file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); + } } // ------ @@ -483,10 +508,11 @@ 'Content-type: multipart/form-data;charset=utf-8' )); - // execute the request - // **** commended to DEBUG *** - $output = curl_exec($ch); - // ***** + if (!$AT_LOCAL) { + // execute the request + $output = curl_exec($ch); + } + // output the profile information - includes the header //echo($output) . PHP_EOL;