Completed
Push — master ( 03dca7...ba93e6 )
by Vojta
01:11
created
updates/create_accesslog_table.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -9,31 +9,31 @@
 block discarded – undo
9 9
 class CreateAccessLogTable extends Migration
10 10
 {
11 11
 
12
-	public function up()
13
-	{
14
-		Schema::create('user_access_log', function($table)
15
-		{
16
-			$table->engine = 'InnoDB';
17
-			$table->increments('id');
18
-
19
-			$table->integer('user_id')->unsigned()->nullable();
20
-			$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
21
-
22
-			$table->string('ip_address')->nullable();
23
-
24
-			$table->timestamps();
25
-		});
26
-	}
27
-
28
-	public function down()
29
-	{
30
-		DB::statement("SET foreign_key_checks = 0");
31
-		Schema::table('user_access_log', function($table)
32
-		{
33
-			$table->dropForeign('user_access_log_user_id_foreign');
34
-		});
35
-		Schema::dropIfExists('user_access_log');
36
-		DB::statement("SET foreign_key_checks = 1");
37
-	}
12
+    public function up()
13
+    {
14
+        Schema::create('user_access_log', function($table)
15
+        {
16
+            $table->engine = 'InnoDB';
17
+            $table->increments('id');
18
+
19
+            $table->integer('user_id')->unsigned()->nullable();
20
+            $table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
21
+
22
+            $table->string('ip_address')->nullable();
23
+
24
+            $table->timestamps();
25
+        });
26
+    }
27
+
28
+    public function down()
29
+    {
30
+        DB::statement("SET foreign_key_checks = 0");
31
+        Schema::table('user_access_log', function($table)
32
+        {
33
+            $table->dropForeign('user_access_log_user_id_foreign');
34
+        });
35
+        Schema::dropIfExists('user_access_log');
36
+        DB::statement("SET foreign_key_checks = 1");
37
+    }
38 38
 
39 39
 }
Please login to merge, or discard this patch.
reportwidgets/AccessLogChartLineAggregated.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@
 block discarded – undo
