<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GrowthBidRecordOn
 *
 * @author Administrator
 */
class GrowthBidSchoolExpertRecordOn extends GrowthBidRecord {

	public function __construct($table = 'growth_bid_school_expert_record_on') {
        parent::__construct($table);
    }
    
    public function save($fieldData) {
        if(array_key_exists('broker_id', $fieldData)&&
                array_key_exists('bid_id', $fieldData)&&
                array_key_exists('school_id', $fieldData)) {
            $brokerId = $fieldData['broker_id'];
            $bidId = $fieldData['bid_id'];
            $schoolId = $fieldData['school_id'];
            $record = $this->findOneBy($brokerId, $bidId, $schoolId);
            if($record) {
                $conf = "broker_id='$brokerId' and bid_id='$bidId' and school_id='$schoolId'";
                $this->update($fieldData, $conf);
                return $this->db->Affected_Rows();
            } else {
                $this->insert($fieldData);
                return $this->db->Affected_Rows();
            }
        } else {
            return false;
        }
        
    }
    public function findOneBy($brokerId,$bidId,$houseId=0) {
        $sql = SqlCombinHelper::select_sql($this->table, $this->fields,"broker_id='$brokerId' and bid_id='$bidId'");
        return $this->dbback->getRow($sql);
    }
}

?>
