Mercurial > hg > extraction-interface
comparison 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 |
comparison
equal
deleted
inserted
replaced
27:4a29bccb6c59 | 28:e6e9bdc4f256 |
---|---|
6 | 6 |
7 public function Index() { | 7 public function Index() { |
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, $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0; | 11 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0; |
12 public $messages = ""; | 12 public $messages = ""; |
13 | 13 |
14 private function Initialize($_urlvalues) { | 14 private function Initialize($_urlvalues) { |
15 $this->SetSectionId($_urlvalues); | 15 $this->SetSectionId($_urlvalues); |
16 | 16 |
17 } | 17 } |
18 | 18 |
19 public function GetTextFromFileId($_postdata) { | 19 public function GetTextFromFileId($_postdata) { |
20 $file_id = $_postdata['fileId']; | 20 |
21 if ($this->current_fileId != 0) { | |
22 $this->file_id = $this->current_fileId; | |
23 } else { | |
24 $this->file_id = $_postdata['fileId']; | |
25 } | |
26 | |
21 $branch_id = $_postdata['branchId']; | 27 $branch_id = $_postdata['branchId']; |
22 $section_id = $_postdata['sectionId']; | 28 $section_id = $_postdata['sectionId']; |
23 | 29 |
24 $this->branch_id = $branch_id; | 30 $this->branch_id = $branch_id; |
25 $this->file_id = $file_id; | |
26 $this->user_id = $_postdata['userId']; | 31 $this->user_id = $_postdata['userId']; |
27 $this->section_id = $section_id; | 32 $this->section_id = $section_id; |
28 | 33 |
29 | 34 |
30 // TODO: get info from LGService | |
31 $this->section_name = $_postdata['sectionName']; | 35 $this->section_name = $_postdata['sectionName']; |
32 $this->book_id = $_postdata['bookId']; | 36 $this->book_id = $_postdata['bookId']; |
33 $this->book_name = $_postdata['bookName']; | 37 $this->book_name = $_postdata['bookName']; |
34 | 38 |
35 | 39 |
36 // get from URL with file_id | 40 // get from URL with file_id |
37 $lg_text_url = $this->get_text_from_fileId_url.$file_id; | 41 $lg_text_url = $this->get_text_from_fileId_url.$this->file_id; |
38 $lg_text = file_get_contents($lg_text_url); | 42 $lg_text = file_get_contents($lg_text_url); |
39 | 43 |
40 $stringInput = $lg_text; | 44 $stringInput = $lg_text; |
41 $stringInput = preg_replace("/ /u", "○", $stringInput); | 45 $stringInput = preg_replace("/ /u", "○", $stringInput); |
42 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | 46 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
110 $this->book_name = $_postdata['bookName']; | 114 $this->book_name = $_postdata['bookName']; |
111 } | 115 } |
112 if ($_postdata['bookId']) { | 116 if ($_postdata['bookId']) { |
113 $this->book_id = $_postdata['bookId']; | 117 $this->book_id = $_postdata['bookId']; |
114 } | 118 } |
115 | 119 if ($_postdata['currentFileId']) { |
116 $this->messages .= "Info: "; | 120 $this->current_fileId = $_postdata['currentFileId']; |
117 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; | 121 } |
118 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; | 122 |
119 $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name."<br>"; | 123 |
120 | |
121 | |
122 | 124 |
123 } | 125 } |
124 public function InitData($_postdata) { | 126 public function InitData($_postdata) { |
125 $file_id = $_postdata['fileId']; | 127 $file_id = $_postdata['fileId']; |
126 $branch_id = $_postdata['branchId']; | 128 $branch_id = $_postdata['branchId']; |
190 $data['topiclistArray'] = $topiclistArray; | 192 $data['topiclistArray'] = $topiclistArray; |
191 $data['default_topic_id'] = $this->GetTopic(); | 193 $data['default_topic_id'] = $this->GetTopic(); |
192 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); | 194 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); |
193 $data['topic_name'] = $this->GetTopicName($this->GetTopic()); | 195 $data['topic_name'] = $this->GetTopicName($this->GetTopic()); |
194 | 196 |
197 | |
195 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, | 198 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, |
196 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, | 199 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, |
197 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, | 200 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, |
198 'current_fileId'=>$this->current_fileId); | 201 'current_fileId'=>$this->current_fileId); |
202 //'current_fileId'=>$this->file_id); | |
203 //'current_fileId'=>'123'); | |
204 | |
205 $this->messages .= "Info: "; | |
206 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; | |
207 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; | |
208 $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; | |
209 $this->messages .= ", current_fileId=".$this->current_fileId."<br>"; | |
199 | 210 |
200 $data['messages'] = $this->messages; | 211 $data['messages'] = $this->messages; |
201 | 212 |
202 return $data; | 213 return $data; |
203 | 214 |
226 } | 237 } |
227 | 238 |
228 } | 239 } |
229 | 240 |
230 public function UpdateInfoByResponseFromLGService($response) { | 241 public function UpdateInfoByResponseFromLGService($response) { |
231 | 242 |
243 | |
244 $status = $response["status"]; | |
245 if ($response["status"] == "error") { | |
246 $response_currentFile = $response["currentFile"]; | |
247 | |
248 $this->current_fileId = (string)$response_currentFile['id']; | |
249 $this->messages .= "saving does not success! ".(string)$response["message"]; | |
250 | |
251 | |
252 } else { | |
253 | |
254 $response_file = $response["file"]; | |
255 $response_branch = $response["branch"]; | |
256 | |
257 $this->messages .= "saving success."; | |
258 $this->file_id = (string)$response_file["id"]; | |
259 $this->branch_id = (string)$response_branch["id"]; | |
260 | |
261 } | |
262 | |
263 | |
264 /* | |
232 $response_file = $response["file"]; | 265 $response_file = $response["file"]; |
233 $response_branch = $response["branch"]; | 266 $response_branch = $response["branch"]; |
234 | |
235 $this->file_id = (string)$response_file["id"]; | |
236 $this->branch_id = (string)$response_branch["id"]; | |
237 | |
238 | |
239 | 267 |
240 $status = (string)$response["status"]; | 268 $status = (string)$response["status"]; |
241 if ($status == "ok") { | 269 if ($status == "ok") { |
242 $this->messages .= "saving success."; | 270 $this->messages .= "saving success."; |
271 $this->file_id = (string)$response_file["id"]; | |
272 $this->branch_id = (string)$response_branch["id"]; | |
243 | 273 |
244 } else if ($status == "error") { | 274 } else if ($status == "error") { |
245 // saving not success | 275 // saving not success |
246 $this->messages .= "saving does not success! ".(string)$response["message"]; | 276 $this->messages .= "saving does not success! ".(string)$response["message"]; |
247 $this->current_fileId = (string)$response['currentFileId']; | 277 $this->current_fileId = $response["currentFileId"]; |
248 // ask to "force save" or "reload" | 278 } |
249 | 279 */ |
250 } | |
251 | 280 |
252 | 281 |
253 } | 282 } |
254 public function SaveFullTextToLGService($_postdata) { | 283 public function SaveFullTextToLGService($_postdata) { |
255 // save tagged text (full text) by Jorge's API to lg service | 284 // save tagged text (full text) by Jorge's API to lg service |
280 | 309 |
281 // ------ | 310 // ------ |
282 | 311 |
283 | 312 |
284 if ($_postdata['branchId'] != 0) { | 313 if ($_postdata['branchId'] != 0) { |
285 // exiting branch case | 314 // -- exiting branch case |
286 $postfields = array( | 315 $postfields = array( |
287 "text" => $require, | 316 "text" => $require, |
288 "branchId" => $_postdata['branchId'], | 317 "branchId" => $_postdata['branchId'], |
289 "userId" => $_postdata['userId'], | 318 "userId" => $_postdata['userId'], |
290 "userPreviousFileId" => $_postdata['fileId'], | 319 "userPreviousFileId" => $_postdata['fileId'], |
291 ); | 320 ); |
292 $save_url = $this->save_to_LGService_url; | 321 $save_url = $this->save_to_LGService_url; |
293 | 322 |
294 } else { | 323 } else { |
295 // new branch case | 324 // -- new branch case |
296 echo "saveNew!"; | 325 echo "saveNew!"; |
297 if ($_postdata['userId']) { | 326 if ($_postdata['userId']) { |
298 $user_id = $_postdata['userId']; | 327 $user_id = $_postdata['userId']; |
299 } else { | 328 } else { |
300 $user_id = "12"; | 329 $user_id = "12"; |
321 'Content-type: multipart/form-data;charset=utf-8' | 350 'Content-type: multipart/form-data;charset=utf-8' |
322 )); | 351 )); |
323 | 352 |
324 // execute the request | 353 // execute the request |
325 | 354 |
326 $output = curl_exec($ch); | 355 //$output = curl_exec($ch); |
356 | |
327 | 357 |
328 // output the profile information - includes the header | 358 // output the profile information - includes the header |
329 //echo($output) . PHP_EOL; | 359 echo($output) . PHP_EOL; |
330 | 360 |
331 // close curl resource to free up system resources | 361 // close curl resource to free up system resources |
332 curl_close($ch); | 362 curl_close($ch); |
333 | 363 |
334 $response = json_decode($output, true); | 364 $response = json_decode($output, true); |