Mercurial > hg > extraction-interface
comparison 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 |
comparison
equal
deleted
inserted
replaced
57:5cf9720a2e25 | 58:a11f9103b8db |
---|---|
8 return array("Index Value 1", "Value 2", "Value 3"); | 8 return array("Index Value 1", "Value 2", "Value 3"); |
9 } | 9 } |
10 | 10 |
11 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, | 11 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, |
12 $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = ""; | 12 $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = ""; |
13 public $messages = ""; | 13 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); |
14 | 14 |
15 private function Initialize($_urlvalues) { | 15 private function Initialize($_urlvalues) { |
16 $this->SetSectionId($_urlvalues); | 16 $this->SetSectionId($_urlvalues); |
17 | 17 |
18 } | 18 } |
87 } | 87 } |
88 | 88 |
89 public function GetTextFromLocal($_id){ | 89 public function GetTextFromLocal($_id){ |
90 $this->section_id = $_id; | 90 $this->section_id = $_id; |
91 $this->branch_id = 1; // local test sets branch_id to 1 | 91 $this->branch_id = 1; // local test sets branch_id to 1 |
92 $this->messages .= "DEBUG: from my local"."<br>"; | 92 // $this->messages .= "DEBUG: from my local"."<br>"; |
93 $this->messages['debug'] .= "[Debug] from my local"."<br>"; | |
93 $this->lg_text = $this->GetSectionContent(); | 94 $this->lg_text = $this->GetSectionContent(); |
94 | 95 |
95 } | 96 } |
96 | 97 |
97 public function GetInfoFromPreviousPage($_postdata) { | 98 public function GetInfoFromPreviousPage($_postdata) { |
277 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, | 278 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, |
278 'current_fileId'=>$this->current_fileId); | 279 'current_fileId'=>$this->current_fileId); |
279 //'current_fileId'=>$this->file_id); | 280 //'current_fileId'=>$this->file_id); |
280 //'current_fileId'=>'123'); | 281 //'current_fileId'=>'123'); |
281 | 282 |
283 $this->messages['debug'] .= "[Debug] "; | |
284 $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id; | |
285 $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; | |
286 $this->messages['debug'] .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; | |
287 $this->messages['debug'] .= ", current_fileId=".$this->current_fileId."<br>"; | |
288 | |
289 $this->messages['info'] .= "[Info] book name: ".$this->book_name; | |
290 $this->messages['info'] .= ", section id: ". $this->section_id; | |
291 $this->messages['info'] .= ", branch id: ".$this->branch_id; | |
292 $this->messages['info'] .= "<br>"; | |
293 | |
294 /* | |
282 $this->messages .= "Info: "; | 295 $this->messages .= "Info: "; |
283 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; | 296 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; |
284 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; | 297 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; |
285 $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; | 298 $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; |
286 $this->messages .= ", current_fileId=".$this->current_fileId."<br>"; | 299 $this->messages .= ", current_fileId=".$this->current_fileId."<br>"; |
300 */ | |
287 | 301 |
288 $data['messages'] = $this->messages; | 302 $data['messages'] = $this->messages; |
289 | 303 |
290 return $data; | 304 return $data; |
291 | 305 |
346 $response_file = $response["file"]; | 360 $response_file = $response["file"]; |
347 $response_branch = $response["branch"]; | 361 $response_branch = $response["branch"]; |
348 | 362 |
349 $status = (string)$response["status"]; | 363 $status = (string)$response["status"]; |
350 if ($status == "ok") { | 364 if ($status == "ok") { |
351 $this->messages .= "Saving success."; | 365 $this->messages['info'] .= "[Info] Saving success. <br>"; |
366 //$this->messages .= "Saving success."; | |
352 $this->file_id = (string)$response_file["id"]; | 367 $this->file_id = (string)$response_file["id"]; |
353 $this->branch_id = (string)$response_branch["id"]; | 368 $this->branch_id = (string)$response_branch["id"]; |
354 | 369 |
355 } else if ($status == "error") { | 370 } else if ($status == "error") { |
356 // saving not success | 371 // saving not success |
372 $this->messages['warning'] .= "[Warning] Saving Failed! ".(string)$response["message"]."<br>"; | |
373 $this->messages['warning'] .= "[Warning] Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>"; | |
374 | |
375 /* | |
357 $this->messages .= "Saving Failed! ".(string)$response["message"]."<br>"; | 376 $this->messages .= "Saving Failed! ".(string)$response["message"]."<br>"; |
358 $this->messages .= "Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>"; | 377 $this->messages .= "Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>"; |
359 | 378 */ |
360 $response_currentFile = $response["currentFile"]; | 379 $response_currentFile = $response["currentFile"]; |
361 //$this->current_fileId = $response["currentFileId"]; | 380 //$this->current_fileId = $response["currentFileId"]; |
362 $this->current_fileId = (string)$response_currentFile["id"]; | 381 $this->current_fileId = (string)$response_currentFile["id"]; |
363 | 382 |
364 } | 383 } |
407 return $text; | 426 return $text; |
408 } | 427 } |
409 public function SaveFullTextToLGService($_postdata) { | 428 public function SaveFullTextToLGService($_postdata) { |
410 // save tagged text (full text) by Jorge's API to lg service | 429 // save tagged text (full text) by Jorge's API to lg service |
411 // -------- | 430 // -------- |
431 global $AT_LOCAL; | |
432 | |
412 if ($_postdata['text']){ | 433 if ($_postdata['text']){ |
413 $date = date('Y_m_d_H_i_s', time()); | 434 $date = date('Y_m_d_H_i_s', time()); |
414 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { | 435 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { |
415 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); | 436 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); |
416 //saving in my local machine in developing phrase | 437 //saving in my local machine in developing phrase |
417 //file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); | 438 if ($AT_LOCAL) { |
439 file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); | |
440 } | |
418 } | 441 } |
419 | 442 |
420 if (get_magic_quotes_gpc()) { | 443 if (get_magic_quotes_gpc()) { |
421 $require = stripslashes($_postdata['text']); | 444 $require = stripslashes($_postdata['text']); |
422 } else { | 445 } else { |
435 $require = "<text_content>\n".$require."</text_content>\n"; | 458 $require = "<text_content>\n".$require."</text_content>\n"; |
436 } | 459 } |
437 $require = $this->AppendMetaData($require); | 460 $require = $this->AppendMetaData($require); |
438 | 461 |
439 //saving in my local machine in developing phrase | 462 //saving in my local machine in developing phrase |
440 //file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); | 463 if ($AT_LOCAL) { |
464 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); | |
465 } | |
441 } | 466 } |
442 | 467 |
443 // ------ | 468 // ------ |
444 | 469 |
445 | 470 |
481 //curl_setopt($ch, CURLOPT_HEADER, true); | 506 //curl_setopt($ch, CURLOPT_HEADER, true); |
482 curl_setopt($ch, CURLOPT_HTTPHEADER, array( | 507 curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
483 'Content-type: multipart/form-data;charset=utf-8' | 508 'Content-type: multipart/form-data;charset=utf-8' |
484 )); | 509 )); |
485 | 510 |
486 // execute the request | 511 if (!$AT_LOCAL) { |
487 // **** commended to DEBUG *** | 512 // execute the request |
488 $output = curl_exec($ch); | 513 $output = curl_exec($ch); |
489 // ***** | 514 } |
515 | |
490 | 516 |
491 // output the profile information - includes the header | 517 // output the profile information - includes the header |
492 //echo($output) . PHP_EOL; | 518 //echo($output) . PHP_EOL; |
493 | 519 |
494 // close curl resource to free up system resources | 520 // close curl resource to free up system resources |