Completed
Push — master ( 1d95ec...eb6b30 )
by Vojta
02:03
created
reportwidgets/AccessLogChartLine.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -37,24 +37,24 @@
 block discarded – undo
37 37
         return $this->makePartial('widget');
38 38
     }
39 39
 
40
-	public function defineProperties()
41
-	{
42
-		return [
43
-			'title' => [
40
+    public function defineProperties()
41
+    {
42
+        return [
43
+            'title' => [
44 44
                 'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title',
45 45
                 'default' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title_default',
46
-				'type' => 'string',
47
-				'validationPattern' => '^.+$',
48
-				'validationMessage' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title_validation',
49
-			],
46
+                'type' => 'string',
47
+                'validationPattern' => '^.+$',
48
+                'validationMessage' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title_validation',
49
+            ],
50 50
             'days' => [
51 51
                 'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.days_title',
52 52
                 'default' => '30',
53 53
                 'type' => 'string',
54 54
                 'validationPattern' => '^[0-9]+$',
55 55
             ]
56
-		];
57
-	}
56
+        ];
57
+    }
58 58
 
59 59
     protected function loadData()
60 60
     {
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
     public function render()
24 24
     {
25 25
         try {
26
-            $this->vars['all'] = $this->loadData()['all'];
27
-            $this->vars['rows'] = $this->loadData()['user_rows'];
28
-            $this->vars['users'] = $this->loadData()['users'];
26
+            $this->vars[ 'all' ] = $this->loadData()[ 'all' ];
27
+            $this->vars[ 'rows' ] = $this->loadData()[ 'user_rows' ];
28
+            $this->vars[ 'users' ] = $this->loadData()[ 'users' ];
29 29
 
30 30
         } catch (Exception $ex) {
31
-            $this->vars['error'] = $ex->getMessage();
32
-            $this->vars['all'] = 0;
33
-            $this->vars['users'] = [];
34
-            $this->vars['rows'] = [];
31
+            $this->vars[ 'error' ] = $ex->getMessage();
32
+            $this->vars[ 'all' ] = 0;
33
+            $this->vars[ 'users' ] = [ ];
34
+            $this->vars[ 'rows' ] = [ ];
35 35
         }
36 36
 
37 37
         return $this->makePartial('widget');
@@ -60,55 +60,55 @@  discard block
 block discarded – undo
60 60
     {
61 61
         $days = $this->property('days');
62 62
         if (!$days) {
63
-            throw new ApplicationException('Invalid days value: ' . $days);
63
+            throw new ApplicationException('Invalid days value: '.$days);
64 64
         }
65 65
 
66 66
         // all accesses for last month
67 67
         $items = AccessLog::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get();
68 68
 
69 69
         // parse data
70
-        $all = [];
71
-        $users = [];
72
-        $user_rows = [];
70
+        $all = [ ];
71
+        $users = [ ];
72
+        $user_rows = [ ];
73 73
         foreach ($items as $item)
74 74
         {
75 75
             // user
76 76
             $user_id = $item->user_id ? $item->user_id : 0;
77
-            $users[$user_id] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser();
77
+            $users[ $user_id ] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser();
78 78
 
79 79
             // date
80 80
             $timestamp = strtotime($item->created_at) * 1000;
81 81
             $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
82 82
 
83
-            if (isset($user_rows[$user_id][$day])) {
84
-                $user_rows[$user_id][$day][1]++;
83
+            if (isset($user_rows[ $user_id ][ $day ])) {
84
+                $user_rows[ $user_id ][ $day ][ 1 ]++;
85 85
             } else {
86
-                $user_rows[$user_id][$day] = [$timestamp, 1];
86
+                $user_rows[ $user_id ][ $day ] = [ $timestamp, 1 ];
87 87
             }
88 88
 
89
-            if (isset($all[$day])) {
90
-                $all[$day][1]++;
89
+            if (isset($all[ $day ])) {
90
+                $all[ $day ][ 1 ]++;
91 91
             } else {
92
-                $all[$day] = [$timestamp, 1];
92
+                $all[ $day ] = [ $timestamp, 1 ];
93 93
             }
94 94
         }
95 95
 
96 96
         // transform user line to json
97 97
         foreach ($user_rows as $key => $user_row) {
98
-            $rows = [];
99
-            foreach($user_row as $row) {
100
-                $rows[] = [
101
-                    $row[0],
102
-                    $row[1],
98
+            $rows = [ ];
99
+            foreach ($user_row as $row) {
100
+                $rows[ ] = [
101
+                    $row[ 0 ],
102
+                    $row[ 1 ],
103 103
                 ];
104 104
             }
105
-            $user_rows[$key] = str_replace('"', '', substr(substr(json_encode($rows), 1), 0, -1));
105
+            $user_rows[ $key ] = str_replace('"', '', substr(substr(json_encode($rows), 1), 0, -1));
106 106
         }
107 107
 
108 108
         // count all
109
-        $all_render = [];
109
+        $all_render = [ ];
110 110
         foreach ($all as $a) {
111
-            $all_render[] = [$a[0], $a[1]];
111
+            $all_render[ ] = [ $a[ 0 ], $a[ 1 ] ];
112 112
         }
113 113
         $all = str_replace('"', '', substr(substr(json_encode($all_render), 1), 0, -1));
114 114
 
Please login to merge, or discard this patch.