Mercurial > hg > extraction-interface
comparison models/extractapp.php @ 95:9a29e9d28ece extractapp
new: create new topic
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Wed, 11 Nov 2015 14:12:55 +0100 |
| parents | b0cecc104639 |
| children | c1bb174a22f3 |
comparison
equal
deleted
inserted
replaced
| 94:b0cecc104639 | 95:9a29e9d28ece |
|---|---|
| 186 $this->branch_id = $_postdata['branchId']; | 186 $this->branch_id = $_postdata['branchId']; |
| 187 } | 187 } |
| 188 if (isset($_postdata['userId'])) { | 188 if (isset($_postdata['userId'])) { |
| 189 $this->user_id = $_postdata['userId']; | 189 $this->user_id = $_postdata['userId']; |
| 190 } | 190 } |
| 191 if (isset($_postdata['topic_id'])) { | 191 if (isset($_postdata['topic'])) { |
| 192 $this->topic = $_postdata['topic_id']; | 192 $this->topic = $_postdata['topic']; |
| 193 } | 193 } |
| 194 | |
| 194 if (isset($_postdata['sectionName'])) { | 195 if (isset($_postdata['sectionName'])) { |
| 195 $this->section_name = $_postdata['sectionName']; | 196 $this->section_name = $_postdata['sectionName']; |
| 196 } | 197 } |
| 197 if (isset($_postdata['bookName'])) { | 198 if (isset($_postdata['bookName'])) { |
| 198 $this->book_name = $_postdata['bookName']; | 199 $this->book_name = $_postdata['bookName']; |
| 952 } | 953 } |
| 953 | 954 |
| 954 } | 955 } |
| 955 | 956 |
| 956 // === for config topic === | 957 // === for config topic === |
| 957 public function ConfigTagsInTopic($postdata) { | 958 public function CreateNewTopic($_postdata) { |
| 959 $new_topic_id = "2"; // default topic_id=1 for 'person' topic | |
| 960 | |
| 961 // get user input data from postdata | |
| 962 $new_topic_name_en = $_postdata['new_topic_name_en']; | |
| 963 $new_topic_name_ch = $_postdata['new_topic_name_ch']; | |
| 964 $new_topic_name_pi = $_postdata['new_topic_name_pi']; | |
| 965 $new_topic_tag = $_postdata['new_topic_tag']; | |
| 966 $new_topic_tag_name = $_postdata['new_topic_tag_name']; | |
| 967 | |
| 968 // -- Start Transaction -- | |
| 969 mysql_query("BEGIN"); | |
| 970 | |
| 971 // create records for the new topic in database | |
| 972 /* In table: | |
| 973 taglist: name, tag, color (default, user can change later in the editing page) | |
| 974 topics: tag, name_en, name_ch, name_pinyin | |
| 975 topic_tag_relation: topic_id (new), tag_id (new) | |
| 976 | |
| 977 - need transaction for the following actions: | |
| 978 taglist.name: topic_tag name in chinese | |
| 979 taglist.tag: topic_tag name in eng | |
| 980 topics.tag: (the same a taglist.tag) | |
| 981 topics.name_en: | |
| 982 topics.name_ch: | |
| 983 topics.name_pinyin: | |
| 984 | |
| 985 | |
| 986 topic_tag_relation.topic_id = new_topic_id | |
| 987 topic_tag_relation.tag_id = new_tag_id | |
| 988 which are the new record that just been created in the 'taglist' and 'topics' table | |
| 989 */ | |
| 990 | |
| 991 // new record in topics table | |
| 992 $query="INSERT INTO topics (tag, name_en, name_ch, name_pinyin) VALUES ('".$new_topic_tag."','".$new_topic_name_en."','".$new_topic_name_ch."','".$new_topic_name_pi."')"; | |
| 993 $result_topics=mysql_query($query); | |
| 994 if($result_topics){ | |
| 995 $new_topic_id = mysql_insert_id(); | |
| 996 } else { | |
| 997 //echo mysql_error(); | |
| 998 } | |
| 999 | |
| 1000 // new record in taglist table | |
| 1001 $query="INSERT INTO taglist (name, tag, color, systemName) VALUES ('".$new_topic_tag_name."','".$new_topic_tag."','rgb(255, 0, 174)','interface')"; | |
| 1002 $result_taglist=mysql_query($query); | |
| 1003 if($result_taglist){ | |
| 1004 $new_tag_id = mysql_insert_id(); | |
| 1005 } else { | |
| 1006 //echo mysql_error(); | |
| 1007 } | |
| 1008 | |
| 1009 // new record in topic_tag_relation | |
| 1010 $query="INSERT INTO topic_tag_relation (topic_id, tag_id) VALUES ('".$new_topic_id."','".$new_tag_id."')"; | |
| 1011 $result_topic_tag_relation=mysql_query($query); | |
| 1012 if($result_topic_tag_relation){ | |
| 1013 | |
| 1014 } else { | |
| 1015 //echo mysql_error(); | |
| 1016 } | |
| 1017 | |
| 1018 | |
| 1019 // --- End Transaction --- | |
| 1020 if ($result_taglist && $result_topics && $result_topic_tag_relation) { | |
| 1021 mysql_query("COMMIT"); | |
| 1022 | |
| 1023 } else { | |
| 1024 mysql_query("ROLLBACK"); | |
| 1025 return "error"; | |
| 1026 } | |
| 1027 | |
| 1028 | |
| 1029 $_postdata['topic'] = $new_topic_id; | |
| 1030 return $_postdata; | |
| 1031 } | |
| 1032 | |
| 1033 public function ConfigTagsInTopic($_postdata) { | |
| 958 /** | 1034 /** |
| 959 * | 1035 * |
| 960 */ | 1036 */ |
| 961 | 1037 |
| 962 $topic = $postdata['topic']; | 1038 $topic = $_postdata['topic']; |
| 963 $result = $this->GetTopicById($topic); | 1039 $result = $this->GetTopicById($topic); |
| 964 $row = mysql_fetch_assoc($result); | 1040 $row = mysql_fetch_assoc($result); |
| 965 $topic_name_en = $row['name_en']; | 1041 $topic_name_en = $row['name_en']; |
| 966 $topic_name_ch = $row['name_ch']; | 1042 $topic_name_ch = $row['name_ch']; |
| 967 $topic_name_pinyin = $row['name_pinyin']; | 1043 $topic_name_pinyin = $row['name_pinyin']; |
| 1044 $data['tag_others'] = $tag_others; | 1120 $data['tag_others'] = $tag_others; |
| 1045 | 1121 |
| 1046 return $data; | 1122 return $data; |
| 1047 } | 1123 } |
| 1048 | 1124 |
| 1049 public function CreateNewTopic($_postdata) { | 1125 |
| 1050 | |
| 1051 | |
| 1052 } | |
| 1053 | 1126 |
| 1054 public function UpdateTagsInTopic($_postdata) { | 1127 public function UpdateTagsInTopic($_postdata) { |
| 1055 $topic_id = $_postdata['topic_id']; | 1128 $topic_id = $_postdata['topic_id']; |
| 1056 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); | 1129 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); |
| 1057 | 1130 |
