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

class Topic_participation_model extends MY_Model {

    public $table = 'topic_participation';
    protected $insert_filed = array(
        'tid','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 get_tid_by_uid($uid){
        $this->db->where('uid',$uid);
        return $this->db->get($this->table)->result_array();
    }

    public function get_by_tid($tid, $field = '', $limit) {
        $this->db->where('tid', $tid);
        if (!empty($field)) {
            $this->db->select($field);
        }
        $this->db->order_by('createtime', 'DESC');
        return $this->db->get($this->table, $limit)->result_array();
    }

    public function check_by_tids($tids, $uid) {
        $tids_part = array();
        $ret = array();
        $this->db->where_in('tid', $tids);
        $this->db->where('uid', $uid);
        $this->db->select('tid');
        $ret = $this->db->get($this->table)->result_array();
        if (!empty($ret)) {
            foreach ($ret as $key => $value) {
                $tids_part[] = $value['tid'];
            }
        }
        return $tids_part;
    }


}