<?php

/**
 * 
 */

/**
 * 经纪人成长体系认证日志
 *
 * @author 
 */
class GrowthCertificateLog {
    //put your code here
    private $db;
    private $dbback;       
    private $table;   
    private $fields;
    private $mc;
    public function __construct() {      
       $container = Container::getInstance();
       $this->db = $container->get('db');
       $this->dbback = $container->get('dbback');	  
       $this->table = "growth_certificate_log";
       //$this->fields = "uid,avatar_credit,avatar_exp,id_credit,id_exp,bcard_credit,bcard_exp,broker_credit,broker_exp";
       $this->mc = $container->get('mc');
        $sqlfield = "DESC $this->table";
        $fieldsMKey = $sqlfield;
        $this->fields = $this->mc->get($fieldsMKey);
        if($this->fields === false) {
            $fields = $this->dbback->getAll($sqlfield);
            foreach ($fields as $field) {
                $this->fields[] = $field['Field'];
            }
            $this->mc->set($fieldsMKey, $this->fields, 3600);
        }
     
    }
    
     /**
     * 获取经纪人是否已经参加认证
     * @param $brokerId
     * @return array 
     * @author  2014-3-27
     */    
     public function isCertificate($brokerId){		 
         $sql = SqlCombinHelper::select_sql($this->table, $this->fields, 
                 "uid = $brokerId");        
         $result = $this->dbback->getRow($sql);	
		 if(!$result){			
		     $this->insertLog($brokerId);
			 $this->isCertificate($brokerId);		
		 }
		 return $result;
     }
     
	 /**
     * 添加经纪人参加认证记录
     * @param 无
     * @return array 
     * @author  2014-3-27
     */    
     public function insertLog($brokerId){		 
        $fieldData = array('uid'=>$brokerId);		
        $sql = SqlCombinHelper::insert_sql($this->table, $fieldData);
        $this->db->execute($sql);		
     }

	 /**
	 *修改经纪人参加认证
	 *
	 *
	 */
   
     public function updateLog($certifiArr,$brokerId){
        for($i=0;$i<count($certifiArr);$i++){
		    $fieldData[$certifiArr[$i]] = 1;
		}		
	    $sql = SqlCombinHelper::update_sql($this->table, $fieldData, "uid = '$brokerId'");
        if($this->db->execute($sql)) {			
            return true;
        } else {
            return false;
        }
    		
     }
     
     
     
     
    
    
}
