Completed
Pull Request — master (#5)
by Vojta
01:49
created
models/AccessLog.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -10,32 +10,32 @@
 block discarded – undo
10 10
  */
11 11
 class AccessLog extends Model
12 12
 {
13
-	/**
14
-	 * @var string The database table used by the model.
15
-	 */
16
-	protected $table = 'user_access_log';
13
+    /**
14
+     * @var string The database table used by the model.
15
+     */
16
+    protected $table = 'user_access_log';
17 17
 
18
-	/**
19
-	 * @var array Relations
20
-	 */
21
-	public $belongsTo = [
22
-		'user' => ['RainLab\User\Models\User']
23
-	];
18
+    /**
19
+     * @var array Relations
20
+     */
21
+    public $belongsTo = [
22
+        'user' => ['RainLab\User\Models\User']
23
+    ];
24 24
 
25
-	/**
26
-	 * Creates a log record
27
-	 *
28
-	 * @param \RainLab\User\Models\User $user Front-end user
29
-	 *
30
-	 * @return self
31
-	 */
32
-	public static function add($user)
33
-	{
34
-		$record = new static;
35
-		$record->user = $user;
36
-		$record->ip_address = Request::getClientIp();
37
-		$record->save();
25
+    /**
26
+     * Creates a log record
27
+     *
28
+     * @param \RainLab\User\Models\User $user Front-end user
29
+     *
30
+     * @return self
31
+     */
32
+    public static function add($user)
33
+    {
34
+        $record = new static;
35
+        $record->user = $user;
36
+        $record->ip_address = Request::getClientIp();
37
+        $record->save();
38 38
 
39
-		return $record;
40
-	}
39
+        return $record;
40
+    }
41 41
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 	 * @var array Relations
20 20
 	 */
21 21
 	public $belongsTo = [
22
-		'user' => ['RainLab\User\Models\User']
22
+		'user' => [ 'RainLab\User\Models\User' ]
23 23
 	];
24 24
 
25 25
 	/**
Please login to merge, or discard this patch.
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/AccessLogStatistics.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@  discard block
 block discarded – undo
21 21
     public function render()
22 22
     {
23 23
         try {
24
-            $this->vars['all'] = $this->getCounts()['all'];
25
-            $this->vars['counts'] = $this->getCounts()['counts'];
24
+            $this->vars[ 'all' ] = $this->getCounts()[ 'all' ];
25
+            $this->vars[ 'counts' ] = $this->getCounts()[ 'counts' ];
26 26
 
27 27
         } catch (Exception $ex) {
28
-            $this->vars['error'] = $ex->getMessage();
29
-            $this->vars['all'] = 0;
30
-            $this->vars['counts'] = [];
28
+            $this->vars[ 'error' ] = $ex->getMessage();
29
+            $this->vars[ 'all' ] = 0;
30
+            $this->vars[ 'counts' ] = [ ];
31 31
         }
32 32
 
33 33
         return $this->makePartial('widget');
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
     {
61 61
         $log = AccessLog::all()->groupBy('user_id');
62 62
 
63
-        $counts = [];
63
+        $counts = [ ];
64 64
         $all = 0;
65 65
         foreach ($log as $l) {
66
-            $first = $l[0];
66
+            $first = $l[ 0 ];
67 67
             $user = $first->user;
68 68
             $size = sizeof($l);
69
-            $counts[] = [
69
+            $counts[ ] = [
70 70
                 'size' => $size,
71 71
                 'id' => $first->user_id,
72 72
                 'name' => $user->username
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/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   +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.
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.