Commit c8500c2f244373c70c43efe45d113ad9d40d49d2
1 parent
685f7422
-Analytics in process
Showing
7 changed files
with
141 additions
and
31 deletions
Show diff stats
backend/config/main.php
| ... | ... | @@ -15,7 +15,6 @@ |
| 15 | 15 | 'controllerNamespace' => 'backend\controllers', |
| 16 | 16 | 'bootstrap' => [ 'log' ], |
| 17 | 17 | 'controllerMap' => [ |
| 18 | - 'settings' => 'artbox\core\controllers\SettingsController', | |
| 19 | 18 | 'profile' => 'artbox\core\controllers\ProfileController', |
| 20 | 19 | 'page' => 'artbox\core\controllers\PageController', |
| 21 | 20 | 'seo' => 'artbox\core\controllers\AliasController', | ... | ... |
| 1 | +<?php | |
| 2 | + namespace backend\controllers; | |
| 3 | + | |
| 4 | + use common\models\Settings; | |
| 5 | + use yii\base\InvalidConfigException; | |
| 6 | + use yii\filters\AccessControl; | |
| 7 | + use yii\web\Controller; | |
| 8 | + use Yii; | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * Class SettingsController | |
| 12 | + * | |
| 13 | + * @package artbox\core\controllers | |
| 14 | + */ | |
| 15 | + class SettingsController extends Controller | |
| 16 | + { | |
| 17 | + /** | |
| 18 | + * @inheritdoc | |
| 19 | + */ | |
| 20 | + public function behaviors() | |
| 21 | + { | |
| 22 | + return [ | |
| 23 | + 'access' => [ | |
| 24 | + 'class' => AccessControl::className(), | |
| 25 | + 'rules' => [ | |
| 26 | + [ | |
| 27 | + 'actions' => [ | |
| 28 | + 'login', | |
| 29 | + 'error', | |
| 30 | + ], | |
| 31 | + 'allow' => true, | |
| 32 | + ], | |
| 33 | + [ | |
| 34 | + 'actions' => [ | |
| 35 | + 'logout', | |
| 36 | + 'index', | |
| 37 | + ], | |
| 38 | + 'allow' => true, | |
| 39 | + 'roles' => [ '@' ], | |
| 40 | + ], | |
| 41 | + ], | |
| 42 | + ], | |
| 43 | + ]; | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Display site settings page | |
| 48 | + * | |
| 49 | + * @return string|\yii\web\Response | |
| 50 | + */ | |
| 51 | + public function actionIndex() | |
| 52 | + { | |
| 53 | + $model = $this->findSettings(); | |
| 54 | + | |
| 55 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 56 | + Yii::$app->session->setFlash('success', 'Settings saved'); | |
| 57 | + | |
| 58 | + return $this->goHome(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + return $this->render( | |
| 62 | + 'settings', | |
| 63 | + [ | |
| 64 | + 'model' => $model, | |
| 65 | + ] | |
| 66 | + ); | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Find site settings | |
| 71 | + * | |
| 72 | + * @return \yii2tech\filedb\ActiveRecord | |
| 73 | + * @throws \yii\base\InvalidConfigException | |
| 74 | + */ | |
| 75 | + public function findSettings() | |
| 76 | + { | |
| 77 | + if ($model = Settings::find() | |
| 78 | + ->one() | |
| 79 | + ) { | |
| 80 | + return $model; | |
| 81 | + } else { | |
| 82 | + throw new InvalidConfigException('Settings file not found'); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 0 | 87 | \ No newline at end of file | ... | ... |
backend/controllers/SiteController.php
| ... | ... | @@ -70,19 +70,23 @@ |
| 70 | 70 | public function actionIndex() |
| 71 | 71 | { |
| 72 | 72 | $settings = Settings::getInstance(); |
| 73 | + | |
| 74 | + if (empty($settings->analytics_key)) { | |
| 75 | + return $this->render('index'); | |
| 76 | + } else { | |
| 77 | + $analytics = new Analytics( | |
| 78 | + [ | |
| 79 | + 'viewId' => $settings->analytics_key, | |
| 80 | + ] | |
| 81 | + ); | |
| 73 | 82 | |
| 74 | - $analytics = new Analytics( | |
| 75 | - [ | |
| 76 | - 'viewId' => $settings->analytics_key, | |
| 77 | - ] | |
| 78 | - ); | |
| 79 | - | |
| 80 | - return $this->render( | |
| 81 | - 'analytics', | |
| 82 | - [ | |
| 83 | - 'data' => $analytics->generateData(), | |
| 84 | - ] | |
| 85 | - ); | |
| 83 | + return $this->render( | |
| 84 | + 'analytics', | |
| 85 | + [ | |
| 86 | + 'data' => $analytics->generateData(), | |
| 87 | + ] | |
| 88 | + ); | |
| 89 | + } | |
| 86 | 90 | } |
| 87 | 91 | |
| 88 | 92 | /** | ... | ... |
backend/views/settings/settings.php
| ... | ... | @@ -35,13 +35,9 @@ |
| 35 | 35 | |
| 36 | 36 | echo $form->field($model, 'description') |
| 37 | 37 | ->textInput(); |
| 38 | - | |
| 39 | - echo $form->field($model, 'analytics') | |
| 40 | - ->textarea( | |
| 41 | - [ | |
| 42 | - 'rows' => 11, | |
| 43 | - ] | |
| 44 | - ); | |
| 38 | + | |
| 39 | + echo $form->field($model, 'analytics_key') | |
| 40 | + ->textInput(); | |
| 45 | 41 | |
| 46 | 42 | echo Html::submitButton( |
| 47 | 43 | 'Save', | ... | ... |
backend/views/site/analytics.php
| ... | ... | @@ -58,7 +58,7 @@ |
| 58 | 58 | <?php $panel = XPanel::begin( |
| 59 | 59 | [ |
| 60 | 60 | 'title' => 'Analytics', |
| 61 | - 'toolbarLayout' => '{collapse}', | |
| 61 | + 'toolbarLayout' => false, | |
| 62 | 62 | ] |
| 63 | 63 | ); ?> |
| 64 | 64 | |
| ... | ... | @@ -124,7 +124,7 @@ |
| 124 | 124 | <?php $panel = XPanel::begin( |
| 125 | 125 | [ |
| 126 | 126 | 'title' => 'Analytics', |
| 127 | - 'toolbarLayout' => '{collapse}', | |
| 127 | + 'toolbarLayout' => false, | |
| 128 | 128 | ] |
| 129 | 129 | ); ?> |
| 130 | 130 | ... | ... |
backend/views/site/index.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - /* @var $this yii\web\View */ | |
| 3 | + /** | |
| 4 | + * @var View $this | |
| 5 | + */ | |
| 4 | 6 | |
| 5 | - use backend\models\Analytics; | |
| 7 | + use artbox\gentelella\widgets\XPanel; | |
| 8 | + use yii\web\View; | |
| 6 | 9 | |
| 7 | - $this->title = 'My Yii Application'; | |
| 8 | - | |
| 9 | - | |
| 10 | 10 | \ No newline at end of file |
| 11 | + $this->title = 'Artbox !'; | |
| 12 | + | |
| 13 | +?> | |
| 14 | + | |
| 15 | +<?php $panel = XPanel::begin( | |
| 16 | + [ | |
| 17 | + 'title' => 'Hello!', | |
| 18 | + 'toolbar' => false, | |
| 19 | + ] | |
| 20 | +); ?> | |
| 21 | + | |
| 22 | +<div class="jumbotron"> | |
| 23 | + <h1>Hello</h1> | |
| 24 | + <p> | |
| 25 | + Configuration info | |
| 26 | + | |
| 27 | + <ul> | |
| 28 | + <li>Step one</li> | |
| 29 | + <li>Step 2</li> | |
| 30 | + <li>Finish !</li> | |
| 31 | + </ul> | |
| 32 | + </p> | |
| 33 | +</div> | |
| 34 | + | |
| 35 | +<?php $panel::end(); ?> | ... | ... |
| ... | ... | @@ -2,9 +2,9 @@ |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | 1 => [ |
| 5 | - 'id' => '1', | |
| 6 | - 'name' => 'Admin321', | |
| 7 | - 'description' => 'Site administrator', | |
| 5 | + 'id' => '1', | |
| 6 | + 'name' => 'Admin321', | |
| 7 | + 'description' => 'Site administrator', | |
| 8 | 8 | 'analytics' => '<!-- Google Analytics --> |
| 9 | 9 | <script> |
| 10 | 10 | (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ |
| ... | ... | @@ -16,6 +16,6 @@ return [ |
| 16 | 16 | ga(\'send\', \'pageview\'); |
| 17 | 17 | </script> |
| 18 | 18 | <!-- End Google Analytics -->', |
| 19 | - 'analytics_key' => '', | |
| 19 | + 'analytics_key' => '119240817', | |
| 20 | 20 | ], |
| 21 | 21 | ]; |
| 22 | 22 | \ No newline at end of file | ... | ... |