comparison models/extractapp.php @ 67:3ada9334ebfc extractapp

New: check taglist is deprecated or not
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 07 Apr 2015 14:45:31 +0200
parents e71a437ae49f
children edb8a2e8ce84
comparison
equal deleted inserted replaced
66:e71a437ae49f 67:3ada9334ebfc
46 46
47 $this->lg_text = $lg_text; 47 $this->lg_text = $lg_text;
48 48
49 } 49 }
50 50
51 public function GetBookMetaData($_postdata) { 51
52 // TODO: get book_meta from $_postdata, depended on LGService 52
53 53
54 public function GetBookMetaDataBySectionId() {
55
56 // TODO: get book_meta from $$this->get_section_metadata_by_sectionId_url ...
57 $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id;
58 $section_meta = file_get_contents($section_meta_url);
59
54 60
55 // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty) 61 // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty)
56 $book_meta = array(); 62 $book_meta = array();
57 array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data","no_data")); // missing author,year,pagenumber 63 array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data","no_data")); // missing author,year,pagenumber
58 64
138 } 144 }
139 145
140 146
141 } 147 }
142 148
143 // TODO: comparison not correct 149
144 private function Taglist_infileUpToDate($taglistArray) { 150
145 // compare $this->taglist_infile is the same as $taglistArray 151 private function TaglistSubsetIn($list1, $list2) { // $l1 is a subset of $l2 or not
146 $taglist_infile = $this->taglist_infile; 152 // l1 and l2: array( $row['id'], $row['name'], $row['tag'], $row['color'] )
147 if (count($taglist_infile) != count($taglistArray)) { 153 $cnt_list1 = count($list1);
154 $cnt_list2 = count($list2);
155
156 if ($cnt_list1 > $cnt_list2) {
148 return false; 157 return false;
149 } 158 }
150 159 foreach ($list1 as $v1) {
151 foreach ($taglistArray as $row_indb) {
152 $cnt = 0; 160 $cnt = 0;
153 foreach ($taglist_infile as $row) { 161 foreach ($list2 as $v2) {
154 //$taglistArray: array( $row['id'], $row['name'], $row['tag'], $row['color'] ) 162 $num_field = count($v2);
155 if ($row[0] == $row_indb[0] && $row[1] == $row_indb[1] && $row[2] == $row_indb[2] && $row[3] == $row_indb[3]) { 163 $matched = true;
156 164 for ($i=0; $i < $num_field; $i++) {
165 if ($v1[$i] != $v2[$i]) {
166 $matched = false;
167 break;
168 }
169 }
170
171 if (!$matched) {
172 // not match with this v2
173 $cnt += 1;
157 } else { 174 } else {
158 $cnt ++; 175 break;
159 } 176 }
160 } 177
161 if ($cnt == count($row)) { 178 }
162 return false; 179 if ($cnt == $cnt_list2) {
180 return false;
163 } 181 }
164 } 182 }
165 return true; 183 return true;
166 } 184
185 }
186
167 // === for tagging === 187 // === for tagging ===
168 public function StartTagging() { 188 public function StartTagging() {
169 189
170 $section_id = $this->section_id; 190 $section_id = $this->section_id;
171 $stringInput = $this->lg_text; 191 $stringInput = $this->lg_text;
174 194
175 //$taglistArray = $this->GetTaglistArray(); 195 //$taglistArray = $this->GetTaglistArray();
176 //for GetTaglistByTopicID: 196 //for GetTaglistByTopicID:
177 $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); 197 $taglistArray = $this->GetTaglistByTopicID($this->GetTopic());
178 198
179 $data['taglist_infile'] = $this->taglist_infile; 199 // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided
180 // TODO: check if taglist_infile is up-to-date 200 // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file.
181 /* 201 if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not
182 if ( !$this->Taglist_infileUpToDate($taglistArray)) { 202 $this->taglist_infile = "";
183 $data['taglist_infile'] = $this->taglist_infile; 203 }
184 } else { 204 $data['taglist_infile'] = $this->taglist_infile; // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file
185 $data['taglist_infile'] = ""; 205
186 }
187 */
188 206
189 // book_meta 207 // book_meta
190 $data['book_meta'] = $this->book_meta; 208 $data['book_meta'] = $this->book_meta;
191 209
192 // topic list 210 // topic list
207 225
208 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 226 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id,
209 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, 227 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id,
210 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, 228 'book_name'=>$this->book_name, 'section_name'=>$this->section_name,
211 'current_fileId'=>$this->current_fileId); 229 'current_fileId'=>$this->current_fileId);
212 //'current_fileId'=>$this->file_id);
213 //'current_fileId'=>'123');
214 230
215 $this->messages['debug'] .= "[Debug] "; 231 $this->messages['debug'] .= "[Debug] ";
216 $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id; 232 $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id;
217 $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; 233 $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic;
218 $this->messages['debug'] .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; 234 $this->messages['debug'] .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name;
668 684
669 return $data; 685 return $data;
670 686
671 } 687 }
672 688
673 private function _GetTag($_postdata) { 689 private function GetTag($_postdata) {
674 if (get_magic_quotes_gpc()) { 690 if (get_magic_quotes_gpc()) {
675 $id = stripslashes($_postdata['id']); 691 $id = stripslashes($_postdata['id']);
676 $name = stripslashes($_postdata['name']); 692 $name = stripslashes($_postdata['name']);
677 $tag = stripslashes($_postdata['tag']); 693 $tag = stripslashes($_postdata['tag']);
678 $color = stripslashes($_postdata['color']); 694 $color = stripslashes($_postdata['color']);
685 return array($id, $name, $tag, $color); 701 return array($id, $name, $tag, $color);
686 } 702 }
687 703
688 public function NewTagElement($postdata) { 704 public function NewTagElement($postdata) {
689 if ($postdata['id']){ 705 if ($postdata['id']){
690 list($id, $name, $tag, $color) = $this->_GetTag($postdata); 706 list($id, $name, $tag, $color) = $this->GetTag($postdata);
691 707
692 $query1 = sprintf("INSERT INTO `taglist` (`id`, `name`, `tag`, `color`, `systemName`) VALUES (%s, %s, %s, %s, %s)", 708 $query1 = sprintf("INSERT INTO `taglist` (`id`, `name`, `tag`, `color`, `systemName`) VALUES (%s, %s, %s, %s, %s)",
693 $this->GetSQLValueString($id, "int"), 709 $this->GetSQLValueString($id, "int"),
694 $this->GetSQLValueString($name, "text"), 710 $this->GetSQLValueString($name, "text"),
695 $this->GetSQLValueString($tag, "text"), 711 $this->GetSQLValueString($tag, "text"),
711 727
712 } 728 }
713 729
714 public function SaveTagElement($postdata) { 730 public function SaveTagElement($postdata) {
715 if ($postdata['id']){ 731 if ($postdata['id']){
716 list($id, $name, $tag, $color) = $this->_GetTag($postdata); 732 list($id, $name, $tag, $color) = $this->GetTag($postdata);
717 733
718 $query = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s", 734 $query = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s",
719 $this->GetSQLValueString($name, "text"), 735 $this->GetSQLValueString($name, "text"),
720 $this->GetSQLValueString($tag, "text"), 736 $this->GetSQLValueString($tag, "text"),
721 $this->GetSQLValueString($color, "text"), 737 $this->GetSQLValueString($color, "text"),