Пример #1
0
 public function run()
 {
     $model = new Province();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Province successfully saved.'));
             $model = new Province();
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Error on saving province.'));
         }
     }
     return $this->controller->render('manage', ['model' => $model]);
 }
Пример #2
0
 public function search($params)
 {
     $query = Province::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']);
     }, 'country' => function ($query) {
         $query->from(['c' => 'country']);
     }]);
     $query->from(['p' => $this->tableName()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['user.username'] = ['asc' => ['u.username' => SORT_ASC], 'desc' => ['u.username' => SORT_DESC]];
     $dataProvider->sort->attributes['country.name'] = ['asc' => ['c.name' => SORT_ASC], 'desc' => ['c.name' => 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(['p.id' => $this->id]);
     $query->andFilterWhere(['like', 'p.name', $this->name]);
     $query->andFilterWhere(['LIKE', 'u.username', $this->getAttribute('user.username')]);
     $query->andFilterWhere(['LIKE', 'c.name', $this->getAttribute('country.name')]);
     return $dataProvider;
 }
Пример #3
0
 public function findModel($id)
 {
     if (($model = Province::findOne($id)) !== null) {
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
Пример #4
0
 public function run()
 {
     $out = [];
     $parents = Yii::$app->getRequest()->post('depdrop_parents', null);
     if ($parents != null) {
         $country_id = $parents[0];
         $out = Province::find()->select(['id', 'name'])->where(['country_id' => $country_id])->asArray()->all();
         return Json::encode(['output' => $out, 'selected' => '']);
     }
     return Json::encode(['output' => '', 'selected' => '']);
 }
Пример #5
0
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = \common\models\province\Province::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);
 }
Пример #6
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('{{%province}}')->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' => Province::findOne($id)->name];
     } else {
         $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
     }
     return Json::encode($out);
 }
Пример #7
0
$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']);
?>
Пример #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvinces()
 {
     return $this->hasMany(Province::className(), ['user_id' => 'id']);
 }
Пример #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdvers()
 {
     return $this->hasMany(Province::className(), ['country_id' => 'id']);
 }
Пример #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvince()
 {
     return $this->hasOne(Province::className(), ['id' => 'province_id']);
 }