Commit 8bc8795316f6549fba5ec641fc19856adbc52075
1 parent
6d62827f
- questions
- comments
Showing
12 changed files
with
788 additions
and
4 deletions
Show diff stats
1 | +<?php | ||
2 | + /** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: stes | ||
5 | + * Date: 23.05.18 | ||
6 | + * Time: 12:55 | ||
7 | + */ | ||
8 | + | ||
9 | + namespace backend\controllers; | ||
10 | + | ||
11 | + use artbox\core\admin\actions\Delete; | ||
12 | + use artbox\core\admin\actions\Index; | ||
13 | + use artbox\core\admin\actions\View; | ||
14 | + use artbox\core\admin\widgets\Form; | ||
15 | + use common\models\Comment; | ||
16 | + use yii\filters\AccessControl; | ||
17 | + use yii\filters\VerbFilter; | ||
18 | + use yii\web\Controller; | ||
19 | + use yii\web\NotFoundHttpException; | ||
20 | + | ||
21 | + class CommentController extends Controller | ||
22 | + { | ||
23 | + public function behaviors() | ||
24 | + { | ||
25 | + return [ | ||
26 | + 'verbs' => [ | ||
27 | + 'class' => VerbFilter::className(), | ||
28 | + 'actions' => [ | ||
29 | + 'delete' => [ 'POST' ], | ||
30 | + ], | ||
31 | + ], | ||
32 | + 'access' => [ | ||
33 | + 'class' => AccessControl::className(), | ||
34 | + 'rules' => [ | ||
35 | + [ | ||
36 | + 'allow' => true, | ||
37 | + 'roles' => [ '@' ], | ||
38 | + ], | ||
39 | + ], | ||
40 | + ], | ||
41 | + ]; | ||
42 | + } | ||
43 | + public function actions() | ||
44 | + { | ||
45 | + return [ | ||
46 | + 'index' => [ | ||
47 | + 'class' => Index::className(), | ||
48 | + 'columns' => [ | ||
49 | + 'name' => [ | ||
50 | + 'type' => Index::ACTION_COL, | ||
51 | + ], | ||
52 | + 'email' => [ | ||
53 | + 'type' => Index::STRING_COL | ||
54 | + ], | ||
55 | + 'status' => [ | ||
56 | + 'type' => Index::STATUS_COL, | ||
57 | + ], | ||
58 | + 'created_at' => [ | ||
59 | + 'type' => Index::DATETIME_COL, | ||
60 | + ] | ||
61 | + ], | ||
62 | + 'model' => Comment::className(), | ||
63 | + 'hasLanguage' => false, | ||
64 | + 'enableMassDelete' => true, | ||
65 | + 'modelPrimaryKey' => 'id', | ||
66 | + 'defaultSort' => [ | ||
67 | + 'created_at' => 'DESC', | ||
68 | + ], | ||
69 | + 'create' => false | ||
70 | + ], | ||
71 | + 'view' => [ | ||
72 | + 'class' => View::className(), | ||
73 | + 'model' => Comment::className(), | ||
74 | + 'hasAlias' => false, | ||
75 | + 'hasGallery' => false, | ||
76 | + 'languageFields' => [ | ||
77 | + ], | ||
78 | + 'fields' => [ | ||
79 | + [ | ||
80 | + 'name' => 'name', | ||
81 | + 'type' => Form::STRING, | ||
82 | + ], | ||
83 | + [ | ||
84 | + 'name' => 'email', | ||
85 | + 'type' => Form::STRING, | ||
86 | + ], | ||
87 | + [ | ||
88 | + 'name' => 'comment', | ||
89 | + 'type' => Form::TEXTAREA, | ||
90 | + ], | ||
91 | + [ | ||
92 | + 'name' => 'created_at', | ||
93 | + 'type' => Form::STRING, | ||
94 | + ], | ||
95 | + | ||
96 | + ], | ||
97 | + ], | ||
98 | + 'delete' => [ | ||
99 | + 'class' => Delete::className(), | ||
100 | + ], | ||
101 | + ]; | ||
102 | + } | ||
103 | + | ||
104 | + public function findModel($id) | ||
105 | + { | ||
106 | + $model = Comment::find() | ||
107 | + ->where([ 'id' => $id ]) | ||
108 | + ->one(); | ||
109 | + if ($model !== null) { | ||
110 | + return $model; | ||
111 | + } else { | ||
112 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
113 | + } | ||
114 | + } | ||
115 | + | ||
116 | + public function deleteModel($id) | ||
117 | + { | ||
118 | + $category = Comment::find() | ||
119 | + ->where( | ||
120 | + [ | ||
121 | + 'id' => $id, | ||
122 | + ] | ||
123 | + ) | ||
124 | + ->one(); | ||
125 | + | ||
126 | + return $category->delete(); | ||
127 | + } | ||
128 | + | ||
129 | + public function actionUpdate($id) | ||
130 | + { | ||
131 | + $model = $this->findModel($id); | ||
132 | + | ||
133 | + if ($model->load(\Yii::$app->request->post()) && $model->save()) { | ||
134 | + return $this->redirect('index'); | ||
135 | + } else { | ||
136 | + return $this->render( | ||
137 | + 'update', | ||
138 | + [ | ||
139 | + 'model' => $model, | ||
140 | + ] | ||
141 | + ); | ||
142 | + } | ||
143 | + } | ||
144 | + } | ||
0 | \ No newline at end of file | 145 | \ No newline at end of file |
1 | +<?php | ||
2 | + /** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: stes | ||
5 | + * Date: 22.05.18 | ||
6 | + * Time: 16:38 | ||
7 | + */ | ||
8 | + | ||
9 | + namespace backend\controllers; | ||
10 | + | ||
11 | + use artbox\core\admin\actions\Delete; | ||
12 | + use artbox\core\admin\actions\Index; | ||
13 | + use artbox\core\admin\actions\View; | ||
14 | + use artbox\core\admin\widgets\Form; | ||
15 | + use common\models\Question; | ||
16 | + use yii\filters\AccessControl; | ||
17 | + use yii\filters\VerbFilter; | ||
18 | + use yii\web\Controller; | ||
19 | + use yii\web\NotFoundHttpException; | ||
20 | + | ||
21 | + class QuestionController extends Controller | ||
22 | + { | ||
23 | + public function behaviors() | ||
24 | + { | ||
25 | + return [ | ||
26 | + 'verbs' => [ | ||
27 | + 'class' => VerbFilter::className(), | ||
28 | + 'actions' => [ | ||
29 | + 'delete' => [ 'POST' ], | ||
30 | + ], | ||
31 | + ], | ||
32 | + 'access' => [ | ||
33 | + 'class' => AccessControl::className(), | ||
34 | + 'rules' => [ | ||
35 | + [ | ||
36 | + 'allow' => true, | ||
37 | + 'roles' => [ '@' ], | ||
38 | + ], | ||
39 | + ], | ||
40 | + ], | ||
41 | + ]; | ||
42 | + } | ||
43 | + public function actions() | ||
44 | + { | ||
45 | + return [ | ||
46 | + 'index' => [ | ||
47 | + 'class' => Index::className(), | ||
48 | + 'columns' => [ | ||
49 | + 'name' => [ | ||
50 | + 'type' => Index::ACTION_COL, | ||
51 | + ], | ||
52 | + 'email' => [ | ||
53 | + 'type' => Index::STRING_COL | ||
54 | + ], | ||
55 | + 'status' => [ | ||
56 | + 'type' => Index::STATUS_COL, | ||
57 | + ], | ||
58 | + 'created_at' => [ | ||
59 | + 'type' => Index::DATETIME_COL, | ||
60 | + ] | ||
61 | + ], | ||
62 | + 'model' => Question::className(), | ||
63 | + 'hasLanguage' => false, | ||
64 | + 'enableMassDelete' => true, | ||
65 | + 'modelPrimaryKey' => 'id', | ||
66 | + 'defaultSort' => [ | ||
67 | + 'created_at' => 'DESC', | ||
68 | + ], | ||
69 | + 'create' => false | ||
70 | + ], | ||
71 | + 'view' => [ | ||
72 | + 'class' => View::className(), | ||
73 | + 'model' => Question::className(), | ||
74 | + 'hasAlias' => false, | ||
75 | + 'hasGallery' => false, | ||
76 | + 'languageFields' => [ | ||
77 | + ], | ||
78 | + 'fields' => [ | ||
79 | + [ | ||
80 | + 'name' => 'name', | ||
81 | + 'type' => Form::STRING, | ||
82 | + ], | ||
83 | + [ | ||
84 | + 'name' => 'email', | ||
85 | + 'type' => Form::STRING, | ||
86 | + ], | ||
87 | + [ | ||
88 | + 'name' => 'question', | ||
89 | + 'type' => Form::TEXTAREA, | ||
90 | + ], | ||
91 | + [ | ||
92 | + 'name' => 'created_at', | ||
93 | + 'type' => Form::STRING, | ||
94 | + ], | ||
95 | + | ||
96 | + ], | ||
97 | + ], | ||
98 | + 'delete' => [ | ||
99 | + 'class' => Delete::className(), | ||
100 | + ], | ||
101 | + ]; | ||
102 | + } | ||
103 | + | ||
104 | + public function findModel($id) | ||
105 | + { | ||
106 | + $model = Question::find() | ||
107 | + ->where([ 'id' => $id ]) | ||
108 | + ->one(); | ||
109 | + if ($model !== null) { | ||
110 | + return $model; | ||
111 | + } else { | ||
112 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
113 | + } | ||
114 | + } | ||
115 | + | ||
116 | + public function deleteModel($id) | ||
117 | + { | ||
118 | + $category = Question::find() | ||
119 | + ->where( | ||
120 | + [ | ||
121 | + 'id' => $id, | ||
122 | + ] | ||
123 | + ) | ||
124 | + ->one(); | ||
125 | + | ||
126 | + return $category->delete(); | ||
127 | + } | ||
128 | + | ||
129 | + public function actionUpdate($id) | ||
130 | + { | ||
131 | + $model = $this->findModel($id); | ||
132 | + | ||
133 | + $model->scenario = Question::SCENARIO_ANSWER; | ||
134 | + if ($model->load(\Yii::$app->request->post()) && $model->save()) { | ||
135 | + return $this->redirect('index'); | ||
136 | + } else { | ||
137 | + return $this->render( | ||
138 | + 'update', | ||
139 | + [ | ||
140 | + 'model' => $model, | ||
141 | + ] | ||
142 | + ); | ||
143 | + } | ||
144 | + } | ||
145 | + } | ||
0 | \ No newline at end of file | 146 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + use artbox\core\admin\assets\Switchery; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\web\View; | ||
6 | + use yii\widgets\ActiveForm; | ||
7 | + | ||
8 | + /* @var $this yii\web\View */ | ||
9 | + /* @var $model \common\models\Question */ | ||
10 | + /* @var $form yii\widgets\ActiveForm */ | ||
11 | + Switchery::register($this); | ||
12 | + $js = <<< JS | ||
13 | +$('.switchery').each(function(idx, elem) { | ||
14 | + new Switchery(elem, { | ||
15 | + color:'#46b749', | ||
16 | + secondaryColor:'#e2e2e2' | ||
17 | + }); | ||
18 | +}); | ||
19 | +JS; | ||
20 | + | ||
21 | + | ||
22 | + $this->registerJs($js, View::POS_READY); | ||
23 | +?> | ||
24 | + | ||
25 | +<div class="feedback-form"> | ||
26 | + | ||
27 | + <?php $form = ActiveForm::begin(); ?> | ||
28 | + | ||
29 | + <?= $form->field($model, 'name') | ||
30 | + ->textInput([ 'maxlength' => true ]) ?> | ||
31 | + | ||
32 | + <?= $form->field($model, 'email') | ||
33 | + ->textInput([ 'maxlength' => true ]) ?> | ||
34 | + | ||
35 | + <?= $form->field($model, 'comment') | ||
36 | + ->textarea([ 'rows' => 6 ]) ?> | ||
37 | + | ||
38 | + <?= $form->field($model, 'status') | ||
39 | + ->checkbox( | ||
40 | + [ | ||
41 | + 'class' => 'switchery', | ||
42 | + ] | ||
43 | + ) ?> | ||
44 | + | ||
45 | + <div class="form-group"> | ||
46 | + <?= Html::submitButton( | ||
47 | + $model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), | ||
48 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
49 | + ) ?> | ||
50 | + </div> | ||
51 | + | ||
52 | + <?php ActiveForm::end(); ?> | ||
53 | + | ||
54 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use yiister\gentelella\widgets\Panel; | ||
4 | + | ||
5 | + /* @var $this yii\web\View */ | ||
6 | + /* @var $model \common\models\Comment */ | ||
7 | + | ||
8 | + $this->title = Yii::t( | ||
9 | + 'app', | ||
10 | + 'Update {modelClass}: ', | ||
11 | + [ | ||
12 | + 'modelClass' => 'Comment', | ||
13 | + ] | ||
14 | + ) . $model->name; | ||
15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
16 | + 'label' => Yii::t('app', 'Comments'), | ||
17 | + 'url' => [ 'index' ], | ||
18 | + ]; | ||
19 | + $this->params[ 'breadcrumbs' ][] = [ | ||
20 | + 'label' => $model->name, | ||
21 | + 'url' => [ | ||
22 | + 'view', | ||
23 | + 'id' => $model->id, | ||
24 | + ], | ||
25 | + ]; | ||
26 | + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); | ||
27 | +?> | ||
28 | + | ||
29 | +<?php $panel = Panel::begin( | ||
30 | + [ | ||
31 | + 'header' => $this->title, | ||
32 | + 'options' => [ | ||
33 | + 'class' => 'x_panel comment-update', | ||
34 | + ], | ||
35 | + ] | ||
36 | +) ?> | ||
37 | + | ||
38 | +<?= $this->render( | ||
39 | + '_form', | ||
40 | + [ | ||
41 | + 'model' => $model, | ||
42 | + ] | ||
43 | +) ?> | ||
44 | + | ||
45 | +<?php $panel::end(); ?> |
backend/views/layouts/main.php
@@ -7,16 +7,13 @@ | @@ -7,16 +7,13 @@ | ||
7 | 7 | ||
8 | use artbox\core\assets\ArtboxCoreAsset; | 8 | use artbox\core\assets\ArtboxCoreAsset; |
9 | use artbox\core\models\User; | 9 | use artbox\core\models\User; |
10 | - use artbox\core\models\UserData; | ||
11 | use artbox\core\widgets\FeedbackWidget; | 10 | use artbox\core\widgets\FeedbackWidget; |
12 | use artbox\core\widgets\FlashWidget; | 11 | use artbox\core\widgets\FlashWidget; |
13 | - use artbox\order\assets\OrderAsset; | ||
14 | - use noam148\imagemanager\components\ImageManagerGetPath; | ||
15 | use yii\bootstrap\Html; | 12 | use yii\bootstrap\Html; |
13 | + use yii\helpers\Url; | ||
16 | use yii\web\View; | 14 | use yii\web\View; |
17 | use yii\widgets\Breadcrumbs; | 15 | use yii\widgets\Breadcrumbs; |
18 | use yiister\gentelella\widgets\Menu; | 16 | use yiister\gentelella\widgets\Menu; |
19 | - use backend\assets\AppAsset; | ||
20 | 17 | ||
21 | ArtboxCoreAsset::register($this); | 18 | ArtboxCoreAsset::register($this); |
22 | // AppAsset::register($this); | 19 | // AppAsset::register($this); |
@@ -169,6 +166,7 @@ | @@ -169,6 +166,7 @@ | ||
169 | <li role="presentation"> | 166 | <li role="presentation"> |
170 | <?= FeedbackWidget::widget(); ?> | 167 | <?= FeedbackWidget::widget(); ?> |
171 | </li> | 168 | </li> |
169 | + <li><a href="<?=Url::to(['/question'])?>">Вопрос-ответ</a></li> | ||
172 | </ul> | 170 | </ul> |
173 | </nav> | 171 | </nav> |
174 | </div> | 172 | </div> |
backend/views/layouts/menu_items.php
1 | +<?php | ||
2 | + | ||
3 | + use artbox\core\admin\assets\Switchery; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\web\View; | ||
6 | + use yii\widgets\ActiveForm; | ||
7 | + | ||
8 | + /* @var $this yii\web\View */ | ||
9 | + /* @var $model \common\models\Question */ | ||
10 | + /* @var $form yii\widgets\ActiveForm */ | ||
11 | + Switchery::register($this); | ||
12 | + $js = <<< JS | ||
13 | +$('.switchery').each(function(idx, elem) { | ||
14 | + new Switchery(elem, { | ||
15 | + color:'#46b749', | ||
16 | + secondaryColor:'#e2e2e2' | ||
17 | + }); | ||
18 | +}); | ||
19 | +JS; | ||
20 | + | ||
21 | + | ||
22 | + $this->registerJs($js, View::POS_READY); | ||
23 | +?> | ||
24 | + | ||
25 | +<div class="feedback-form"> | ||
26 | + | ||
27 | + <?php $form = ActiveForm::begin(); ?> | ||
28 | + | ||
29 | + <?= $form->field($model, 'name') | ||
30 | + ->textInput([ 'maxlength' => true ]) ?> | ||
31 | + | ||
32 | + <?= $form->field($model, 'email') | ||
33 | + ->textInput([ 'maxlength' => true ]) ?> | ||
34 | + | ||
35 | + <?= $form->field($model, 'question') | ||
36 | + ->textarea([ 'rows' => 6 ]) ?> | ||
37 | + | ||
38 | + <?= $form->field($model, 'answer') | ||
39 | + ->textarea([ 'rows' => 6 ]) ?> | ||
40 | + | ||
41 | + <?= $form->field($model, 'status') | ||
42 | + ->checkbox( | ||
43 | + [ | ||
44 | + 'class' => 'switchery', | ||
45 | + ] | ||
46 | + ) ?> | ||
47 | + | ||
48 | + <div class="form-group"> | ||
49 | + <?= Html::submitButton( | ||
50 | + $model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), | ||
51 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
52 | + ) ?> | ||
53 | + </div> | ||
54 | + | ||
55 | + <?php ActiveForm::end(); ?> | ||
56 | + | ||
57 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use yiister\gentelella\widgets\Panel; | ||
4 | + | ||
5 | + /* @var $this yii\web\View */ | ||
6 | + /* @var $model \common\models\Question */ | ||
7 | + | ||
8 | + $this->title = Yii::t( | ||
9 | + 'app', | ||
10 | + 'Update {modelClass}: ', | ||
11 | + [ | ||
12 | + 'modelClass' => 'Question', | ||
13 | + ] | ||
14 | + ) . $model->name; | ||
15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
16 | + 'label' => Yii::t('app', 'Questions'), | ||
17 | + 'url' => [ 'index' ], | ||
18 | + ]; | ||
19 | + $this->params[ 'breadcrumbs' ][] = [ | ||
20 | + 'label' => $model->name, | ||
21 | + 'url' => [ | ||
22 | + 'view', | ||
23 | + 'id' => $model->id, | ||
24 | + ], | ||
25 | + ]; | ||
26 | + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); | ||
27 | +?> | ||
28 | + | ||
29 | +<?php $panel = Panel::begin( | ||
30 | + [ | ||
31 | + 'header' => $this->title, | ||
32 | + 'options' => [ | ||
33 | + 'class' => 'x_panel question-update', | ||
34 | + ], | ||
35 | + ] | ||
36 | +) ?> | ||
37 | + | ||
38 | +<?= $this->render( | ||
39 | + '_form', | ||
40 | + [ | ||
41 | + 'model' => $model, | ||
42 | + ] | ||
43 | +) ?> | ||
44 | + | ||
45 | +<?php $panel::end(); ?> |
1 | +<?php | ||
2 | + | ||
3 | +namespace common\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "comment". | ||
9 | + * | ||
10 | + * @property int $id | ||
11 | + * @property string $name | ||
12 | + * @property string $email | ||
13 | + * @property string $comment | ||
14 | + * @property bool $status | ||
15 | + * @property int $service_id | ||
16 | + * @property int $created_at | ||
17 | + * @property int $updated_at | ||
18 | + */ | ||
19 | +class Comment extends \yii\db\ActiveRecord | ||
20 | +{ | ||
21 | + /** | ||
22 | + * {@inheritdoc} | ||
23 | + */ | ||
24 | + public static function tableName() | ||
25 | + { | ||
26 | + return 'comment'; | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * {@inheritdoc} | ||
31 | + */ | ||
32 | + public function rules() | ||
33 | + { | ||
34 | + return [ | ||
35 | + [['comment'], 'string'], | ||
36 | + [['status'], 'boolean'], | ||
37 | + [['service_id', 'created_at', 'updated_at'], 'default', 'value' => null], | ||
38 | + [['service_id', 'created_at', 'updated_at'], 'integer'], | ||
39 | + [['name', 'email'], 'string', 'max' => 255], | ||
40 | + ]; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * {@inheritdoc} | ||
45 | + */ | ||
46 | + public function attributeLabels() | ||
47 | + { | ||
48 | + return [ | ||
49 | + 'id' => Yii::t('app', 'ID'), | ||
50 | + 'name' => Yii::t('app', 'Name'), | ||
51 | + 'email' => Yii::t('app', 'Email'), | ||
52 | + 'comment' => Yii::t('app', 'Comment'), | ||
53 | + 'status' => Yii::t('app', 'Status'), | ||
54 | + 'service_id' => Yii::t('app', 'Service ID'), | ||
55 | + 'created_at' => Yii::t('app', 'Created At'), | ||
56 | + 'updated_at' => Yii::t('app', 'Updated At'), | ||
57 | + ]; | ||
58 | + } | ||
59 | +} |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use yii\behaviors\TimestampBehavior; | ||
7 | + | ||
8 | + /** | ||
9 | + * This is the model class for table "question". | ||
10 | + * | ||
11 | + * @property int $id | ||
12 | + * @property string $name | ||
13 | + * @property string $email | ||
14 | + * @property string $question | ||
15 | + * @property bool $status | ||
16 | + * @property int $service_id | ||
17 | + * @property int $created_at | ||
18 | + * @property int $updated_at | ||
19 | + * @property Service $service | ||
20 | + */ | ||
21 | + class Question extends \yii\db\ActiveRecord | ||
22 | + { | ||
23 | + const SCENARIO_QUESTION = 'question'; | ||
24 | + const SCENARIO_ANSWER = 'answer'; | ||
25 | + /** | ||
26 | + * {@inheritdoc} | ||
27 | + */ | ||
28 | + public static function tableName() | ||
29 | + { | ||
30 | + return 'question'; | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * @inheritdoc | ||
35 | + */ | ||
36 | + public function scenarios() | ||
37 | + { | ||
38 | + $scenarios = parent::scenarios(); | ||
39 | + $scenarios = array_merge( | ||
40 | + $scenarios, | ||
41 | + [ | ||
42 | + self::SCENARIO_QUESTION => [ | ||
43 | + 'name', | ||
44 | + 'email', | ||
45 | + 'question', | ||
46 | + ], | ||
47 | + self::SCENARIO_ANSWER => [ | ||
48 | + 'answer', | ||
49 | + 'status' | ||
50 | + ], | ||
51 | + ] | ||
52 | + ); | ||
53 | + return $scenarios; | ||
54 | + } | ||
55 | + /** | ||
56 | + * @inheritdoc | ||
57 | + */ | ||
58 | + public function behaviors() | ||
59 | + { | ||
60 | + return [ | ||
61 | + [ | ||
62 | + 'class' => TimestampBehavior::className(), | ||
63 | + ], | ||
64 | + ]; | ||
65 | + } | ||
66 | + /** | ||
67 | + * {@inheritdoc} | ||
68 | + */ | ||
69 | + public function rules() | ||
70 | + { | ||
71 | + return [ | ||
72 | + [ | ||
73 | + ['name', 'email', 'question'], 'required', 'on' => self::SCENARIO_QUESTION | ||
74 | + ], | ||
75 | + [ | ||
76 | + [ 'status' ], | ||
77 | + 'boolean', | ||
78 | + ], | ||
79 | + [ | ||
80 | + [ | ||
81 | + 'service_id', | ||
82 | + 'created_at', | ||
83 | + 'updated_at', | ||
84 | + ], | ||
85 | + 'default', | ||
86 | + 'value' => null, | ||
87 | + ], | ||
88 | + [ | ||
89 | + [ | ||
90 | + 'service_id', | ||
91 | + 'created_at', | ||
92 | + 'updated_at', | ||
93 | + ], | ||
94 | + 'integer', | ||
95 | + ], | ||
96 | + [ | ||
97 | + [ | ||
98 | + 'name', | ||
99 | + 'email', | ||
100 | + | ||
101 | + ], | ||
102 | + 'string', | ||
103 | + 'max' => 255, | ||
104 | + ], | ||
105 | + [ | ||
106 | + ['question', 'answer'], 'string' | ||
107 | + ], | ||
108 | + [ | ||
109 | + [ 'service_id' ], | ||
110 | + 'exist', | ||
111 | + 'skipOnError' => true, | ||
112 | + 'targetClass' => Service::className(), | ||
113 | + 'targetAttribute' => [ 'service_id' => 'id' ], | ||
114 | + ], | ||
115 | + ]; | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * {@inheritdoc} | ||
120 | + */ | ||
121 | + public function attributeLabels() | ||
122 | + { | ||
123 | + return [ | ||
124 | + 'id' => Yii::t('app', 'ID'), | ||
125 | + 'name' => Yii::t('app', 'Name'), | ||
126 | + 'email' => Yii::t('app', 'Email'), | ||
127 | + 'question' => Yii::t('app', 'Question'), | ||
128 | + 'status' => Yii::t('app', 'Status'), | ||
129 | + 'service_id' => Yii::t('app', 'Service ID'), | ||
130 | + 'created_at' => Yii::t('app', 'Created At'), | ||
131 | + 'updated_at' => Yii::t('app', 'Updated At'), | ||
132 | + ]; | ||
133 | + } | ||
134 | + | ||
135 | + /** | ||
136 | + * @return \yii\db\ActiveQuery | ||
137 | + */ | ||
138 | + public function getService() | ||
139 | + { | ||
140 | + return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]); | ||
141 | + } | ||
142 | + } |
console/migrations/m180522_130149_create_question_table.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +/** | ||
6 | + * Handles the creation of table `question`. | ||
7 | + */ | ||
8 | +class m180522_130149_create_question_table extends Migration | ||
9 | +{ | ||
10 | + /** | ||
11 | + * {@inheritdoc} | ||
12 | + */ | ||
13 | + public function safeUp() | ||
14 | + { | ||
15 | + $this->createTable('question', [ | ||
16 | + 'id' => $this->primaryKey(), | ||
17 | + 'name' => $this->string(), | ||
18 | + 'email' => $this->string(), | ||
19 | + 'question' => $this->text(), | ||
20 | + 'answer' => $this->text(), | ||
21 | + 'status' => $this->boolean(), | ||
22 | + 'service_id' => $this->integer(), | ||
23 | + 'created_at' => $this->integer(), | ||
24 | + 'updated_at' => $this->integer(), | ||
25 | + | ||
26 | + ]); | ||
27 | + | ||
28 | + $this->addForeignKey('question_service_fk', | ||
29 | + 'question', | ||
30 | + 'service_id', | ||
31 | + 'service', | ||
32 | + 'id', | ||
33 | + 'SET NULL', | ||
34 | + 'CASCADE'); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * {@inheritdoc} | ||
39 | + */ | ||
40 | + public function safeDown() | ||
41 | + { | ||
42 | + $this->dropForeignKey('question_service_fk', 'question'); | ||
43 | + $this->dropTable('question'); | ||
44 | + } | ||
45 | +} |
console/migrations/m180523_094805_create_table_comment.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +/** | ||
6 | + * Class m180523_094805_create_table_comment | ||
7 | + */ | ||
8 | +class m180523_094805_create_table_comment extends Migration | ||
9 | +{ | ||
10 | + /** | ||
11 | + * {@inheritdoc} | ||
12 | + */ | ||
13 | + public function safeUp() | ||
14 | + { | ||
15 | + $this->createTable('comment', [ | ||
16 | + 'id' => $this->primaryKey(), | ||
17 | + 'name' => $this->string(), | ||
18 | + 'email' => $this->string(), | ||
19 | + 'comment' => $this->text(), | ||
20 | + 'status' => $this->boolean(), | ||
21 | + 'service_id' => $this->integer(), | ||
22 | + 'created_at' => $this->integer(), | ||
23 | + 'updated_at' => $this->integer(), | ||
24 | + | ||
25 | + ]); | ||
26 | + | ||
27 | + $this->addForeignKey('comment_service_fk', | ||
28 | + 'question', | ||
29 | + 'service_id', | ||
30 | + 'service', | ||
31 | + 'id', | ||
32 | + 'SET NULL', | ||
33 | + 'CASCADE'); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * {@inheritdoc} | ||
38 | + */ | ||
39 | + public function safeDown() | ||
40 | + { | ||
41 | + $this->dropForeignKey('comment_service_fk', 'question'); | ||
42 | + $this->dropTable('comment'); | ||
43 | + } | ||
44 | + | ||
45 | +} |