1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\GroupsModule\Controller; |
15
|
|
|
|
16
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
17
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
20
|
|
|
use Zikula\Bundle\CoreBundle\Controller\AbstractController; |
21
|
|
|
use Zikula\GroupsModule\Entity\RepositoryInterface\GroupRepositoryInterface; |
22
|
|
|
use Zikula\GroupsModule\Form\Type\ConfigType; |
23
|
|
|
use Zikula\PermissionsModule\Annotation\PermissionCheck; |
24
|
|
|
use Zikula\ThemeModule\Engine\Annotation\Theme; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class ConfigController |
28
|
|
|
* |
29
|
|
|
* @Route("/config") |
30
|
|
|
* @PermissionCheck("admin") |
31
|
|
|
*/ |
32
|
|
|
class ConfigController extends AbstractController |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @Route("/config") |
36
|
|
|
* @Theme("admin") |
37
|
|
|
* @Template("@ZikulaGroupsModule/Config/config.html.twig") |
38
|
|
|
* |
39
|
|
|
* @return array|RedirectResponse |
40
|
|
|
*/ |
41
|
|
|
public function configAction(Request $request, GroupRepositoryInterface $groupRepository) |
42
|
|
|
{ |
43
|
|
|
// build a groups array suitable for the form choices |
44
|
|
|
$groupsList = []; |
45
|
|
|
$groups = $groupRepository->findAll(); |
46
|
|
|
foreach ($groups as $group) { |
47
|
|
|
$groupsList[$group->getName()] = $group->getGid(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$form = $this->createForm(ConfigType::class, $this->getVars(), [ |
51
|
|
|
'groups' => $groupsList |
52
|
|
|
]); |
53
|
|
|
$form->handleRequest($request); |
54
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
55
|
|
|
if ($form->get('save')->isClicked()) { |
|
|
|
|
56
|
|
|
$this->setVars($form->getData()); |
57
|
|
|
$this->addFlash('status', 'Done! Configuration updated.'); |
58
|
|
|
} elseif ($form->get('cancel')->isClicked()) { |
59
|
|
|
$this->addFlash('status', 'Operation cancelled.'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->redirectToRoute('zikulagroupsmodule_group_adminlist'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return [ |
66
|
|
|
'form' => $form->createView() |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|