<?php
require_once 'Config.php';
/**
 * 新闻列表类
 *
 * @author Wzb
 *        
 */
class USL_NewsList extends USL_Base {
	/**
	 * 标签
	 *
	 * @var string
	 */
	private $_tag;
	
	/**
	 * 根类别ID
	 *
	 * @var int
	 */
	private $_rootSortId;
	
	/**
	 * 当前类别对象
	 *
	 * @var object
	 */
	private $_currentSortObj;
	
	/**
	 * 翻页对象
	 *
	 * @var object
	 */
	private $_pdObj;
	
	/**
	 * 翻页所需要的字段
	 *
	 * @var string
	 */
	private $_needCode;
	
	/**
	 * 排版样式
	 *
	 * @var string
	 */
	private $_stype;
	
	/**
	 * 每页显示的数量
	 *
	 * @var int
	 */
	private $_pageSize;
	
	/**
	 * 构造类
	 *
	 * @param string $tag 标签
	 * @param int $theId ID
	 */
	public function __construct($tag, $theId) {
		parent::__construct ();
		$this->init ( $tag );
		$this->setNewsList ( $theId );
		$this->setNewsPd ();
		$this->setWeiZhi ();
	}
	
	/**
	 * 初始化
	 *
	 * @param string $tag 标签
	 *       
	 */
	private function init($tag) {
		$this->_weizhi = $this->_tag = $tag;
		switch ($tag) {
			
			case "production" : // 产品与服务
				$this->_rootSortId = 1;
				$this->_stype = "PicList"; // 如果为非文字列表在这里设置排版样式
				break;
			
			default :
				die ( COM_OftenJavaScript::showInfo ( "标签错误" ) );
				break;
		}
		
		switch ($this->_stype) {
			case "PicList" : // 图片列表
				$this->_needCode = 'id,title,picture';
				$this->_pageSize = 6;
				break;
			default :
				$this->_stype = "TitleList"; // 默认为文字列表
				$this->_needCode = 'id,title,addTime';
				$this->_pageSize = 18;
				break;
		}
	}
	
	/**
	 * 设置变量值
	 */
	public function _assignContent() {
		parent::_showComm ();
		$this->_tpl->assign ( "webName", $this->_webStr ); // 网站标题
		$this->_tpl->assign ( "theKeyWords", $this->_keywords ); // 网站关键字
		$this->_tpl->assign ( "thisName", $this->_thisName ); // 栏目名称
		$this->_tpl->assign ( "leftNav", $this->_leftNav ); // 左侧导航
		$this->_tpl->assign ( "address", $this->_address ); // 当前位置
		$this->_tpl->assign ( "style", $this->_stype ); // 排版样式
		$this->_tpl->assign ( "dataList1", $this->listData($this->_pdObj->_getDataList ())); // 数据列表
		$this->_tpl->assign ( "pageInfo", $this->_pdObj->_getPageInfo () ); // 设置翻页信息
// 		print_r($this->_pdObj->_getPageInfo ());die;
	}
	
	//分开显示数据
/*
	 * 取4个一组数据，用于滚动一组图片
	 * */
	public function listData($dataList){		
		$b=0;
		$arr=array();
		$length=count($dataList);
		for($i=0;$i<$length;$i++){
			$arr[$b][]=$dataList[$i];				
			if(($i+1)%3==0){
				$b++;
			}
				
		}
		return $arr;
	}
	/**
	 * 设置位置信息
	 */
	private function setWeiZhi() {
		$rootObj = BLL_NewsSort::getOne ( $this->_rootSortId, "id,sortName" );
		switch ($this->weizhiRoot ()) {
			// 在这里进行 “ 当前位置 、左侧导航 ” 的非常规设置!!!!!
			default :
				$this->_leftNav = USL_LeftNav::_NewsSortList ( $this->_rootSortId, $rootObj ['sortName'], $this->_tag, $this->_currentSortObj ['id'] );
				break;
		}
		
		// 这里是根据左侧导航推理出当前位置，一般不需要修改
		if ($rootObj ['id'] != $this->_currentSortObj ['id']) {
			$this->_address [] = array ("title" => $rootObj ['sortName'],"url" => "News_List.php?tag=" . $this->_tag );
			$this->getAddress ( $this->_leftNav ['list'], $this->_address );
		}
		$this->_address [] = array ("title" => $this->_currentSortObj ['sortName'],"url" => "" );
	}
	
	/**
	 * 设置新闻翻页
	 */
	private function setNewsPd() {
		$this->_pdObj = new COM_PagingDevice ( $this->_pageSize );
		$this->_pdObj->_setDataList ( BLL_News::getList ( $this->_currentSortObj ['id'], true, $this->_needCode, $this->_pdObj->_getLimitArr () ) );
		$this->_pdObj->_setSuffixal ( 'tag=' . $this->_tag . '&theId=' . $this->_currentSortObj ['id'] );
	}
	
	/**
	 * 设置系列新闻列表常规信息
	 *
	 * @param int $theId 当前栏目ID
	 */
	private function setNewsList($theId) {
		$this->_currentSortObj = BLL_NewsSort::getOne ( intval ( $theId > 0 ? $theId : $this->_rootSortId ), 'id,pid,sortName' );
		if (count ( $this->_currentSortObj ) == 0) {
			die ( COM_OftenJavaScript::showInfo ( "该类别不存在" ) );
		}
		$this->_weizhi .= '_' . $this->_currentSortObj ['id'];
		$this->_thisName = $this->_currentSortObj ['sortName'];
		$this->_webStr = COM_OftenFunction::setWebName ( $this->_currentSortObj ['sortName'] . '-' );
		$this->_keywords = $this->_currentSortObj ['sortName'];
	}
}

// 实例化
$configObj = BLL_WebSet::getOne ();
$thisPage = new USL_NewsList ( $_GET ['tag'], array_key_exists ( 'theId', $_GET ) ? intval ( $_GET ['theId'] ) : 0 );
$thisPage->_assignContent ();
$thisPage->_tpl->display ( "Tpl/News_List.tpl" );
?>