Show.class.php 2.28 KB
<?php
class Controller_Show extends Controller_Abstract
{
	public function indexAction()
	{
		$total = 0;
		$limit = 24;
		$offset = 0;
		$page = new Lib_Helper_Pagination($total, $limit);
		list($offset, $limit) = $page->getLimit();
		$this->_view['fragments'] = $this->getShowTopicFragment($offset, $limit, $total);
		$page->setRecordCount($total);
		$this->_view['pagination'] = $page->getPagination();
	}
	
	/**
	 * 客户端html5
	 * 
	 */
	public function clientAction()
	{
		$banner = '';
		$total = 0;
		$platforms = array('android' => array('scheme' =>'yohoshow://', 'download' => 'http://demo.yoho.cn/uploads/Android/show/1.4.0/release/YohoShow_1.4.0_70_9454_YOHO.apk'), 'ios'=> array('scheme' =>'yohoshow://', 'download' => 'https://itunes.apple.com/cn/app/yoho!-you-huo/id794364666?mt=8'));
		$yohoshowState = $this->_request->query('yohoshowState', 0);
		$platform = Lib_Utils::agentToPlatform($_SERVER['HTTP_USER_AGENT']);
		$offset = $this->_request->query('offset', 0);
		$limit = $this->_request->query('limit', 24);
		$isAjax = $this->_request->query('isAjax', 0);
		if($isAjax || $this->_request->isAjax())
		{
			$isAjax = 1;
		}
		else
		{
			$isAjax = 0;
		}
		if($platform != 'android')
		{
			$platform = 'ios';
		}
		if($yohoshowState)
		{
			$url = $platforms[$platform]['scheme'];
		}
		else
		{
			$url = $platforms[$platform]['download'];
		}
		$this->_view['url'] = $url;
		$this->_view['fragments'] = $this->getShowTopicFragment($offset, $limit, $total, $banner);
		$this->_view['banner'] = $banner;
		$this->_view['yohoshowState'] = $yohoshowState;
		$this->_view['offset'] = $offset;
		$this->_view['limit'] = $limit;
		$this->_view['isAjax'] = $isAjax;
		$this->_viewname = 'clientmobile';
	}
	
	/**
	 * 获取show话题
	 * 
	 * @param int $offset
	 * @param int $limit
	 * @param int $total
	 * @param string $banner
	 * @return array
	 */
	private function getShowTopicFragment($offset, $limit, &$total = 0, &$banner = '')
	{
		$params = array(
			'offset'=> $offset,  
			'limit' => $limit,
		);
		$data = Util_Curl::get('http://www.yohoshow.com/api/yohood/topic?'.http_build_query($params));
		$data = json_decode($data, true);
		if(!empty($data['data']))
		{
			$list = $data['data']['list'];
			$total = $data['data']['totalCount'];
			$banner = $data['data']['bannerUrl'];
		}
		return $list;
	}
}