예제 #1
0
 public function testRemove()
 {
     $tag = 'iphone';
     $data = array('site_id' => TagSite::getSiteId('ent'), 'news_id' => ArticleTags::genId(1), 'type' => 1, 'time' => util_time(7));
     $tag_id = Tag::model()->fetch($tag)->id;
     $count = TagArticles::model()->count($tag_id);
     $this->assertEquals(2, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id']);
     $this->assertEquals(1, $count);
     $count = TagArticles::model()->count($tag_id, 0, $data['type']);
     $this->assertEquals(1, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id'], $data['type']);
     $this->assertEquals(1, $count);
     $result = TagArticles::model()->removeIndex($tag_id, $data);
     //$this->assertTrue($result);
     $count = TagArticles::model()->count($tag_id);
     $this->assertEquals(1, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id']);
     $this->assertEquals(0, $count);
     $count = TagArticles::model()->count($tag_id, 0, $data['type']);
     $this->assertEquals(0, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id'], $data['type']);
     $this->assertEquals(0, $count);
     $result = TagArticles::model()->index($tag_id, $data);
     //$this->assertTrue($result);
 }
예제 #2
0
 /**
  * 根据文章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;
 }
예제 #3
0
 public function testfindArticles()
 {
     $pk_list = array(array(TagSite::getSiteId('ent'), util_genId(1)), array(TagSite::getSiteId('news'), util_genId(1)));
     $articles = ArticleMini::model()->findArticles($pk_list);
     $this->assertEquals(count($pk_list), count($articles));
     $this->assertNotNull($articles[0]);
     $this->assertNotNull($articles[1]);
     $this->assertEquals($pk_list[0][1], $articles[0]['Farticle_id']);
     $this->assertEquals($pk_list[1][1], $articles[1]['Farticle_id']);
     $site_id = TagSite::getSiteId('news');
     $id_list = array(ArticleTags::genId(3), ArticleTags::genId(1));
     $articles = ArticleMini::model()->findArticles($site_id, $id_list);
     $this->assertEquals(count($pk_list), count($articles));
     $this->assertEquals($id_list[0], $articles[0]['Farticle_id']);
     $this->assertEquals($id_list[1], $articles[1]['Farticle_id']);
 }
예제 #4
0
파일: set.php 프로젝트: reedboat/TagProject
$id = $query('id');
$tags_str = trim($query('tags'));
$errors = array(10 => '参数错误: site或Id未提供', 11 => '参数错误:未指定标签', 90 => '处理错误: 设定标签失败');
try {
    if (empty($site) || empty($id)) {
        throw new CmsInterfaceException(10);
        _log("参数错误 site:{$site};id:{$id};tags_str:{$tags_str}", 'DEBUG');
    }
    if (empty($tags_str)) {
        throw new CmsInterfaceException(11);
        _log("未指定标签, site:{$site};id:{$id}", 'DEBUG');
    }
    //过滤输入, 转义输出
    $tags_str = strip_tags($tags_str);
    $tags_str = project_convert_input($prj, $tags_str);
    $tags = ArticleTags::model()->str2arr($tags_str);
    $controller = $prj->rs->data->ext['tags'];
    $db = $prj->CData->CDb->w;
    WF_Registry::set('db', $db);
    $result = $controller->setNewsTags($site, $id, $tags);
    if (!$result) {
        throw new CmsInterfaceException(90);
        _log("标签设定失败, site:{$site}; id:{$id}; tags:{$tags_str}", 'ERROR');
    }
    $prj->fw->interface->out(0, 'success', '', true);
} catch (CmsInterfaceException $e) {
    project_output_error($prj, $e, $errors);
} catch (Exception $e) {
    $this->fw->interface->out($e->getCode(), $e->getMessage(), '', '');
}
function _log($msg, $level = 'ERROR')
예제 #5
0
 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']);
 }
예제 #6
0
 public function testListArticles()
 {
     $tagsController = $this->tagsController;
     $tag = 'iphone';
     $articles = $tagsController->listArticles($tag, 0);
     $this->assertEquals(2, count($articles));
     $this->assertTrue(!!$articles[0]);
     $this->assertTrue(!!$articles[1]);
     $site = 'news';
     $news_id = ArticleTags::genId(1);
     $tags = array('iphone', 'apple');
     $result = $tagsController->setNewsTags($site, $news_id, $tags);
     $this->assertTrue($result);
     $articles = $tagsController->listArticles($tag, 0);
     $this->assertEquals(2, count($articles));
     $this->assertTrue(!!$articles[0]);
     $this->assertTrue(!!$articles[1]);
 }