Mercurial > hg > extraction-interface
diff develop/models/extractapp.php @ 10:54a235d43694
add topic choosing in the TaggingText page
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 10 Feb 2015 16:20:29 +0100 |
parents | 584b1623e9ef |
children | 3d6fba07bfbd |
line wrap: on
line diff
--- a/develop/models/extractapp.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/models/extractapp.php Tue Feb 10 16:20:29 2015 +0100 @@ -24,9 +24,13 @@ $stringInput = $this->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;