comparison 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
comparison
equal deleted inserted replaced
9:584b1623e9ef 10:54a235d43694
22 22
23 $section_id = $this->GetSectionId(); 23 $section_id = $this->GetSectionId();
24 24
25 $stringInput = $this->GetSectionContent(); 25 $stringInput = $this->GetSectionContent();
26 26
27 $taglistArray = $this->GetTaglistArray(); 27 //$taglistArray = $this->GetTaglistArray();
28 // test for GetTaglistByTopicID: 28 //for GetTaglistByTopicID:
29 // $taglistArray = $this->GetTaglistByTopicID(1); 29
30 $taglistArray = $this->GetTaglistByTopicID($this->GetTopic());
31
32 // topic list?
33 $topiclistArray = $this->GetTopiclistArray();
30 34
31 35
32 $wordlistArray = $this->GetWordlistArray(); 36 $wordlistArray = $this->GetWordlistArray();
33 37
34 $data = array(); 38 $data = array();
35 $data['stringInput'] = $stringInput; 39 $data['stringInput'] = $stringInput;
36 $data['taglistArray'] = $taglistArray; 40 $data['taglistArray'] = $taglistArray;
37 $data['wordlistArray'] = $wordlistArray; 41 $data['wordlistArray'] = $wordlistArray;
38 $data['section_id'] = $section_id; 42 $data['section_id'] = $section_id;
39 43 $data['topiclistArray'] = $topiclistArray;
40 44 $data['default_topic_id'] = $this->GetTopic();
45
41 return $data; 46 return $data;
42 47
43 } 48 }
44 49
45 public function SaveFullText($postdata) { 50 public function SaveFullText($postdata) {
64 file_put_contents("data/parsing_files/".$postdata['filename'].".txt", $require); 69 file_put_contents("data/parsing_files/".$postdata['filename'].".txt", $require);
65 } 70 }
66 71
67 } 72 }
68 73
69 74
70
71 // === for export table === 75 // === for export table ===
72 public function ExportTable($urlvalues, $postdata) { 76 public function ExportTable($urlvalues, $postdata) {
73 $this->Initialize($urlvalues); 77 $this->Initialize($urlvalues);
74 $content = $postdata['content']; 78 $content = $postdata['content'];
75 79
233 $resultInsert = mysql_query($queryInsert); 237 $resultInsert = mysql_query($queryInsert);
234 } 238 }
235 239
236 } 240 }
237 241
238 242 // === for config topic ===
239 // TODO: get taglist by choosen topic 243
244
240 private function GetTaglistByTopicID($topic_id) { 245 private function GetTaglistByTopicID($topic_id) {
241 $taglistArray = ""; 246 $taglistArray = array();
242 247 // select taglist ids from topic_tag_relation table
243 $query = "SELECT * FROM topic_tag_relation WHERE topic_id=".$topic_id; 248 $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id);
244 $result = mysql_query($query); 249 $result = mysql_query($query);
245 if (!$result) { 250 if (!$result) {
246 return json_encode("Failed during selecting topics table."); 251 return json_encode("Failed during selecting topic_tag_relation table.");
247 } 252 }
248 253 $taglist_ids = array();
249 while ($row = mysql_fetch_assoc($result)) { 254
250 $tag_id = $row['tag_id']; 255 while ($row = mysql_fetch_assoc($result)) {
251 $query = "SELECT * FROM taglist WHERE id=".$tag_id; 256 array_push($taglist_ids, $row['tag_id']);
252 $tag_result = mysql_query($query); 257 }
253 if ($tag_result) { 258
259 // select taglist by tag ids
260 foreach ($taglist_ids as $tag_id) {
261 $query = sprintf("SELECT * FROM `taglist` WHERE `id`='%s'", $tag_id);
262 $result = mysql_query($query);
263 if (!$result) {
264 echo mysql_error();
254 return json_encode("Failed during selecting taglist table."); 265 return json_encode("Failed during selecting taglist table.");
255 } 266 }
256 $row = mysql_fetch_assoc($tag_result)); 267
257 $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); 268 $row = mysql_fetch_assoc($result);
258 // array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); 269 array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] ));
259 } 270
260 271 }
261
262 return $taglistArray; 272 return $taglistArray;
263 273 }
264 274
265 275 public function SetTopic($topic) {
266 276 $this->topic = $topic;
267 277 }
268 } 278
279 public function GetTopic() {
280 return $this->topic;
281 }
282
283 private function GetTopiclistArray() {
284 $topiclistArray = array();
285 $result = $this->GetTopiclist();
286 while ($row = mysql_fetch_assoc($result)) {
287 array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name']));
288 }
289 return $topiclistArray;
290 }
291
269 // =========================== 292 // ===========================
270 293
271 // === for manage wordlist === 294 // === for manage wordlist ===
272 public function EditWordlist($urlvalues) { 295 public function EditWordlist($urlvalues) {
273 $this->Initialize($urlvalues); 296 $this->Initialize($urlvalues);
437 private function GetDataPath() { 460 private function GetDataPath() {
438 return getcwd()."/data/"; // get the current file path, which is getcwd(), and concatenate with "/data/" 461 return getcwd()."/data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
439 } 462 }
440 463
441 private function GetTaglistArray() { 464 private function GetTaglistArray() {
442 $taglistArray=""; 465 $taglistArray = array();
443 $result = $this->GetTaglist(); 466 $result = $this->GetTaglist();
444 while ($row = mysql_fetch_assoc($result)) { 467 while ($row = mysql_fetch_assoc($result)) {
445 $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); 468 array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] ));
446
447 } 469 }
448 470
449 return $taglistArray; 471 return $taglistArray;
450 472
451 } 473 }