<?php

/**
 * 后台文章栏目模块 Model
 * ============================================================================
 * zhuna_php 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: article_class.class.php 50 2011-12-05 02:56:32Z zhangwentao $
 * http://un.zhuna.cn；
 */
class article_class extends Model
{

    private $db;
    private $class_table;

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
        $this->db = $this->connect();
        $this->class_table = DB_PREFIX . 'article_class';
    }

    /**
     * 保存
     * @param string $menusMain
     * return Boole
     */
    public function addClass($sortname, $mode = 'INSERT', $where = '')
    {
        $info = array(
            'class_name' => $sortname,
            'pid' => '0'
        );
        $rs = $this->db->autoExecute($this->class_table, $info, $mode, $where);
        return $rs;
    }

    /**
     * 获取一个资讯栏目信息
     * @param int $class_id 栏目id
     * return array
     */
    public function getClassInfo($class_id)
    {
        $rs = $this->db->cacheGetRow("SELECT * FROM $this->class_table WHERE class_id = $class_id LIMIT 0,1");
        return $rs;
    }

    /**
     * 获取资讯栏目
     * return article_class,pages
     */
    public function getClass($url = '')
    {
        $count = $this->db->getOne("SELECT COUNT(*) FROM $this->class_table");
        if ($url == '')
            $url = PHP_SELF . '?m=article_class&page=';
        $pages = $this->P('Pages');
        $pages->setTotal($count);
        $pages->setUrl($url);
        $pages->setPrepage(10);
        $limit = $pages->getSqlLimit();
        $rs = $this->db->getAll("SELECT * FROM $this->class_table ORDER BY orderid DESC, class_id DESC LIMIT $limit");
        $result = array('rs' => $rs, 'page' => $pages->show());
        return $result;
    }

    /**
     * del
     * @param int $class_id
     */
    public function delClass($class_id)
    {
        $rs = $this->db->execute("DELETE FROM $this->class_table WHERE class_id = $class_id");
        return $rs;
    }

    /**
     * changeClassOrder 改栏目排序　order
     * @param int $class_id
     * @param int $orderid
     * return Boole
     */
    public function changeClassOrder($class_id, $orderid)
    {
        $mode = 'UPDATE';
        $where = 'class_id = ' . $class_id . '';
        $info = array(
            'orderid' => $orderid
        );
        $rs = $this->db->autoExecute($this->class_table, $info, $mode, $where);
        return $rs;
    }

}