/** * 根据文章ID,获取文章的Tags * @param string $site * @param string $news_id * @param array $tags * @return boolean 设置成功与否 **/ public function setNewsTags($site, $news_id, $tags) { $key = $this->genKey('NewsTags', $site, $news_id); $site_id = TagsSite::getSiteId($site); $model = ArticleTags::model()->findByPk(array($site_id, $news_id)); if ($model == null) { $model = new ArticleTags(); $model->site_id = $site_id; $model->news_id = $news_id; $result = $model->saveTags($tags); } else { $result = $model->updateTags($tags); } if ($result) { $cache = $this->CP->CData->CCache; $cache->set($key, json_encode($tags), 3600); } return $result; }
public function testTagsIndexMobile() { $tags = array('iphone', 'ipad'); $site_id = TagSite::getSiteId('news'); //'news'; $news_id = util_genId(51); $indexer = new TagArticles(); $tag_id = Tag::fetch('iphone')->id; $rows = $indexer->search($tag_id, 0, 0, 'mobile', 1); $this->assertEquals(1, count($rows)); $this->assertEquals($news_id, $rows[0]['news_id']); $article = new ArticleTags(); $article->setAttributes(array('site_id' => $site_id, 'news_id' => $news_id, 'time' => util_time(23), 'type' => 0, 'source' => 'mobile')); $result = $article->saveTags($tags); $this->assertTrue($result); $rows = $indexer->search($tag_id, 0, 0, 'web', 1); $this->assertEquals(1, count($rows)); $this->assertEquals($news_id, $rows[0]['news_id']); $rows = $indexer->search($tag_id, 0, 0, 'mobile', 1); $this->assertEquals(1, count($rows)); $this->assertEquals($news_id, $rows[0]['news_id']); }