Index.class.php 2.17 KB
<?php
/**
 * 首页控制器
 */
class Controller_Admin_Index extends Controller_Admin_Base 
{
    
    /**
     * 首页列表Index
     */
    public function indexAction()
    {
        $type = $this->_request->query('type', 1);
        $info = Facade_Index::getIndex($type);
        $this->_view['data'] = $info;
        $this->_view['type'] = $type;
        $this->_view['typeDescription'] = array( 1 =>'banner', 2 =>'广告', 3 =>'广告', 4=> '广告');
        $this->_view['sizeDescription'] = array( 1 =>'980x474 [移动端:320x155]', 2 =>'308x392', 3=>'980x474px[移动端:320x155]', 4 =>'280x357px');
        $this->_view['key'] = Lib_Images::genKey('fragmentimg');
    }
    
    /**
     * 提交首页
     */
    public function submitAction()
    {
        $id = $this->_request->query('id', 0);
        $url = $this->_request->query('url','');
        $text = $this->_request->query('text','');
        $res = $this->_request->query('res','');
        $sort = $this->_request->query('sort', 0);
        $type = $this->_request->query('type', 1);
        $width = $height = $times = 0;
        while($width <= 0 && $height <= 0 && $times++<=5)
        {
             $info = Lib_Images::getImageInfo($res, 'fragmentimg');
             $width = intval($info['width']);
             $height = intval($info['height']);
        }
        $res_size = json_encode(array('width'=> $width, 'height'=> $height));
        if($id)
        {
            $ret = Facade_Index::updateIndex($url, $text, $res, $type, $sort, $res_size, $id);
        }
        else
        {
            $ret = Facade_Index::submitIndex($url, $text, $res, $type, $sort, $res_size);
        }
        if($ret)
        {
            return $this->returnJson(true,200,null);
        }
        else
        {
            return $this->returnJson(false,404,null);
        }
    }
    
    /**
     * 删除首页信息
     */
    public function delAction()
    {
        $id = $this->_request->query('id',0);
        $ret = Facade_Index::delIndex($id);
        if($ret)
        {
            return $this->returnJson(true,200,null);
        }
        else
        {
            return $this->returnJson(false,404,null);
        }
    }
}