Esempio n. 1
0
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;
//        }
//    }
//}
?>
<div class="audit-index">
Esempio n. 2
0
<div class="row">
    <div class="col-md-10">
<?php 
echo Html::tag('h2', Yii::t('audit', 'Request'), ['id' => 'entry', 'class' => 'hashtag']);
echo DetailView::widget(['model' => $entry, 'attributes' => ['id', ['label' => $entry->getAttributeLabel('user_id'), 'value' => intval($entry->user_id) ? $entry->user_id : Yii::t('audit', 'Guest')], 'ip', 'created', ['attribute' => 'start_time', 'format' => 'datetime'], ['attribute' => 'end_time', 'format' => 'datetime'], ['attribute' => 'duration', 'format' => 'decimal'], 'referrer', 'redirect', 'url', 'route', ['attribute' => 'memory', 'format' => 'shortsize'], ['attribute' => 'memory_max', 'format' => 'shortsize']]]);
foreach ($entry->extraData as $data) {
    $attributes = [];
    foreach ($data->data as $name => $value) {
        $attributes[] = ['label' => $name, 'value' => Helper::formatValue($value), 'format' => 'raw'];
    }
    echo Html::tag('h2', $data->name . ' (' . count($attributes) . ')', ['id' => $data->type, 'class' => 'hashtag']);
    echo DetailView::widget(['model' => $data, 'attributes' => $attributes, 'template' => '<tr><th>{label}</th><td style="word-break:break-word;">{value}</td></tr>']);
}
if (count($entry->trail)) {
    $dataProvider = new ActiveDataProvider(['query' => AuditTrail::find()->where(['audit_id' => $entry->id]), 'pagination' => ['pageSize' => 1000]]);
    echo Html::tag('h2', Yii::t('audit', 'Trail ({i})', ['i' => count($entry->trail)]), ['id' => 'trail', 'class' => 'hashtag']);
    echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', 'action', 'model', 'model_id', 'field', ['label' => Yii::t('audit', 'Diff'), 'value' => function ($model) {
        /** @var AuditTrail $model */
        return $model->getDiffHtml();
    }, 'format' => 'raw'], 'stamp', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}', 'buttons' => ['view' => function ($url, $model, $key) {
        return Html::a(Html::tag('span', '', ['class' => 'glyphicon glyphicon-eye-open']), ['diff', 'id' => $model->id], ['class' => '', 'data' => ['toggle' => 'modal']]);
    }]]]]);
}
if (count($entry->linkedErrors)) {
    echo Html::tag('h2', Yii::t('audit', 'Errors ({i})', ['i' => count($entry->linkedErrors)]), ['id' => 'errors', 'class' => 'hashtag']);
    foreach ($entry->linkedErrors as $i => $error) {
        echo Html::tag('h3', Yii::t('audit', 'Error #{i}', ['i' => $i + 1]));
        echo DetailView::widget(['model' => $error, 'attributes' => ['message', 'code', ['label' => Yii::t('audit', 'Location'), 'value' => $error->file . '(' . $error->line . ')']]]);
    }
}
Esempio n. 3
0
 /**
  * (string) actionHistory : 删除的历史数据
  * @param string $pid personal_id
  * @return string
  */
 public function actionHistory($pid)
 {
     return $this->render('@bedezign/yii2/audit/views/_audit_trails', ['query' => \bedezign\yii2\audit\models\AuditTrail::find()->andFilterWhere(['like', 'old_value', $pid]), 'params' => ['AuditTrailSearch' => []], 'columns' => ['user_id', 'entry_id', 'action', 'old_value', 'created'], 'filter' => false]);
 }
 public static function actionFilter()
 {
     return \yii\helpers\ArrayHelper::map(parent::find()->select('action')->groupBy('action')->orderBy('action ASC')->all(), 'action', 'action');
 }
Esempio n. 5
0
 /**
  * Find an attribute from a version.
  *
  * @param $class
  * @param $id
  * @param $attribute
  * @param $version
  * @return null|integer|float|string
  */
 public static function findAttribute($class, $id, $attribute, $version)
 {
     /** @var AuditTrail $trail */
     $trail = AuditTrail::find()->andWhere(['model' => $class, 'model_id' => $id, 'field' => $attribute])->andWhere(['<=', 'entry_id', $version])->orderBy(['id' => SORT_DESC])->one();
     return $trail ? $trail->new_value : null;
 }