Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Airports::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(['id' => $this->id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'airport_code', $this->airport_code])->andFilterWhere(['like', 'airport_name', $this->airport_name])->andFilterWhere(['like', 'country', $this->country])->andFilterWhere(['like', 'city', $this->city]);
     return $dataProvider;
 }
Пример #2
0
 public function actionIndex()
 {
     if (!Yii::$app->user->isGuest && Yii::$app->user->identity->isadmin) {
         $model = new Airports();
         if ($pdata = Yii::$app->request->post('Airports')) {
             if (!empty($pdata['id'])) {
                 $model = Airports::findOne($pdata['id']);
             }
             unset($pdata['id']);
             $model->attributes = $pdata;
             $model->save();
             $this->refresh();
         }
     }
     $model = new Airports();
     return $this->render('booking', ['model' => $model]);
 }
Пример #3
0
 /**
  * @methods GET or POST
  * @params airport_code
  * @return array|string|\yii\db\ActiveRecord[]
  */
 public function actionSearchAirport()
 {
     $request = Yii::$app->request;
     if ($request->isGet) {
         $code = $request->get('airport_code');
     }
     if ($request->isPost) {
         $code = $request->post('airport_code');
     }
     if (!empty($code)) {
         $search_results = Airports::find()->where(['like', 'airport_code', $code])->asArray()->all();
         if (!empty($search_results)) {
             return $search_results;
         } else {
             return 'No match found against airport_code';
         }
     } else {
         return 'Invalid Parameter';
     }
 }
Пример #4
0
 /**
  * Relation with Airport model.
  * 
  * @return \yii\db\ActiveQuery
  */
 public function getAirport()
 {
     return $this->hasMany(Airports::className(), ['user_id' => 'id']);
 }
 /**
  * Finds the Airports model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Airports the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Airports::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #6
0
 public function getAirport()
 {
     return $this->hasOne(Airports::className(), ['id' => 'airport_id']);
 }
Пример #7
0
 public function actionRemoveApt()
 {
     $id = Yii::$app->request->post('id');
     foreach (Flights::find()->andWhere(['airport_id' => $id])->all() as $flight) {
         $flight->delete();
     }
     $apt = Airports::findOne($id);
     $apt->delete();
 }