|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Controller\Admin; |
|
5
|
|
|
|
|
6
|
|
|
use Sylius\Bundle\SettingsBundle\Controller\SettingsController as SyliusSettingsController; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
9
|
|
|
use Symfony\Component\Validator\Exception\ValidatorException; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
12
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
13
|
|
|
use Chamilo\SettingsBundle\Manager\SettingsManager; |
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class SettingsController |
|
18
|
|
|
* @package Chamilo\SettingsBundle\Controller |
|
19
|
|
|
*/ |
|
20
|
|
|
class SettingsController extends SyliusSettingsController |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
24
|
|
|
* @Route("/settings", name="admin_settings") |
|
25
|
|
|
* |
|
26
|
|
|
* @return array |
|
27
|
|
|
*/ |
|
28
|
|
|
public function indexAction() |
|
29
|
|
|
{ |
|
30
|
|
|
$manager = $this->getSettingsManager(); |
|
31
|
|
|
$schemas = $manager->getSchemas(); |
|
32
|
|
|
|
|
33
|
|
|
return $this->render( |
|
34
|
|
|
'@ChamiloCore/Admin/Settings/index.html.twig', |
|
35
|
|
|
array( |
|
36
|
|
|
'schemas' => $schemas |
|
37
|
|
|
) |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Edit configuration with given namespace. |
|
43
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
44
|
|
|
* |
|
45
|
|
|
* @Route("/settings/{namespace}", name="chamilo_platform_settings") |
|
46
|
|
|
* |
|
47
|
|
|
* @param Request $request |
|
48
|
|
|
* @param string $namespace |
|
49
|
|
|
* |
|
50
|
|
|
* @return Response |
|
51
|
|
|
*/ |
|
52
|
|
|
public function updateSettingAction(Request $request, $namespace) |
|
53
|
|
|
{ |
|
54
|
|
|
$manager = $this->getSettingsManager(); |
|
55
|
|
|
|
|
56
|
|
|
$builder = $this->container->get('form.factory')->createNamedBuilder( |
|
57
|
|
|
'search' |
|
58
|
|
|
); |
|
59
|
|
|
$builder->add('keyword', 'text'); |
|
60
|
|
|
$builder->add('search', 'submit'); |
|
61
|
|
|
$searchForm = $builder->getForm(); |
|
62
|
|
|
|
|
63
|
|
|
$keyword = ''; |
|
64
|
|
|
if ($searchForm->handleRequest($request)->isValid()) { |
|
65
|
|
|
$values = $searchForm->getData(); |
|
66
|
|
|
$keyword = $values['keyword']; |
|
67
|
|
|
$settingsFromKeyword = $manager->getParametersFromKeyword( |
|
68
|
|
|
$namespace, |
|
69
|
|
|
$keyword |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$keywordFromGet = $request->query->get('keyword'); |
|
74
|
|
|
if ($keywordFromGet) { |
|
75
|
|
|
$keyword = $keywordFromGet; |
|
76
|
|
|
$searchForm->setData(['keyword' => $keyword]); |
|
77
|
|
|
$settingsFromKeyword = $manager->getParametersFromKeyword( |
|
78
|
|
|
$namespace, |
|
79
|
|
|
$keywordFromGet |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$settings = $manager->load($manager->convertNameSpaceToService($namespace)); |
|
84
|
|
|
|
|
85
|
|
|
$form = $this->getSettingsFormFactory()->create($namespace); |
|
86
|
|
|
|
|
87
|
|
|
if (!empty($keyword)) { |
|
88
|
|
|
$params = $settings->getParameters(); |
|
89
|
|
|
foreach ($params as $name => $value) { |
|
90
|
|
|
if (!in_array($name, array_keys($settingsFromKeyword))) { |
|
91
|
|
|
$form->remove($name); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$form->setData($settings); |
|
97
|
|
|
|
|
98
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
99
|
|
|
$messageType = 'success'; |
|
100
|
|
|
try { |
|
101
|
|
|
$manager->save($namespace, $form->getData()); |
|
102
|
|
|
$message = $this->getTranslator()->trans('sylius.settings.update', array(), 'flashes'); |
|
103
|
|
|
} catch (ValidatorException $exception) { |
|
104
|
|
|
$message = $this->getTranslator()->trans($exception->getMessage(), array(), 'validators'); |
|
105
|
|
|
$messageType = 'error'; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$this->addFlash($messageType, $message); |
|
109
|
|
|
|
|
110
|
|
|
/*if ($request->headers->has('referer')) { |
|
111
|
|
|
return $this->redirect($request->headers->get('referer')); |
|
112
|
|
|
}*/ |
|
113
|
|
|
} |
|
114
|
|
|
$schemas = $manager->getSchemas(); |
|
115
|
|
|
|
|
116
|
|
|
return $this->render( |
|
117
|
|
|
'@ChamiloCore/Admin/Settings/default.html.twig', |
|
118
|
|
|
array( |
|
119
|
|
|
'schemas' => $schemas, |
|
120
|
|
|
'settings' => $settings, |
|
121
|
|
|
'form' => $form->createView(), |
|
122
|
|
|
'keyword' => $keyword, |
|
123
|
|
|
'search_form' => $searchForm->createView(), |
|
124
|
|
|
) |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return SettingsManager |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function getSettingsManager() |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->get('chamilo.settings.manager'); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|