Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace app\components;
- use app\models\FiasAddrobj;
- class AddressParser
- {
- /**
- * Код населенного пункта = код поселка, села, etc
- * @property string $placecode
- * Наименование
- * @property string $formalname
- * Номер дома: 5, 42-1, 2А, 43-а, 32/1, 42б
- * @property string $housenum
- * Номер корпуса
- * @property string $buildnum
- * Номер строения 5, 42-1, 2А, 43-а, 32/1, 42б
- * @property string $strucnum
- *
- * улица Ясная (с. Горный Щит) д.52
- */
- public $city = 'Екатеринбург';
- public $city_type = 'г';
- public $source;
- public $result;
- public $settlement;
- public $settlementType;
- public $settlementFiasId;
- public $street;
- public $streetFiasId;
- public $housenum;
- public $buildnum;
- public $strucnum;
- public $house_fias_id;
- const VILLAGE = '(с.';
- const TOWNSHIP = '(пос.';
- public function getPlacecode($addressSting)
- {
- //улица Ясная (с. Горный Щит) д.52
- $query = explode(' д.', $addressSting); //разбиваем строку адреса по "д." [0] первая часть строки, [1] вторая часть строки - номер дома + строение и тд
- // array(2) { [0]=> string(47) "улица Ясная (с. Горный Щит)" [1]=> string(2) "52" }
- $query[0]= str_replace('улица ', '', $query[0]); //убираем слово улица
- $query[0]= str_replace('переулок ', '', $query[0]); //убираем слово переулок
- // array(2) { [0]=> string(36) "Ясная (с. Горный Щит)" [1]=> string(2) "52" }
- $pos = strripos($query[0], self::VILLAGE);
- if($pos>0){
- $this->settlementType = 'c';
- $village = explode('(с.', $query[0]); // вытаскиваем село
- }else{
- $this->settlementType = 'пос';
- $village = explode('(пос.', $query[0]); // вытаскиваем поселок
- };
- // array(2) { [0]=> string(11) "Ясная " [1]=> string(21) " Горный Щит)" }
- $village[1] = str_replace(')','', $village[1]);
- // array(2) { [0]=> string(11) "Ясная " [1]=> string(20) " Горный Щит" }
- $village[1] = trim($village[1]);
- // array(2) { [0]=> string(11) "Ясная " [1]=> string(19) "Горный Щит" }
- $village[0] = trim($village[0]);
- //array(2) { [0]=> string(10) "Ясная" [1]=> string(19) "Горный Щит" }
- $settlement_fias_id = FiasAddrobj::getFiasSettlement($village[1]);
- $street_fias_id = FiasAddrobj::getFiasStreet($village[0], $settlement_fias_id[0]['aoguid']);
- $this->source = $addressSting;
- $this->result = null;
- $this->settlement = $village[1];
- // $this->settlementType = null;
- $this->settlementFiasId = $settlement_fias_id[0]['aoguid'];
- $this->street = $village[0];
- $this->streetFiasId = $street_fias_id[0]['aoguid'];
- $this->housenum = $query[1];
- $this->buildnum = null;
- $this->strucnum = null;
- $this->house_fias_id = $query[0];
- // $result = [
- // 'source'=>$addressSting,
- // 'settlement' => $village[1],
- // 'settlement_fias_id' => $settlement_fias_id[0]['aoguid'],
- // 'street' => $village[0],
- // 'street_fias_id' => $street_fias_id[0]['aoguid'],
- // 'housenum' => $query[1],
- // 'buildnum' => '',
- // 'strucnum' => '',
- // 'house_fias_id' => ''
- // ];
- // return $result;
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment