Mercurial > hg > extraction-interface
diff 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 |
line wrap: on
line diff
--- a/models/extractapp.php Mon Apr 13 15:43:59 2015 +0200 +++ b/models/extractapp.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,13 +1,11 @@ - - <?php +/** + * ExtractappModel is extended from the BaseModel. + * This is where we implement the functions/models that related to extraction-interface. +*/ class ExtractappModel extends BaseModel{ - public function Index() { - return array("Index Value 1", "Value 2", "Value 3"); - } - protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty=""; public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); @@ -45,9 +43,6 @@ } - - - public function SetBookMetaDataBySectionId() { // get book_meta from $$this->get_section_metadata_by_sectionId_url @@ -64,7 +59,6 @@ } - public function GetTextFromSectionId() { // remove $_postdata as input /* $section_id = $_postdata['sectionId']; @@ -92,7 +86,6 @@ $this->lg_text = $lg_text; } - // This is only used on localhost public function GetTextFromLocal($_id){ $this->section_id = $_id; @@ -329,6 +322,11 @@ $text .= "</book>\n"; } + // --- section info --- + $text .= "<section>\n"; + $text .= "<id>".$this->section_id."</id>\n"; + $text .= "<name>".$this->section_name."</name>\n"; + $text .= "</section>\n"; // ---- taglist --- // $taglist = $this->taglist_infile; @@ -547,30 +545,13 @@ } - // === for export table === - public function ExportTable($postdata) { - - $content = $postdata['content']; - $topic = $postdata['topic']; - $section_id = $postdata['sectionId']; - - //$section_id = $this->section_id; - - $sectionName = $postdata['sectionName']; - $bookId = $postdata['bookId']; - $bookName = $postdata['bookName']; - - // ===== + private function GetTableArray($_taglistArray, $_topic_tag, $_content) { $outputTableArray = array(); - - //$taglistArray = $this->GetTaglistArray(); - $taglistArray = $this->GetTaglistByTopicID($topic); - $outputTableArray[0]=array(); $outputTableArray[0][0]=array(); $outputTableArray[0][1]=array(); - foreach ( $taglistArray as $value ) { + foreach ( $_taglistArray as $value ) { $outputTableArray[0][0][$value[2]] = $value[1]; $outputTableArray[0][1][$value[2]] = $value[1]."(Title)"; } @@ -578,9 +559,9 @@ $outputTableArray[0]["page"] = "頁數"; $outputTableArray[0]["full"] = "全文"; - foreach ( $taglistArray as $tagValue ) { - $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $content); - $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $content); + foreach ( $_taglistArray as $tagValue ) { + $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $_content); + $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $_content); } $contentLineArray = explode( "<br>", $content ); @@ -595,7 +576,7 @@ if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) { $pageNow = $matches[2]; } - foreach ( $taglistArray as $tagValue ) { + foreach ( $_taglistArray as $tagValue ) { if ( preg_match_all("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", $recordString, $matches, PREG_SET_ORDER) ) { foreach ( $matches as $matchesValue ) { $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]); @@ -626,19 +607,57 @@ $outputTableArray[$count]["full"] = $value; } - $topic_tag = $this->GetTopicTag($topic); + foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { // output each row which the topic tag // e.g. the original version is for 'person' - if ( !isset($arrayValue[0][$topic_tag]) ) { + if ( !isset($arrayValue[0][$_topic_tag]) ) { unset($outputTableArray[$arrayIndex]); } } + // ----- + return $outputTableArray; + } + + // === for export table === + + public function ExportTable($postdata, $isFromFile) { + if ($isFromFile) { + $content = $this->lg_text; + $topic = $this->topic; + $sectionId = $this->section_id; + $sectionName = $this->section_name; + $bookId = $this->book_id; + $bookName = $this->book_name; + + $taglistArray = $this->taglist_infile; + + } else { + $content = $postdata['content']; + $topic = $postdata['topic']; + + $section_id = $postdata['sectionId']; + $sectionName = $postdata['sectionName']; + $bookId = $postdata['bookId']; + $bookName = $postdata['bookName']; + + //$taglistArray = $this->GetTaglistArray(); + $taglistArray = $this->GetTaglistByTopicID($topic); + } + // ===== + + $topic_tag = $this->GetTopicTag($topic); + + // input data: taglistArray, topic_tag, content; output: outputTableArray + $outputTableArray = $this->GetTableArray($taglistArray, $topic_tag, $content); + + + + // data for view $data = array(); - $data['outputTableArray'] = $outputTableArray; $data['bookId'] = $bookId; $data['section_id'] = $section_id; @@ -651,6 +670,9 @@ // === for manage tag list === public function EditTaglist($_postdata) { + /** + */ + $query = "SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='taglist'"; $result = mysql_query($query); if (!$result) { @@ -757,6 +779,10 @@ // === for config topic === public function ConfigTagsInTopic($postdata) { + /** + * + */ + $topic = $postdata['topic']; $result = $this->GetTopicByID($topic); $row = mysql_fetch_assoc($result); @@ -1015,6 +1041,11 @@ // === for manage wordlist === public function EditWordlist() { + /** + * EditWordlist shows the wordlist in a new window. + * User can view each one of the wordlist and edit it, also s/he can create a new wordlist here. + */ + $result = $this->GetWordlist(); $wordlistArray = array(); while ($row = mysql_fetch_assoc($result)) { @@ -1164,6 +1195,20 @@ } */ // ----- + // TODO: get section_id, section_name from file + if ($this->section_id == 0 && isset($xml->section)) { + if ($xml->section) { + $this->section_id = (string)$xml->section->id; + $this->section_name = (string)$xml->section->name; + } + } + // book meta data + if (!isset($this->book_id) && isset($xml->book)) { + $this->book_id = (string)$xml->book->id; + $this->book_name = (string)$xml->book->name; + } + + $contentString = (string)($xml->text_content->asXML()); @@ -1174,7 +1219,10 @@ } - private function GetSectionContent() { // called only by GetTextFromLocal() + private function GetSectionContent() { + /** This is only been called by GetTextFromLocal(). + */ + $section_id = $this->GetSectionId(); $section_info = $this->GetSectionInfo();