24 24
     {
25 25
         try {
26 26
             $this->vars['all'] = $this->loadData();
27
-        }
28
-        catch (Exception $ex) {
27
+        } catch (Exception $ex) {
29 28
             $this->vars['error'] = $ex->getMessage();
30 29
             $this->vars['all'] = '';
31 30
         }
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,24 +38,24 @@
 block discarded – undo
38 38
      *
39 39
      * @return array
40 40
      */
41
-	public function defineProperties()
42
-	{
43
-		return [
44
-			'title' => [
45
-				'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.title',
46
-				'default' => 'Access statistics in time',
47
-				'type' => 'string',
48
-				'validationPattern' => '^.+$',
49
-				'validationMessage' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.title_validation',
50
-			],
41
+    public function defineProperties()
42
+    {
43
+        return [
44
+            'title' => [
45
+                'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.title',
46
+                'default' => 'Access statistics in time',
47
+                'type' => 'string',
48
+                'validationPattern' => '^.+$',
49
+                'validationMessage' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.title_validation',
50
+            ],
51 51
             'days' => [
52 52
                 'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.days_title',
53 53
                 'default' => '30',
54 54
                 'type' => 'string',
55 55
                 'validationPattern' => '^[0-9]+$',
56 56
             ]
57
-		];
58
-	}
57
+        ];
58
+    }
59 59
 
60 60
     protected function loadData()
61 61
     {
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
     public function render()
22 22
     {
23 23
         try {
24
-            $this->vars['all'] = $this->loadData();
24
+            $this->vars[ 'all' ] = $this->loadData();
25 25
         }
26 26
         catch (Exception $ex) {
27
-            $this->vars['error'] = $ex->getMessage();
28
-            $this->vars['all'] = '';
27
+            $this->vars[ 'error' ] = $ex->getMessage();
28
+            $this->vars[ 'all' ] = '';
29 29
         }
30 30
 
31 31
         return $this->makePartial('widget');
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     {
60 60
         $days = $this->property('days');
61 61
         if (!$days) {
62
-            throw new ApplicationException('Invalid days value: ' . $days);
62
+            throw new ApplicationException('Invalid days value: '.$days);
63 63
         }
64 64
 
65 65
         // all accesses for last month
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
         // we need at least two days, to display chart
72 72
         if (sizeof($all) == 1) {
73 73
             $day = reset($all);
74
-            $date = Carbon::createFromFormat('Y-m-d', $day['date'])->subDays(1);
74
+            $date = Carbon::createFromFormat('Y-m-d', $day[ 'date' ])->subDays(1);
75 75
             $dateFormated = $date->format('Y-m-d');
76
-            $all[$dateFormated] = [
76
+            $all[ $dateFormated ] = [
77 77
                 'timestamp' => $date->timestamp * 1000,
78 78
                 'date' => $dateFormated,
79 79
                 'count' => 0,
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
         }
82 82
 
83 83
         // count accessess for each day
84
-        $all_render = [];
84
+        $all_render = [ ];
85 85
         foreach ($all as $a) {
86
-            $all_render[] = [$a['timestamp'], $a['count']];
86
+            $all_render[ ] = [ $a[ 'timestamp' ], $a[ 'count' ] ];
87 87
         }
88 88
 
89 89
         return $all_render;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     private function sortItemsToDays($items)
100 100
     {
101
-        $all = [];
101
+        $all = [ ];
102 102
 
103 103
         foreach ($items as $item)
104 104
         {
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
             $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
108 108
 
109 109
             // init empty day
110
-            if (!isset($all[$day])) {
111
-                $all[$day] = [
110
+            if (!isset($all[ $day ])) {
111
+                $all[ $day ] = [
112 112
                     'timestamp' => $timestamp,
113 113
                     'date' => $day,
114 114
                     'count' => 0,
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             }
117 117
 
118 118
             // increase count
119
-            $all[$day]['count']++;
119
+            $all[ $day ][ 'count' ]++;
120 120
         }
121 121
 
122 122
         return $all;
Please login to merge, or discard this patch.
reportwidgets/Registrations.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
     public function render()
21 21
     {
22 22
         try {
23
-            $this->vars['registrations'] = $this->loadData();
23
+            $this->vars[ 'registrations' ] = $this->loadData();
24 24
 
25 25
         } catch (Exception $ex) {
26
-            $this->vars['error'] = $ex->getMessage();
27
-            $this->vars['registrations'] = [];
26
+            $this->vars[ 'error' ] = $ex->getMessage();
27
+            $this->vars[ 'registrations' ] = [ ];
28 28
         }
29 29
 
30 30
         return $this->makePartial('widget');
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     {
54 54
         $days = $this->property('days');
55 55
         if (!$days) {
56
-            throw new ApplicationException('Invalid days value: ' . $days);
56
+            throw new ApplicationException('Invalid days value: '.$days);
57 57
         }
58 58
 
59 59
         // all accesses for last month
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         // we need at least two days, to display chart
66 66
         if (sizeof($all) == 1) {
67 67
             $day = reset($all);
68
-            $date = Carbon::createFromFormat('Y-m-d', $day['date'])->subDays(1);
68
+            $date = Carbon::createFromFormat('Y-m-d', $day[ 'date' ])->subDays(1);
69 69
             $dateFormated = $date->format('Y-m-d');
70
-            $all[$dateFormated] = [
70
+            $all[ $dateFormated ] = [
71 71
                 'timestamp' => $date->timestamp * 1000,
72 72
                 'date' => $dateFormated,
73 73
                 'count' => 0,
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
         }
76 76
 
77 77
         // count all
78
-        $all_render = [];
78
+        $all_render = [ ];
79 79
         foreach ($all as $a) {
80
-            $all_render[] = [$a['timestamp'], $a['count']];
80
+            $all_render[ ] = [ $a[ 'timestamp' ], $a[ 'count' ] ];
81 81
         }
82 82
 
83 83
         return $all_render;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     private function sortItemsToDays($items)
94 94
     {
95
-        $all = [];
95
+        $all = [ ];
96 96
 
97 97
         foreach ($items as $item)
98 98
         {
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
             $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
102 102
 
103 103
             // init empty day
104
-            if (!isset($all[$day])) {
105
-                $all[$day] = [
104
+            if (!isset($all[ $day ])) {
105
+                $all[ $day ] = [
106 106
                     'timestamp' => $timestamp,
107 107
                     'date' => $day,
108 108
                     'count' => 0,
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
             }
111 111
 
112 112
             // increase count
113
-            $all[$day]['count']++;
113
+            $all[ $day ][ 'count' ]++;
114 114
         }
115 115
 
116 116
         return $all;
Please login to merge, or discard this patch.
reportwidgets/AccessLogChartLine.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
     public function render()
22 22
     {
23 23
         try {
24
-            $this->vars['all'] = $this->loadData()['all'];
25
-            $this->vars['rows'] = $this->loadData()['user_rows'];
26
-            $this->vars['users'] = $this->loadData()['users'];
24
+            $this->vars[ 'all' ] = $this->loadData()[ 'all' ];
25
+            $this->vars[ 'rows' ] = $this->loadData()[ 'user_rows' ];
26
+            $this->vars[ 'users' ] = $this->loadData()[ 'users' ];
27 27
 
28 28
         } catch (Exception $ex) {
29
-            $this->vars['error'] = $ex->getMessage();
30
-            $this->vars['all'] = 0;
31
-            $this->vars['users'] = [];
32
-            $this->vars['rows'] = [];
29
+            $this->vars[ 'error' ] = $ex->getMessage();
30
+            $this->vars[ 'all' ] = 0;
31
+            $this->vars[ 'users' ] = [ ];
32
+            $this->vars[ 'rows' ] = [ ];
33 33
         }
34 34
 
35 35
         return $this->makePartial('widget');
@@ -58,35 +58,35 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $days = $this->property('days');
60 60
         if (!$days) {
61
-            throw new ApplicationException('Invalid days value: ' . $days);
61
+            throw new ApplicationException('Invalid days value: '.$days);
62 62
         }
63 63
 
64 64
         // all accesses for last month
65 65
         $items = AccessLog::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get();
66 66
 
67 67
         // parse data
68
-        $all = [];
69
-        $users = [];
70
-        $user_rows = [];
68
+        $all = [ ];
69
+        $users = [ ];
70
+        $user_rows = [ ];
71 71
         foreach ($items as $item)
72 72
         {
73 73
             // user
74 74
             $user_id = $item->user_id ? $item->user_id : 0;
75
-            $users[$user_id] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser();
75
+            $users[ $user_id ] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser();
76 76
 
77 77
             // date
78 78
             $timestamp = strtotime($item->created_at) * 1000;
79 79
             $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
80 80
 
81
-            if (isset($user_rows[$user_id][$day])) {
82
-                $user_rows[$user_id][$day][1]++;
81
+            if (isset($user_rows[ $user_id ][ $day ])) {
82
+                $user_rows[ $user_id ][ $day ][ 1 ]++;
83 83
             } else {
84
-                $user_rows[$user_id][$day] = [$timestamp, 1];
84
+                $user_rows[ $user_id ][ $day ] = [ $timestamp, 1 ];
85 85
             }
86 86
 
87 87
             // init empty day
88
-            if (!isset($all[$day])) {
89
-                $all[$day] = [
88
+            if (!isset($all[ $day ])) {
89
+                $all[ $day ] = [
90 90
                     'timestamp' => $timestamp,
91 91
                     'date' => $day,
92 92
                     'count' => 0,
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
             }
95 95
 
96 96
             // increase count
97
-            $all[$day]['count']++;
97
+            $all[ $day ][ 'count' ]++;
98 98
         }
99 99
 
100 100
         // we need at least two days, to display chart
101 101
         if (sizeof($all) == 1) {
102 102
             $day = reset($all);
103
-            $date = Carbon::createFromFormat('Y-m-d', $day['date'])->subDays(1);
103
+            $date = Carbon::createFromFormat('Y-m-d', $day[ 'date' ])->subDays(1);
104 104
             $dateFormated = $date->format('Y-m-d');
105
-            $all[$dateFormated] = [
105
+            $all[ $dateFormated ] = [
106 106
                 'timestamp' => $date->timestamp * 1000,
107 107
                 'date' => $dateFormated,
108 108
                 'count' => 0,
@@ -112,27 +112,27 @@  discard block
 block discarded – undo
112 112
         // transform user line to json
113 113
         foreach ($user_rows as $key => $user_row)
114 114
         {
115
-            $rows = [];
116
-            foreach($user_row as $row) {
117
-                $rows[] = [
118
-                    $row[0],
119
-                    $row[1],
115
+            $rows = [ ];
116
+            foreach ($user_row as $row) {
117
+                $rows[ ] = [
118
+                    $row[ 0 ],
119
+                    $row[ 1 ],
120 120
                 ];
121 121
             }
122 122
 
123 123
             // we need at least two days, to display chart
124 124
             if (sizeof($rows) == 1) {
125 125
                 $first = reset($rows);
126
-                $rows[] = [$first[0] - 86400000, 0];
126
+                $rows[ ] = [ $first[ 0 ] - 86400000, 0 ];
127 127
             }
128 128
 
129
-            $user_rows[$key] = $rows;
129
+            $user_rows[ $key ] = $rows;
130 130
         }
131 131
 
132 132
         // count all
133
-        $all_render = [];
133
+        $all_render = [ ];
134 134
         foreach ($all as $a) {
135
-            $all_render[] = [$a['timestamp'], $a['count']];
135
+            $all_render[ ] = [ $a[ 'timestamp' ], $a[ 'count' ] ];
136 136
         }
137 137
 
138 138
         return [
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -35,24 +35,24 @@
 block discarded – undo
35 35
         return $this->makePartial('widget');
36 36
     }
37 37
 
38
-	public function defineProperties()
39
-	{
40
-		return [
41
-			'title' => [
38
+    public function defineProperties()
39
+    {
40
+        return [
41
+            'title' => [
42 42
                 'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title',
43 43
                 'default' => 'Access statistics in time each user',
44
-				'type' => 'string',
45
-				'validationPattern' => '^.+$',
46
-				'validationMessage' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title_validation',
47
-			],
44
+                'type' => 'string',
45
+                'validationPattern' => '^.+$',
46
+                'validationMessage' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.title_validation',
47
+            ],
48 48
             'days' => [
49 49
                 'title' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.days_title',
50 50
                 'default' => '30',
51 51
                 'type' => 'string',
52 52
                 'validationPattern' => '^[0-9]+$',
53 53
             ]
54
-		];
55
-	}
54
+        ];
55
+    }
56 56
 
57 57
     protected function loadData()
58 58
     {
Please login to merge, or discard this patch.
models/AccessLog.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
      * @var array Relations
19 19
      */
20 20
     public $belongsTo = [
21
-        'user' => [User::class],
21
+        'user' => [ User::class ],
22 22
     ];
23 23
 
24 24
     /**
Please login to merge, or discard this patch.
models/Settings.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 {
8 8
     use ValidationTrait;
9 9
 
10
-    public $implement = ['System.Behaviors.SettingsModel'];
10
+    public $implement = [ 'System.Behaviors.SettingsModel' ];
11 11
 
12 12
     public $settingsCode = 'vojtasvoboda_useraccesslog_settings';
13 13
 
Please login to merge, or discard this patch.
reportwidgets/AccessLogStatistics.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
     public function render()
20 20
     {
21 21
         try {
22
-            $this->vars['all'] = $this->getCounts()['all'];
23
-            $this->vars['counts'] = $this->getCounts()['counts'];
22
+            $this->vars[ 'all' ] = $this->getCounts()[ 'all' ];
23
+            $this->vars[ 'counts' ] = $this->getCounts()[ 'counts' ];
24 24
 
25 25
         } catch (Exception $ex) {
26
-            $this->vars['error'] = $ex->getMessage();
27
-            $this->vars['all'] = 0;
28
-            $this->vars['counts'] = [];
26
+            $this->vars[ 'error' ] = $ex->getMessage();
27
+            $this->vars[ 'all' ] = 0;
28
+            $this->vars[ 'counts' ] = [ ];
29 29
         }
30 30
 
31 31
         return $this->makePartial('widget');
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $log = AccessLog::all()->groupBy('user_id');
60 60
 
61
-        $counts = [];
61
+        $counts = [ ];
62 62
         $all = 0;
63 63
         foreach ($log as $l) {
64
-            $first = $l[0];
64
+            $first = $l[ 0 ];
65 65
             $user = $first->user ? $first->user : $this->getDeletedFakeUser();
66 66
             $size = sizeof($l);
67
-            $counts[] = [
67
+            $counts[ ] = [
68 68
                 'size' => $size,
69 69
                 'id' => $first->user_id,
70 70
                 'name' => $user->username
Please login to merge, or discard this patch.
Plugin.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
     public function boot()
39 39
     {
40 40
         // log user after login
41
-        Event::listen('rainlab.user.login', function ($user) {
41
+        Event::listen('rainlab.user.login', function($user) {
42 42
             AccessLog::add($user);
43 43
         });
44 44
 
45 45
         // extend users side-menu with User Access log
46 46
         if (!empty(Settings::get('show_access_log_listing', false))) {
47
-            Event::listen('backend.menu.extendItems', function ($manager) {
47
+            Event::listen('backend.menu.extendItems', function($manager) {
48 48
                 $manager->addSideMenuItem('RainLab.User', 'user', 'access_log', [
49 49
                     'label' => 'backend::lang.access_log.menu_label',
50 50
                     'url' => Backend::url('vojtasvoboda/useraccesslog/log'),
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                 'icon' => 'icon-cog',
87 87
                 'description' => 'vojtasvoboda.useraccesslog::lang.settings.description',
88 88
                 'class' => Settings::class,
89
-                'permissions' => ['vojtasvoboda.useraccesslog.*'],
89
+                'permissions' => [ 'vojtasvoboda.useraccesslog.*' ],
90 90
                 'order' => 600,
91 91
             ]
92 92
         ];
Please login to merge, or discard this patch.