diff --git a/backend/controllers/SupportController.php b/backend/controllers/SupportController.php new file mode 100644 index 0000000..bddb7cc --- /dev/null +++ b/backend/controllers/SupportController.php @@ -0,0 +1,146 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'name' => [ + 'type' => Index::ACTION_COL, + ], + 'email' => [ + 'type' => Index::STRING_COL + ], + 'status' => [ + 'type' => Index::STATUS_COL, + ], + 'created_at' => [ + 'type' => Index::DATETIME_COL, + ] + ], + 'model' => Support::className(), + 'hasLanguage' => false, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + 'defaultSort' => [ + 'created_at' => 'DESC', + ], + 'create' => false + ], + 'view' => [ + 'class' => View::className(), + 'model' => Support::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + ], + 'fields' => [ + [ + 'name' => 'name', + 'type' => Form::STRING, + ], + [ + 'name' => 'email', + 'type' => Form::STRING, + ], + [ + 'name' => 'sum', + 'type' => Form::STRING, + ], + [ + 'name' => 'created_at', + 'type' => Form::STRING, + ], + + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + + $model = Support::find() + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function deleteModel($id) + { + $category = Support::find() + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + + + return $category->delete(); + } + + public function actionUpdate($id) + { + $model = $this->findModel($id); + if ($model->load(\Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } else { + return $this->render( + 'update', + [ + 'model' => $model, + ] + ); + } + } + } \ No newline at end of file diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index b81c637..5279742 100755 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -60,6 +60,11 @@ 'url' => [ '/comment/index' ], ], + [ + 'label' => \Yii::t('app', 'Support'), + 'url' => [ '/support/index' ], + + ], ], ], diff --git a/backend/views/support/_form.php b/backend/views/support/_form.php new file mode 100644 index 0000000..b56d948 --- /dev/null +++ b/backend/views/support/_form.php @@ -0,0 +1,59 @@ +registerJs($js, View::POS_READY); + +?> + +
+ + + book->title?> + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'email') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'sum') + ->textInput() ?> + + field($model, 'status') + ->checkbox( + [ + 'class' => 'switchery', + ] + ) ?> + +
+ isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
+ + + +
diff --git a/backend/views/support/update.php b/backend/views/support/update.php new file mode 100644 index 0000000..0188871 --- /dev/null +++ b/backend/views/support/update.php @@ -0,0 +1,45 @@ +title = Yii::t( + 'app', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Comment', + ] + ) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Comments'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); +?> + + $this->title, + 'options' => [ + 'class' => 'x_panel comment-update', + ], + ] +) ?> + +render( + '_form', + [ + 'model' => $model, + ] +) ?> + + diff --git a/common/models/Support.php b/common/models/Support.php index 2fe9381..c66c846 100644 --- a/common/models/Support.php +++ b/common/models/Support.php @@ -3,7 +3,8 @@ namespace common\models; use Yii; - + use yii\behaviors\TimestampBehavior; + /** * This is the model class for table "support". * @@ -24,6 +25,17 @@ return 'support'; } + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'updatedAtAttribute' => false, + ], + ]; + + } + /** * {@inheritdoc} */ diff --git a/console/migrations/m180620_100416_alter_table_support.php b/console/migrations/m180620_100416_alter_table_support.php new file mode 100644 index 0000000..d7ef7b3 --- /dev/null +++ b/console/migrations/m180620_100416_alter_table_support.php @@ -0,0 +1,40 @@ +addColumn('support', 'created_at', $this->integer()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('support', 'created_at'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m180620_100416_alter_table_support cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 4dafdc3..22cbb5f 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -54,7 +54,7 @@ */ public function actionIndex() { - $books = Book::find()->where(['status' => Book::STATUS_ACTIVE])->andWhere(['on_main' => true])->all(); + $books = Book::find()->where(['status' => Book::STATUS_ACTIVE])->andWhere(['on_main' => true])->limit(2)->all(); $articles = Article::find() ->with('language') ->where([ 'status' => true ]) -- libgit2 0.21.4