<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Rent_star_base_model CLASS
 *
 * 出租多图属性类
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          xz
 */

//加载父类
load_m("rent_attr_model");

class Rent_star_base_model extends Rent_attr_model {
    
    /**
     * 多图标识对应值
     * @var const
     */
    const  ISSTAR_VALUE = 3;
    
    /**
     * 类初始化
     */
    public function __construct() 
    {
        parent::__construct(0,0,0);
    }
    
    /**
     * 返回多图标志值
     */
    public function get_isstar_value()
    {
        return self::ISSTAR_VALUE;
    }
    
    
    /**
     * 判断房源是否为多图房源
     *
     * @access	public
     * @return	boolean   是否为多图房源
     */
    public function is_star()
    {   
        $is_star = FALSE;
        
        $house_info = $this->init_houseinfo();
        
        if( is_array( $house_info ) && !empty( $house_info ) )
        {
            $is_star = self::ISSTAR_VALUE == $house_info['isstar'] 
                    ? TRUE : FALSE;
        }
        
        return $is_star;
    }
    
    
    /**
     * 设置多图房源
     *
     * @access  protected
     * @return  boolean  是否设置成功
     */
    public function set_star()
    {   
        $result = FALSE;
        
        $house_info = $this->init_houseinfo();
        $row_id = isset($house_info['id']) ? intval($house_info['id']) : 0;
        
        if( $row_id > 0 )
        {   
            $update_info = array();
            
            //需要设置的房源属性值
            $update_info['isstar'] = self::ISSTAR_VALUE;
            
            //设置多图房源
            $result = $this->update_house_atrr_val( $update_info , $row_id );
        }
        
        return $result;
    }
    
    
    /**
     * 去除多图房源属性
     *
     * @access  public
     * @return  boolean  是否设置成功
     */
    public function remove_star()
    {   
        $result = FALSE;
        
        $house_info = $this->init_houseinfo();
        $rowid = intval($house_info['id']);
        
        if( $rowid > 0 )
        {   
            $update_info = array();
            
            //需要设置的房源属性值
            $update_info['isstar'] = 0;
            
            //设置多图房源
            $result = $this->update_house_atrr_val( $update_info , $rowid );
        }
        
        return $result;
    }
    
    
    /**
     * 检测是房源是否符合多图房源标准
     *
     * @access  protected
     * @return  boolean  是否符合多图房源标准
     */
    public function check_star_standard()
    {   
        $tbl = 'rent';
        $is_star = FALSE;
        
        $houseinfo = $this->init_houseinfo();
        
        //1、必须是收费经纪人并且有经纪人头像
        $this->load->model('broker_model');
        
        $this->broker_model->set_uid($houseinfo['uid']);
        $broker_info = $this->broker_model->get_broker_info();
        
        if( $broker_info['groupid'] == 2 || $broker_info['smallphoto'] == '')
        {
            return $is_star;
        }
        
        //2、房源标题20字及以上
        if( strlen( $houseinfo['address'] ) < 20)
        {
            return $is_star;
        }
        
        //3、房源描述字数限制
        if( strlen( $houseinfo['remark'] ) < 60 )
        {
            return $is_star;
        }

        //4、张以上房源图片个数限制
        $pic_info = array();
        $this->load->model('pic_model');
        $pic_info = $this->pic_model->find_house_pic_by($tbl , $houseinfo['id'] , 2);
        
        //室内图
        $pic_indoor = 0;
        
        if( is_array( $pic_info ) && isset( $pic_info ) )
        {   
            $pic_indoor = count( $pic_info );//室内
        }
        
        //室内图最低数量
        $pic_indoor_limit = 3;
        if( $pic_indoor >= $pic_indoor_limit )
        {
            $is_star = TRUE;
        }
        
        return $is_star;
    }
}
/* End of file rent_attr_base_model.php */
/* Location: ./applications/models/rent_attr_base_model.php */