<?php

class CustomerDao
{
    public static function insert_customer($params){
        global $wpdb;
        $result =  $wpdb->insert(Config::TOSPUR_CUSTOMER_TABLE, $params);
        $insert_id = $wpdb->insert_id;
        if($result){
            return $insert_id;
        }else{
            return 0;
        }
    }

    public static function searchCustomer($id)
    {
        global $wpdb;
        $sql = "SELECT tcs.* FROM tospur_customer tcs where tcs.id = %d";
        $result = $wpdb->get_row($wpdb->prepare($sql, $id));
        $context = array();
        if($result){
            $context['result'] = $result;
            $consultant_sql = "SELECT * FROM tospur_consultant where id = %d";
            $consultant = $wpdb->get_results($wpdb->prepare($consultant_sql, $result->consultant_id));
            $context['consultant'] = $consultant;
        }
        return $context;
    }
}

?>