<?php

/**
 * 前台 酒店列表 模块 Controller
 * ============================================================================
 * ZhunaCMS 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhaojianjun $  <zwttmac@qq.com>
 * $Id: hotellist.php 86 2011-12-28 08:02:07Z zhaojianjun $
 * http://un.zhuna.cn；
 */
class hotellistAction extends Action
{

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

    /**
     * _init 方法 在执行任何Action前执行
     */
    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->assign('method',$_GET['TMAC_CONTROLLER']);
        $this->tmp_model = Tmac::model('hotellist');
        $this->hotel_left_model = Tmac::model('hotelLeft');
        $this->searchlist_model = Tmac::model('searchlist');
        $this->common_model = Tmac::model('common');

        //取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()
    {
        //搜索块默认值
        $SearchArray = $this->hotel_left_model->setLeftSearch();
        //设置SearchCookies$Searchinfo
        $Searchinfo = $this->hotel_left_model->getSearchCookies($SearchArray);

        //开始接收 初始化 hotellist右上部分参数
        $cbd_id = !empty($_GET['cbd_id']) ? intval($_GET['cbd_id']) : 0;  //商圈cbd_id
        $rank = !empty($_GET['rank']) ? intval($_GET['rank']) : '';  //星级档次
        $chain_id = !empty($_GET['chain_id']) ? intval($_GET['chain_id']) : 0;  //连锁酒店chain_id
        $px = !empty($_GET['px']) ? intval($_GET['px']) : 1;  //人气
        $subwayid = !empty($_GET['subwayid']) ? intval($_GET['subwayid']) : 0;  //人气
        $stationid = !empty($_GET['stationid']) ? intval($_GET['stationid']) : 0;  //人气

        $searchArray = array(
            'cityid' => $this->cityinfo['cityid'],
            'cityname' => $this->cityinfo['cityname'],
            'tm1' => $Searchinfo['tm1'],
            'tm2' => $Searchinfo['tm2'],
            'key' => $Searchinfo['key'],
            'minprice' => $Searchinfo['minprice'],
            'maxprice' => $Searchinfo['maxprice'],
            'hn' => $Searchinfo['hn'],
            'rank' => $rank,
            'cbd_id' => $cbd_id,
            'chain_id' => $chain_id,
            'px' => $px
        );
        //取出搜索结果酒店列表
        $hotel_ary = $this->tmp_model->getHotelList($searchArray);
        $price_ary = UtilityConfig::price_ary();    //价格
        $rank_ary = UtilityConfig::rank_ary();    //星级        
        //search_save
        //$this->tmp_model->save_search($searchArray);

        $keywords_info = $this->hotel_left_model->getKeywordsInfo(11);        
        $keywords_array = $keywords_info[1];
        $keywords_search = array('{doname}', '{key?附近}', '{key}', '{bidname}', '{lsname}', '{cityname}', '{pg}', '{star?星级}', '{minjiage?元}', '{maxjiage?元}', '{hn}');
        $keywords_replace = array("$keywords_info[0]", $hotel_ary['title_key_des_array']['key_fu'], $hotel_ary['title_key_des_array']['key'], $hotel_ary['title_key_des_array']['cbd_name'], $hotel_ary['title_key_des_array']['chain_name'], $this->cityinfo['cityname'], $hotel_ary['title_key_des_array']['dibiao_string'], $hotel_ary['title_key_des_array']['star'], $hotel_ary['title_key_des_array']['minjiage'], $hotel_ary['title_key_des_array']['maxjiage'], $Searchinfo['hn']);
        $keywords_array = str_replace($keywords_search, $keywords_replace, $keywords_array);
        $keywords_array = str_replace($this->cityinfo['cityname'].$this->cityinfo['cityname'], $this->cityinfo['cityname'], $keywords_array);
        $this->assign('keywords_array', $keywords_array);
    
        $this->assign('subwayid', $subwayid);
        $this->assign('stationid', $stationid);
            
        $this->assign('city', $this->cityinfo);
        $this->assign('price_ary', $price_ary);
        $this->assign('rank_ary', $rank_ary);
        $this->assign('sk_array', $searchArray);
        $this->assign($hotel_ary);
        $this->V('hotellist');
    }

}