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() |
36
|
|
|
{ |
37
|
|
|
return $this->render('ONGRSettingsBundle:Settings:list.html.twig'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Setting update action. |
42
|
|
|
* |
43
|
|
|
* @param Request $request |
44
|
|
|
* |
45
|
|
|
* @return JsonResponse |
46
|
|
|
*/ |
47
|
|
|
public function updateValueAction(Request $request) |
48
|
|
|
{ |
49
|
|
|
$name = $request->get('name'); |
50
|
|
|
$value = $request->get('value'); |
51
|
|
|
|
52
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
53
|
|
|
$manager->update($name, ['value' => $value]); |
54
|
|
|
|
55
|
|
|
return new JsonResponse(['error' => false]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Setting delete action |
60
|
|
|
* |
61
|
|
|
* @param Request $request |
62
|
|
|
* @param $id |
63
|
|
|
* |
64
|
|
|
* @return JsonResponse |
65
|
|
|
*/ |
66
|
|
|
public function deleteAction(Request $request, $id) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
try { |
69
|
|
|
/** @var Repository $repo */ |
70
|
|
|
$repo = $this->get($this->getParameter('ongr_settings.repo')); |
71
|
|
|
|
72
|
|
|
$repo->remove($id); |
73
|
|
|
|
74
|
|
|
return new JsonResponse(['error' => false]); |
75
|
|
|
|
76
|
|
|
} catch (\Exception $e) { |
77
|
|
|
return new JsonResponse( |
78
|
|
|
[ |
79
|
|
|
'error' => true, |
80
|
|
|
'message' => 'Error occurred please try to delete setting again.' |
81
|
|
|
] |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Submit action to create or edit setting if not exists. |
88
|
|
|
* |
89
|
|
|
* @param Request $request |
90
|
|
|
* |
91
|
|
|
* @return JsonResponse |
92
|
|
|
*/ |
93
|
|
|
public function submitAction(Request $request) |
94
|
|
|
{ |
95
|
|
|
try { |
96
|
|
|
$manager = $this->get('ongr_settings.settings_manager'); |
97
|
|
|
$data = $request->get('setting'); |
98
|
|
|
|
99
|
|
|
if ($request->get('force')) { |
100
|
|
|
$name = $request->get('name'); |
101
|
|
|
$manager->update($name, $data); |
102
|
|
|
} else { |
103
|
|
|
$manager->create($data); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return new JsonResponse(['error' => false]); |
107
|
|
|
|
108
|
|
|
} catch (\Exception $e) { |
109
|
|
|
return new JsonResponse( |
110
|
|
|
[ |
111
|
|
|
'error' => true, |
112
|
|
|
'message' => 'Error occurred! Something is wrong with provided data. Please try to submit form again.' |
113
|
|
|
] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.