]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
add page statistics view
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 12 Mar 2024 14:10:31 +0000 (17:10 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 12 Mar 2024 14:10:31 +0000 (17:10 +0300)
erp24/actions/pages/StatisticsAction.php [new file with mode: 0644]
erp24/controllers/PagesController.php
erp24/records/PageStatistics.php [new file with mode: 0644]
erp24/views/pages/statistics.php [new file with mode: 0644]
erp24/web/index.php

diff --git a/erp24/actions/pages/StatisticsAction.php b/erp24/actions/pages/StatisticsAction.php
new file mode 100644 (file)
index 0000000..35efa43
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+namespace yii_app\actions\pages;
+
+use yii\base\Action;
+use yii\data\ActiveDataProvider;
+use yii_app\records\PageStatistics;
+
+class StatisticsAction extends Action
+{
+    public function run() {
+        $dataProvider = new ActiveDataProvider(['query' => PageStatistics::find()->with('admin')]);
+        return $this->controller->render('statistics', compact('dataProvider'));
+    }
+}
\ No newline at end of file
index 1509a2d060be923842894b1d95f0288424034e32..55701630f26e3674788afb2f509da24723074098 100755 (executable)
@@ -11,6 +11,7 @@ class PagesController extends \yii\web\Controller
     {
         return [
             'index' => \yii_app\actions\pages\IndexAction::class,
+            'statistics' => \yii_app\actions\pages\StatisticsAction::class,
         ];
     }
 }
\ No newline at end of file
diff --git a/erp24/records/PageStatistics.php b/erp24/records/PageStatistics.php
new file mode 100644 (file)
index 0000000..90f8923
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "page_statistics".
+ *
+ * @property int $id
+ * @property int $admin_id ID в таблице admins
+ * @property string $url api request url
+ * @property string|null $post POST параметры, если имеются
+ * @property string $created_at дата создания лога
+ */
+class PageStatistics extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'page_statistics';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['admin_id', 'url', 'created_at'], 'required'],
+            [['admin_id'], 'integer'],
+            [['post'], 'string'],
+            [['created_at'], 'safe'],
+            [['url'], 'string', 'max' => 255],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'admin_id' => 'Admin ID',
+            'url' => 'Url',
+            'post' => 'Post-запрос',
+            'created_at' => 'Created At',
+        ];
+    }
+
+    public function getAdmin() {
+        return $this->hasOne(Admin::class, ['id' => 'admin_id']);
+    }
+}
diff --git a/erp24/views/pages/statistics.php b/erp24/views/pages/statistics.php
new file mode 100644 (file)
index 0000000..15f45b2
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+use yii\data\ArrayDataProvider;
+
+/** @var $dataProvider ArrayDataProvider */
+
+?>
+
+<div class="pagesStatistics m-5">
+
+    <div style="overflow: scroll">
+
+        <?= \yii\grid\GridView::widget([
+            'dataProvider' => $dataProvider,
+            'columns' => [
+                'id',
+                [
+                    'label' => 'Пользователь',
+                    'format' => 'html',
+                    'value' => function ($model) {
+                        return $model->admin->name ?? '';
+                    }
+                ],
+                'url',
+                [
+                    'label' => 'Время',
+                    'format' => 'html',
+                    'value' => function ($model) {
+                        return \yii_app\services\DateTimeService::formatHuman($model->created_at);
+                    }
+                ],
+                'post'
+            ]
+        ]);?>
+
+    </div>
+</div>
index 20583dc2c9d0269d5d2d580e0bf0b3259ef01b85..21568001fb31caf06bf92e2792c686ea85df8b7b 100644 (file)
@@ -25,6 +25,7 @@ if (
     && strpos($url, '/i/') !== 0
     && strpos($url, '/debug/default/toolbar') !== 0
     && strpos($url, '/assets/') !== 0
+    && strpos($url, '/pages/statistics') !== 0
 ) {
     $postJson = Yii::$app->request->post();
     unset($postJson["_csrf"]);