示例#1
0
 /**
  * @return KladrLocation
  */
 public function getRussiaLocation()
 {
     if (!$this->russiaId) {
         return null;
     }
     return KladrLocation::findOne($this->russiaId);
 }
示例#2
0
/* @var $this yii\web\View */
/* @var $abc array */
?>

<? \yii\bootstrap\Alert::begin([
    'options' => [
      'class' => 'alert-info',
    ],
]); ?>
    Вы можете автоматически наполнить базу адресов на вашем сайте, при помоще сервиса http://kladr-api.ru/.
    Для начала обновления посетите раздел настроек.
<? \yii\bootstrap\Alert::end(); ?>


<?php 
echo \skeeks\cms\modules\admin\widgets\GridView::widget(["pjaxOptions" => ["id" => "sx-stat"], "dataProvider" => new \yii\data\ArrayDataProvider(['allModels' => [['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_COUNTRY, 'name' => 'Страна', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_COUNTRY])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_REGION, 'name' => 'Регион', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_REGION])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_DISTRICT, 'name' => 'Район', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_DISTRICT])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_CITY, 'name' => 'Город', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_CITY])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_VILLAGE, 'name' => 'Поселок', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_VILLAGE])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_VILLAGE_SMALL, 'name' => 'Деревня', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_VILLAGE_SMALL])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_STREET, 'name' => 'Улица', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_STREET])->count()], ['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_BUILDING, 'name' => 'Строение', 'count' => \skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_BUILDING])->count()]]]), 'columns' => [['attribute' => 'name', 'label' => 'Тип местоположения'], ['attribute' => 'count', 'label' => 'Количество'], ['format' => 'raw', 'label' => '', 'attribute' => 'count', 'class' => \yii\grid\DataColumn::className(), 'value' => function ($data) {
    $name = \yii\helpers\ArrayHelper::getValue($data, 'name');
    $type = \yii\helpers\ArrayHelper::getValue($data, 'type');
    if ($type == \skeeks\cms\kladr\models\KladrLocation::TYPE_COUNTRY) {
        return "";
    }
    return \yii\helpers\Html::a('Запустить импорт', '#', ['class' => 'btn-primary btn btn-xs', 'onclick' => new \yii\web\JsExpression(<<<JS
                    sx.KladrImport.execute('{$type}', '{$name}');
JS
)]);
}]]]);
?>


<div class="sx-progress-global" id="sx-progress-global" style="display: none;">
    <span style="vertical-align:middle;"><h3>Общий процесс (Выполнено <span class="sx-executing-ptc">0</span>%)</h3></span>
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLocation()
 {
     return $this->hasOne(KladrLocation::className(), ['id' => 'location_id']);
 }
示例#4
0
$form = ActiveForm::begin();
?>

<?php 
echo $form->fieldSet('Основное');
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 255]);
?>

    <?php 
echo $form->fieldSelect($model, 'type', \skeeks\cms\kladr\models\KladrLocation::possibleTypes());
?>
    <?php 
echo $form->fieldSelect($model, 'parent_id', \yii\helpers\ArrayHelper::map(\skeeks\cms\kladr\models\KladrLocation::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'name_short')->textInput(['maxlength' => 255]);
?>
    <?php 
echo $form->field($model, 'name_full')->textInput(['maxlength' => 255]);
?>

<?php 
echo $form->fieldSetEnd();
?>

<?php 
echo $form->buttonsCreateOrUpdate($model);
 /**
  * @param $locationData
  * @param $parent
  * @param $type
  * @return bool
  */
 protected function _writeLocation($locationData, $parent, $type)
 {
     $apiRegion = KladrLocation::findOne(['kladr_api_id' => ArrayHelper::getValue($locationData, 'id')]);
     if ($apiRegion) {
         return false;
     }
     $kladrLocation = new KladrLocation();
     $kladrLocation->kladr_api_id = ArrayHelper::getValue($locationData, 'id');
     $kladrLocation->name = ArrayHelper::getValue($locationData, 'name');
     $kladrLocation->zip = ArrayHelper::getValue($locationData, 'zip');
     $kladrLocation->type = $type;
     $kladrLocation->name_short = ArrayHelper::getValue($locationData, 'name') . " " . ArrayHelper::getValue($locationData, 'typeShort');
     $kladrLocation->name_full = ArrayHelper::getValue($locationData, 'name') . " " . ArrayHelper::getValue($locationData, 'type');
     return (bool) $kladrLocation->appendTo($parent)->save();
 }