Revision #2 was created by sefburhan on Jan 28, 2014, 10:46:16 AM.
Tags manipulation using Select2 in single field
Content
[...]
```php // check if Tags extis
if (isset($_POST['Tags'])) { // Tags exits
$tagsList = explode(',', $_POST['Tags']); // get the array of tags
$currentTagsList = array(); // track to have currently selected tags used for deleted
foreach ($tagsList as $TagValue) { // added to list
$isExists = Tags::model()->find('name=:name', array(':name' => $TagValue));
if (count($isExists) > 0) {
// if exists just assign
$tag = new FeedbackTags;
$tag->feedback_id = $feedback_id;
$tag->tag_id = update currentTagList
$currentTagsList[]=$isExists->id;
$tag->save();} else {
$currentTagsList[]=$tag->tag_id; // add to array for track
} else { // if not exist add to tag table and then to tags// add new and update currentTagList
$tagNew = new Tags;
$tagNew->name = $TagValue;
if ($tagNew->save()) {
// now add to feedbacktags table$currentTagsList[]=$tagNew->id;
}
$tag2 = new FeedbackTags;
}
$tag2->feedback_id = $feedback_id;
$tag2->tag_id = $tagNew->id;
$tag2->save();
$currentTagsList[]=$tag->tag_id }
$deletedList=array_diff($previousTagsList2, $currentTagsList); // deleted list
$addedList=array_diff($currentTagsList, $previousTagsList2); // add to array for track
}
ed list
foreach ($addedList as $add) { // added new items
}
$tag }
}
$previousTagsList = Feedback::getAssignedTagsIDs($feedbackModel->id); // get all exist in feedbackTags table