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 ONGR\ElasticsearchBundle\Result\Aggregation\AggregationValue; |
15
|
|
|
use ONGR\ElasticsearchBundle\Service\Repository; |
16
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation; |
17
|
|
|
use ONGR\SettingsBundle\Document\Setting; |
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
19
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class SettingsListController. Is used for managing settings in General env. |
25
|
|
|
*/ |
26
|
|
|
class SettingsController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Renders settings list page. |
30
|
|
|
* |
31
|
|
|
* @param Request $request |
32
|
|
|
* |
33
|
|
|
* @return Response |
34
|
|
|
*/ |
35
|
|
|
public function listAction(Request $request) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
/** @var Repository $repo */ |
38
|
|
|
$repo = $this->get($this->getParameter('ongr_settings.repo')); |
39
|
|
|
$className = $repo->getClassName(); |
40
|
|
|
$form = $this->createForm($this->getParameter('ongr_settings.type.setting.class'), new $className); |
41
|
|
|
|
42
|
|
|
return $this->render( |
43
|
|
|
'ONGRSettingsBundle:Settings:list.html.twig', |
44
|
|
|
[ |
45
|
|
|
'form' => $form->createView(), |
46
|
|
|
] |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Setting update action. |
52
|
|
|
* |
53
|
|
|
* @param Request $request |
54
|
|
|
* |
55
|
|
|
* @return JsonResponse |
56
|
|
|
*/ |
57
|
|
|
public function updateValueAction(Request $request) |
58
|
|
|
{ |
59
|
|
|
$name = $request->get('name'); |
60
|
|
|
$value = $request->get('value'); |
61
|
|
|
|
62
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
63
|
|
|
$manager->update($name, ['value' => $value]); |
64
|
|
|
|
65
|
|
|
return new JsonResponse(['error' => false]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Setting delete action |
70
|
|
|
* |
71
|
|
|
* @param Request $request |
72
|
|
|
* @param $id |
73
|
|
|
* |
74
|
|
|
* @return JsonResponse |
75
|
|
|
*/ |
76
|
|
|
public function deleteAction(Request $request, $id) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
try { |
79
|
|
|
/** @var Repository $repo */ |
80
|
|
|
$repo = $this->get($this->getParameter('ongr_settings.repo')); |
81
|
|
|
|
82
|
|
|
$repo->remove($id); |
83
|
|
|
|
84
|
|
|
return new JsonResponse(['error' => false]); |
85
|
|
|
|
86
|
|
|
} catch (\Exception $e) { |
87
|
|
|
return new JsonResponse( |
88
|
|
|
[ |
89
|
|
|
'error' => true, |
90
|
|
|
'message' => 'Error occurred please try to delete setting again.' |
91
|
|
|
] |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Submit action to create or edit setting if not exists. |
98
|
|
|
* |
99
|
|
|
* @param Request $request |
100
|
|
|
* |
101
|
|
|
* @return JsonResponse |
102
|
|
|
*/ |
103
|
|
|
public function submitAction(Request $request) |
104
|
|
|
{ |
105
|
|
|
try { |
106
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
107
|
|
|
$data = $request->get('setting'); |
108
|
|
|
|
109
|
|
|
if ($request->get('force')) { |
110
|
|
|
$name = $request->get('name'); |
111
|
|
|
$manager->update($name, $data); |
112
|
|
|
} else { |
113
|
|
|
$manager->create($data); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return new JsonResponse(['error' => false]); |
117
|
|
|
|
118
|
|
|
} catch (\Exception $e) { |
119
|
|
|
return new JsonResponse( |
120
|
|
|
[ |
121
|
|
|
'error' => true, |
122
|
|
|
'message' => 'Error occurred! Something is wrong with provided data. Please try to submit form again.' |
123
|
|
|
] |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.