1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\SettingsBundle\Controller; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
15
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class SettingsListController. Is used for managing settings in General env. |
21
|
|
|
*/ |
22
|
|
|
class SettingsController extends Controller |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
public function enableProfileAction($key) |
26
|
|
|
{ |
27
|
|
|
$profileName = $key; |
28
|
|
|
|
29
|
|
|
$cookie = $this->get('ongr_settings.cookie.active_profiles'); |
30
|
|
|
$currentActiveProfiles = $cookie->getValue(); |
31
|
|
|
|
32
|
|
|
if (is_array($currentActiveProfiles) && !array_intersect($currentActiveProfiles, [$profileName])) { |
33
|
|
|
$currentActiveProfiles[] = $profileName; |
34
|
|
|
$cookie->setValue($currentActiveProfiles); |
35
|
|
|
} else { |
36
|
|
|
$cookie->setValue([$profileName]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$settingsManager = $this->get('ongr_settings.settings_manager'); |
40
|
|
|
$settings = $settingsManager->getProfileSettings($profileName); |
41
|
|
|
|
42
|
|
|
return $this->render('ONGRSettingsBundle:Settings:enableProfile.html.twig', [ |
43
|
|
|
'profile' => $profileName, |
44
|
|
|
'profiles' => $settings, |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Renders settings list page. |
50
|
|
|
* |
51
|
|
|
* @return Response |
52
|
|
|
*/ |
53
|
|
|
public function listAction() |
54
|
|
|
{ |
55
|
|
|
return $this->render('ONGRSettingsBundle:Settings:list.html.twig'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Setting update action. |
60
|
|
|
* |
61
|
|
|
* @param Request $request |
62
|
|
|
* |
63
|
|
|
* @return JsonResponse |
64
|
|
|
*/ |
65
|
|
|
public function updateValueAction(Request $request) |
66
|
|
|
{ |
67
|
|
|
$name = $request->get('name'); |
68
|
|
|
$value = $request->get('value'); |
69
|
|
|
|
70
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
71
|
|
|
$manager->update($name, ['value' => $value]); |
72
|
|
|
|
73
|
|
|
return new JsonResponse(['error' => false]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Setting delete action |
78
|
|
|
* |
79
|
|
|
* @param Request $request |
80
|
|
|
* |
81
|
|
|
* @return JsonResponse |
82
|
|
|
*/ |
83
|
|
|
public function deleteAction(Request $request) |
84
|
|
|
{ |
85
|
|
|
try { |
86
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
87
|
|
|
$manager->delete($request->get('name')); |
88
|
|
|
|
89
|
|
|
return new JsonResponse(['error' => false]); |
90
|
|
|
} catch (\Exception $e) { |
91
|
|
|
return new JsonResponse( |
92
|
|
|
[ |
93
|
|
|
'error' => true, |
94
|
|
|
'message' => 'Error occurred please try to delete setting again.' |
95
|
|
|
] |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Submit action to create or edit setting if not exists. |
102
|
|
|
* |
103
|
|
|
* @param Request $request |
104
|
|
|
* |
105
|
|
|
* @return JsonResponse |
106
|
|
|
*/ |
107
|
|
|
public function submitAction(Request $request) |
108
|
|
|
{ |
109
|
|
|
try { |
110
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
111
|
|
|
$data = $request->get('setting'); |
112
|
|
|
|
113
|
|
|
if ($request->get('force')) { |
114
|
|
|
$name = $request->get('name'); |
115
|
|
|
$manager->update($name, $data); |
116
|
|
|
} else { |
117
|
|
|
$manager->create($data); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return new JsonResponse(['error' => false]); |
121
|
|
|
} catch (\Exception $e) { |
122
|
|
|
return new JsonResponse( |
123
|
|
|
[ |
124
|
|
|
'error' => true, |
125
|
|
|
'message' => 'Error occurred! Something is wrong with provided data. '. |
126
|
|
|
'Please try to submit form again.' |
127
|
|
|
] |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|