diff --git a/backend/controllers/CommentController.php b/backend/controllers/CommentController.php
new file mode 100644
index 0000000..19376a3
--- /dev/null
+++ b/backend/controllers/CommentController.php
@@ -0,0 +1,144 @@
+ [
+ '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' => Comment::className(),
+ 'hasLanguage' => false,
+ 'enableMassDelete' => true,
+ 'modelPrimaryKey' => 'id',
+ 'defaultSort' => [
+ 'created_at' => 'DESC',
+ ],
+ 'create' => false
+ ],
+ 'view' => [
+ 'class' => View::className(),
+ 'model' => Comment::className(),
+ 'hasAlias' => false,
+ 'hasGallery' => false,
+ 'languageFields' => [
+ ],
+ 'fields' => [
+ [
+ 'name' => 'name',
+ 'type' => Form::STRING,
+ ],
+ [
+ 'name' => 'email',
+ 'type' => Form::STRING,
+ ],
+ [
+ 'name' => 'comment',
+ 'type' => Form::TEXTAREA,
+ ],
+ [
+ 'name' => 'created_at',
+ 'type' => Form::STRING,
+ ],
+
+ ],
+ ],
+ 'delete' => [
+ 'class' => Delete::className(),
+ ],
+ ];
+ }
+
+ public function findModel($id)
+ {
+ $model = Comment::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 = Comment::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/controllers/QuestionController.php b/backend/controllers/QuestionController.php
new file mode 100644
index 0000000..a02749a
--- /dev/null
+++ b/backend/controllers/QuestionController.php
@@ -0,0 +1,145 @@
+ [
+ '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' => Question::className(),
+ 'hasLanguage' => false,
+ 'enableMassDelete' => true,
+ 'modelPrimaryKey' => 'id',
+ 'defaultSort' => [
+ 'created_at' => 'DESC',
+ ],
+ 'create' => false
+ ],
+ 'view' => [
+ 'class' => View::className(),
+ 'model' => Question::className(),
+ 'hasAlias' => false,
+ 'hasGallery' => false,
+ 'languageFields' => [
+ ],
+ 'fields' => [
+ [
+ 'name' => 'name',
+ 'type' => Form::STRING,
+ ],
+ [
+ 'name' => 'email',
+ 'type' => Form::STRING,
+ ],
+ [
+ 'name' => 'question',
+ 'type' => Form::TEXTAREA,
+ ],
+ [
+ 'name' => 'created_at',
+ 'type' => Form::STRING,
+ ],
+
+ ],
+ ],
+ 'delete' => [
+ 'class' => Delete::className(),
+ ],
+ ];
+ }
+
+ public function findModel($id)
+ {
+ $model = Question::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 = Question::find()
+ ->where(
+ [
+ 'id' => $id,
+ ]
+ )
+ ->one();
+
+ return $category->delete();
+ }
+
+ public function actionUpdate($id)
+ {
+ $model = $this->findModel($id);
+
+ $model->scenario = Question::SCENARIO_ANSWER;
+ 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/comment/_form.php b/backend/views/comment/_form.php
new file mode 100644
index 0000000..3b6ca38
--- /dev/null
+++ b/backend/views/comment/_form.php
@@ -0,0 +1,54 @@
+registerJs($js, View::POS_READY);
+?>
+
+
diff --git a/backend/views/comment/update.php b/backend/views/comment/update.php
new file mode 100644
index 0000000..0188871
--- /dev/null
+++ b/backend/views/comment/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',
+ ],
+ ]
+) ?>
+
+= $this->render(
+ '_form',
+ [
+ 'model' => $model,
+ ]
+) ?>
+
+
diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php
index edabbd4..7c46fd6 100755
--- a/backend/views/layouts/main.php
+++ b/backend/views/layouts/main.php
@@ -7,16 +7,13 @@
use artbox\core\assets\ArtboxCoreAsset;
use artbox\core\models\User;
- use artbox\core\models\UserData;
use artbox\core\widgets\FeedbackWidget;
use artbox\core\widgets\FlashWidget;
- use artbox\order\assets\OrderAsset;
- use noam148\imagemanager\components\ImageManagerGetPath;
use yii\bootstrap\Html;
+ use yii\helpers\Url;
use yii\web\View;
use yii\widgets\Breadcrumbs;
use yiister\gentelella\widgets\Menu;
- use backend\assets\AppAsset;
ArtboxCoreAsset::register($this);
// AppAsset::register($this);
@@ -169,6 +166,7 @@
= FeedbackWidget::widget(); ?>
+ Вопрос-ответ
diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php
index 0f9b6cf..e9a88a6 100755
--- a/backend/views/layouts/menu_items.php
+++ b/backend/views/layouts/menu_items.php
@@ -50,6 +50,11 @@
'url' => [ '/service/index' ],
],
+ [
+ 'label' => \Yii::t('app', 'Comments'),
+ 'url' => [ '/comment/index' ],
+
+ ],
],
],
diff --git a/backend/views/question/_form.php b/backend/views/question/_form.php
new file mode 100644
index 0000000..d1b8686
--- /dev/null
+++ b/backend/views/question/_form.php
@@ -0,0 +1,57 @@
+registerJs($js, View::POS_READY);
+?>
+
+
diff --git a/backend/views/question/update.php b/backend/views/question/update.php
new file mode 100644
index 0000000..b52dc90
--- /dev/null
+++ b/backend/views/question/update.php
@@ -0,0 +1,45 @@
+title = Yii::t(
+ 'app',
+ 'Update {modelClass}: ',
+ [
+ 'modelClass' => 'Question',
+ ]
+ ) . $model->name;
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => Yii::t('app', 'Questions'),
+ '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 question-update',
+ ],
+ ]
+) ?>
+
+= $this->render(
+ '_form',
+ [
+ 'model' => $model,
+ ]
+) ?>
+
+
diff --git a/common/models/Comment.php b/common/models/Comment.php
new file mode 100644
index 0000000..c18ec4b
--- /dev/null
+++ b/common/models/Comment.php
@@ -0,0 +1,59 @@
+ null],
+ [['service_id', 'created_at', 'updated_at'], 'integer'],
+ [['name', 'email'], 'string', 'max' => 255],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => Yii::t('app', 'ID'),
+ 'name' => Yii::t('app', 'Name'),
+ 'email' => Yii::t('app', 'Email'),
+ 'comment' => Yii::t('app', 'Comment'),
+ 'status' => Yii::t('app', 'Status'),
+ 'service_id' => Yii::t('app', 'Service ID'),
+ 'created_at' => Yii::t('app', 'Created At'),
+ 'updated_at' => Yii::t('app', 'Updated At'),
+ ];
+ }
+}
diff --git a/common/models/Question.php b/common/models/Question.php
new file mode 100644
index 0000000..96cc287
--- /dev/null
+++ b/common/models/Question.php
@@ -0,0 +1,142 @@
+ [
+ 'name',
+ 'email',
+ 'question',
+ ],
+ self::SCENARIO_ANSWER => [
+ 'answer',
+ 'status'
+ ],
+ ]
+ );
+ return $scenarios;
+ }
+ /**
+ * @inheritdoc
+ */
+ public function behaviors()
+ {
+ return [
+ [
+ 'class' => TimestampBehavior::className(),
+ ],
+ ];
+ }
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [
+ ['name', 'email', 'question'], 'required', 'on' => self::SCENARIO_QUESTION
+ ],
+ [
+ [ 'status' ],
+ 'boolean',
+ ],
+ [
+ [
+ 'service_id',
+ 'created_at',
+ 'updated_at',
+ ],
+ 'default',
+ 'value' => null,
+ ],
+ [
+ [
+ 'service_id',
+ 'created_at',
+ 'updated_at',
+ ],
+ 'integer',
+ ],
+ [
+ [
+ 'name',
+ 'email',
+
+ ],
+ 'string',
+ 'max' => 255,
+ ],
+ [
+ ['question', 'answer'], 'string'
+ ],
+ [
+ [ 'service_id' ],
+ 'exist',
+ 'skipOnError' => true,
+ 'targetClass' => Service::className(),
+ 'targetAttribute' => [ 'service_id' => 'id' ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => Yii::t('app', 'ID'),
+ 'name' => Yii::t('app', 'Name'),
+ 'email' => Yii::t('app', 'Email'),
+ 'question' => Yii::t('app', 'Question'),
+ 'status' => Yii::t('app', 'Status'),
+ 'service_id' => Yii::t('app', 'Service ID'),
+ 'created_at' => Yii::t('app', 'Created At'),
+ 'updated_at' => Yii::t('app', 'Updated At'),
+ ];
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getService()
+ {
+ return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]);
+ }
+ }
diff --git a/console/migrations/m180522_130149_create_question_table.php b/console/migrations/m180522_130149_create_question_table.php
new file mode 100644
index 0000000..2bff3e4
--- /dev/null
+++ b/console/migrations/m180522_130149_create_question_table.php
@@ -0,0 +1,45 @@
+createTable('question', [
+ 'id' => $this->primaryKey(),
+ 'name' => $this->string(),
+ 'email' => $this->string(),
+ 'question' => $this->text(),
+ 'answer' => $this->text(),
+ 'status' => $this->boolean(),
+ 'service_id' => $this->integer(),
+ 'created_at' => $this->integer(),
+ 'updated_at' => $this->integer(),
+
+ ]);
+
+ $this->addForeignKey('question_service_fk',
+ 'question',
+ 'service_id',
+ 'service',
+ 'id',
+ 'SET NULL',
+ 'CASCADE');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('question_service_fk', 'question');
+ $this->dropTable('question');
+ }
+}
diff --git a/console/migrations/m180523_094805_create_table_comment.php b/console/migrations/m180523_094805_create_table_comment.php
new file mode 100644
index 0000000..5647677
--- /dev/null
+++ b/console/migrations/m180523_094805_create_table_comment.php
@@ -0,0 +1,45 @@
+createTable('comment', [
+ 'id' => $this->primaryKey(),
+ 'name' => $this->string(),
+ 'email' => $this->string(),
+ 'comment' => $this->text(),
+ 'status' => $this->boolean(),
+ 'service_id' => $this->integer(),
+ 'created_at' => $this->integer(),
+ 'updated_at' => $this->integer(),
+
+ ]);
+
+ $this->addForeignKey('comment_service_fk',
+ 'question',
+ 'service_id',
+ 'service',
+ 'id',
+ 'SET NULL',
+ 'CASCADE');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('comment_service_fk', 'question');
+ $this->dropTable('comment');
+ }
+
+}
--
libgit2 0.21.4