Exemplo n.º 1
0
 /**
  * REQUEST:
  * - term str
  * - country int or empty
  * @return array
  */
 public function actionRegion()
 {
     $term = \Yii::$app->request->get('term');
     $country = \Yii::$app->request->get('country');
     \Yii::$app->response->format = Response::FORMAT_JSON;
     return \cs\models\Place\Region::findAll($term, $country);
 }
Exemplo n.º 2
0
 public function getNameByTemplate()
 {
     $thisPlaceArea = $this->getPlaceArea();
     switch ($thisPlaceArea->getType()) {
         case PlaceArea::TYPE_COUNTRY:
             return $this->country->getName();
         case PlaceArea::TYPE_REGION:
             return $this->region->getName() . '. ' . $this->country->getName();
         case PlaceArea::TYPE_TOWN:
             return $this->town->getName() . '. ' . $this->country->getName();
     }
 }
Exemplo n.º 3
0
 /**
  * Возращает список городов по запросу get param=term
  *
  * @return string JSON
  */
 public function actionPlace_region($id)
 {
     $term = static::getParam('term');
     return Json::encode(\cs\models\Place\Region::findAll($term, $id));
 }
Exemplo n.º 4
0
 private function renderItem($id, $name, \yii\web\View $view, $source, $idInt, $key)
 {
     // добавляю опции input'а
     $optionsName = $key . 'InputOptions';
     $inputOptions = $this->{$optionsName};
     if (!is_null($inputOptions)) {
         if (ArrayHelper::keyExists('class', $inputOptions)) {
             $inputOptions['class'] .= ' form-control ui-autocomplete-input';
         } else {
             $inputOptions['class'] = 'form-control ui-autocomplete-input';
         }
     } else {
         $inputOptions = ['class' => 'form-control ui-autocomplete-input'];
     }
     $attrName = $this->attribute . '_' . $key;
     $value = null;
     if ($this->model->hasProperty($attrName)) {
         $value = $this->model->{$attrName};
         if (!is_null($value)) {
             switch ($key) {
                 case 'town':
                     $value = Town::find($value)->getName();
                     break;
                 case 'region':
                     $value = Region::find($value)->getName();
                     break;
                 case 'country':
                     $value = Country::find($value)->getName();
                     break;
             }
         }
     }
     return Html::input('text', $name, $value, ArrayHelper::merge($inputOptions, ['id' => $id, 'autocomplete' => 'off']));
 }