From c8500c2f244373c70c43efe45d113ad9d40d49d2 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Mar 2017 18:15:14 +0200 Subject: [PATCH] -Analytics in process --- backend/config/main.php | 1 - backend/controllers/SettingsController.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/controllers/SiteController.php | 28 ++++++++++++++++------------ backend/views/settings/settings.php | 10 +++------- backend/views/site/analytics.php | 4 ++-- backend/views/site/index.php | 35 ++++++++++++++++++++++++++++++----- common/config/settings.php | 8 ++++---- 7 files changed, 141 insertions(+), 31 deletions(-) create mode 100755 backend/controllers/SettingsController.php mode change 100644 => 100755 common/config/settings.php diff --git a/backend/config/main.php b/backend/config/main.php index 8518676..1995c18 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -15,7 +15,6 @@ 'controllerNamespace' => 'backend\controllers', 'bootstrap' => [ 'log' ], 'controllerMap' => [ - 'settings' => 'artbox\core\controllers\SettingsController', 'profile' => 'artbox\core\controllers\ProfileController', 'page' => 'artbox\core\controllers\PageController', 'seo' => 'artbox\core\controllers\AliasController', diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php new file mode 100755 index 0000000..b0a0f9c --- /dev/null +++ b/backend/controllers/SettingsController.php @@ -0,0 +1,86 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'actions' => [ + 'logout', + 'index', + ], + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + + /** + * Display site settings page + * + * @return string|\yii\web\Response + */ + public function actionIndex() + { + $model = $this->findSettings(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + Yii::$app->session->setFlash('success', 'Settings saved'); + + return $this->goHome(); + } + + return $this->render( + 'settings', + [ + 'model' => $model, + ] + ); + } + + /** + * Find site settings + * + * @return \yii2tech\filedb\ActiveRecord + * @throws \yii\base\InvalidConfigException + */ + public function findSettings() + { + if ($model = Settings::find() + ->one() + ) { + return $model; + } else { + throw new InvalidConfigException('Settings file not found'); + } + } + } + \ No newline at end of file diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index 7b274cb..413dba4 100755 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -70,19 +70,23 @@ public function actionIndex() { $settings = Settings::getInstance(); + + if (empty($settings->analytics_key)) { + return $this->render('index'); + } else { + $analytics = new Analytics( + [ + 'viewId' => $settings->analytics_key, + ] + ); - $analytics = new Analytics( - [ - 'viewId' => $settings->analytics_key, - ] - ); - - return $this->render( - 'analytics', - [ - 'data' => $analytics->generateData(), - ] - ); + return $this->render( + 'analytics', + [ + 'data' => $analytics->generateData(), + ] + ); + } } /** diff --git a/backend/views/settings/settings.php b/backend/views/settings/settings.php index 99b3a61..115796f 100755 --- a/backend/views/settings/settings.php +++ b/backend/views/settings/settings.php @@ -35,13 +35,9 @@ echo $form->field($model, 'description') ->textInput(); - - echo $form->field($model, 'analytics') - ->textarea( - [ - 'rows' => 11, - ] - ); + + echo $form->field($model, 'analytics_key') + ->textInput(); echo Html::submitButton( 'Save', diff --git a/backend/views/site/analytics.php b/backend/views/site/analytics.php index f1d64e1..4836968 100644 --- a/backend/views/site/analytics.php +++ b/backend/views/site/analytics.php @@ -58,7 +58,7 @@ 'Analytics', - 'toolbarLayout' => '{collapse}', + 'toolbarLayout' => false, ] ); ?> @@ -124,7 +124,7 @@ 'Analytics', - 'toolbarLayout' => '{collapse}', + 'toolbarLayout' => false, ] ); ?> diff --git a/backend/views/site/index.php b/backend/views/site/index.php index 6719567..d1a56a8 100755 --- a/backend/views/site/index.php +++ b/backend/views/site/index.php @@ -1,9 +1,34 @@ title = 'My Yii Application'; - - \ No newline at end of file + $this->title = 'Artbox !'; + +?> + + 'Hello!', + 'toolbar' => false, + ] +); ?> + +
+

Hello

+

+ Configuration info + +

+

+
+ + diff --git a/common/config/settings.php b/common/config/settings.php old mode 100644 new mode 100755 index e35c03a..878125f --- a/common/config/settings.php +++ b/common/config/settings.php @@ -2,9 +2,9 @@ return [ 1 => [ - 'id' => '1', - 'name' => 'Admin321', - 'description' => 'Site administrator', + 'id' => '1', + 'name' => 'Admin321', + 'description' => 'Site administrator', 'analytics' => ' ', - 'analytics_key' => '', + 'analytics_key' => '119240817', ], ]; \ No newline at end of file -- libgit2 0.21.4