<?php 
/**
 * 新建infoBokunData表，主要是用来保存抓取下来的bokun数据
 * 
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class InfoBokunData_model extends CI_Model {

    
    public function __construct()
    {
        parent::__construct();
        //$this->HT = $this->load->database('HT', TRUE);
        $this->HT = $this->load->database('INFORMATION', TRUE);    
    }
    
    var $ibd_ic_id;
    var $ibd_parentId=0;
    var $ibd_ItemName;
    var $ibd_Itemvalue;
    var $ibd_ItemType="";
    var $ibd_ItemDescription="";

    /**
     * @description: 增加一条bokun产品的新附加属性
     * @param {type} 
     * @return: 
     * @Date Changed: 
     */
    function Add(){

        $sql = "
                INSERT INTO [infoBokunData]
                    ([ibd_ic_id]
                    ,[ibd_parentId]
                    ,[ibd_ItemName]
                    ,[ibd_Itemvalue]
                    ,[ibd_ItemType]
                    ,[ibd_ItemDescription])
                VALUES
                    (?,?,?,?,?,?)
                ";
        $query = $this->HT->query($sql,array(
            $this->ibd_ic_id,
            $this->ibd_parentId,
            $this->ibd_ItemName,
            (string)$this->ibd_Itemvalue,
            $this->ibd_ItemType,
            $this->ibd_ItemDescription
        ));
        return $this->HT->query("select max(ibd_id) as ibd_id from infoBokunData")->row("ibd_id") ;
    }

    /**
     * @description: 根据ID更新
     * @param {type} 
     * @return: 
     * @Date Changed: 
     */
    function update_byId($ibd_id,$ibd_Itemvalue,$ibd_ItemType,$ibd_ItemDescription){
        $sql = "
            UPDATE [infoBokunData]
            SET [ibd_Itemvalue] = ?
            ,[ibd_ItemType] = ?
            ,[ibd_ItemDescription] = ?
             WHERE ibd_id=?
        ";
        $query = $this->HT->query($sql,array(
            $ibd_Itemvalue,
            $ibd_ItemType,
            $ibd_ItemDescription,
            $ibd_id
        ));
        return $query;        
    }

    /**
     * @description: 根据ic_id，ibd_ItemName 及ibd_ItemType（由于图片等可能多个key名称相同，所以加个类别）
     * @param {type} 
     * @return: 
     * @Date Changed: 
     */
    function update(){

    }

    /**
     * @description: 根据ID删除
     * @param {type} 
     * @return: 
     * @Date Changed: 
     */
    function delete_byid($ibd_id){
        $sql =" delete from infoBokunData where ibd_id =?";
        return $this->HT->query($sql,array($ibd_id));
    }

    /**
     * @description: 根据ic_id获取所有的附加属性
     * @param {type} 
     * @return: 
     * @Date Changed: 
     */
    function getList($ic_id){
        $sql = " select * from infobokundata 
        where ibd_ic_id = ?
        order by case when CHARINDEX('Photo',ibd_itemName)>0 then 999 else 1 end ,ibd_id ";
        $query = $this->HT->query($sql,array($ic_id));
        return $query->result();

    }

}

/* End of file InfoBokunData.php */
