public function saveTags($articleId, $tags)
 {
     if (!is_array($tags)) {
         $rawTags = explode(',', strtolower($tags));
         $tags = array();
         foreach ($rawTags as $tag) {
             $tag = trim($tag);
             while (false !== strpos($tag, '  ')) {
                 $tag = str_replace('  ', ' ', $tag);
             }
             if ($tag) {
                 $tags[] = $tag;
             }
         }
     }
     $existing = $this->getTags($articleId);
     $common = array_intersect($existing, $tags);
     $deleted = array_diff($existing, $common);
     $new = array_diff($tags, $common);
     $db = $this->_getWriteAdapter();
     if (!empty($deleted)) {
         foreach ($deleted as $tagName) {
             $arrayWords[] = $db->getConnection()->quote($tagName);
         }
         $db->delete($this->getTable('kbase/tag'), 'tag_article_id=' . $articleId . ' AND tag_name IN (' . implode(',', $arrayWords) . ')');
     }
     if (!empty($new)) {
         $data = array();
         foreach ($new as $tagName) {
             $data[] = array($articleId, $tagName);
         }
         AW_Kbase_Helper_Data::insertArray($this->getTable('kbase/tag'), array('tag_article_id', 'tag_name'), $data);
     }
     return $this;
 }
 public function saveStoreIds($categoryId, $storeIds)
 {
     if (!is_array($storeIds)) {
         $storeIds = explode(',', $storeIds);
     }
     $existing = $this->getStoreIds($categoryId);
     $common = array_intersect($existing, $storeIds);
     $deleted = array_diff($existing, $common);
     $new = array_diff($storeIds, $common);
     $db = $this->_getWriteAdapter();
     if (!empty($deleted)) {
         $db->delete($this->getTable('kbase/category_store'), 'category_id=' . $categoryId . ' AND store_id IN (' . implode(',', $deleted) . ')');
     }
     if (!empty($new)) {
         $data = array();
         foreach ($new as $storeId) {
             $data[] = array($categoryId, $storeId);
         }
         AW_Kbase_Helper_Data::insertArray($this->getTable('kbase/category_store'), array('category_id', 'store_id'), $data);
     }
     return $this;
 }