<?php

class ContractDao {
    public static function insert($params){
        global $wpdb;
        $wpdb->insert(Config::TOSPUR_CONTRACT,$params);
        if($wpdb->insert_id){
            return $wpdb->insert_id;
        }
        return $wpdb->last_error;
    }

    public static function setContractId($id,$contractId){
        global $wpdb;
        $result = $wpdb->update(Config::TOSPUR_CONTRACT,array(
            "contractId" => $contractId
        ),array(
            "id" => $id
        ));
        if($result){
            return $result;
        }else{
            return $wpdb->last_error;
        }
    }

    public static function update($id,$params){
        global $wpdb;
        $result = $wpdb->update(Config::TOSPUR_CONTRACT,$params,array(
            "id" => $id
        ));
        if($result){
            return $result;
        }else{
            return $wpdb->last_error;
        }
    }

    public static function searchContract($id){
        global $wpdb;
        $sql = "select * from ".Config::TOSPUR_CONTRACT." where id = %d;";
        $result = $wpdb->get_row($wpdb->prepare($sql,$id));
        if($result){
            return $result;
        }else{
            return $wpdb->last_error;
        }
    }
} 