Index.class.php 2.21 KB
<?php

/**
 *  首页
 *
 * @name Service_Index
 * @version 1.0 (2013-6-5)
 * @package Service/News
 * @since 1.0
 */

class Service_Index extends Lib_Service
{
    const ROUTER = 'index.yohood.index';
    private static $_tag = 'tag_yohood_index_';
    private static $_key = 'key_yohood_index_';
    
    /**
     * 获取首页信息
     * 
     * @param string $type
     * @return array
     */
    public function getIndex ($type)
    {
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getBannerByType', array('type' => $type));
    }

    /**
     * 根据id更新首页信息状态.
     * 用于管理员更新一个首页信息的操作.
     * 
     * @param int $url
     * @param int $text
     * @param int $res
     * @param int $type
     * @param int $sort
     * @param int $id
     * @return boolean
     */
    public function updateIndex ($url, $text, $res, $type, $sort, $id)
    {
        $param = array('id' => $id, 'text' => $text, 'res' => $res,'url'=> $url,'type'=> $type, 'sort' => $sort);
        $status = self::service(self::ROUTER)->cache(false)->update('updateBanner', $param)->status();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }

    /**
     * 用户提交首页信息
     * 
     * @param int $url
     * @param int $text
     * @param int $res
     * @param int $type
     * @param int $sort
     * @return boolean
     */
    public function submitIndex ($url, $text, $res, $type, $sort)
    {
        $param = array('url' => $url, 'res' => $res, 'text'=> $text, 'type'=> $type,'sort' => $sort);
        $status = self::service(self::ROUTER)->cache(false)->insert('insertBanner', $param)->lastInsertId();
      	if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }

    /**
     * 删除首页信息
     * 
     * @param int $id
     * @return boolean
     */
    public function delIndex($id)
    {
        $status = self::service(self::ROUTER)->cache(false)->delete('delIndex',array('id'=>$id))->status();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }
    
}