wertex15

AddressParser

Sep 22nd, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.75 KB | None | 0 0
  1. namespace app\components;
  2. use app\models\FiasAddrobj;
  3.  
  4. class AddressParser
  5. {
  6. /**
  7.  * Код населенного пункта = код поселка, села, etc
  8. * @property string $placecode
  9.  * Наименование
  10. * @property string $formalname
  11.  * Номер дома: 5, 42-1, 2А, 43-а, 32/1, 42б
  12. * @property string $housenum
  13.  * Номер корпуса
  14. * @property string $buildnum
  15.  * Номер строения 5, 42-1, 2А, 43-а, 32/1, 42б
  16. * @property string $strucnum
  17.  *
  18.  * улица Ясная (с. Горный Щит) д.52
  19. */
  20.     public $city = 'Екатеринбург';
  21.     public $city_type = 'г';
  22.  
  23.     public $source;
  24.     public $result;
  25.     public $settlement;
  26.     public $settlementType;
  27.     public $settlementFiasId;
  28.     public $street;
  29.     public $streetFiasId;
  30.     public $housenum;
  31.     public $buildnum;
  32.     public $strucnum;
  33.     public $house_fias_id;
  34.  
  35.     const VILLAGE = '(с.';
  36.     const TOWNSHIP = '(пос.';
  37.  
  38.     public function getPlacecode($addressSting)
  39.     {
  40.         //улица Ясная (с. Горный Щит) д.52
  41.         $query = explode(' д.', $addressSting); //разбиваем строку адреса по "д." [0] первая часть строки, [1] вторая часть строки - номер дома + строение и тд
  42.         // array(2) { [0]=> string(47) "улица Ясная (с. Горный Щит)" [1]=> string(2) "52" }
  43.         $query[0]= str_replace('улица ', '', $query[0]); //убираем слово улица
  44.         $query[0]= str_replace('переулок ', '', $query[0]); //убираем слово переулок
  45.         // array(2) { [0]=> string(36) "Ясная (с. Горный Щит)" [1]=> string(2) "52" }
  46.  
  47.         $pos = strripos($query[0], self::VILLAGE);
  48.         if($pos>0){
  49.             $this->settlementType = 'c';
  50.             $village =  explode('(с.', $query[0]); // вытаскиваем село
  51.         }else{
  52.             $this->settlementType = 'пос';
  53.             $village =  explode('(пос.', $query[0]); // вытаскиваем поселок
  54.         };
  55.  
  56.  
  57.  
  58.         // array(2) { [0]=> string(11) "Ясная " [1]=> string(21) " Горный Щит)" }
  59.         $village[1] = str_replace(')','', $village[1]);
  60.         // array(2) { [0]=> string(11) "Ясная " [1]=> string(20) " Горный Щит" }
  61.         $village[1] = trim($village[1]);
  62.         // array(2) { [0]=> string(11) "Ясная " [1]=> string(19) "Горный Щит" }
  63.         $village[0] = trim($village[0]);
  64.         //array(2) { [0]=> string(10) "Ясная" [1]=> string(19) "Горный Щит" }
  65.         $settlement_fias_id = FiasAddrobj::getFiasSettlement($village[1]);
  66.         $street_fias_id = FiasAddrobj::getFiasStreet($village[0], $settlement_fias_id[0]['aoguid']);
  67.  
  68.         $this->source = $addressSting;
  69.         $this->result = null;
  70.         $this->settlement = $village[1];
  71. //        $this->settlementType = null;
  72.         $this->settlementFiasId = $settlement_fias_id[0]['aoguid'];
  73.         $this->street = $village[0];
  74.         $this->streetFiasId = $street_fias_id[0]['aoguid'];
  75.         $this->housenum = $query[1];
  76.         $this->buildnum = null;
  77.         $this->strucnum = null;
  78.         $this->house_fias_id = $query[0];
  79.  
  80. //        $result = [
  81. //            'source'=>$addressSting,
  82. //            'settlement' => $village[1],
  83. //            'settlement_fias_id' => $settlement_fias_id[0]['aoguid'],
  84. //            'street' => $village[0],
  85. //            'street_fias_id' => $street_fias_id[0]['aoguid'],
  86. //            'housenum' => $query[1],
  87. //            'buildnum' => '',
  88. //            'strucnum' => '',
  89. //            'house_fias_id' => ''
  90. //        ];
  91.  
  92. //        return $result;
  93.         return $this;
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment