From e831dbd2b19829bee7d03f2001506c0344cc6e9c Mon Sep 17 00:00:00 2001 From: dvaganov Date: Thu, 2 Jun 2016 11:38:13 +0300 Subject: [PATCH] Create Access model; Generate CRUD on Access. --- controllers/AccessController.php | 124 +++++++++++++++++++++++++++++++ models/Access.php | 79 ++++++++++++++++++++ models/query/AccessQuery.php | 34 +++++++++ models/search/AccessSearch.php | 70 +++++++++++++++++ views/access/_form.php | 27 +++++++ views/access/_search.php | 33 ++++++++ views/access/create.php | 21 ++++++ views/access/index.php | 35 +++++++++ views/access/update.php | 23 ++++++ views/access/view.php | 38 ++++++++++ 10 files changed, 484 insertions(+) create mode 100644 controllers/AccessController.php create mode 100644 models/Access.php create mode 100644 models/query/AccessQuery.php create mode 100644 models/search/AccessSearch.php create mode 100644 views/access/_form.php create mode 100644 views/access/_search.php create mode 100644 views/access/create.php create mode 100644 views/access/index.php create mode 100644 views/access/update.php create mode 100644 views/access/view.php diff --git a/controllers/AccessController.php b/controllers/AccessController.php new file mode 100644 index 0000000..964aafe --- /dev/null +++ b/controllers/AccessController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Access models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AccessSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Access model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Access model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Access(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Access model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Access model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Access model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Access the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Access::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/models/Access.php b/models/Access.php new file mode 100644 index 0000000..a9a3a80 --- /dev/null +++ b/models/Access.php @@ -0,0 +1,79 @@ + true, 'targetClass' => Users::className(), 'targetAttribute' => ['userGuest' => 'id']], + [['userOwner'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['userOwner' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'userOwner' => Yii::t('app', 'User Owner'), + 'userGuest' => Yii::t('app', 'User Guest'), + 'date' => Yii::t('app', 'Date'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUserGuest0() + { + return $this->hasOne(Users::className(), ['id' => 'userGuest']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUserOwner0() + { + return $this->hasOne(Users::className(), ['id' => 'userOwner']); + } + + /** + * @inheritdoc + * @return \app\models\query\AccessQuery the active query used by this AR class. + */ + public static function find() + { + return new \app\models\query\AccessQuery(get_called_class()); + } +} diff --git a/models/query/AccessQuery.php b/models/query/AccessQuery.php new file mode 100644 index 0000000..cac08cf --- /dev/null +++ b/models/query/AccessQuery.php @@ -0,0 +1,34 @@ +andWhere('[[status]]=1'); + }*/ + + /** + * @inheritdoc + * @return \app\models\Access[]|array + */ + public function all($db = null) + { + return parent::all($db); + } + + /** + * @inheritdoc + * @return \app\models\Access|array|null + */ + public function one($db = null) + { + return parent::one($db); + } +} diff --git a/models/search/AccessSearch.php b/models/search/AccessSearch.php new file mode 100644 index 0000000..e098ac7 --- /dev/null +++ b/models/search/AccessSearch.php @@ -0,0 +1,70 @@ + $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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'userOwner' => $this->userOwner, + 'userGuest' => $this->userGuest, + 'date' => $this->date, + ]); + + return $dataProvider; + } +} diff --git a/views/access/_form.php b/views/access/_form.php new file mode 100644 index 0000000..88fb27e --- /dev/null +++ b/views/access/_form.php @@ -0,0 +1,27 @@ + + +
+ + + + field($model, 'userOwner')->textInput() ?> + + field($model, 'userGuest')->textInput() ?> + + field($model, 'date')->textInput() ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/views/access/_search.php b/views/access/_search.php new file mode 100644 index 0000000..9293a99 --- /dev/null +++ b/views/access/_search.php @@ -0,0 +1,33 @@ + + + diff --git a/views/access/create.php b/views/access/create.php new file mode 100644 index 0000000..541138f --- /dev/null +++ b/views/access/create.php @@ -0,0 +1,21 @@ +title = Yii::t('app', 'Create Access'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Accesses'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/views/access/index.php b/views/access/index.php new file mode 100644 index 0000000..f7da6f4 --- /dev/null +++ b/views/access/index.php @@ -0,0 +1,35 @@ +title = Yii::t('app', 'Accesses'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'userOwner', + 'userGuest', + 'date', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/views/access/update.php b/views/access/update.php new file mode 100644 index 0000000..b8754d7 --- /dev/null +++ b/views/access/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Access', +]) . $model->id; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Accesses'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/views/access/view.php b/views/access/view.php new file mode 100644 index 0000000..a7e9290 --- /dev/null +++ b/views/access/view.php @@ -0,0 +1,38 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Accesses'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'userOwner', + 'userGuest', + 'date', + ], + ]) ?> + +