# HG changeset patch # User Zoe Hong # Date 1423581629 -3600 # Node ID 54a235d436947be1696cfe3dab6905ea3381c458 # Parent 584b1623e9ef2997b47da8e6f408994fdceb8531 add topic choosing in the TaggingText page diff -r 584b1623e9ef -r 54a235d43694 develop/classes/basemodel.php --- a/develop/classes/basemodel.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/classes/basemodel.php Tue Feb 10 16:20:29 2015 +0100 @@ -2,7 +2,7 @@ abstract class BaseModel { // protected $database; - protected $systemNAME; + protected $systemNAME, $topic; public function __construct() { global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME; @@ -23,6 +23,7 @@ die ('Can\'t use foo : ' . mysql_error()); } + $this->topic = 1; // set the default topic to person (人物) } protected function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { @@ -88,6 +89,15 @@ return $result; } + protected function GetTopiclist() { + $query = sprintf("SELECT * FROM `topics`"); + $result = mysql_query($query); + if (!$result) { + return json_encode("Failed during selecting topics table."); + } + return $result; + } + } diff -r 584b1623e9ef -r 54a235d43694 develop/controllers/extractapp.php --- a/develop/controllers/extractapp.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/controllers/extractapp.php Tue Feb 10 16:20:29 2015 +0100 @@ -12,9 +12,12 @@ case 'SaveFullText': $viewmodel->SaveFullText($this->postdata); $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); - break; - + break; + default: + if ($this->postdata['topic']) { + $viewmodel->SetTopic($this->postdata['topic']); + } $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); break; } @@ -62,6 +65,8 @@ } } + + protected function TestAction() { $viewmodel = new ExtractappModel(); diff -r 584b1623e9ef -r 54a235d43694 develop/index.php --- a/develop/index.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/index.php Tue Feb 10 16:20:29 2015 +0100 @@ -15,8 +15,9 @@ GetSectionContent(); - $taglistArray = $this->GetTaglistArray(); - // test for GetTaglistByTopicID: - // $taglistArray = $this->GetTaglistByTopicID(1); + //$taglistArray = $this->GetTaglistArray(); + //for GetTaglistByTopicID: + + $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); + + // topic list? + $topiclistArray = $this->GetTopiclistArray(); $wordlistArray = $this->GetWordlistArray(); @@ -36,8 +40,9 @@ $data['taglistArray'] = $taglistArray; $data['wordlistArray'] = $wordlistArray; $data['section_id'] = $section_id; - - + $data['topiclistArray'] = $topiclistArray; + $data['default_topic_id'] = $this->GetTopic(); + return $data; } @@ -66,8 +71,7 @@ } - - + // === for export table === public function ExportTable($urlvalues, $postdata) { $this->Initialize($urlvalues); @@ -235,37 +239,56 @@ } + // === for config topic === + - // TODO: get taglist by choosen topic private function GetTaglistByTopicID($topic_id) { - $taglistArray = ""; - - $query = "SELECT * FROM topic_tag_relation WHERE topic_id=".$topic_id; + $taglistArray = array(); + // select taglist ids from topic_tag_relation table + $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id); $result = mysql_query($query); if (!$result) { - return json_encode("Failed during selecting topics table."); + return json_encode("Failed during selecting topic_tag_relation table."); } + $taglist_ids = array(); while ($row = mysql_fetch_assoc($result)) { - $tag_id = $row['tag_id']; - $query = "SELECT * FROM taglist WHERE id=".$tag_id; - $tag_result = mysql_query($query); - if ($tag_result) { + array_push($taglist_ids, $row['tag_id']); + } + + // select taglist by tag ids + foreach ($taglist_ids as $tag_id) { + $query = sprintf("SELECT * FROM `taglist` WHERE `id`='%s'", $tag_id); + $result = mysql_query($query); + if (!$result) { + echo mysql_error(); return json_encode("Failed during selecting taglist table."); } - $row = mysql_fetch_assoc($tag_result)); - $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); - // array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); + + $row = mysql_fetch_assoc($result); + array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); + } - - return $taglistArray; + } + public function SetTopic($topic) { + $this->topic = $topic; + } + public function GetTopic() { + return $this->topic; + } - + private function GetTopiclistArray() { + $topiclistArray = array(); + $result = $this->GetTopiclist(); + while ($row = mysql_fetch_assoc($result)) { + array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name'])); + } + return $topiclistArray; + } - } // =========================== // === for manage wordlist === @@ -439,11 +462,10 @@ } private function GetTaglistArray() { - $taglistArray=""; + $taglistArray = array(); $result = $this->GetTaglist(); while ($row = mysql_fetch_assoc($result)) { - $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); - + array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); } return $taglistArray; diff -r 584b1623e9ef -r 54a235d43694 develop/views/Extractapp/taggingtext.php --- a/develop/views/Extractapp/taggingtext.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/views/Extractapp/taggingtext.php Tue Feb 10 16:20:29 2015 +0100 @@ -4,9 +4,8 @@ $wordlistArray = $viewmodel['wordlistArray']; $taglistArray = $viewmodel['taglistArray']; $section_id = $viewmodel['section_id']; - - -var_dump($taglistArray); +$topiclistArray = $viewmodel['topiclistArray']; +$default_topic_id = $viewmodel['default_topic_id']; ?> @@ -226,6 +225,73 @@ } +function chooseTopic(section_id, default_topic_id) { + var t = JSON.parse( '' ); + + $('#load_topic_div').html(""); + $('#load_topic_div').css("display", "block"); + $('#load_topic_div').css("border", "1px solid black"); + $('#load_topic_div').css("background-color", "White"); + $('#load_topic_div').css("width", "200px"); + $('#load_topic_div').css("height", "50px"); + $('#load_topic_div').css("top", "20px"); + $('#load_topic_div').css("left", "-200px"); + + var topic_select = document.createElement("select"); + topic_select.id = "loadTopiclist"; + var selected_topic = t[0]; + topic_select.onchange = function(){ + + selected_topic = topic_select.options[topic_select.selectedIndex]; + console.log(selected_topic.text); + + var topic_id = selected_topic.value; + var topic_name = selected_topic.text; + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "./"+section_id); // hand to controller + form.setAttribute("target", "_self"); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "topic"); + hiddenField.setAttribute("value", topic_id); + form.appendChild(hiddenField); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + } else { + form.submit(); // works under IE and Chrome, but not FF + } + + + + }; + + + //Create and append the options + for (var i = 0; i < t.length; i++) { + console.log(t[i]['id']+","+t[i]['name']); + var option = document.createElement("option"); + option.value = t[i]['id']; + option.text = t[i]['name']; + if (option.value == default_topic_id) { + option.selected = true; + }; + topic_select.appendChild(option); + } + + $('#load_topic_div').append(topic_select); + + var newbutton = document.createElement("button"); + $(newbutton).html("Close"); + $(newbutton).attr("onclick", "$('#load_topic_div').css(\"display\", \"none\");"); + $('#load_topic_div').append(newbutton); + +} + + $(document).on("change", '#smartRegexPopUpSelectWord', function (e) {
+
+ +
Replace By Smart Regex©:

@@ -331,4 +400,5 @@ +