News.class.php 6.37 KB
<?php
/**
 * 资讯业务处理
 *
 */
class Facade_News
{
    /**
     * 服务
     */
    private static $service = null;
    
    /**
     * 资讯分类
     *
     * @var unknown_type
     */
    public static $types = array
    (
        1 => '品牌资讯',
        2 => '现场活动',
        3 => '独家合作',
    	4 => '主理人',
    	5 => '明星',
    	6 =>'限量产品',
    	7 => '票务',
    	8 =>'视频',
    	9 =>'专题'
    );

    /**
     *
     * @return Service_News
     */
    private static function service ()
    {
        if (! isset(self::$service))
        {
            self::$service = new Service_News();
        }
        return self::$service;
    }
    
    /**
     * 更新信息
     *
     * @param unknown_type $data
     * @param unknown_type $id
     */
    public static function setInfo($data, $id = 0 )
    {
        if ($id == 0)
        {
            $data['create_time'] = time() ;
        }else
        {
            $data['id'] = $id ;
        }
       
        $ret = self::service()->setInfo($data) ;
        //更新TAG
        self::resetTags();
        return $ret ;
    }
    
    /**
     * 获取总数
     *
     * @param array $conditions
     * @param array $exceptTags
     * @return int
     */
    public static function getTotal($conditions = array(), $exceptTags = array())
    {
        return self::service()->getTotal($conditions, $exceptTags);
    }
    
	/**
     * 删除信息
     *
     * @param unknown_type $id
     */
    public static function delInfo($id = 0 )
    {
        $ret = self::service()->delInfo($id);
        //更新TAG
        self::resetTags();
        return $ret ;
    }
    
    
	/**
     * 获取信息
     *
     * @param string $tag
     * @param int $offset
     * @param int $limit
     * @param array $exceptTags
     * @return array
     */
    public static function getList($tag, $offset, $limit, $exceptTags = array())
    {
        return self::service()->getList($tag, $offset, $limit, $exceptTags);
    }
    
    /**
     * 获取一条记录
     *
     */
    public static function getOneById($id)
    {
        return self::service()->getOneById($id);
    }
    
    /**
     * 更新浏览量+1
     *
     * @param unknown_type $id
     * @return unknown
     */
    public static function updateHits($id)
    {
        return self::service()->updateHits($id);
    }
    
    /**
     * 重置Tag
     *
     */
    public static function resetTags()
    {
        //获取所有信息
        $news = self::getList(array(),0, 100000);
        $tags = array() ;
        foreach ($news as $val)
        {
            if ($val['tag'] == '')
            {
                continue ;
            }
            $temp_tag = explode(',',$val['tag']);//获取
            $temp_tag = array_filter($temp_tag); //去空
            $temp_tag = array_unique($temp_tag) ;//去重
            foreach ($temp_tag as $t)
            {
                $t = trim($t);
                if (isset($tags[$t]))
                {
                    $tags[$t] = $tags[$t] + 1 ;
                }else
                {
                    $tags[$t] = 1 ;
                }
            }
        }
        //删除所有标签,重新存储
        self::service()->delAllTags();
        //存储
        foreach ($tags as $tag => $num)
        {
            //@FIXED 重新查询数据库获取数量
            $num = self::getTotal( $tag );
            self::service()->createTag(trim($tag), $num);
        }
        return $tags ;
    }
    
    /**
     * 获取标签
     *
     */
    public static function getTags()
    {
        return self::service()->getTags();
    }
    
    /**
     * 获取 下一个资讯
     *
     * @param unknown_type $id
     */
    public static function getNextNews($id)
    {
        return self::service()->getNextNews($id);
    }
    
    /**
     * 获取 上一个资讯
     *
     * @param unknown_type $id
     */
    public static function getPrevNews($id)
    {
        return self::service()->getPrevNews($id);
    }
    
    /**
     * 获取所有资讯
     *
     * @param int $offset
     * @param int $limit
     * @return array
     */
    public static function getAllNews($offset, $limit)
    {
    	return self::service()->getAllNews($offset, $limit);
    }
    
    /**
     * 时间之前获取视频
     * 
     * @param string $tag
     * @param string $datetime
     * @param int $offset
     * @param int $limit
     * @return array
     */
    public static function getListBeforeTime($tag, $datetime, $offset, $limit)
    {
    	return self::service()->getListBeforeTime($tag, $datetime, $offset, $limit);
    }
    
    /**
     * 时间之前获取总数
     * 
     * @param string $tag
     * @param string $datetime
     * @return int
     */
    public static function getTotalBeforeTime($tag, $datetime)
    {
        return self::service()->getTotalBeforeTime($tag, $datetime);
    }
    
    /**
     * 根据点击率获取列表
     * 
     * @param string $tag
     * @param int $offset
     * @param int $limit
     * @param array $exceptTags
     * @return array
     */
    public static function getListByHits($tag, $offset, $limit, $exceptTags = array())
    {
    	return self::service()->getListByHits($tag, $offset, $limit, $exceptTags);
    }
    
	/**
     * 获取信息
     *
     * @param string $tag
     * @param int $offset
     * @param int $limit
     * @param array $exceptTags
     * @return array
     */
    public static function getLatestNews($tag, $offset, $limit, $exceptTags = array())
    {
        return self::service()->getLatestNews($tag, $offset, $limit, $exceptTags);
    }
    
    /**
     * 根据id获取相同的新闻
     *
     * @param int $id
     * @param array $exceptTags
     * @return int
     */
    public static function getSameNewsById($id, $exceptTags = array())
    {
        $ids = Facade_Brand::getSameNewsByNewsID($id);
        $news = array();
        if(!empty($ids))
        {
            $news = self::service()->getNewsByIds($ids, $exceptTags);
        }
        return $news;
    }
    
    /**
     * 根据日期点击率获取列表
     *
     * @param string $tag
     * @param int $offset
     * @param int $limit
     * @param array $exceptTags
     * @return array
     */
    public static function getListByDateHits($tag, $offset, $limit, $exceptTags)
    {
        return self::service()->getListByDateHits($tag, $offset, $limit, $exceptTags);
    }
}