diff 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
line wrap: on
line diff
--- a/develop/models/extractapp.php	Tue Feb 24 17:29:56 2015 +0100
+++ b/develop/models/extractapp.php	Wed Feb 25 10:59:45 2015 +0100
@@ -633,12 +633,32 @@
         $tag_tmp_others = array();
         while ($row = mysql_fetch_assoc($result)) {
             if ($row['topic_id'] == $topic) {
-                array_push($tag_intopic, array('id=>'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']));
+                array_push($tag_intopic, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']));
             } else {
-                array_push($tag_tmp_others, array('id=>'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']));
+                array_push($tag_tmp_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']));
             }
         }
 
+        // check if there's any duplicated tags in tag_tmp_others. remove the duplicated tags
+        $num_others = count($tag_tmp_others);
+        for ($i=0; $i < $num_others; $i++) { 
+            $cnt = 0;
+            for ($j=$i+1; $j < $num_others; $j++) { 
+                if ($tag_tmp_others[$i]['tag'] == $tag_tmp_others[$j]['tag']) {
+                    break;
+                } else {
+                    $cnt++;
+                }
+            }
+            if ($cnt == ($num_others-$i-1) ) {
+                $row = $tag_tmp_others[$i];
+                array_push($tag_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) );
+            }
+        }
+
+        // remove duplicated tags in tag_others that is duplicated with tags in tag_intopic
+        $tag_tmp_others = $tag_others;
+        $tag_others = array();
         
         foreach ($tag_tmp_others as $tmp) {
             $cnt = 0;
@@ -650,6 +670,7 @@
                 }
             }
             if ($cnt == count($tag_intopic)) {
+                // not appear in $tag_intopic
                 array_push($tag_others, $tmp);
             }
         }
@@ -723,7 +744,7 @@
     
 
         /*
-ยง        $query = "SELECT * FROM topic_tag_relation";
+        $query = "SELECT * FROM topic_tag_relation";
         $result = mysql_query($query);
         if (!$result) {
             echo json_encode("error when select from topic_tag_relation");