comparison develop/models/extractapp.php @ 25:4b6d2d7e706e

update for the integration
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 02 Mar 2015 16:16:54 +0100
parents b55f5d3564c4
children 579f03f8bee5
comparison
equal deleted inserted replaced
24:b55f5d3564c4 25:4b6d2d7e706e
23 23
24 $this->branch_id = $branch_id; 24 $this->branch_id = $branch_id;
25 $this->file_id = $file_id; 25 $this->file_id = $file_id;
26 $this->user_id = $_postdata['userId']; 26 $this->user_id = $_postdata['userId'];
27 $this->section_id = $section_id; 27 $this->section_id = $section_id;
28
29
30 // TODO: get info from LGService
31 $this->section_name = $_postdata['sectionName'];
32 $this->book_id = $_postdata['bookId'];
33 $this->book_name = $_postdata['bookName'];
34
28 35
29 // get from URL with file_id 36 // get from URL with file_id
30 $lg_text_url = $this->get_text_from_fileId_url.$file_id; 37 $lg_text_url = $this->get_text_from_fileId_url.$file_id;
31 $lg_text = file_get_contents($lg_text_url); 38 $lg_text = file_get_contents($lg_text_url);
32 39
43 public function GetTextFromSectionId($_postdata) { 50 public function GetTextFromSectionId($_postdata) {
44 51
45 $section_id = $_postdata['sectionId']; 52 $section_id = $_postdata['sectionId'];
46 $this->section_id = $section_id; 53 $this->section_id = $section_id;
47 $this->user_id = $_postdata['userId']; 54 $this->user_id = $_postdata['userId'];
55
56 // TODO: get info from LGService
57 $this->section_name = $_postdata['sectionName'];
58 $this->book_id = $_postdata['bookId'];
59 $this->book_name = $_postdata['bookName'];
60
61
48 62
49 // get from URL with file_id 63 // get from URL with file_id
50 $lg_text_url = $this->get_text_from_sectionId_url.$section_id; 64 $lg_text_url = $this->get_text_from_sectionId_url.$section_id;
51 $lg_text = file_get_contents($lg_text_url); 65 $lg_text = file_get_contents($lg_text_url);
52 66
86 } 100 }
87 if ($_postdata['topic_id']) { 101 if ($_postdata['topic_id']) {
88 $this->topic = $_postdata['topic_id']; 102 $this->topic = $_postdata['topic_id'];
89 } 103 }
90 104
105 // TODO: LGService
106 if ($_postdata['sectionName']) {
107 $this->section_name = $_postdata['sectionName'];
108 }
109 if ($_postdata['bookName']) {
110 $this->book_name = $_postdata['bookName'];
111 }
112 if ($_postdata['bookId']) {
113 $this->book_id = $_postdata['bookId'];
114 }
115
91 $this->messages .= "Info: "; 116 $this->messages .= "Info: ";
92 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; 117 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id;
93 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic."<br>"; 118 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic;
119 $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name."<br>";
120
121
94 122
95 } 123 }
96 public function InitData($_postdata) { 124 public function InitData($_postdata) {
97 $file_id = $_postdata['fileId']; 125 $file_id = $_postdata['fileId'];
98 $branch_id = $_postdata['branchId']; 126 $branch_id = $_postdata['branchId'];
162 $data['topiclistArray'] = $topiclistArray; 190 $data['topiclistArray'] = $topiclistArray;
163 $data['default_topic_id'] = $this->GetTopic(); 191 $data['default_topic_id'] = $this->GetTopic();
164 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); 192 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic());
165 $data['topic_name'] = $this->GetTopicName($this->GetTopic()); 193 $data['topic_name'] = $this->GetTopicName($this->GetTopic());
166 194
167 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id); 195 $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);
168 $data['messages'] = $this->messages; 196 $data['messages'] = $this->messages;
169 197
170 return $data; 198 return $data;
171 199
172 } 200 }
200 $response_file = $response["file"]; 228 $response_file = $response["file"];
201 $response_branch = $response["branch"]; 229 $response_branch = $response["branch"];
202 230
203 $this->file_id = (string)$response_file["id"]; 231 $this->file_id = (string)$response_file["id"];
204 $this->branch_id = (string)$response_branch["id"]; 232 $this->branch_id = (string)$response_branch["id"];
205 233
206 //$this->messages .= "file_id: ".$this->file_id."<br>"; 234
207 //$this->messages .= "branch_id: ".$this->branch_id."<br>"; 235
236 $status = (string)$response["status"];
237 if ($status == "ok") {
238 $this->messages .= "saving success.";
239
240 } else if ($status == "error") {
241 // saving not success
242 $this->messages .= "saving does not success! ".(string)$response["message"];
243
244
245 }
246
208 247
209 } 248 }
210 public function SaveFullTextToLGService($_postdata) { 249 public function SaveFullTextToLGService($_postdata) {
211 // save tagged text (full text) by Jorge's API to lg service 250 // save tagged text (full text) by Jorge's API to lg service
212 251
213 // -------- 252 // --------
214 // saving in my local machine in developing phrase
215 if ($_postdata['text']){ 253 if ($_postdata['text']){
216 $date = date('Y_m_d_H_i_s', time()); 254 $date = date('Y_m_d_H_i_s', time());
217 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { 255 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) {
218 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); 256 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt");
257 //saving in my local machine in developing phrase
219 file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); 258 file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile);
220 } 259 }
221 260
222 if (get_magic_quotes_gpc()) { 261 if (get_magic_quotes_gpc()) {
223 $require = stripslashes($_postdata['text']); 262 $require = stripslashes($_postdata['text']);
228 $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require); 267 $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
229 $require = preg_replace('/&amp;/u', "&", $require); 268 $require = preg_replace('/&amp;/u', "&", $require);
230 $require = preg_replace("/○/u", " ", $require); 269 $require = preg_replace("/○/u", " ", $require);
231 $require = preg_replace("/<br>/u", "\n", $require); 270 $require = preg_replace("/<br>/u", "\n", $require);
232 $require = preg_replace("/<br>/u", "\n", $require); 271 $require = preg_replace("/<br>/u", "\n", $require);
272 //saving in my local machine in developing phrase
233 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); 273 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
234 } 274 }
235 275
236 // ------ 276 // ------
237 277
248 $save_url = $this->save_to_LGService_url; 288 $save_url = $this->save_to_LGService_url;
249 289
250 } else { 290 } else {
251 // new branch case 291 // new branch case
252 echo "saveNew!"; 292 echo "saveNew!";
293 if ($_postdata['userId']) {
294 $user_id = $_postdata['userId'];
295 } else {
296 $user_id = "12";
297 }
253 $postfields = array( 298 $postfields = array(
254 //"text" => $_postdata['text'], 299 //"text" => $_postdata['text'],
255 "text" => $require, 300 "text" => $require,
256 "sectionId" => $_postdata['sectionId'], 301 "sectionId" => $_postdata['sectionId'],
257 //"userId" => $_postdata['userId'], 302 //"userId" => $_postdata['userId'],
258 // TODO: change userId when we can query by sectionId from LGService using search 303 // TODO: change userId when we can query by sectionId from LGService using search
259 "userId" => "12", 304 "userId" => $user_id,
260 "label" => $_postdata['label'], 305 "label" => $_postdata['label'],
261 // TODO: ask user for lable 306 // TODO: ask user for lable
262 //"label" => "label for section ".$_postdata['sectionId'], 307 //"label" => "label for section ".$_postdata['sectionId'],
263 ); 308 );
264 $save_url = $this->save_new_to_LGService_url; 309 $save_url = $this->save_new_to_LGService_url;
374 $section_id = $postdata['sectionId']; 419 $section_id = $postdata['sectionId'];
375 420
376 //$section_id = $this->section_id; 421 //$section_id = $this->section_id;
377 422
378 423
379 // TODO: this should be get from LGServic: sectionName, bookId, bookName 424 // TODO: this should be get from LGService: sectionName, bookId, bookName
425 $sectionName = $postdata['sectionName'];
426 $bookId = $postdata['bookId'];
427 $bookName = $postdata['bookName'];
428
429
430 // --- replace if get info from LGService
431 /*
380 $section_info = $this->GetSectionInfo(); 432 $section_info = $this->GetSectionInfo();
381 433
382 $sectionName = $section_info['sectionName']; 434 $sectionName = $section_info['sectionName'];
383 $bookId = $section_info['bookId']; 435 $bookId = $section_info['bookId'];
384 436
385 $books_info = $this->GetBooksInfo($bookId); 437 $books_info = $this->GetBooksInfo($bookId);
386 $bookName = $books_info['bookName']; 438 $bookName = $books_info['bookName'];
439 */
387 // ===== 440 // =====
388 441
389 442
390 $outputTableArray = array(); 443 $outputTableArray = array();
391 444