Commits

Arkadiusz Dzięgiel committed 965f483

Setting tags from string, better version

  • Participants
  • Parent commits 1e41484

Comments (0)

Files changed (1)

Lib/Behavior/TaggableBehavior.php

     	$s = <<<EOF
 
     	if(is_string(\$tags)){
-    		\$this->removeAllTags(\$con);
-    		\$this->clearTags();
-    		\$this->addTags(\$tags, \$con);
-    		return;
+    		\$tagNames = explode(',',\$tags);
+    		
+    		\$tags = TagQuery::create()
+    		->filterByName(\$tagNames)
+    		->find();
+    		
+    		\$existingTags = array();
+    		foreach(\$tags as \$t) \$existingTags[] = \$t->getName();
+    		foreach(array_diff(\$tagNames, \$existingTags) as \$t){
+    			\$tag=new Tag();
+    			\$tag->setName(\$t);
+				\$tags->append(\$tag);
+    		}
     	}
 
 EOF;