diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index 5a51140..872d76d 100755 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -1,6 +1,7 @@ true, 'roles' => [ '@' ], @@ -49,7 +51,7 @@ ], ]; } - + /** * @inheritdoc */ @@ -61,7 +63,7 @@ ], ]; } - + /** * Displays homepage. * @@ -70,14 +72,14 @@ public function actionIndex() { $settings = Settings::getInstance(); - + if (empty($settings->analytics_key)) { return $this->render('instruction'); } else { return $this->render('index'); } } - + /** * Login action. * @@ -88,7 +90,7 @@ if (!Yii::$app->user->isGuest) { return $this->goHome(); } - + $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); @@ -101,7 +103,7 @@ ); } } - + /** * Logout action. * @@ -110,7 +112,25 @@ public function actionLogout() { Yii::$app->user->logout(); - + return $this->goHome(); } + + public function actionGallery() + { + $model = new Gallery(); + + if (\Yii::$app->request->isPost) { + $model->saveImages(\Yii::$app->request->post('images')); + + return $this->redirect([ 'site/index' ]); + } + + return $this->render( + 'gallery', + [ + 'model' => $model, + ] + ); + } } diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index 886c67e..d99806c 100755 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -105,5 +105,10 @@ 'url' => [ '/comment' ], 'icon' => 'comment', ], + [ + 'label' => \Yii::t('app', 'Gallery'), + 'url' => [ 'site/gallery' ], + 'icon' => 'camera', + ], ] ); \ No newline at end of file diff --git a/backend/views/site/gallery.php b/backend/views/site/gallery.php new file mode 100644 index 0000000..a32a185 --- /dev/null +++ b/backend/views/site/gallery.php @@ -0,0 +1,46 @@ + 'Gallery', + ] + ); + + echo Html::beginForm(); +?> + +
+ $model, ] + ); + ?> +
+
+ 'btn btn-lg btn-primary', + ] + ) ?> +
+ + + \ No newline at end of file diff --git a/common/models/Gallery.php b/common/models/Gallery.php new file mode 100644 index 0000000..b5bba74 --- /dev/null +++ b/common/models/Gallery.php @@ -0,0 +1,63 @@ +where( + [ + 'gallery' => true, + ] + ) + ->all(); + } + + /** + * @param array $images + */ + public function saveImages(array $images) + { + if (empty($images)) { + \Yii::$app->db->createCommand() + ->update( + 'ImageManager', + [ + 'gallery' => false, + ], + '1 = 1' + ) + ->execute(); + } else { + $condition = 'id IN (' . implode(',', $images) . ')'; + \Yii::$app->db->createCommand() + ->update( + 'ImageManager', + [ + 'gallery' => true, + ], + $condition + ) + ->execute(); + } + } + } \ No newline at end of file diff --git a/console/migrations/m170928_095137_add_column_to_image_table.php b/console/migrations/m170928_095137_add_column_to_image_table.php new file mode 100644 index 0000000..aede72d --- /dev/null +++ b/console/migrations/m170928_095137_add_column_to_image_table.php @@ -0,0 +1,16 @@ +addColumn('ImageManager', 'gallery', $this->boolean()); + } + + public function safeDown() + { + $this->dropColumn('ImageManager', 'gallery'); + } + } -- libgit2 0.21.4