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

class Floor_model extends MY_Model {

    public $table = 'channel_floor';
    protected $insert_filed = array('name','ordernum','dateline');
    public function __construct()
    {
        parent::__construct();
    }

    public function del_floor( $id )
    {
        $this->db->where('id', $id);
        $this->db->delete($this->table);
        return true;
    }

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

    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 update_order($data)
    {
        foreach ($data as $id => $val) {
            $this->db->where('id',$id);
            $this->db->update($this->table,array('ordernum'=>$val));
        }
        return true;
    }
    public function get(){
        $this->db->order_by('ordernum', 'asc');
        return $this->db->get($this->table)->result_array();
    }

    /**
     * [get_one 获得频道设置值]
     * @param  [type] $id [主键]
     * @author [刘厚望] <[<email address>]>
     * @return [type]     [数组]
     */
    public function get_one($id)
    {
        $this->db->where('id',$id);
        return $this->db->get($this->table)->row_array();
    }


    public function check_cid($id)
    {
        if(preg_match('/^20.*$/', $id))
        {
            $this->db->where('cid',$id);
            $num = $this->db->get($this->table)->num_rows();
            if($num>0) return false;
        }
        return true;
    }

}