1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Donatas Navidonskis <[email protected]> |
5
|
|
|
* @since 2017 |
6
|
|
|
* @class LangEditor |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
class LangEditor extends LeftAndMain implements PermissionProvider { |
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
* @config |
14
|
|
|
*/ |
15
|
|
|
private static $menu_title = 'Lang Editor'; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
* @config |
20
|
|
|
*/ |
21
|
|
|
private static $url_segment = 'lang-editor'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var float |
25
|
|
|
* @config |
26
|
|
|
*/ |
27
|
|
|
private static $menu_priority = -0.6; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
* @config |
32
|
|
|
*/ |
33
|
|
|
private static $allowed_actions = [ |
|
|
|
|
34
|
|
|
'FormEntities', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Default configuration of items per page. |
39
|
|
|
* Set "null" if unlimited. |
40
|
|
|
* |
41
|
|
|
* @var int |
42
|
|
|
* @config |
43
|
|
|
*/ |
44
|
|
|
private static $items_per_page = 30; |
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function providePermissions() { |
50
|
|
|
$title = _t('LangEditor.MENU_TITLE', 'Lang Editor'); |
51
|
|
|
|
52
|
|
|
return [ |
53
|
|
|
"CMS_ACCESS_LangEditorAdmin" => [ |
54
|
|
|
'name' => _t('CMSMain.ACCESS', "Access to '{title}' section", ['title' => $title]), |
|
|
|
|
55
|
|
|
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access'), |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @param Member $member |
63
|
|
|
* |
64
|
|
|
* @return int|bool |
65
|
|
|
*/ |
66
|
|
|
public function canView($member = null) { |
67
|
|
|
return Permission::check('CMS_ACCESS_LangEditorAdmin', 'any', $member); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function init() { |
71
|
|
|
static::config()->menu_title = _t('LangEditor.MENU_TITLE', 'Lang Editor'); |
72
|
|
|
|
73
|
|
|
return parent::init(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function flushCache() { |
77
|
|
|
$cache = SS_Cache::factory(static::class); |
78
|
|
|
$cache->clean(Zend_Cache::CLEANING_MODE_ALL); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getModules() { |
82
|
|
|
$list = new ArrayList(); |
83
|
|
|
$parameters = $this->getRequest()->getVars(); |
84
|
|
|
|
85
|
|
|
unset($parameters['url']); |
86
|
|
|
unset($parameters['start']); |
87
|
|
|
unset($parameters['search']); |
88
|
|
|
|
89
|
|
|
LangModule::get()->each(function (LangModule $module) use ($parameters, &$list) { |
90
|
|
|
if (array_key_exists('moduleId', $parameters) && $parameters['moduleId'] == $module->ID) { |
91
|
|
|
$module->Current = true; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$parameters['moduleId'] = $module->ID; |
95
|
|
|
|
96
|
|
|
$module->Link = Controller::join_links( |
|
|
|
|
97
|
|
|
Controller::curr()->Link(), |
98
|
|
|
"?".http_build_query($parameters) |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$list->push($module); |
102
|
|
|
}); |
103
|
|
|
|
104
|
|
|
if (! $list->filter('Current', true)->first() && $list->count() > 0) { |
105
|
|
|
$list->first()->Current = true; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $list; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getCurrentModule() { |
112
|
|
|
return $this->getModules()->filter('Current', true)->first(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function getCurrentSearchTerm() { |
116
|
|
|
return $this->getRequest()->getVar('search'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function FormEntities() { |
120
|
|
|
/** @var LangModule $module */ |
121
|
|
|
if ($module = $this->getModules()->filter('Current', true)->first()) { |
122
|
|
|
$entities = $module->Entities(); |
123
|
|
|
$searchTerm = $this->getRequest()->getVar('search'); |
124
|
|
|
|
125
|
|
|
if (! empty($searchTerm)) { |
126
|
|
|
$entities = $entities->filter('SearchFields:LangFulltextBoolean', $searchTerm); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$parameters = $this->getRequest()->getVars(); |
130
|
|
|
|
131
|
|
|
unset($parameters['url']); |
132
|
|
|
|
133
|
|
|
$parameters = count($parameters) > 0 ? '?'.http_build_query($parameters) : ''; |
134
|
|
|
|
135
|
|
|
$form = new FormEntities(Controller::curr(), __FUNCTION__, $entities); |
136
|
|
|
$form->clearMessage(); |
137
|
|
|
$form->setFormAction(Controller::join_links( |
138
|
|
|
$this->Link('FormEntities'), |
139
|
|
|
$parameters |
140
|
|
|
)); |
141
|
|
|
|
142
|
|
|
return $form; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return false; |
146
|
|
|
} |
147
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.