public function testIncrement() { $name = 'iphone'; $tag = Tag::fetch($name); $count = $tag->frequency; $tag->increment(); $tag2 = Tag::fetch($name); $this->assertEquals($count + 1, $tag2->frequency); }
public function testUpdate() { $tag = 'iphone'; $pk = array('site_id' => TagSite::getSiteId('ent'), 'news_id' => util_genId(21)); $tag_id = Tag::fetch($tag)->id; $data = $pk + array('time' => util_time(10), 'type' => 0); $result = TagArticles::model()->index($tag_id, $data); //$this->assertTrue($result); $articles = TagArticles::model()->search($tag_id); $article = $articles[0]; $this->assertEquals($pk['news_id'], $article['news_id']); $this->assertEquals($pk['site_id'], $article['site_id']); $result = TagArticles::model()->removeIndex($tag_id, $data); //$this->assertTrue($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']); }
protected function onArticleRemoveTag($data) { $tag = Tag::fetch($data['tag']); if ($tag) { $tag->increment(-1); } else { return false; } unset($data['tag']); $item = new TagArticles(); $item->removeIndex($tag->id, $data); return true; }
public function _listByTag($tag, $site_id = 'all', $page = 1, $len = 20) { $news_list = array(); do { $record = Tag::fetch($tag); if (!$record) { break; } $len = intval($len); $page = intval($page) > 0 ? intval($page) : 1; $offset = ($page - 1) * $len; $rows = TagArticles::model()->search($record->id, $site_id, $len, $offset); if (empty($rows)) { break; } $pks = array(); foreach ($rows as $row) { $site = TagsSite::getSite($row['site_id']); $pks[] = array($site, $row['news_id']); } $news_list = ArticleMini::model()->findArticles($pks); } while (0); return $news_list; }