Example #1
0
 public function run()
 {
     $model = new Country();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Country successfully saved.'));
             $model = new Country();
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Error on saving country.'));
         }
     }
     return $this->controller->render('manage', ['model' => $model]);
 }
Example #2
0
 public function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
Example #3
0
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = \common\models\country\Country::findOne($id)) !== null) {
         if ($model->delete()) {
             $output = ['error' => false, 'message' => Yii::t('app', 'Successfully deleted!')];
         }
     }
     if (empty($output)) {
         $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')];
     }
     return \yii\helpers\Json::encode($output);
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Country::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['countryid' => $this->countryid]);
     $query->andFilterWhere(['like', 'countryname', $this->countryname])->andFilterWhere(['like', 'acronym', $this->acronym]);
     return $dataProvider;
 }
Example #5
0
 public function run($search = null, $id = null)
 {
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = new Query();
         $query->select('[[id]], [[name]] AS [[text]]')->from('{{%country}}')->filterWhere(['like', '[[name]]', $search])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Country::findOne($id)->name];
     } else {
         $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
     }
     return Json::encode($out);
 }
Example #6
0
 public function search($params)
 {
     $query = Country::find();
     // join with relation `author` that is a relation to the table `users`
     // and set the table alias to be `author`
     $query->joinWith(['user' => function ($query) {
         $query->from(['u' => 'user']);
     }]);
     $query->from(['c' => $this->tableName()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['user.username'] = ['asc' => ['u.username' => SORT_ASC], 'desc' => ['u.username' => SORT_DESC]];
     //$dataProvider->sort->defaultOrder = ['updated_at' => SORT_DESC];
     // load the seach form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     // adjust the query by adding the filters
     $query->andFilterWhere(['c.id' => $this->id]);
     $query->andFilterWhere(['like', 'c.name', $this->name]);
     $query->andFilterWhere(['LIKE', 'u.username', $this->getAttribute('user.username')]);
     return $dataProvider;
 }
Example #7
0
SCRIPT;
$met_description = Yii::t('app', 'Introduce your business, Your business on the map, image gallery for your business, attachments for your business, Mark your business location in map');
$this->registerMetaTag(['property' => 'og:description', 'content' => $met_description]);
$this->registerMetaTag(['name' => 'description', 'content' => $met_description]);
$this->registerMetaTag(['name' => 'keywords', 'content' => $met_description]);
?>
<div class="row">
    <div class="col-md-2">
        <?php 
$form = ActiveForm::begin(['id' => $searchModel->formName(), 'enableAjaxValidation' => false, 'enableClientValidation' => false, 'method' => 'get']);
?>
        <?php 
echo $form->field($searchModel, 'category_id')->widget(Select2::classname(), ['language' => Yii::$app->helper->getTwoCharLanguage(), 'size' => Select2::MEDIUM, 'options' => [], 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 2, 'ajax' => ['url' => $categoriesListUrl, 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {search:params.term}; }'), 'results' => new JsExpression('function(data,page) { return {results:data.results}; }')], 'initSelection' => new JsExpression($initCategoriesListScript)]]);
?>
        <?php 
echo $form->field($searchModel, 'country_id')->widget(Select2::className(), ['data' => ArrayHelper::map(Country::find()->asArray()->all(), 'id', 'name'), 'language' => Yii::$app->helper->getTwoCharLanguage(), 'options' => ['placeholder' => Yii::t('app', 'Select...')], 'pluginOptions' => ['allowClear' => true]]);
echo $form->field($searchModel, 'province_id')->widget(DepDrop::classname(), ['data' => !$searchModel->country_id ? [] : ArrayHelper::map(Province::find()->where(['country_id' => $searchModel->country_id])->asArray()->all(), 'id', 'name'), 'type' => DepDrop::TYPE_SELECT2, 'options' => ['placeholder' => Yii::t('app', 'Select...')], 'select2Options' => ['pluginOptions' => ['allowClear' => true], 'language' => Yii::$app->helper->getTwoCharLanguage()], 'pluginOptions' => ['depends' => ['search-country_id'], 'url' => Url::to(['/province/dep-list']), 'loadingText' => Yii::t('app', 'Loading...')]]);
echo $form->field($searchModel, 'city_id')->widget(DepDrop::classname(), ['data' => !$searchModel->province_id ? [] : ArrayHelper::map(City::find()->where(['province_id' => $searchModel->province_id])->asArray()->all(), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select...')], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['allowClear' => true], 'language' => Yii::$app->helper->getTwoCharLanguage()], 'pluginOptions' => ['depends' => ['search-province_id'], 'url' => Url::to(['/city/dep-list']), 'loadingText' => Yii::t('app', 'Loading...')]]);
?>
            <?php 
echo $form->field($searchModel, 'title')->textInput();
?>
            <?php 
echo $form->field($searchModel, 'address')->textInput();
?>
            <?php 
echo Html::hiddenInput('view', $adverView, ['id' => 'hiddenViewMode']);
?>
        <div class="form-group">
            <?php 
echo Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']);
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCountry()
 {
     return $this->hasOne(Country::className(), ['countryid' => 'countryid']);
 }
Example #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCountries()
 {
     return $this->hasMany(Country::className(), ['user_id' => 'id']);
 }
Example #10
0
 public static function getCountriesList()
 {
     return ArrayHelper::map(Country::find()->orderBy('countryname ASC')->all(), 'countryid', 'countryname');
 }
Example #11
0
 /**
  * Finds the Country model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Country the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }