JavascriptPanel   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 94
rs 10
c 0
b 0
f 0
ccs 32
cts 32
cp 1
wmc 11
lcom 2
cbo 7

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getLabel() 0 4 1
A hasEntryData() 0 4 1
A getDetail() 0 13 1
A getIndexUrl() 0 4 1
A getChartModel() 0 4 1
A getChart() 0 7 1
A registerAssets() 0 4 1
A cleanup() 0 9 3
1
<?php
2
3
namespace bedezign\yii2\audit\panels;
4
5
use bedezign\yii2\audit\components\panels\Panel;
6
use bedezign\yii2\audit\components\panels\RendersSummaryChartTrait;
7
use bedezign\yii2\audit\models\AuditJavascript;
8
use bedezign\yii2\audit\models\AuditJavascriptSearch;
9
use Yii;
10
use yii\grid\GridViewAsset;
11
12
/**
13
 * JavascriptPanel
14
 * @package bedezign\yii2\audit\panels
15
 */
16
class JavascriptPanel extends Panel
17
{
18
    use RendersSummaryChartTrait;
19
20 33
    /**
21
     * @inheritdoc
22 33
     */
23
    public function getName()
24
    {
25
        return \Yii::t('audit', 'Javascripts');
26
    }
27
28 3
    /**
29
     * @inheritdoc
30 3
     */
31
    public function getLabel()
32
    {
33
        return $this->getName() . ' <small>(' . count($this->_model->javascripts) . ')</small>';
34
    }
35
36 3
    /**
37
     * @inheritdoc
38 3
     */
39
    public function hasEntryData($entry)
40
    {
41
        return count($entry->javascripts) > 0;
42
    }
43
44 3
    /**
45
     * @inheritdoc
46 3
     */
47 3
    public function getDetail()
48 3
    {
49 3
        $searchModel = new AuditJavascriptSearch();
50
        $params = \Yii::$app->request->getQueryParams();
51 3
        $params['AuditJavascriptSearch']['entry_id'] = $params['id'];
52 3
        $dataProvider = $searchModel->search($params);
53 3
54 3
        return \Yii::$app->view->render('panels/javascript/detail', [
55 3
            'panel'        => $this,
56
            'dataProvider' => $dataProvider,
57
            'searchModel'  => $searchModel,
58
        ]);
59
    }
60
61 33
    /**
62
     * @inheritdoc
63 33
     */
64
    public function getIndexUrl()
65
    {
66
        return ['javascript/index'];
67
    }
68
69 3
    /**
70
     * @inheritdoc
71 3
     */
72 3
    protected function getChartModel()
73 3
    {
74
        return AuditJavascript::className();
75
    }
76
77
    /**
78
     * @inheritdoc
79 3
     */
80
    public function getChart()
81 3
    {
82 3
        return \Yii::$app->view->render('panels/mail/chart', [
83
            'panel' => $this,
84
            'chartData' => $this->getChartData()
85
        ]);
86
    }
87 3
88
    /**
89 3
     * @inheritdoc
90 3
     */
91 3
    public function registerAssets($view)
92 3
    {
93 3
        GridViewAsset::register($view);
94 3
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function cleanup($maxAge = null)
100
    {
101
        $maxAge = $maxAge !== null ? $maxAge : $this->maxAge;
102
        if ($maxAge === null)
103
            return false;
104
        return AuditJavascript::deleteAll([
105
            '<=', 'created', date('Y-m-d 23:59:59', strtotime("-$maxAge days"))
106
        ]);
107
    }
108
109
}