Ejemplo n.º 1
0
 /**
  * REQUEST:
  * - term str
  * - country int or empty
  * - region int or empty
  * @return array
  */
 public function actionTown()
 {
     $term = \Yii::$app->request->get('term');
     $country = \Yii::$app->request->get('country');
     $region = \Yii::$app->request->get('region');
     \Yii::$app->response->format = Response::FORMAT_JSON;
     return \cs\models\Place\Town::findAll($term, $country, $region);
 }
Ejemplo 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();
     }
 }
Ejemplo n.º 3
0
 /**
  * Возращает список городов по запросу get param=term
  *
  * @return string JSON
  */
 public function actionPlace_town_all()
 {
     $term = \Yii::$app->request->get('term');
     return Json::encode(\cs\models\Place\Town::findAll($term));
 }
Ejemplo 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']));
 }