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

class Comment_like_model extends MY_Model {

    public $table = 'comment_like';
    protected $insert_filed = array(
        'commentid', 'uid', 'username', 'createtime'
    );
    public function __construct()
    {
        parent::__construct();
    }

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

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

    public function like($commentid, $uid, $username) {
        $data = array(
            'commentid' => $commentid,
            'uid' => $uid,
            'username' => $username,
            'createtime' => time()
        );
        $this->replace($data);
    }

    public function is_liked_ids($uid, $cids) {
        $ret = array();
        $cids_liked = array();
        $this->db->where('uid', $uid);
        $this->db->where_in('commentid', $cids);
        $ret = $this->db->get($this->table)->result_array();
        if (!empty($ret)) {
            foreach ($ret as $value) {
                $cids_liked[] = $value['commentid'];
            }
        }
        return $cids_liked;
    }

//    public function get_by_postid($postid, $limit) {
//        $this->db->where('postid', $postid);
//        $this->db->order_by('createtime', 'DESC');
//        return $this->db->get($this->table, $limit)->result_array();
//    }



}