--- /dev/null
+<?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
{
return [
'index' => \yii_app\actions\pages\IndexAction::class,
+ 'statistics' => \yii_app\actions\pages\StatisticsAction::class,
];
}
}
\ No newline at end of file
--- /dev/null
+<?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']);
+ }
+}
--- /dev/null
+<?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>
&& 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"]);