1
|
|
|
<?php namespace StudioBonito\Security\Controllers; |
2
|
|
|
|
3
|
|
|
use GridFieldButtonRow; |
4
|
|
|
use GridFieldExportButton; |
5
|
|
|
use GridFieldPrintButton; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* ModelAdmin implementation for handling member, group and role data-objects. |
9
|
|
|
* |
10
|
|
|
* @author Tom Densham <[email protected]> |
11
|
|
|
* @copyright Studio Bonito Ltd. |
12
|
|
|
*/ |
13
|
|
|
class MemberAdmin extends \ModelAdmin |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The current url segment. {@link LeftAndMain::$url_segment} |
17
|
|
|
* |
18
|
|
|
* @config |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private static $url_segment = 'members'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The current menu title. {@link LeftAndMain::$menu_title} |
25
|
|
|
* |
26
|
|
|
* @config |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private static $menu_title = 'Security'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The menu icon. |
33
|
|
|
* |
34
|
|
|
* @config |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private static $menu_icon = 'framework/admin/images/menu-icons/16x16/community.png'; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @config |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
private static $menu_priority = -1; |
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* List of all managed {@link DataObject}s in this interface. {@link ModelAdmin::$managed_models} |
47
|
|
|
* |
48
|
|
|
* @config |
49
|
|
|
* @var array|string |
50
|
|
|
*/ |
51
|
|
|
private static $managed_models = array( |
|
|
|
|
52
|
|
|
'Member', |
53
|
|
|
'Group', |
54
|
|
|
'PermissionRole', |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* List of all {@link DataObject}s which can be imported through a subclass of {@link BulkLoader} (mostly CSV data). |
59
|
|
|
* |
60
|
|
|
* @config |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
private static $model_importers = array( |
|
|
|
|
64
|
|
|
'Member' => 'MemberCsvBulkLoader', |
65
|
|
|
'Group' => 'GroupCsvBulkLoader', |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Override managed model labels with CMS defaults for member, group and role. |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function getManagedModels() |
74
|
|
|
{ |
75
|
|
|
$models = parent::getManagedModels(); |
76
|
|
|
|
77
|
|
|
if (isset($models['Member']) && isset($models['Member']['title'])) { |
78
|
|
|
$models['Member']['title'] = _t('SecurityAdmin.Users', 'Users'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (isset($models['Group']) && isset($models['Group']['title'])) { |
82
|
|
|
$models['Group']['title'] = singleton('Group')->i18n_plural_name(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (isset($models['PermissionRole']) && isset($models['PermissionRole']['title'])) { |
86
|
|
|
$models['PermissionRole']['title'] = _t('SecurityAdmin.TABROLES', 'Roles'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $models; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Override gridfield configuration to provide a consistent UX. |
94
|
|
|
* |
95
|
|
|
* @param null $id |
96
|
|
|
* @param null $fields |
97
|
|
|
* |
98
|
|
|
* @return \CMSForm |
99
|
|
|
*/ |
100
|
|
|
public function getEditForm($id = null, $fields = null) |
101
|
|
|
{ |
102
|
|
|
$form = parent::getEditForm($id, $fields); |
103
|
|
|
|
104
|
|
|
$gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass)); |
105
|
|
|
$gridFieldConfig = $gridField->getConfig(); |
106
|
|
|
|
107
|
|
|
$gridFieldConfig->addComponent(new GridFieldButtonRow('after')); |
108
|
|
|
|
109
|
|
|
$gridFieldConfig->removeComponentsByType('GridFieldExportButton'); |
110
|
|
|
|
111
|
|
|
$exportButton = new GridFieldExportButton('buttons-after-left'); |
112
|
|
|
$exportButton->setExportColumns($this->getExportFields()); |
113
|
|
|
|
114
|
|
|
$gridFieldConfig->addComponent($exportButton); |
115
|
|
|
|
116
|
|
|
$gridFieldConfig->removeComponentsByType('GridFieldPrintButton'); |
117
|
|
|
|
118
|
|
|
$gridFieldConfig->addComponent(new GridFieldPrintButton('buttons-after-left')); |
119
|
|
|
|
120
|
|
|
return $form; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|