comparison models/extractapp.php @ 77:97c1e5102a22 extractapp

New: export table for a file from LGService
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 16 Apr 2015 14:53:22 +0200
parents c49192885290
children 960ba96efce1
comparison
equal deleted inserted replaced
76:c49192885290 77:97c1e5102a22
1
2
3 <?php 1 <?php
2 /**
3 * ExtractappModel is extended from the BaseModel.
4 * This is where we implement the functions/models that related to extraction-interface.
5 */
4 6
5 class ExtractappModel extends BaseModel{ 7 class ExtractappModel extends BaseModel{
6
7 public function Index() {
8 return array("Index Value 1", "Value 2", "Value 3");
9 }
10 8
11 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, 9 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 = "",$book_dynasty=""; 10 $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty="";
13 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); 11 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>"");
14 12
43 41
44 $this->lg_text = $lg_text; 42 $this->lg_text = $lg_text;
45 43
46 } 44 }
47 45
48
49
50
51 public function SetBookMetaDataBySectionId() { 46 public function SetBookMetaDataBySectionId() {
52 47
53 // get book_meta from $$this->get_section_metadata_by_sectionId_url 48 // get book_meta from $$this->get_section_metadata_by_sectionId_url
54 $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id; 49 $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id;
55 $section_meta = json_decode(file_get_contents($section_meta_url), true); 50 $section_meta = json_decode(file_get_contents($section_meta_url), true);
61 $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'], 56 $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'],
62 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber 57 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber
63 $this->book_meta = $book_meta; 58 $this->book_meta = $book_meta;
64 59
65 } 60 }
66
67 61
68 public function GetTextFromSectionId() { // remove $_postdata as input 62 public function GetTextFromSectionId() { // remove $_postdata as input
69 /* 63 /*
70 $section_id = $_postdata['sectionId']; 64 $section_id = $_postdata['sectionId'];
71 $this->section_id = $section_id; 65 $this->section_id = $section_id;
89 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$this->book_id."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); 83 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$this->book_id."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput);
90 $lg_text = $stringInput; 84 $lg_text = $stringInput;
91 85
92 $this->lg_text = $lg_text; 86 $this->lg_text = $lg_text;
93 } 87 }
94
95 88
96 // This is only used on localhost 89 // This is only used on localhost
97 public function GetTextFromLocal($_id){ 90 public function GetTextFromLocal($_id){
98 $this->section_id = $_id; 91 $this->section_id = $_id;
99 //$this->branch_id = 1; // local test sets branch_id to 1 92 //$this->branch_id = 1; // local test sets branch_id to 1
327 $text .= "<in_jibengujiku>".$b[12]."</in_jibengujiku>\n"; 320 $text .= "<in_jibengujiku>".$b[12]."</in_jibengujiku>\n";
328 $text .= "<admin_type>".$b[13]."</admin_type>\n"; 321 $text .= "<admin_type>".$b[13]."</admin_type>\n";
329 $text .= "</book>\n"; 322 $text .= "</book>\n";
330 323
331 } 324 }
325 // --- section info ---
326 $text .= "<section>\n";
327 $text .= "<id>".$this->section_id."</id>\n";
328 $text .= "<name>".$this->section_name."</name>\n";
329 $text .= "</section>\n";
332 330
333 // ---- taglist --- 331 // ---- taglist ---
334 // $taglist = $this->taglist_infile; 332 // $taglist = $this->taglist_infile;
335 // obtain the latest taglist from db 333 // obtain the latest taglist from db
336 $taglist = $this->GetTaglistByTopicID($this->GetTopic()); 334 $taglist = $this->GetTaglistByTopicID($this->GetTopic());
545 543
546 } 544 }
547 } 545 }
548 546
549 547
550 // === for export table === 548 private function GetTableArray($_taglistArray, $_topic_tag, $_content) {
551 public function ExportTable($postdata) {
552
553 $content = $postdata['content'];
554 $topic = $postdata['topic'];
555 $section_id = $postdata['sectionId'];
556
557 //$section_id = $this->section_id;
558
559 $sectionName = $postdata['sectionName'];
560 $bookId = $postdata['bookId'];
561 $bookName = $postdata['bookName'];
562
563 // =====
564 549
565 $outputTableArray = array(); 550 $outputTableArray = array();
566
567 //$taglistArray = $this->GetTaglistArray();
568 $taglistArray = $this->GetTaglistByTopicID($topic);
569
570 $outputTableArray[0]=array(); 551 $outputTableArray[0]=array();
571 $outputTableArray[0][0]=array(); 552 $outputTableArray[0][0]=array();
572 $outputTableArray[0][1]=array(); 553 $outputTableArray[0][1]=array();
573 foreach ( $taglistArray as $value ) { 554 foreach ( $_taglistArray as $value ) {
574 $outputTableArray[0][0][$value[2]] = $value[1]; 555 $outputTableArray[0][0][$value[2]] = $value[1];
575 $outputTableArray[0][1][$value[2]] = $value[1]."(Title)"; 556 $outputTableArray[0][1][$value[2]] = $value[1]."(Title)";
576 } 557 }
577 $outputTableArray[0]["other"] = "其他"; 558 $outputTableArray[0]["other"] = "其他";
578 $outputTableArray[0]["page"] = "頁數"; 559 $outputTableArray[0]["page"] = "頁數";
579 $outputTableArray[0]["full"] = "全文"; 560 $outputTableArray[0]["full"] = "全文";
580 561
581 foreach ( $taglistArray as $tagValue ) { 562 foreach ( $_taglistArray as $tagValue ) {
582 $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $content); 563 $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $_content);
583 $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $content); 564 $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $_content);
584 } 565 }
585 566
586 $contentLineArray = explode( "<br>", $content ); 567 $contentLineArray = explode( "<br>", $content );
587 568
588 $count=0; 569 $count=0;
593 $otherString = $recordString; 574 $otherString = $recordString;
594 //echo $recordString."<br>\n"; 575 //echo $recordString."<br>\n";
595 if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) { 576 if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) {
596 $pageNow = $matches[2]; 577 $pageNow = $matches[2];
597 } 578 }
598 foreach ( $taglistArray as $tagValue ) { 579 foreach ( $_taglistArray as $tagValue ) {
599 if ( preg_match_all("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", $recordString, $matches, PREG_SET_ORDER) ) { 580 if ( preg_match_all("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", $recordString, $matches, PREG_SET_ORDER) ) {
600 foreach ( $matches as $matchesValue ) { 581 foreach ( $matches as $matchesValue ) {
601 $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]); 582 $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]);
602 if ( preg_match_all("/〈(.*?)〉/u", $matchesValue[1], $matches2, PREG_SET_ORDER) ) { 583 if ( preg_match_all("/〈(.*?)〉/u", $matchesValue[1], $matches2, PREG_SET_ORDER) ) {
603 foreach ( $matches2 as $matches2Value ) { 584 foreach ( $matches2 as $matches2Value ) {
624 $value = preg_replace("/>/u", "&gt;", $value); 605 $value = preg_replace("/>/u", "&gt;", $value);
625 $value = preg_replace("/</u", "&lt;", $value); 606 $value = preg_replace("/</u", "&lt;", $value);
626 $outputTableArray[$count]["full"] = $value; 607 $outputTableArray[$count]["full"] = $value;
627 } 608 }
628 609
629 $topic_tag = $this->GetTopicTag($topic); 610
630 611
631 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { 612 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) {
632 // output each row which the topic tag 613 // output each row which the topic tag
633 // e.g. the original version is for 'person' 614 // e.g. the original version is for 'person'
634 if ( !isset($arrayValue[0][$topic_tag]) ) { 615 if ( !isset($arrayValue[0][$_topic_tag]) ) {
635 unset($outputTableArray[$arrayIndex]); 616 unset($outputTableArray[$arrayIndex]);
636 } 617 }
637 618
638 } 619 }
639 620 // -----
621
622 return $outputTableArray;
623 }
624
625 // === for export table ===
626
627 public function ExportTable($postdata, $isFromFile) {
628 if ($isFromFile) {
629 $content = $this->lg_text;
630 $topic = $this->topic;
631 $sectionId = $this->section_id;
632 $sectionName = $this->section_name;
633 $bookId = $this->book_id;
634 $bookName = $this->book_name;
635
636 $taglistArray = $this->taglist_infile;
637
638 } else {
639 $content = $postdata['content'];
640 $topic = $postdata['topic'];
641
642 $section_id = $postdata['sectionId'];
643 $sectionName = $postdata['sectionName'];
644 $bookId = $postdata['bookId'];
645 $bookName = $postdata['bookName'];
646
647 //$taglistArray = $this->GetTaglistArray();
648 $taglistArray = $this->GetTaglistByTopicID($topic);
649 }
650 // =====
651
652 $topic_tag = $this->GetTopicTag($topic);
653
654 // input data: taglistArray, topic_tag, content; output: outputTableArray
655 $outputTableArray = $this->GetTableArray($taglistArray, $topic_tag, $content);
656
657
658
659 // data for view
640 $data = array(); 660 $data = array();
641
642 $data['outputTableArray'] = $outputTableArray; 661 $data['outputTableArray'] = $outputTableArray;
643 $data['bookId'] = $bookId; 662 $data['bookId'] = $bookId;
644 $data['section_id'] = $section_id; 663 $data['section_id'] = $section_id;
645 $data['bookName'] = $bookName; 664 $data['bookName'] = $bookName;
646 $data['sectionName'] = $sectionName; 665 $data['sectionName'] = $sectionName;
649 668
650 } 669 }
651 670
652 // === for manage tag list === 671 // === for manage tag list ===
653 public function EditTaglist($_postdata) { 672 public function EditTaglist($_postdata) {
673 /**
674 */
675
654 $query = "SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='taglist'"; 676 $query = "SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='taglist'";
655 $result = mysql_query($query); 677 $result = mysql_query($query);
656 if (!$result) { 678 if (!$result) {
657 echo json_encode(mysql_error()); 679 echo json_encode(mysql_error());
658 } 680 }
755 777
756 } 778 }
757 779
758 // === for config topic === 780 // === for config topic ===
759 public function ConfigTagsInTopic($postdata) { 781 public function ConfigTagsInTopic($postdata) {
782 /**
783 *
784 */
785
760 $topic = $postdata['topic']; 786 $topic = $postdata['topic'];
761 $result = $this->GetTopicByID($topic); 787 $result = $this->GetTopicByID($topic);
762 $row = mysql_fetch_assoc($result); 788 $row = mysql_fetch_assoc($result);
763 $topic_name_en = $row['name_en']; 789 $topic_name_en = $row['name_en'];
764 $topic_name_ch = $row['name_ch']; 790 $topic_name_ch = $row['name_ch'];
1013 1039
1014 // =========================== 1040 // ===========================
1015 1041
1016 // === for manage wordlist === 1042 // === for manage wordlist ===
1017 public function EditWordlist() { 1043 public function EditWordlist() {
1044 /**
1045 * EditWordlist shows the wordlist in a new window.
1046 * User can view each one of the wordlist and edit it, also s/he can create a new wordlist here.
1047 */
1048
1018 $result = $this->GetWordlist(); 1049 $result = $this->GetWordlist();
1019 $wordlistArray = array(); 1050 $wordlistArray = array();
1020 while ($row = mysql_fetch_assoc($result)) { 1051 while ($row = mysql_fetch_assoc($result)) {
1021 $wordlistArray[$row['id']] = $row['name']; 1052 $wordlistArray[$row['id']] = $row['name'];
1022 } 1053 }
1162 if ($book_metaArray) { 1193 if ($book_metaArray) {
1163 $this->book_meta = $book_metaArray; 1194 $this->book_meta = $book_metaArray;
1164 } 1195 }
1165 */ 1196 */
1166 // ----- 1197 // -----
1198 // TODO: get section_id, section_name from file
1199 if ($this->section_id == 0 && isset($xml->section)) {
1200 if ($xml->section) {
1201 $this->section_id = (string)$xml->section->id;
1202 $this->section_name = (string)$xml->section->name;
1203 }
1204 }
1205 // book meta data
1206 if (!isset($this->book_id) && isset($xml->book)) {
1207 $this->book_id = (string)$xml->book->id;
1208 $this->book_name = (string)$xml->book->name;
1209 }
1210
1211
1167 1212
1168 $contentString = (string)($xml->text_content->asXML()); 1213 $contentString = (string)($xml->text_content->asXML());
1169 1214
1170 $removed_str = array("<text_content>","</text_content>"); 1215 $removed_str = array("<text_content>","</text_content>");
1171 $new_contentString = str_replace($removed_str, "", $contentString); 1216 $new_contentString = str_replace($removed_str, "", $contentString);
1172 1217
1173 return $new_contentString; 1218 return $new_contentString;
1174 } 1219 }
1175 1220
1176 1221
1177 private function GetSectionContent() { // called only by GetTextFromLocal() 1222 private function GetSectionContent() {
1223 /** This is only been called by GetTextFromLocal().
1224 */
1225
1178 $section_id = $this->GetSectionId(); 1226 $section_id = $this->GetSectionId();
1179 $section_info = $this->GetSectionInfo(); 1227 $section_info = $this->GetSectionInfo();
1180 1228
1181 $bookId = $section_info['bookId']; 1229 $bookId = $section_info['bookId'];
1182 $startPage = $section_info['startPage']; 1230 $startPage = $section_info['startPage'];