Mercurial > hg > extraction-interface
comparison develop/models/extractapp.php @ 23:a879f6b9d166
modification for select-move-taglist: tags don't appear to be duplicated in other topics.
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Wed, 25 Feb 2015 10:59:45 +0100 |
| parents | a8ae5cbc3364 |
| children | b55f5d3564c4 |
comparison
equal
deleted
inserted
replaced
| 22:a8ae5cbc3364 | 23:a879f6b9d166 |
|---|---|
| 631 $tag_intopic = array(); | 631 $tag_intopic = array(); |
| 632 $tag_others = array(); | 632 $tag_others = array(); |
| 633 $tag_tmp_others = array(); | 633 $tag_tmp_others = array(); |
| 634 while ($row = mysql_fetch_assoc($result)) { | 634 while ($row = mysql_fetch_assoc($result)) { |
| 635 if ($row['topic_id'] == $topic) { | 635 if ($row['topic_id'] == $topic) { |
| 636 array_push($tag_intopic, array('id=>'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); | 636 array_push($tag_intopic, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); |
| 637 } else { | 637 } else { |
| 638 array_push($tag_tmp_others, array('id=>'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); | 638 array_push($tag_tmp_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); |
| 639 } | 639 } |
| 640 } | 640 } |
| 641 | 641 |
| 642 // check if there's any duplicated tags in tag_tmp_others. remove the duplicated tags | |
| 643 $num_others = count($tag_tmp_others); | |
| 644 for ($i=0; $i < $num_others; $i++) { | |
| 645 $cnt = 0; | |
| 646 for ($j=$i+1; $j < $num_others; $j++) { | |
| 647 if ($tag_tmp_others[$i]['tag'] == $tag_tmp_others[$j]['tag']) { | |
| 648 break; | |
| 649 } else { | |
| 650 $cnt++; | |
| 651 } | |
| 652 } | |
| 653 if ($cnt == ($num_others-$i-1) ) { | |
| 654 $row = $tag_tmp_others[$i]; | |
| 655 array_push($tag_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); | |
| 656 } | |
| 657 } | |
| 658 | |
| 659 // remove duplicated tags in tag_others that is duplicated with tags in tag_intopic | |
| 660 $tag_tmp_others = $tag_others; | |
| 661 $tag_others = array(); | |
| 642 | 662 |
| 643 foreach ($tag_tmp_others as $tmp) { | 663 foreach ($tag_tmp_others as $tmp) { |
| 644 $cnt = 0; | 664 $cnt = 0; |
| 645 foreach ($tag_intopic as $intopic) { | 665 foreach ($tag_intopic as $intopic) { |
| 646 if ($tmp['tag'] == $intopic['tag']) { | 666 if ($tmp['tag'] == $intopic['tag']) { |
| 648 } else { | 668 } else { |
| 649 $cnt ++; | 669 $cnt ++; |
| 650 } | 670 } |
| 651 } | 671 } |
| 652 if ($cnt == count($tag_intopic)) { | 672 if ($cnt == count($tag_intopic)) { |
| 673 // not appear in $tag_intopic | |
| 653 array_push($tag_others, $tmp); | 674 array_push($tag_others, $tmp); |
| 654 } | 675 } |
| 655 } | 676 } |
| 656 | 677 |
| 657 | 678 |
| 721 } | 742 } |
| 722 | 743 |
| 723 | 744 |
| 724 | 745 |
| 725 /* | 746 /* |
| 726 ยง $query = "SELECT * FROM topic_tag_relation"; | 747 $query = "SELECT * FROM topic_tag_relation"; |
| 727 $result = mysql_query($query); | 748 $result = mysql_query($query); |
| 728 if (!$result) { | 749 if (!$result) { |
| 729 echo json_encode("error when select from topic_tag_relation"); | 750 echo json_encode("error when select from topic_tag_relation"); |
| 730 } | 751 } |
| 731 $topic_tag = array(); | 752 $topic_tag = array(); |
