<?php
/**
 * Description of Street
 *
 * @author user
 */
class Street {
    /**
     *
     * @var TINY_ADODB 主数据库
     */
    private $db;
    /**
     *
     * @var TINY_ADODB 从数据库
     */
    private $dbback;
    /**
     *
     * @var Memcache 缓存
     */
    private $mc;
    /**
     *
     * @var string 表名
     */
    private $table;
    /**
     *
     * @var 表中字段数组 
     */
    private $fields;
    
    /**
     * 初始化类
     * @param string $table 表名，默认为growth_bid_periods
     */
    public function __construct($table = 'street') {
        $container = Container::getInstance();
        $this->db = $container->get('db');
        $this->dbback = $container->get('dbback');
        $this->mc = $container->get('mc');
        $this->table = $table;
        $sqlfield = "DESC $this->table";
        $fields = $this->dbback->getAll($sqlfield);
        foreach ($fields as $field) {
            $this->fields[] = $field['Field'];
        }
    }
    
    public function findOneBy($streetId) {
        $sql = SqlCombinHelper::select_sql($this->table, $this->fields,"id=$streetId");
        return $this->dbback->getRow($sql);
    }
    
    public function findAll() {
         $sql = SqlCombinHelper::select_sql($this->table, $this->fields);
         return $this->dbback->GetAll($sql);
    }
    
    public function findAllIdByLikeName($streetname) {
        $sql = SqlCombinHelper::select_sql($this->table, 'id',"esta = 2 "
                . "AND streetname like '%{$streetname}%'");
        $arrStreetId = $this->dbback->GetAll($sql);
        $arrStreetIdOne = array();
        if(CommonBase::isFullArray($arrStreetId)) {
            foreach($arrStreetId as $k => $v) {
                $arrStreetIdOne[] = $v['id'];
            }
        }
        return $arrStreetIdOne;
    }
}
