Mercurial > hg > extraction-interface
comparison models/extractapp.php @ 63:3395385476d1 extractapp
bug fixed: popup tag window is closed automatically when saving text file
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 01 Apr 2015 15:10:35 +0200 |
parents | 3fb9e3884401 |
children | f9ae94a9b041 |
comparison
equal
deleted
inserted
replaced
62:3fb9e3884401 | 63:3395385476d1 |
---|---|
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, $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 = "",$book_dynasty=""; |
13 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); | 13 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); |
14 | 14 |
15 private function Initialize($_urlvalues) { | |
16 $this->SetSectionId($_urlvalues); | |
17 | |
18 } | |
19 | 15 |
20 public function GetTextFromFileId() { // remove $_postdata as input | 16 public function GetTextFromFileId() { // remove $_postdata as input |
21 /* | 17 /* |
22 $this->file_id = $_postdata['fileId']; | 18 $this->file_id = $_postdata['fileId']; |
23 $branch_id = $_postdata['branchId']; | 19 $branch_id = $_postdata['branchId']; |
50 | 46 |
51 $this->lg_text = $lg_text; | 47 $this->lg_text = $lg_text; |
52 | 48 |
53 } | 49 } |
54 | 50 |
51 public function GetBookMetaData($_postdata) { | |
52 // TODO: get book_meta from $_postdata, depended on LGService | |
53 | |
54 | |
55 // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty) | |
56 $book_meta = array(); | |
57 array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data","no_data")); // missing author,year,pagenumber | |
58 | |
59 $this->book_meta = $book_meta; | |
60 | |
61 } | |
62 | |
63 | |
55 public function GetTextFromSectionId() { // remove $_postdata as input | 64 public function GetTextFromSectionId() { // remove $_postdata as input |
56 /* | 65 /* |
57 $section_id = $_postdata['sectionId']; | 66 $section_id = $_postdata['sectionId']; |
58 $this->section_id = $section_id; | 67 $this->section_id = $section_id; |
59 $this->user_id = $_postdata['userId']; | 68 $this->user_id = $_postdata['userId']; |
66 // get from URL with file_id | 75 // get from URL with file_id |
67 // $lg_text_url = $this->get_text_from_sectionId_url.$section_id; | 76 // $lg_text_url = $this->get_text_from_sectionId_url.$section_id; |
68 $lg_text_url = $this->get_text_from_sectionId_url.$this->section_id; | 77 $lg_text_url = $this->get_text_from_sectionId_url.$this->section_id; |
69 $lg_text = file_get_contents($lg_text_url); | 78 $lg_text = file_get_contents($lg_text_url); |
70 | 79 |
71 // TODO: get book_meta from $_postdata and set $this->book_meta: book_id,book_name,author,year,pagenumber | 80 |
72 $book_meta = array(); | |
73 array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data")); // missing author,year,pagenumber | |
74 | |
75 $this->book_meta = $book_meta; | |
76 | |
77 | |
78 | 81 |
79 $stringInput = $lg_text; | 82 $stringInput = $lg_text; |
80 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); | 83 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); |
81 $stringInput = preg_replace("/ /u", "○", $stringInput); | 84 $stringInput = preg_replace("/ /u", "○", $stringInput); |
82 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | 85 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
86 $this->lg_text = $lg_text; | 89 $this->lg_text = $lg_text; |
87 } | 90 } |
88 | 91 |
89 public function GetTextFromLocal($_id){ | 92 public function GetTextFromLocal($_id){ |
90 $this->section_id = $_id; | 93 $this->section_id = $_id; |
91 $this->branch_id = 1; // local test sets branch_id to 1 | 94 //$this->branch_id = 1; // local test sets branch_id to 1 |
92 // $this->messages .= "DEBUG: from my local"."<br>"; | |
93 $this->messages['debug'] .= "[Debug] from my local"."<br>"; | 95 $this->messages['debug'] .= "[Debug] from my local"."<br>"; |
94 $this->lg_text = $this->GetSectionContent(); | 96 $this->lg_text = $this->GetSectionContent(); |
95 | 97 |
96 } | 98 } |
97 | 99 |
133 } | 135 } |
134 if ($_postdata['book_meta']) { | 136 if ($_postdata['book_meta']) { |
135 $this->book_meta = json_decode($_postdata['book_meta']); | 137 $this->book_meta = json_decode($_postdata['book_meta']); |
136 } | 138 } |
137 | 139 |
138 } | 140 |
139 public function InitData($_postdata) { | 141 } |
140 $file_id = $_postdata['fileId']; | |
141 $branch_id = $_postdata['branchId']; | |
142 $section_id = $_postdata['sectionId']; | |
143 | |
144 $this->branch_id = $branch_id; | |
145 $this->file_id = $file_id; | |
146 $this->user_id = $_postdata['userId']; | |
147 $this->section_id = $section_id; | |
148 | |
149 if ($file_id != 0 && $branch_id != 0) { | |
150 // get from URL with file_id | |
151 $lg_text_url = $this->get_text_from_fileId_url.$file_id; | |
152 } else if ($section_id != 0) { | |
153 // get from URL with section_id | |
154 $lg_text_url = $this->get_text_from_sectionId_url.$section_id; | |
155 } else { | |
156 echo "wrong url!!"; | |
157 return; | |
158 } | |
159 | |
160 | |
161 $lg_text = file_get_contents($lg_text_url); | |
162 | |
163 /* | |
164 $stringInput = preg_replace("/ /u", "○", $stringInput); | |
165 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | |
166 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); | |
167 */ | |
168 | |
169 // the text is from database | |
170 $stringInput = $lg_text; | |
171 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); | |
172 $stringInput = preg_replace("/ /u", "○", $stringInput); | |
173 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | |
174 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); | |
175 $lg_text = $stringInput; | |
176 | |
177 $this->lg_text = $lg_text; | |
178 | |
179 | |
180 } | |
181 | |
182 | 142 |
183 // TODO: comparison not correct | 143 // TODO: comparison not correct |
184 private function Taglist_infileUpToDate($taglistArray) { | 144 private function Taglist_infileUpToDate($taglistArray) { |
185 // compare $this->taglist_infile is the same as $taglistArray | 145 // compare $this->taglist_infile is the same as $taglistArray |
186 $taglist_infile = $this->taglist_infile; | 146 $taglist_infile = $this->taglist_infile; |
338 $text .= "<id>".$b[0]."</id>\n"; | 298 $text .= "<id>".$b[0]."</id>\n"; |
339 $text .= "<name>".$b[1]."</name>\n"; | 299 $text .= "<name>".$b[1]."</name>\n"; |
340 $text .= "<author>".$b[2]."</author>\n"; | 300 $text .= "<author>".$b[2]."</author>\n"; |
341 $text .= "<year>".$b[3]."</year>\n"; | 301 $text .= "<year>".$b[3]."</year>\n"; |
342 $text .= "<pagenumber>".$b[4]."</pagenumber>\n"; | 302 $text .= "<pagenumber>".$b[4]."</pagenumber>\n"; |
303 $text .= "<dynasty>".$b[5]."</dynasty>\n"; | |
343 $text .= "</book>\n"; | 304 $text .= "</book>\n"; |
344 } | 305 } |
345 // taglist | 306 // taglist |
346 $taglist = $this->taglist_infile; | 307 $taglist = $this->taglist_infile; |
347 foreach ($taglist as $tagitem) { | 308 foreach ($taglist as $tagitem) { |
551 } | 512 } |
552 | 513 |
553 | 514 |
554 // === for export table === | 515 // === for export table === |
555 public function ExportTable($postdata) { | 516 public function ExportTable($postdata) { |
556 // $this->Initialize($urlvalues); | |
557 | 517 |
558 $content = $postdata['content']; | 518 $content = $postdata['content']; |
559 $topic = $postdata['topic']; | 519 $topic = $postdata['topic']; |
560 $section_id = $postdata['sectionId']; | 520 $section_id = $postdata['sectionId']; |
561 | 521 |
562 //$section_id = $this->section_id; | 522 //$section_id = $this->section_id; |
563 | 523 |
564 | |
565 // TODO: this should be get from LGService: sectionName, bookId, bookName | |
566 $sectionName = $postdata['sectionName']; | 524 $sectionName = $postdata['sectionName']; |
567 $bookId = $postdata['bookId']; | 525 $bookId = $postdata['bookId']; |
568 $bookName = $postdata['bookName']; | 526 $bookName = $postdata['bookName']; |
569 | 527 |
570 | 528 // ===== |
571 // --- replace if get info from LGService | |
572 /* | |
573 $section_info = $this->GetSectionInfo(); | |
574 | |
575 $sectionName = $section_info['sectionName']; | |
576 $bookId = $section_info['bookId']; | |
577 | |
578 $books_info = $this->GetBooksInfo($bookId); | |
579 $bookName = $books_info['bookName']; | |
580 */ | |
581 // ===== | |
582 | |
583 | 529 |
584 $outputTableArray = array(); | 530 $outputTableArray = array(); |
585 | 531 |
586 //$taglistArray = $this->GetTaglistArray(); | 532 //$taglistArray = $this->GetTaglistArray(); |
587 $taglistArray = $this->GetTaglistByTopicID($topic); | 533 $taglistArray = $this->GetTaglistByTopicID($topic); |
642 $outputTableArray[$count]["page"] = $pageNow; | 588 $outputTableArray[$count]["page"] = $pageNow; |
643 $value = preg_replace("/>/u", ">", $value); | 589 $value = preg_replace("/>/u", ">", $value); |
644 $value = preg_replace("/</u", "<", $value); | 590 $value = preg_replace("/</u", "<", $value); |
645 $outputTableArray[$count]["full"] = $value; | 591 $outputTableArray[$count]["full"] = $value; |
646 } | 592 } |
647 /* | |
648 echo "<br>"."DEBUG: outputTableArray:"."<br>"; | |
649 var_dump($outputTableArray); | |
650 */ | |
651 | 593 |
652 $topic_tag = $this->GetTopicTag($topic); | 594 $topic_tag = $this->GetTopicTag($topic); |
653 | 595 |
654 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { | 596 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { |
655 // output each row which the topic tag | 597 // output each row which the topic tag |
703 $taglistArray = array(); | 645 $taglistArray = array(); |
704 | 646 |
705 foreach ($result as $row) { | 647 foreach ($result as $row) { |
706 $taglistArray[$row[0]] = array($row[1], $row[2], $row[3]); | 648 $taglistArray[$row[0]] = array($row[1], $row[2], $row[3]); |
707 //$taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); | 649 //$taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); |
708 // TODO: the format is not good, so I use $row[0], $row[1],... This could be changed some time. | |
709 } | 650 } |
710 | 651 |
711 $topic_tag_name = $this->GetTopicTag($topic_id); | 652 $topic_tag_name = $this->GetTopicTag($topic_id); |
712 | 653 |
713 $query = "SELECT id FROM taglist WHERE taglist.tag='".$topic_tag_name."'"; | 654 $query = "SELECT id FROM taglist WHERE taglist.tag='".$topic_tag_name."'"; |
1127 | 1068 |
1128 public function sortFunction($a,$b) { | 1069 public function sortFunction($a,$b) { |
1129 return strlen($b)-strlen($a); | 1070 return strlen($b)-strlen($a); |
1130 } | 1071 } |
1131 | 1072 |
1132 // TODO: delete this | |
1133 private function SetSectionId($_urlvalues) { | |
1134 // TODO: maybe get user info also | |
1135 // get book id from url | |
1136 if ($_urlvalues['id'] != "") { | |
1137 $section_id = $_urlvalues['id']; | |
1138 } else { | |
1139 return json_encode("Error: No section id"); | |
1140 /* ???? */ | |
1141 /* | |
1142 $get_book_id = $urlvalues['book']; | |
1143 $get_start = $urlvalues['start']; | |
1144 $get_end = $urlvalues['end']; | |
1145 */ | |
1146 } | |
1147 $this->section_id = $section_id; | |
1148 | |
1149 } | |
1150 | |
1151 private function GetSectionId() { | 1073 private function GetSectionId() { |
1152 | 1074 |
1153 if (is_numeric($this->section_id)) { | 1075 if (is_numeric($this->section_id)) { |
1154 return $this->section_id; | 1076 return $this->section_id; |
1155 } else { | 1077 } else { |
1205 | 1127 |
1206 // get book meta data from file | 1128 // get book meta data from file |
1207 $book_meta = $xml->book; | 1129 $book_meta = $xml->book; |
1208 $book_metaArray = array(); | 1130 $book_metaArray = array(); |
1209 foreach ($book_meta as $row) { | 1131 foreach ($book_meta as $row) { |
1210 array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->author,(string)$row->year,(string)$row->pagenumber )); | 1132 array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->author,(string)$row->year,(string)$row->pagenumber,(string)$row->dynasty )); |
1211 } | 1133 } |
1212 if ($book_metaArray) { | 1134 if ($book_metaArray) { |
1213 $this->book_meta = $book_metaArray; | 1135 $this->book_meta = $book_metaArray; |
1214 } | 1136 } |
1215 | 1137 |
1241 | 1163 |
1242 // if the text is from file system | 1164 // if the text is from file system |
1243 $stringInput = preg_replace("/ /u", "○", $stringInput); | 1165 $stringInput = preg_replace("/ /u", "○", $stringInput); |
1244 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | 1166 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
1245 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); | 1167 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); |
1168 | |
1169 $this->branch_id = 1; // testing at local | |
1170 | |
1246 } else { | 1171 } else { |
1247 $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage); | 1172 $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage); |
1248 $result = mysql_query($query); | 1173 $result = mysql_query($query); |
1249 if (!$result) { | 1174 if (!$result) { |
1250 return json_encode("Failed during selecting content table."); | 1175 return json_encode("Failed during selecting content table."); |
1263 | 1188 |
1264 // get book_meta from books table | 1189 // get book_meta from books table |
1265 $book_meta = array(); | 1190 $book_meta = array(); |
1266 $books_result = $this->GetBooksByID($bookId); | 1191 $books_result = $this->GetBooksByID($bookId); |
1267 while ($row = mysql_fetch_assoc($books_result)) { | 1192 while ($row = mysql_fetch_assoc($books_result)) { |
1268 array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'])); | 1193 array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'],(string)$row['dynasty'])); |
1269 // use 'start_year' as year, 'line' is pagenumber | 1194 // use 'start_year' as year, 'line' is pagenumber |
1270 } | 1195 } |
1271 | 1196 |
1272 $this->book_meta = $book_meta; | 1197 $this->book_meta = $book_meta; |
1273 | 1198 |