comparison develop/models/extractapp.php @ 19:f60969462226

save tag modification of topic configration into topic_tag_relation table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 23 Feb 2015 12:46:03 +0100
parents 82f8c6bd2b69
children 04db1dd9d10d
comparison
equal deleted inserted replaced
18:115dda3d1728 19:f60969462226
530 $result1 = mysql_query($query1); 530 $result1 = mysql_query($query1);
531 531
532 532
533 // add it to topic_tag_relation table 533 // add it to topic_tag_relation table
534 $topic_id = $postdata['topic_id']; 534 $topic_id = $postdata['topic_id'];
535 535
536 // tag_id is $id; 536 // tag_id is $id;
537 $query = sprintf("INSERT INTO `topic_tag_relation` (`topic_id`,`tag_id`) VALUES (%s,%s)", $topic_id, $id); 537 $query = sprintf("INSERT INTO `topic_tag_relation` (`topic_id`,`tag_id`) VALUES (%s,%s)", $topic_id, $id);
538 $result = mysql_query($query); 538 $result = mysql_query($query);
539 if (!$result) { 539 if (!$result) {
540 echo json_encode("error when insert into topic_tag_relation table"); 540 echo json_encode("error when insert into topic_tag_relation table");
545 545
546 public function SaveTagElement($postdata) { 546 public function SaveTagElement($postdata) {
547 if ($postdata['id']){ 547 if ($postdata['id']){
548 list($id, $name, $tag, $color) = $this->_GetTag($postdata); 548 list($id, $name, $tag, $color) = $this->_GetTag($postdata);
549 549
550 $queryInsert = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s", 550 $query = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s",
551 $this->GetSQLValueString($name, "text"), 551 $this->GetSQLValueString($name, "text"),
552 $this->GetSQLValueString($tag, "text"), 552 $this->GetSQLValueString($tag, "text"),
553 $this->GetSQLValueString($color, "text"), 553 $this->GetSQLValueString($color, "text"),
554 $this->GetSQLValueString($id, "int")); 554 $this->GetSQLValueString($id, "int"));
555 $resultInsert = mysql_query($queryInsert); 555 $result = mysql_query($query);
556 556
557 } 557 }
558 558
559 } 559 }
560 560
561 public function DeleteTag($postdata) { 561 public function DeleteTag($postdata) {
589 $data['topic'] = $topic; 589 $data['topic'] = $topic;
590 $data['topic_name'] = $topic_name; 590 $data['topic_name'] = $topic_name;
591 591
592 return $data; 592 return $data;
593 } 593 }
594 public function UpdateTagsInTopic($_postdata) {
595 $topic_id = $_postdata['topic_id'];
596 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids']));
597
598 // update topic_tag_relation by tags_ids array as `tag_id` and topic_id as `topic_id`
599 $query = "SELECT * FROM topic_tag_relation";
600 $result = mysql_query($query);
601 if (!$result) {
602 echo json_encode("error when select from topic_tag_relation");
603 }
604 $topic_tag = array();
605 while ($row = mysql_fetch_assoc($result)) {
606 array_push($topic_tag, array('tag_id'=>$row['tag_id'], 'topic_id'=>$row['topic_id']));
607 }
608
609 foreach ($topic_tag as $value) {
610 $flag = false;
611 foreach ($tag_ids as $tag_id) {
612 if ($value['tag_id'] == $tag_id) {
613 //update its topic_id to $topic_id
614 $queryUpdate = "UPDATE topic_tag_relation SET topic_id=".$topic_id." WHERE tag_id=".$tag_id;
615 $resultUpdate = mysql_query($queryUpdate);
616 if (!$resultUpdate) {
617 return json_encode("error when update topic_tag_relation table");
618 }
619 $flag = true;
620 break;
621 }
622 }
623 if (!$flag && $value['topic_id'] == $topic_id) {
624 // set its topic_id to 0, indicating unsigned
625 $queryUpdate = "UPDATE topic_tag_relation SET topic_id=0 WHERE tag_id=".$value['tag_id'];
626 $resultUpdate = mysql_query($queryUpdate);
627 if (!$resultUpdate) {
628 return json_encode("error when update topic_tag_relation table");
629 }
630 }
631 }
632
633 }
634
594 635
595 private function GetTaglistByTopicID($topic_id) { 636 private function GetTaglistByTopicID($topic_id) {
596 $taglistArray = array(); 637 $taglistArray = array();
597 // select taglist ids from topic_tag_relation table 638 // select taglist ids from topic_tag_relation table
598 $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id); 639 $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id);
652 $row = mysql_fetch_assoc($result); 693 $row = mysql_fetch_assoc($result);
653 $name = $row['name']; 694 $name = $row['name'];
654 return $name; 695 return $name;
655 696
656 } 697 }
698
657 699
658 // =========================== 700 // ===========================
659 701
660 // === for manage wordlist === 702 // === for manage wordlist ===
661 public function EditWordlist() { 703 public function EditWordlist() {