/
options.php
90 lines (85 loc) · 2.65 KB
/
options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php defined('C5_EXECUTE') or die('Access Denied.');
class DashboardSystemBasicsLocalizerOptionsController extends DashboardBaseController {
private function getContexts() {
return array(
'AttributeSetName' => t('Attribute sets names'),
'AttributeKeyName' => t('Attribute key names'),
'AttributeTypeName' => t('Attribute type names'),
'PermissionKeyName' => t('Permission key names'),
'PermissionKeyDescription' => t('Permission key descriptions'),
'PermissionAccessEntityTypeName' => t('Access entity type names'),
'JobSetName' => t('Job set names'),
'GroupName' => t('User group names'),
'GroupDescription' => t('User group descriptions'),
'GroupSetName' => t('User group set names'),
'SelectAttributeValue' => t('Values of the select attributes'),
'AreaName' => t('Area names')
);
}
public function view() {
$translationTables = array();
$lh = Loader::helper('localizer', 'localizer');
foreach($this->getContexts() as $context => $name) {
$vMin = $lh->getMinAppVersionForContext($context);
if(!strlen($vMin)) {
$selected = t('Still in development');
}
elseif(version_compare(APP_VERSION, $vMin) < 0) {
$selected = t('Available from concrete5 %s', $vMin);
}
elseif($this->isPost()) {
$posted = $this->post("enable_$context");
$selected = empty($posted) ? false : true;
}
else {
$selected = $lh->getContextEnabled($context);
}
$translationTables[] = array(
'context' => $context,
'name' => $name,
'selected' => $selected
);
}
$this->set('translationTables', $translationTables);
}
public function updated() {
$this->set('message', t('The options have been saved.'));
$this->view();
}
public function update() {
if($this->isPost()) {
if ($this->token->validate('update')) {
try {
$map = array();
$someEnabled = false;
foreach(array_keys($this->getContexts()) as $context) {
$posted = $this->post("enable_$context");
$enabled = empty($posted) ? false : true;
$map[$context] = $enabled;
if($enabled) {
$someEnabled = true;
}
}
if(!$someEnabled) {
$this->error->add(t('Please enable at least one item class to be translated.'));
}
else {
$lh = Loader::helper('localizer', 'localizer');
foreach($map as $context => $enabled) {
$lh->setContextEnabled($context, $enabled);
}
$lh->setConfigured(true);
$this->redirect('/dashboard/system/basics/localizer/options/updated/');
}
}
catch(Exception $x) {
$this->error->add($x->getMessage());
}
}
else {
$this->error->add($this->token->getErrorMessage());
}
}
$this->view();
}
}