<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Comment_model extends MY_Model {

    public $table = 'comment';
    protected $key = 'id';
    protected $insert_filed = array(
        'uid','username','content','postid','to_uid',
        'to_username','status','likecount','isdelete','createtime'
    );
    public function __construct()
    {
        parent::__construct();
    }

    public function insert($data)
    {
        return parent::insert($data);
    }

    //获取一个帖子的评论数量
    public function get_total_by_postid($postid) {
        $this->db->where('postid', $postid);
        $this->db->where('isdelete', 0);
        return $this->db->count_all_results($this->table);
    }

    /*public function get_by_postid($postid, $limit, $page = 1) {
        $offset = ($page - 1) * $limit;
        $this->db->where('postid', $postid);
        $this->db->order_by('id', 'ASC');
        return $this->db->get($this->table, $limit, $offset)->result_array();
    }*/

    public function get_by_postid($postid, $limit, $offset = 0) {
        $this->db->where('postid', $postid);
        $this->db->where('isdelete', 0);
        $this->db->order_by('id', 'ASC');
        return $this->db->get($this->table, $limit, $offset)->result_array();
    }


}