<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */

class quecommentAModel extends X {
    private $tbname = "question_comment";
    private $pkid = "commentid";

    
    public function getList($items) {
        $where = " WHERE 1=1".$items['searchsql'];
        $start = ($items['page']-1)*$items['pagesize'];
        $countsql = "SELECT COUNT(*) AS my_count".
                    " FROM ".DB_PREFIX."{$this->tbname} AS v".
                    " LEFT JOIN ".DB_PREFIX."question_topic AS t ON v.topicid=t.topicid".
                    $where;
        $total = parent::$obj->fetch_count($countsql);
        if ($total > 0) {
            $sql = "SELECT v.*, t.topicname FROM ".DB_PREFIX."{$this->tbname} AS v".
                    " LEFT JOIN ".DB_PREFIX."question_topic AS t ON v.topicid=t.topicid".
                    $where." ORDER BY v.{$this->pkid} DESC LIMIT {$start}, {$items['pagesize']}";
            $_data = parent::$obj->getall($sql);
        }
        return array($total, $_data);
    }

    
    public function getData($id) {
        $sql = "SELECT v.*, t.topicname FROM ".DB_PREFIX."{$this->tbname} AS v".
                " LEFT JOIN ".DB_PREFIX."question_topic AS t ON v.topicid=t.topicid".
                " WHERE v.{$this->pkid}='{$id}'";
        return parent::$obj->fetch_first($sql);
    }

    
    public function doEdit($id, $args) {
        return parent::$obj->update(DB_PREFIX."{$this->tbname}", $args, "{$this->pkid}='{$id}'");
    }

    
    public function doDel($id) {
        return parent::$obj->query("DELETE FROM ".DB_PREFIX."{$this->tbname} WHERE {$this->pkid}='{$id}'");
    }

    
    public function doUpdate($id, $type) {
        if ($type == 'flagopen') {
            return parent::$obj->query("UPDATE ".DB_PREFIX.$this->tbname." SET flag='1' WHERE {$this->pkid}='{$id}'");
        }
        elseif ($type == 'flagclose') {
            return parent::$obj->query("UPDATE ".DB_PREFIX.$this->tbname." SET flag='0' WHERE {$this->pkid}='{$id}'");
        }
    }
}
?>
