Ejemplo n.º 1
0
 public function actionImportDbf($filename, $region = false)
 {
     $db = @dbase_open($filename, 0);
     if (!$db) {
         $this->stderr("Не удалось открыть DBF файл: '{$filename}'\n");
         return 1;
     }
     $classMap = ['/^.*DADDROBJ\\.DBF$/' => FiasDaddrobj::className(), '/^.*ADDROBJ\\.DBF$/' => FiasAddrobj::className(), '/^.*LANDMARK\\.DBF$/' => FiasLandmark::className(), '/^.*DHOUSE\\.DBF$/' => FiasDhouse::className(), '/^.*HOUSE\\d\\d\\.DBF$/' => FiasHouse::className(), '/^.*DHOUSINT\\.DBF$/' => FiasDhousint::className(), '/^.*HOUSEINT\\.DBF$/' => FiasHouseint::className(), '/^.*DLANDMRK\\.DBF$/' => FiasDlandmrk::className(), '/^.*DNORDOC\\.DBF$/' => FiasDnordoc::className(), '/^.*NORDOC\\d\\d\\.DBF$/' => FiasNordoc::className(), '/^.*ESTSTAT\\.DBF$/' => FiasDhousint::className(), '/^.*ACTSTAT\\.DBF$/' => FiasActstat::className(), '/^.*CENTERST\\.DBF$/' => FiasCenterst::className(), '/^.*ESTSTAT\\.DBF$/' => FiasEststat::className(), '/^.*HSTSTAT\\.DBF$/' => FiasHststat::className(), '/^.*OPERSTAT\\.DBF$/' => FiasOperstat::className(), '/^.*INTVSTAT\\.DBF$/' => FiasIntvstat::className(), '/^.*STRSTAT\\.DBF$/' => FiasStrstat::className(), '/^.*CURENTST\\.DBF$/' => FiasCurentst::className(), '/^.*SOCRBASE\\.DBF$/' => FiasSocrbase::className()];
     $modelClass = false;
     foreach ($classMap as $pattern => $className) {
         if (preg_match($pattern, $filename)) {
             $modelClass = $className;
             break;
         }
     }
     if ($modelClass === false) {
         $this->stderr("Не поддерживаемый DBF файл: '{$filename}'\n");
         return 1;
     }
     $rowsCount = dbase_numrecords($db);
     $this->stdout("Записей в DBF файле '{$filename}' : {$rowsCount}\n");
     $j = 0;
     for ($i = 1; $i <= $rowsCount; $i++) {
         $row = dbase_get_record_with_names($db, $i);
         if ($modelClass == FiasAddrobj::className() && $this->region && intval($row['REGIONCODE']) != intval($this->region)) {
             continue;
         }
         if ($j == 0) {
             $transaction = Yii::$app->db->beginTransaction();
         }
         $model = new $modelClass();
         foreach ($row as $key => $value) {
             if ($key == 'deleted') {
                 continue;
             }
             $key = strtolower($key);
             $model->{$key} = trim(mb_convert_encoding($value, 'UTF-8', 'CP866'));
         }
         $model->save();
         $j++;
         if ($j == 1000) {
             $transaction->commit();
             $j = 0;
             $this->stdout("Обработано {$i} из {$rowsCount} записей\n");
         }
     }
     if ($j != 0) {
         $transaction->commit();
     }
     return 0;
 }
Ejemplo n.º 2
0
 public static function toString($id, $separator = ", ")
 {
     if ($house = FiasHouse::findOne(['houseguid' => $id])) {
         $parent = FiasAddrobj::findOne(['aoguid' => $house->aoguid]);
         $result = $house->housenum;
     } elseif ($landmark = FiasLandmark::findOne(['landguid' => $id])) {
         $parent = FiasAddrobj::findOne(['aoguid' => $landmark->aoguid]);
         $result = $landmark->location;
     } else {
         $current = FiasAddrobj::find()->andWhere(['aoguid' => $id, 'currstatus' => 0])->one();
         $parent = FiasAddrobj::find()->andWhere(['aoguid' => $current->parentguid, 'currstatus' => 0])->one();
         $result = $current->name;
     }
     if ($parent) {
         $result = static::toString($parent->aoguid, $separator) . $separator . $result;
     }
     return $result;
 }
Ejemplo n.º 3
0
 private function renderChildren($id)
 {
     $data = [];
     if ($house = FiasHouse::findOne(['houseguid' => $id])) {
         $current = null;
         $parent = FiasAddrobj::findOne(['aoguid' => $house->aoguid]);
     } elseif ($landmark = FiasLandmark::findOne(['landguid' => $id])) {
         $current = null;
         $parent = FiasAddrobj::findOne(['aoguid' => $landmark->aoguid]);
     } else {
         $current = FiasAddrobj::find()->andWhere(['aoguid' => $id, 'currstatus' => 0])->one();
         $parent = FiasAddrobj::find()->andWhere(['aoguid' => $current->parentguid, 'currstatus' => 0])->one();
     }
     if ($current) {
         // Улицы
         $query = FiasAddrobj::find();
         $query->andWhere(['parentguid' => $current->aoguid, 'currstatus' => 0]);
         $query->orderBy('formalname');
         $data = ArrayHelper::merge($data, ArrayHelper::map($query->all(), 'aoguid', 'name'));
         // Дома
         $query = FiasHouse::find();
         $query->andWhere(['aoguid' => $current->aoguid]);
         $query->orderBy(new \yii\db\Expression('housenum + 0'));
         $data = ArrayHelper::merge($data, ArrayHelper::map($query->all(), 'houseguid', 'housenum'));
         // Места
         $query = FiasLandmark::find();
         $query->andWhere(['aoguid' => $current->aoguid]);
         $query->orderBy('location');
         $data = ArrayHelper::merge($data, ArrayHelper::map($query->all(), 'landguid', 'location'));
         echo $this->renderDropDownList($data);
     }
 }