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

class Post_img_model extends MY_Model {

    public $table = 'post_img';
    protected $insert_filed = array(
        'postid', 'width', 'height', 'path', 'isdelete', 'createtime'
    );
    public function __construct()
    {
        parent::__construct();
    }

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

    public function getall() {
        return $this->db->get($this->table)->result_array();
    }

    public function update($data, $id)
    {
        $data = $this->check_insert($data);
        $this->db->where('id', $id);
        $this->db->update($this->table, $data);
        return $id;
    }

    public function get_img_by_pid($postid, $field = 'width, height, path')
    {
        $this->db->select($field);
        $this->db->where('postid',$postid);
        $this->db->order_by('id', 'ASC');
        return $this->db->get($this->table)->result_array();
    }

    public function get_first_img($postid, $field = 'width, height, path') {
        $this->db->select($field);
        $this->db->where('postid',$postid);
        $this->db->order_by('id', 'ASC');
        return $this->db->get($this->table)->row_array();
    }

    public function get_img_by_pids($post_ids, $field = '') {
        if (!empty($field)) {
            $this->db->select($field);
        }
        $where=array();
        $where['isdelete']=0;
        $this->db->where($where);
        $this->db->where_in('postid', $post_ids);
        $this->db->order_by('id', 'ASC');
        return $this->db->get($this->table)->result_array();
    }

    public function get_post_img_by_postid($postid){
        $where=array();
        $where['postid']=$postid;
        $where['isdelete']=0;
        $this->db->where($where);
        return $this->db->get($this->table)->result_array();

    }

 
}