@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @var array Plugin dependencies |
16 | 16 | */ |
17 | - public $require = ['RainLab.User']; |
|
17 | + public $require = [ 'RainLab.User' ]; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Returns information about this plugin. |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * Log user after login |
38 | 38 | */ |
39 | - Event::listen('rainlab.user.login', function ($user) { |
|
39 | + Event::listen('rainlab.user.login', function($user) { |
|
40 | 40 | AccessLog::add($user); |
41 | 41 | }); |
42 | 42 | } |
@@ -10,32 +10,32 @@ |
||
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 | } |
@@ -19,7 +19,7 @@ |
||
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 | /** |
@@ -9,31 +9,31 @@ |
||
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 | } |
@@ -21,13 +21,13 @@ discard block |
||
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 |
||
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 |
@@ -38,24 +38,24 @@ |
||
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' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.title_default', |
|
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' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.title_default', |
|
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 | { |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | public function render() |
24 | 24 | { |
25 | 25 | try { |
26 | - $this->vars['all'] = $this->loadData(); |
|
26 | + $this->vars[ 'all' ] = $this->loadData(); |
|
27 | 27 | } |
28 | 28 | catch (Exception $ex) { |
29 | - $this->vars['error'] = $ex->getMessage(); |
|
30 | - $this->vars['all'] = ''; |
|
29 | + $this->vars[ 'error' ] = $ex->getMessage(); |
|
30 | + $this->vars[ 'all' ] = ''; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | return $this->makePartial('widget'); |
@@ -61,31 +61,31 @@ discard block |
||
61 | 61 | { |
62 | 62 | $days = $this->property('days'); |
63 | 63 | if (!$days) { |
64 | - throw new ApplicationException('Invalid days value: ' . $days); |
|
64 | + throw new ApplicationException('Invalid days value: '.$days); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // all accesses for last month |
68 | 68 | $items = AccessLog::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get(); |
69 | 69 | |
70 | 70 | // parse data |
71 | - $all = []; |
|
71 | + $all = [ ]; |
|
72 | 72 | foreach ($items as $item) |
73 | 73 | { |
74 | 74 | // date |
75 | 75 | $timestamp = strtotime($item->created_at) * 1000; |
76 | 76 | $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d'); |
77 | 77 | |
78 | - if (isset($all[$day])) { |
|
79 | - $all[$day][1]++; |
|
78 | + if (isset($all[ $day ])) { |
|
79 | + $all[ $day ][ 1 ]++; |
|
80 | 80 | } else { |
81 | - $all[$day] = [$timestamp, 1]; |
|
81 | + $all[ $day ] = [ $timestamp, 1 ]; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | 85 | // count accessess for each day |
86 | - $all_render = []; |
|
86 | + $all_render = [ ]; |
|
87 | 87 | foreach ($all as $a) { |
88 | - $all_render[] = [$a[0], $a[1]]; |
|
88 | + $all_render[ ] = [ $a[ 0 ], $a[ 1 ] ]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | return str_replace('"', '', substr(substr(json_encode($all_render), 1), 0, -1)); |
@@ -24,8 +24,7 @@ |
||
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 | } |