1
|
|
|
<?php namespace VojtaSvoboda\UserExportPdf; |
2
|
|
|
|
3
|
|
|
use Event; |
4
|
|
|
use Lang; |
5
|
|
|
use RainLab\User\Controllers\Users as UserController; |
6
|
|
|
use RainLab\User\Models\User as UserModel; |
7
|
|
|
use System\Classes\PluginBase; |
8
|
|
|
|
9
|
|
|
class Plugin extends PluginBase |
10
|
|
|
{ |
11
|
|
|
public $require = [ |
12
|
|
|
'RainLab.User', |
13
|
|
|
'Renatio.DynamicPDF', |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
public function pluginDetails() |
17
|
|
|
{ |
18
|
|
|
return [ |
19
|
|
|
'name' => 'vojtasvoboda.userexportpdf::lang.plugin.name', |
20
|
|
|
'description' => 'vojtasvoboda.userexportpdf::lang.plugin.description', |
21
|
|
|
'author' => 'Vojta Svoboda', |
22
|
|
|
'icon' => 'icon-file-pdf-o', |
23
|
|
|
'homepage' => 'https://github.com/vojtasvoboda/oc-userexportpdf-plugin', |
24
|
|
|
]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function boot() |
28
|
|
|
{ |
29
|
|
|
UserController::extend(function($controller) { |
30
|
|
|
$controller->implement[ ] = 'VojtaSvoboda.UserExportPdf.Behaviors.PdfExportBehavior'; |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
// extend user listing |
34
|
|
|
Event::listen('backend.list.extendColumns', function($widget) { |
35
|
|
|
// Only for the User controller |
36
|
|
|
if (!$widget->getController() instanceof UserController) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// Only for the User model |
41
|
|
|
if (!$widget->model instanceof UserModel) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Add an extra birthday column |
46
|
|
|
$widget->addColumns([ |
47
|
|
|
'export' => [ |
48
|
|
|
'label' => 'vojtasvoboda.userexportpdf::lang.list.export.column', |
49
|
|
|
'sortable' => false, |
50
|
|
|
'clickable' => false, |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
// extend export column value to add export button |
56
|
|
|
Event::listen('backend.list.overrideColumnValue', function($widget, $model, $column, $value) { |
|
|
|
|
57
|
|
|
// Only for the User model |
58
|
|
|
if (!$model instanceof UserModel) { |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($column->columnName == 'export') { |
63
|
|
|
$button = '<a role="button" style="color:white"'; |
64
|
|
|
$button .= ' href="' . url('/backend/rainlab/user/users/pdf/' . $model->id) . '"'; |
65
|
|
|
$button .= ' class="btn btn-xs btn-warning"'; |
66
|
|
|
$button .= '>' . Lang::get('vojtasvoboda.userexportpdf::lang.list.export.button') . '</a>'; |
67
|
|
|
|
68
|
|
|
return $button; |
69
|
|
|
} |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function registerPermissions() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
'vojtasvoboda.userexportpdf.export' => [ |
77
|
|
|
'tab' => 'vojtasvoboda.userexportpdf::lang.permission.tab', |
78
|
|
|
'label' => 'vojtasvoboda.userexportpdf::lang.permission.export', |
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.