Commit f44b09d4b36c3f48abae5d554b9e7400e5c1710e
1 parent
5531f04d
- add support
- main page book limit 2
Showing
7 changed files
with
309 additions
and
2 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 common\models\Support; | |
17 | + use yii\filters\AccessControl; | |
18 | + use yii\filters\VerbFilter; | |
19 | + use yii\web\Controller; | |
20 | + use yii\web\NotFoundHttpException; | |
21 | + | |
22 | + class SupportController extends Controller | |
23 | + { | |
24 | + public function behaviors() | |
25 | + { | |
26 | + return [ | |
27 | + 'verbs' => [ | |
28 | + 'class' => VerbFilter::className(), | |
29 | + 'actions' => [ | |
30 | + 'delete' => [ 'POST' ], | |
31 | + ], | |
32 | + ], | |
33 | + 'access' => [ | |
34 | + 'class' => AccessControl::className(), | |
35 | + 'rules' => [ | |
36 | + [ | |
37 | + 'allow' => true, | |
38 | + 'roles' => [ '@' ], | |
39 | + ], | |
40 | + ], | |
41 | + ], | |
42 | + ]; | |
43 | + } | |
44 | + public function actions() | |
45 | + { | |
46 | + return [ | |
47 | + 'index' => [ | |
48 | + 'class' => Index::className(), | |
49 | + 'columns' => [ | |
50 | + 'name' => [ | |
51 | + 'type' => Index::ACTION_COL, | |
52 | + ], | |
53 | + 'email' => [ | |
54 | + 'type' => Index::STRING_COL | |
55 | + ], | |
56 | + 'status' => [ | |
57 | + 'type' => Index::STATUS_COL, | |
58 | + ], | |
59 | + 'created_at' => [ | |
60 | + 'type' => Index::DATETIME_COL, | |
61 | + ] | |
62 | + ], | |
63 | + 'model' => Support::className(), | |
64 | + 'hasLanguage' => false, | |
65 | + 'enableMassDelete' => true, | |
66 | + 'modelPrimaryKey' => 'id', | |
67 | + 'defaultSort' => [ | |
68 | + 'created_at' => 'DESC', | |
69 | + ], | |
70 | + 'create' => false | |
71 | + ], | |
72 | + 'view' => [ | |
73 | + 'class' => View::className(), | |
74 | + 'model' => Support::className(), | |
75 | + 'hasAlias' => false, | |
76 | + 'hasGallery' => false, | |
77 | + 'languageFields' => [ | |
78 | + ], | |
79 | + 'fields' => [ | |
80 | + [ | |
81 | + 'name' => 'name', | |
82 | + 'type' => Form::STRING, | |
83 | + ], | |
84 | + [ | |
85 | + 'name' => 'email', | |
86 | + 'type' => Form::STRING, | |
87 | + ], | |
88 | + [ | |
89 | + 'name' => 'sum', | |
90 | + 'type' => Form::STRING, | |
91 | + ], | |
92 | + [ | |
93 | + 'name' => 'created_at', | |
94 | + 'type' => Form::STRING, | |
95 | + ], | |
96 | + | |
97 | + ], | |
98 | + ], | |
99 | + 'delete' => [ | |
100 | + 'class' => Delete::className(), | |
101 | + ], | |
102 | + ]; | |
103 | + } | |
104 | + | |
105 | + public function findModel($id) | |
106 | + { | |
107 | + | |
108 | + $model = Support::find() | |
109 | + ->where([ 'id' => $id ]) | |
110 | + ->one(); | |
111 | + if ($model !== null) { | |
112 | + return $model; | |
113 | + } else { | |
114 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + public function deleteModel($id) | |
119 | + { | |
120 | + $category = Support::find() | |
121 | + ->where( | |
122 | + [ | |
123 | + 'id' => $id, | |
124 | + ] | |
125 | + ) | |
126 | + ->one(); | |
127 | + | |
128 | + | |
129 | + return $category->delete(); | |
130 | + } | |
131 | + | |
132 | + public function actionUpdate($id) | |
133 | + { | |
134 | + $model = $this->findModel($id); | |
135 | + if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |
136 | + return $this->redirect('index'); | |
137 | + } else { | |
138 | + return $this->render( | |
139 | + 'update', | |
140 | + [ | |
141 | + 'model' => $model, | |
142 | + ] | |
143 | + ); | |
144 | + } | |
145 | + } | |
146 | + } | |
0 | 147 | \ No newline at end of file | ... | ... |
backend/views/layouts/menu_items.php
1 | +<?php | |
2 | + | |
3 | + use artbox\core\admin\assets\Select2; | |
4 | + use artbox\core\admin\assets\Switchery; | |
5 | + use yii\helpers\Html; | |
6 | + use yii\web\View; | |
7 | + use yii\widgets\ActiveForm; | |
8 | + | |
9 | + /* @var $this yii\web\View */ | |
10 | + /* @var $model \common\models\Comment */ | |
11 | + /* @var $form yii\widgets\ActiveForm */ | |
12 | + Switchery::register($this); | |
13 | + $js = <<< JS | |
14 | +$('.switchery').each(function(idx, elem) { | |
15 | + new Switchery(elem, { | |
16 | + color:'#46b749', | |
17 | + secondaryColor:'#e2e2e2' | |
18 | + }); | |
19 | +}); | |
20 | + | |
21 | +$(".select_service").select2(); | |
22 | +JS; | |
23 | + | |
24 | + Select2::register($this); | |
25 | + $this->registerJs($js, View::POS_READY); | |
26 | + | |
27 | +?> | |
28 | + | |
29 | +<div class="feedback-form"> | |
30 | + | |
31 | + <?php $form = ActiveForm::begin(); ?> | |
32 | + <?=$model->book->title?> | |
33 | + | |
34 | + <?= $form->field($model, 'name') | |
35 | + ->textInput([ 'maxlength' => true ]) ?> | |
36 | + | |
37 | + <?= $form->field($model, 'email') | |
38 | + ->textInput([ 'maxlength' => true ]) ?> | |
39 | + | |
40 | + <?= $form->field($model, 'sum') | |
41 | + ->textInput() ?> | |
42 | + | |
43 | + <?= $form->field($model, 'status') | |
44 | + ->checkbox( | |
45 | + [ | |
46 | + 'class' => 'switchery', | |
47 | + ] | |
48 | + ) ?> | |
49 | + | |
50 | + <div class="form-group"> | |
51 | + <?= Html::submitButton( | |
52 | + $model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), | |
53 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
54 | + ) ?> | |
55 | + </div> | |
56 | + | |
57 | + <?php ActiveForm::end(); ?> | |
58 | + | |
59 | +</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(); ?> | ... | ... |
common/models/Support.php
... | ... | @@ -3,7 +3,8 @@ |
3 | 3 | namespace common\models; |
4 | 4 | |
5 | 5 | use Yii; |
6 | - | |
6 | + use yii\behaviors\TimestampBehavior; | |
7 | + | |
7 | 8 | /** |
8 | 9 | * This is the model class for table "support". |
9 | 10 | * |
... | ... | @@ -24,6 +25,17 @@ |
24 | 25 | return 'support'; |
25 | 26 | } |
26 | 27 | |
28 | + public function behaviors() | |
29 | + { | |
30 | + return [ | |
31 | + [ | |
32 | + 'class' => TimestampBehavior::className(), | |
33 | + 'updatedAtAttribute' => false, | |
34 | + ], | |
35 | + ]; | |
36 | + | |
37 | + } | |
38 | + | |
27 | 39 | /** |
28 | 40 | * {@inheritdoc} |
29 | 41 | */ | ... | ... |
console/migrations/m180620_100416_alter_table_support.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +/** | |
6 | + * Class m180620_100416_alter_table_support | |
7 | + */ | |
8 | +class m180620_100416_alter_table_support extends Migration | |
9 | +{ | |
10 | + /** | |
11 | + * {@inheritdoc} | |
12 | + */ | |
13 | + public function safeUp() | |
14 | + { | |
15 | + $this->addColumn('support', 'created_at', $this->integer()); | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * {@inheritdoc} | |
20 | + */ | |
21 | + public function safeDown() | |
22 | + { | |
23 | + $this->dropColumn('support', 'created_at'); | |
24 | + } | |
25 | + | |
26 | + /* | |
27 | + // Use up()/down() to run migration code without a transaction. | |
28 | + public function up() | |
29 | + { | |
30 | + | |
31 | + } | |
32 | + | |
33 | + public function down() | |
34 | + { | |
35 | + echo "m180620_100416_alter_table_support cannot be reverted.\n"; | |
36 | + | |
37 | + return false; | |
38 | + } | |
39 | + */ | |
40 | +} | ... | ... |
frontend/controllers/SiteController.php
... | ... | @@ -54,7 +54,7 @@ |
54 | 54 | */ |
55 | 55 | public function actionIndex() |
56 | 56 | { |
57 | - $books = Book::find()->where(['status' => Book::STATUS_ACTIVE])->andWhere(['on_main' => true])->all(); | |
57 | + $books = Book::find()->where(['status' => Book::STATUS_ACTIVE])->andWhere(['on_main' => true])->limit(2)->all(); | |
58 | 58 | $articles = Article::find() |
59 | 59 | ->with('language') |
60 | 60 | ->where([ 'status' => true ]) | ... | ... |