Commit 6af5dbe35d72f985e334f84a5ebef45c0eb44fec
1 parent
ffda4a19
-Admin gallery ready
Showing
5 changed files
with
158 additions
and
8 deletions
Show diff stats
backend/controllers/SiteController.php
1 | <?php | 1 | <?php |
2 | namespace backend\controllers; | 2 | namespace backend\controllers; |
3 | - | 3 | + |
4 | + use common\models\Gallery; | ||
4 | use common\models\Settings; | 5 | use common\models\Settings; |
5 | use Yii; | 6 | use Yii; |
6 | use yii\web\Controller; | 7 | use yii\web\Controller; |
@@ -34,6 +35,7 @@ | @@ -34,6 +35,7 @@ | ||
34 | 'logout', | 35 | 'logout', |
35 | 'index', | 36 | 'index', |
36 | 'analytics', | 37 | 'analytics', |
38 | + 'gallery', | ||
37 | ], | 39 | ], |
38 | 'allow' => true, | 40 | 'allow' => true, |
39 | 'roles' => [ '@' ], | 41 | 'roles' => [ '@' ], |
@@ -49,7 +51,7 @@ | @@ -49,7 +51,7 @@ | ||
49 | ], | 51 | ], |
50 | ]; | 52 | ]; |
51 | } | 53 | } |
52 | - | 54 | + |
53 | /** | 55 | /** |
54 | * @inheritdoc | 56 | * @inheritdoc |
55 | */ | 57 | */ |
@@ -61,7 +63,7 @@ | @@ -61,7 +63,7 @@ | ||
61 | ], | 63 | ], |
62 | ]; | 64 | ]; |
63 | } | 65 | } |
64 | - | 66 | + |
65 | /** | 67 | /** |
66 | * Displays homepage. | 68 | * Displays homepage. |
67 | * | 69 | * |
@@ -70,14 +72,14 @@ | @@ -70,14 +72,14 @@ | ||
70 | public function actionIndex() | 72 | public function actionIndex() |
71 | { | 73 | { |
72 | $settings = Settings::getInstance(); | 74 | $settings = Settings::getInstance(); |
73 | - | 75 | + |
74 | if (empty($settings->analytics_key)) { | 76 | if (empty($settings->analytics_key)) { |
75 | return $this->render('instruction'); | 77 | return $this->render('instruction'); |
76 | } else { | 78 | } else { |
77 | return $this->render('index'); | 79 | return $this->render('index'); |
78 | } | 80 | } |
79 | } | 81 | } |
80 | - | 82 | + |
81 | /** | 83 | /** |
82 | * Login action. | 84 | * Login action. |
83 | * | 85 | * |
@@ -88,7 +90,7 @@ | @@ -88,7 +90,7 @@ | ||
88 | if (!Yii::$app->user->isGuest) { | 90 | if (!Yii::$app->user->isGuest) { |
89 | return $this->goHome(); | 91 | return $this->goHome(); |
90 | } | 92 | } |
91 | - | 93 | + |
92 | $model = new LoginForm(); | 94 | $model = new LoginForm(); |
93 | if ($model->load(Yii::$app->request->post()) && $model->login()) { | 95 | if ($model->load(Yii::$app->request->post()) && $model->login()) { |
94 | return $this->goBack(); | 96 | return $this->goBack(); |
@@ -101,7 +103,7 @@ | @@ -101,7 +103,7 @@ | ||
101 | ); | 103 | ); |
102 | } | 104 | } |
103 | } | 105 | } |
104 | - | 106 | + |
105 | /** | 107 | /** |
106 | * Logout action. | 108 | * Logout action. |
107 | * | 109 | * |
@@ -110,7 +112,25 @@ | @@ -110,7 +112,25 @@ | ||
110 | public function actionLogout() | 112 | public function actionLogout() |
111 | { | 113 | { |
112 | Yii::$app->user->logout(); | 114 | Yii::$app->user->logout(); |
113 | - | 115 | + |
114 | return $this->goHome(); | 116 | return $this->goHome(); |
115 | } | 117 | } |
118 | + | ||
119 | + public function actionGallery() | ||
120 | + { | ||
121 | + $model = new Gallery(); | ||
122 | + | ||
123 | + if (\Yii::$app->request->isPost) { | ||
124 | + $model->saveImages(\Yii::$app->request->post('images')); | ||
125 | + | ||
126 | + return $this->redirect([ 'site/index' ]); | ||
127 | + } | ||
128 | + | ||
129 | + return $this->render( | ||
130 | + 'gallery', | ||
131 | + [ | ||
132 | + 'model' => $model, | ||
133 | + ] | ||
134 | + ); | ||
135 | + } | ||
116 | } | 136 | } |
backend/views/layouts/menu_items.php
@@ -105,5 +105,10 @@ | @@ -105,5 +105,10 @@ | ||
105 | 'url' => [ '/comment' ], | 105 | 'url' => [ '/comment' ], |
106 | 'icon' => 'comment', | 106 | 'icon' => 'comment', |
107 | ], | 107 | ], |
108 | + [ | ||
109 | + 'label' => \Yii::t('app', 'Gallery'), | ||
110 | + 'url' => [ 'site/gallery' ], | ||
111 | + 'icon' => 'camera', | ||
112 | + ], | ||
108 | ] | 113 | ] |
109 | ); | 114 | ); |
110 | \ No newline at end of file | 115 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + use artbox\core\widgets\GalleryWidget; | ||
4 | + use common\models\Gallery; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + use yiister\gentelella\widgets\Panel; | ||
8 | + | ||
9 | + /** | ||
10 | + * @var View $this | ||
11 | + * @var Gallery $model | ||
12 | + */ | ||
13 | + | ||
14 | + Panel::begin( | ||
15 | + [ | ||
16 | + 'header' => 'Gallery', | ||
17 | + ] | ||
18 | + ); | ||
19 | + | ||
20 | + echo Html::beginForm(); | ||
21 | +?> | ||
22 | + | ||
23 | +<div class="row"> | ||
24 | + <?php | ||
25 | + echo GalleryWidget::widget( | ||
26 | + [ 'model' => $model, ] | ||
27 | + ); | ||
28 | + ?> | ||
29 | +</div> | ||
30 | +<div class="row"> | ||
31 | + <?= Html::submitButton( | ||
32 | + \Yii::t('app', 'Save'), | ||
33 | + [ | ||
34 | + 'class' => 'btn btn-lg btn-primary', | ||
35 | + ] | ||
36 | + ) ?> | ||
37 | +</div> | ||
38 | +<?php | ||
39 | + | ||
40 | + echo Html::endForm(); | ||
41 | + | ||
42 | + Panel::end(); | ||
43 | + | ||
44 | +?> | ||
45 | + | ||
46 | + | ||
0 | \ No newline at end of file | 47 | \ No newline at end of file |
1 | +<?php | ||
2 | + /** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: beer | ||
5 | + * Date: 28.09.17 | ||
6 | + * Time: 12:38 | ||
7 | + */ | ||
8 | + | ||
9 | + namespace common\models; | ||
10 | + | ||
11 | + use artbox\core\models\Image; | ||
12 | + | ||
13 | + /** | ||
14 | + * Stub class Gallery | ||
15 | + * for holding gallery | ||
16 | + * | ||
17 | + * @package common\models | ||
18 | + */ | ||
19 | + class Gallery | ||
20 | + { | ||
21 | + /** | ||
22 | + * @return array | ||
23 | + */ | ||
24 | + public function getImages(): array | ||
25 | + { | ||
26 | + return Image::find() | ||
27 | + ->where( | ||
28 | + [ | ||
29 | + 'gallery' => true, | ||
30 | + ] | ||
31 | + ) | ||
32 | + ->all(); | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * @param array $images | ||
37 | + */ | ||
38 | + public function saveImages(array $images) | ||
39 | + { | ||
40 | + if (empty($images)) { | ||
41 | + \Yii::$app->db->createCommand() | ||
42 | + ->update( | ||
43 | + 'ImageManager', | ||
44 | + [ | ||
45 | + 'gallery' => false, | ||
46 | + ], | ||
47 | + '1 = 1' | ||
48 | + ) | ||
49 | + ->execute(); | ||
50 | + } else { | ||
51 | + $condition = 'id IN (' . implode(',', $images) . ')'; | ||
52 | + \Yii::$app->db->createCommand() | ||
53 | + ->update( | ||
54 | + 'ImageManager', | ||
55 | + [ | ||
56 | + 'gallery' => true, | ||
57 | + ], | ||
58 | + $condition | ||
59 | + ) | ||
60 | + ->execute(); | ||
61 | + } | ||
62 | + } | ||
63 | + } | ||
0 | \ No newline at end of file | 64 | \ No newline at end of file |
console/migrations/m170928_095137_add_column_to_image_table.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | + use yii\db\Migration; | ||
4 | + | ||
5 | + class m170928_095137_add_column_to_image_table extends Migration | ||
6 | + { | ||
7 | + public function safeUp() | ||
8 | + { | ||
9 | + $this->addColumn('ImageManager', 'gallery', $this->boolean()); | ||
10 | + } | ||
11 | + | ||
12 | + public function safeDown() | ||
13 | + { | ||
14 | + $this->dropColumn('ImageManager', 'gallery'); | ||
15 | + } | ||
16 | + } |