# HG changeset patch # User Zoe Hong # Date 1429188802 -7200 # Node ID 97c1e5102a22a026ca4aab1a9e62fd2394b2c15a # Parent c491928852900ca548d904740081e580951c7f80 New: export table for a file from LGService diff -r c49192885290 -r 97c1e5102a22 classes/basecontroller.php --- a/classes/basecontroller.php Mon Apr 13 15:43:59 2015 +0200 +++ b/classes/basecontroller.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,8 +1,11 @@ action . '.php'; if ($fullview) { require('views/maintemplate.php'); @@ -27,6 +39,10 @@ } protected function ReturnView_localtest($viewmodel, $fullview) { + /** Return the corresponding view in the views folder. + * + * This is only been used when developing on local machine. + */ $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; if ($fullview) { require('views/maintemplate_local.php'); diff -r c49192885290 -r 97c1e5102a22 classes/basemodel.php --- a/classes/basemodel.php Mon Apr 13 15:43:59 2015 +0200 +++ b/classes/basemodel.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,14 +1,11 @@ urlvalues = $urlvalues; $this->postdata = $postdata; if ($this->urlvalues['controller'] == "") { - $this->controller = "extractapp"; - // TODO: develope home page for the whole service. - // change $this->controller to home after developed extract app. - // $this->controller = "home"; - + $this->controller = "Extractapp"; // the default controller + } else { $this->controller = $this->urlvalues['controller']; } if ($this->urlvalues['action'] == "") { - $this->action = "taggingtext"; - // $this->action = "index"; + $this->action = "TaggingText"; // the default action + } else { $this->action = $this->urlvalues['action']; } - } - //establish the requested controller as an object public function CreateController() { + /** + * Establish the requested controller as an object, and check if the query is valid. + * The queried controller, which should be extended from BaseController, exists and the queried action should be one of its method. + */ + //does the class exist? if (class_exists($this->controller)) { $parents = class_parents($this->controller); diff -r c49192885290 -r 97c1e5102a22 config/config.php --- a/config/config.php Mon Apr 13 15:43:59 2015 +0200 +++ b/config/config.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,27 +1,44 @@ Configuration(); -$AT_LOCAL = false; +class Config { -if (!$AT_LOCAL) { - // host at localgazetteers-dev server - $mysql_database = "Gazetteer"; - $mysql_server = "localhost"; - $mysql_user = "root"; - $mysql_password = "admin"; - $server_host = "http://localgazetteers-dev/"; - $lgserver_url = $server_host."LGServices/"; + public function Configuration() { + /** + * Configuration for the system. + * If it runs with LGService, set $AT_LOCAL to be true; + * otherwise (runs on localhost), set it to be false. + */ + + global $AT_LOCAL, $mysql_database, $mysql_server, $mysql_user, $mysql_password, $server_host, $lgserver_url, + $systemNAME, $system_root_url; + + $AT_LOCAL = false; -} else { - // localhost - $mysql_database = "Gazetteers"; - $mysql_server = "localhost"; - $mysql_user = "root"; - $mysql_password = "root"; - $server_host = "http://localhost:1080/localgazetteers-dev/"; - $lgserver_url = "http://localgazetteers-dev/LGServices/"; + if (!$AT_LOCAL) { + // host at localgazetteers-dev server + $mysql_database = "Gazetteer"; + $mysql_server = "localhost"; + $mysql_user = "root"; + $mysql_password = "admin"; + $server_host = "http://localgazetteers-dev/"; + $lgserver_url = $server_host."LGServices/"; + + } else { + // localhost + $mysql_database = "Gazetteers"; + $mysql_server = "localhost"; + $mysql_user = "root"; + $mysql_password = "root"; + $server_host = "http://localhost:1080/localgazetteers-dev/"; + $lgserver_url = "http://localgazetteers-dev/LGServices/"; + } + + $systemNAME = "interface"; + $system_root_url = $server_host."extraction-interface"; + + } + } - -$systemNAME = "interface"; -$system_root_url = $server_host."extraction-interface"; - ?> diff -r c49192885290 -r 97c1e5102a22 controllers/extractapp.php --- a/controllers/extractapp.php Mon Apr 13 15:43:59 2015 +0200 +++ b/controllers/extractapp.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,4 +1,11 @@ viewmodel; if (isset($this->postdata['func'])) { @@ -57,7 +79,8 @@ break; - default: // first time visit extraction interface from LGService + default: + // This is where the first time user visit extraction interface from LGService $viewmodel->messages['info'] .= "Welcome to Extraction Interface. "; if (isset($this->postdata['fileId'])) { @@ -100,13 +123,37 @@ } + protected function ExportTable() { + /** + * ExportTable action returns "./views/Extractapp/ExportTable.php" view. + */ $viewmodel = $this->viewmodel; - $this->ReturnView($viewmodel->ExportTable($this->postdata), true); + + if (isset($this->postdata['func'])) { + $func = $this->postdata['func']; + } + switch ($func) { + case 'exportFromExtractionInterface': + $this->ReturnView($viewmodel->ExportTable($this->postdata, false), true); + break; + + default: // from file + $viewmodel->GetInfoFromPreviousPage($this->postdata); + $viewmodel->GetTextFromFileId(); + $this->ReturnView($viewmodel->ExportTable($this->postdata, true), true); + break; + + } } protected function EditWordlist() { + /** + * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, + * It adds or saves wordlist based on the 'func' variable in postdata. + */ + $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) { $func = $this->postdata['func']; @@ -126,6 +173,11 @@ protected function EditTaglist() { + /** + * EditTaglist action returns "./views/Extractapp/EditTaglist.php" view. + * It adds, saves or delete tag in the current topic. + */ + $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) { $func = $this->postdata['func']; @@ -148,6 +200,11 @@ protected function ConfigTagsInTopic() { + /** + * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view. + * It shows or updates the tags-in-topic relation. + */ + $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) { $func = $this->postdata['func']; @@ -162,10 +219,6 @@ } } - protected function TestAction() { - $this->ReturnView($viewmodel->Test(), true); - } - diff -r c49192885290 -r 97c1e5102a22 controllers/home.php --- a/controllers/home.php Mon Apr 13 15:43:59 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -viewmodel = new ExtractappModel(); - } - - protected function Index() { - $viewmodel = new HomeModel(); - $this->ReturnView($viewmodel->Index(), false); - } - - protected function Test() { - $viewmodel = new HomeModel(); - $this->ReturnView($viewmodel->Test(), true); - } - - -} - - -?> diff -r c49192885290 -r 97c1e5102a22 index.php --- a/index.php Mon Apr 13 15:43:59 2015 +0200 +++ b/index.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,7 +1,17 @@ CreateController(); $controller->ExecuteAction(); + ?> diff -r c49192885290 -r 97c1e5102a22 js/taggingtext.js --- a/js/taggingtext.js Mon Apr 13 15:43:59 2015 +0200 +++ b/js/taggingtext.js Thu Apr 16 14:53:22 2015 +0200 @@ -1,3 +1,7 @@ +/*! \file +* This is a js file. +*/ + // === for taggingtext.php === var stringBeforeChange=""; var stringBeforeChangeStack = []; diff -r c49192885290 -r 97c1e5102a22 models/extractapp.php --- 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 @@ - - "",'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 .= "\n"; } + // --- section info --- + $text .= "
\n"; + $text .= "".$this->section_id."\n"; + $text .= "".$this->section_name."\n"; + $text .= "
\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( "
", $content ); @@ -595,7 +576,7 @@ if ( preg_match("/【(.*?)<\/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(); diff -r c49192885290 -r 97c1e5102a22 models/home.php --- a/models/home.php Mon Apr 13 15:43:59 2015 +0200 +++ b/models/home.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,16 +1,13 @@
-

Topic: (, )

@@ -131,7 +136,6 @@ -
diff -r c49192885290 -r 97c1e5102a22 views/Extractapp/EditTaglist.php --- a/views/Extractapp/EditTaglist.php Mon Apr 13 15:43:59 2015 +0200 +++ b/views/Extractapp/EditTaglist.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,4 +1,11 @@ '); var topic_tag_id = JSON.parse(''); -function addTag( ) { +function addTag() { + largestId++; var row = tableMain.insertBefore(document.createElement("tr"), document.getElementById("trAddTag") ); row.setAttribute("height","50"); diff -r c49192885290 -r 97c1e5102a22 views/Extractapp/EditWordlist.php --- a/views/Extractapp/EditWordlist.php Mon Apr 13 15:43:59 2015 +0200 +++ b/views/Extractapp/EditWordlist.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,4 +1,10 @@ diff -r c49192885290 -r 97c1e5102a22 views/Extractapp/ExportTable.php --- a/views/Extractapp/ExportTable.php Mon Apr 13 15:43:59 2015 +0200 +++ b/views/Extractapp/ExportTable.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,4 +1,9 @@ diff -r c49192885290 -r 97c1e5102a22 views/Extractapp/TaggingText.php --- a/views/Extractapp/TaggingText.php Mon Apr 13 15:43:59 2015 +0200 +++ b/views/Extractapp/TaggingText.php Thu Apr 16 14:53:22 2015 +0200 @@ -1,4 +1,11 @@ '); if (info) { - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "bookId"); - hiddenField.setAttribute("value", info['book_id']); - form.appendChild(hiddenField); + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "bookId"); + hiddenField.setAttribute("value", info['book_id']); + form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "bookName"); - hiddenField.setAttribute("value", info['book_name']); - form.appendChild(hiddenField); - - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "sectionName"); - hiddenField.setAttribute("value", info['section_name']); - form.appendChild(hiddenField); + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "bookName"); + hiddenField.setAttribute("value", info['book_name']); + form.appendChild(hiddenField); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "sectionName"); + hiddenField.setAttribute("value", info['section_name']); + form.appendChild(hiddenField); }; @@ -404,6 +421,11 @@ form.setAttribute("target", "_blank"); var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "func"); + hiddenField.setAttribute("value", "exportFromExtractionInterface"); + form.appendChild(hiddenField); + + var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "content"); hiddenField.setAttribute("value", str.match(new RegExp(regexText, "g"))); form.appendChild(hiddenField); @@ -464,6 +486,13 @@ form.setAttribute("target", "_blank"); var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "func"); + hiddenField.setAttribute("value", "exportFromExtractionInterface"); + form.appendChild(hiddenField); + + + + var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "content"); hiddenField.setAttribute("value", str); form.appendChild(hiddenField); diff -r c49192885290 -r 97c1e5102a22 views/Home/index.php --- a/views/Home/index.php Mon Apr 13 15:43:59 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -

Home/index.php

diff -r c49192885290 -r 97c1e5102a22 views/Home/test.php --- a/views/Home/test.php Mon Apr 13 15:43:59 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -

Home/test.php

- - \ No newline at end of file