/** * @return array */ public static function methodFilter() { $methods = AuditEntry::getDb()->cache(function () { return AuditEntry::find()->distinct(true)->select('request_method')->where(['is not', 'request_method', null])->groupBy('request_method')->orderBy('request_method ASC')->column(); }, 240); return array_combine($methods, $methods); }
public static function routeFilter() { $routes = AuditEntry::getDb()->cache(function ($db) { return AuditEntry::find()->distinct(true)->select('route')->where(['is not', 'route', null])->groupBy('route')->orderBy('route ASC')->column(); }, 30); return array_combine($routes, $routes); }
public function safeUp() { $this->addColumn(self::TABLE, 'request_method', 'varchar(255) NULL AFTER memory_max'); $this->createIndex('idx_audit_entry_request_method', self::TABLE, ['request_method']); echo " > filling 'request_method' from data ..."; $time = microtime(true); foreach (\bedezign\yii2\audit\models\AuditEntry::find()->batch() as $auditEntries) { foreach ($auditEntries as $auditEntry) { $auditEntry->request_method = \yii\helpers\ArrayHelper::getValue($auditEntry->data, 'env.REQUEST_METHOD'); if (!$auditEntry->request_method) { $auditEntry->request_method = 'CLI'; } $auditEntry->save(false, ['request_method']); } } echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; }
use dosamigos\chartjs\ChartJs; use yii\helpers\ArrayHelper; use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('audit', 'Audit Module'); $this->params['breadcrumbs'][] = $this->title; $this->registerCss('canvas {width: 100% !important;height: 400px;}'); $dataSet = ['fillColor' => "rgba(151,187,205,0.5)", 'strokeColor' => "rgba(151,187,205,1)", 'pointColor' => "rgba(151,187,205,1)", 'pointStrokeColor' => "#fff"]; $options = ['height' => 400, 'width' => 400]; $days = []; $count = ['entry' => [], 'trail' => [], 'javascript' => [], 'error' => []]; foreach (range(-6, 0) as $day) { $date = strtotime($day . 'days'); $days[] = date('D: Y-m-d', $date); $count['entry'][] = AuditEntry::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['trail'][] = AuditTrail::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['mail'][] = AuditMail::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['javascript'][] = AuditJavascript::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['error'][] = AuditError::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); } //fake data //foreach ($count as $type => $data) { // foreach ($data as $k => $v) { // if (!$v) { // $v = $type == 'entry' ? rand(100, 1000) : rand(0, 100); // $count[$type][$k] = $v; // } // } //} ?>