comparison develop/models/extractapp.php @ 14:ac77748bb813

- Load regex files based on current topic. Only show the regex in this topic. To do that, it needs to lookup a table called 'topic_regex_relation' which has the relation of topic and regex filename in filesystem. - Extractapp UI with some layout modification: button, popup window, responsive (by bootstrap now). It was just for quick prototyping.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 19 Feb 2015 11:07:27 +0100
parents cc36a20a68ab
children 1f98c92ebbfb
comparison
equal deleted inserted replaced
13:cc36a20a68ab 14:ac77748bb813
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=""; 11 protected $section_id = 0, $data_path, $file_id = 0, $branch_id = 0, $user_id = 0, $lg_text = "";
12 public $messages = "";
12 13
13 private function Initialize($_urlvalues) { 14 private function Initialize($_urlvalues) {
14 $this->SetSectionId($_urlvalues); 15 $this->SetSectionId($_urlvalues);
15 16
16 } 17 }
59 $this->lg_text = $lg_text; 60 $this->lg_text = $lg_text;
60 } 61 }
61 62
62 public function GetTextFromLocal($_id){ 63 public function GetTextFromLocal($_id){
63 $this->section_id = $_id; 64 $this->section_id = $_id;
64 echo "DEBUG: from my local"."<br>"; 65 $this->messages .= "DEBUG: from my local"."<br>";
65 $this->lg_text = $this->GetSectionContent(); 66 $this->lg_text = $this->GetSectionContent();
66 67
67 } 68 }
68 69
69 public function GetInfoFromPreviousPage($_postdata) { 70 public function GetInfoFromPreviousPage($_postdata) {
155 $data['topiclistArray'] = $topiclistArray; 156 $data['topiclistArray'] = $topiclistArray;
156 $data['default_topic_id'] = $this->GetTopic(); 157 $data['default_topic_id'] = $this->GetTopic();
157 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); 158 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic());
158 159
159 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id); 160 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id);
160 161 $data['messages'] = $this->messages;
162
161 return $data; 163 return $data;
162 164
163 } 165 }
164 166
165 public function SaveFullText($postdata) { 167 public function SaveFullText($postdata) {
189 public function UpdateInfoByResponseFromLGService($response) { 191 public function UpdateInfoByResponseFromLGService($response) {
190 192
191 $response_file = $response["file"]; 193 $response_file = $response["file"];
192 $response_branch = $response["branch"]; 194 $response_branch = $response["branch"];
193 195
194 $this->file_id = (string)$response_file["id"]; // should updated 196 $this->file_id = (string)$response_file["id"];
195 echo "file_id: ".$this->file_id;
196 echo "<br>";
197 $this->branch_id = (string)$response_branch["id"]; 197 $this->branch_id = (string)$response_branch["id"];
198 echo "branch_id: ".$this->branch_id; 198
199 echo "<br>"; 199 $this->messages .= "file_id: ".$this->file_id."<br>";
200 $this->messages .= "branch_id: ".$this->branch_id."<br>";
200 201
201 } 202 }
202 public function SaveFullTextToLGService($_postdata) { 203 public function SaveFullTextToLGService($_postdata) {
203 // save tagged text (full text) by Jorge's API to lg service 204 // save tagged text (full text) by Jorge's API to lg service
204 205
223 $require = preg_replace("/<br>/u", "\n", $require); 224 $require = preg_replace("/<br>/u", "\n", $require);
224 $require = preg_replace("/<br>/u", "\n", $require); 225 $require = preg_replace("/<br>/u", "\n", $require);
225 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); 226 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
226 } 227 }
227 228
228 echo getcwd()."<br>";
229 // ------ 229 // ------
230 230
231 231
232 if ($_postdata['branchId'] != 0) { 232 if ($_postdata['branchId'] != 0) {
233 // exiting branch case 233 // exiting branch case
248 "text" => $require, 248 "text" => $require,
249 "sectionId" => $_postdata['sectionId'], 249 "sectionId" => $_postdata['sectionId'],
250 //"userId" => $_postdata['userId'], 250 //"userId" => $_postdata['userId'],
251 // TODO: change userId when we can query by sectionId from LGService using search 251 // TODO: change userId when we can query by sectionId from LGService using search
252 "userId" => "12", 252 "userId" => "12",
253 // "label" => $_postdata['label'], 253 "label" => $_postdata['label'],
254 // TODO: ask user for lable 254 // TODO: ask user for lable
255 "label" => "label for section ".$_postdata['sectionId'], 255 //"label" => "label for section ".$_postdata['sectionId'],
256 ); 256 );
257 $save_url = $this->save_new_to_LGService_url; 257 $save_url = $this->save_new_to_LGService_url;
258 } 258 }
259 259
260 260
284 284
285 $response = json_decode($output, true); 285 $response = json_decode($output, true);
286 return $response; 286 return $response;
287 287
288 } 288 }
289 289
290 // --- for regex ----
291 public function GetRegexFilenameById($topic_id) {
292 $query = sprintf("SELECT regex_filename FROM `topic_regex_relation` WHERE topic_id=\"%s\"", $topic_id);
293 $result = mysql_query($query);
294 if (!$result) {
295 return json_encode("Failed during selecting topic_regex_relation table.");
296 }
297
298 $filenames = array();
299 while ($row = mysql_fetch_assoc($result)) {
300 array_push($filenames, $row['regex_filename']);
301 }
302
303 return $filenames;
304 }
305 public function SmartRegexLoad($topic_id) {
306
307 // Load regex file based on current topic. Only shows the regex in this topic --
308 $filenames = $this->GetRegexFilenameById($topic_id);
309
310 // Get regex file from filesystem ----
311 $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
312 $returnArray = array();
313 $files1 = scandir($data_path."regex_files");
314 foreach ( $files1 as $file ) {
315 if ( $file != "." && $file != ".." && $file != ".DS_Store") {
316 foreach ($filenames as $filename) {
317 if ($file == $filename) {
318 $returnArray[preg_replace("/\.txt/", "", $file)] = file_get_contents( $data_path."regex_files/".$file );
319 break;
320 }
321 }
322 }
323 }
324 echo json_encode($returnArray);
325 return;
326 }
327
328
329 public function SmartRegexSave($_postdata) {
330 if ($_postdata['text']){
331 /*
332 $date = date('Y_m_d_H_i_s', time());
333 if ( file_exists("regex_files/".$_POST['filename'].".txt") ) {
334 $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt");
335 file_put_contents("regex_files/".$_POST['filename']."_".$date.".txt", $oldFile);
336 }
337 */
338 $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
339
340 if (get_magic_quotes_gpc()) {
341 $require = stripslashes($_postdata['text']);
342 } else {
343 $require = $_postdata['text'];
344 }
345
346 file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require);
347 }
348 }
349
350
290 // === for export table === 351 // === for export table ===
291 public function ExportTable($postdata) { 352 public function ExportTable($postdata) {
292 // $this->Initialize($urlvalues); 353 // $this->Initialize($urlvalues);
293 354
294 $content = $postdata['content']; 355 $content = $postdata['content'];
411 return $data; 472 return $data;
412 473
413 } 474 }
414 475
415 // === for manage tag list === 476 // === for manage tag list ===
416 public function EditTaglist($urlvalues) { 477 public function EditTaglist() {
417 // $this->Initialize($urlvalues); 478 // $this->Initialize($urlvalues);
418 $result = $this->GetTaglist(); 479 $result = $this->GetTaglist();
419 $taglistArray = array(); 480 $taglistArray = array();
420 while ($row = mysql_fetch_assoc($result)) { 481 while ($row = mysql_fetch_assoc($result)) {
421 $taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); 482 $taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']);
563 } 624 }
564 625
565 // =========================== 626 // ===========================
566 627
567 // === for manage wordlist === 628 // === for manage wordlist ===
568 public function EditWordlist($urlvalues) { 629 public function EditWordlist() {
569 $result = $this->GetWordlist(); 630 $result = $this->GetWordlist();
570 $wordlistArray = array(); 631 $wordlistArray = array();
571 while ($row = mysql_fetch_assoc($result)) { 632 while ($row = mysql_fetch_assoc($result)) {
572 $wordlistArray[$row['id']] = $row['name']; 633 $wordlistArray[$row['id']] = $row['name'];
573 } 634 }
700 761
701 private function GetSectionContent() { 762 private function GetSectionContent() {
702 $section_id = $this->GetSectionId(); 763 $section_id = $this->GetSectionId();
703 $section_info = $this->GetSectionInfo(); 764 $section_info = $this->GetSectionInfo();
704 765
705 var_dump($section_id);
706 var_dump($section_info);
707
708 $bookId = $section_info['bookId']; 766 $bookId = $section_info['bookId'];
709 $startPage = $section_info['startPage']; 767 $startPage = $section_info['startPage'];
710 $endPage = $section_info['endPage']; 768 $endPage = $section_info['endPage'];
711 769
712 $contentString=""; 770 $contentString="";