<?php

/**
 * 前台首页 模块 Controller 
 * ============================================================================
 * ZhunaCMS 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: index.php 43 2011-12-01 11:09:19Z zhangwentao $
 * http://www.t-mac.org；
 */
class indexAction extends Action
{

    private $tmp_model;
    private $common_model;
    private $hotel_left_model;
    private $cityinfo;

    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->assign('method',$_GET['TMAC_CONTROLLER']);
        $this->tmp_model = Tmac::model('index');
        $this->common_model = Tmac::model('common');
        $this->hotel_left_model = Tmac::model('hotelLeft');

        //取cityinfo
        $this->cityinfo = $this->hotel_left_model->getCityinfo();

        //footer里的相关设置
        $config_footer = $this->common_model->footer();
        $this->assign($config_footer);
        $this->assign('cityinfo', $this->cityinfo);
    }

    public function index()
    {
        //取酒店总数/评价总数
        $hotel_count = $this->tmp_model->getHotelCount();
        //设置首页默认第一的搜索城市 $uncityinfo
        $uncityinfo = $this->tmp_model->setDefaultCity();

        //title keywords description k_page(index)
        $keywords_info = $this->hotel_left_model->getKeywordsInfo(1);
        $keywords_array = $keywords_info[1];
        $keywords_search = array('{doname}');
        $keywords_replace = array("$keywords_info[0]");
        $keywords_array = str_replace($keywords_search, $keywords_replace, $keywords_array);
        $this->assign('keywords_array', $keywords_array);
        $this->assign($uncityinfo);
        $this->assign($hotel_count);

        $this->V('index');
    }

    public function getQuestionLimitIndex()
    {        
        $limit = (int) $this->getParam('limit', 4);
        $result = $this->tmp_model->indexWenda($limit, $this->cityinfo['cityid']);
        $array = json_encode($result);
        echo $array;        
    }
    
    public function getCommentLimitIndex()
    {        
        $limit = (int) $this->getParam('limit', 4);
        $is_pic = (int) $this->getParam('pic', 0);
        $result = $this->tmp_model->indexPinglun($limit, $this->cityinfo['cityid'], $is_pic);
        $array = json_encode($result);
        echo $array;        
    }  

}