diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php new file mode 100644 index 00000000..f48a9cb1 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -0,0 +1,58 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
7 | use Symfony\Component\HttpFoundation\Request; | ||
8 | use Wallabag\CoreBundle\Entity\Config; | ||
9 | use Wallabag\CoreBundle\Form\Type\ConfigType; | ||
10 | |||
11 | class ConfigController extends Controller | ||
12 | { | ||
13 | /** | ||
14 | * @param Request $request | ||
15 | * | ||
16 | * @Route("/config", name="config") | ||
17 | * | ||
18 | * @return \Symfony\Component\HttpFoundation\Response | ||
19 | */ | ||
20 | public function indexAction(Request $request) | ||
21 | { | ||
22 | $config = $this->getConfig(); | ||
23 | |||
24 | $form = $this->createForm(new ConfigType(), $config); | ||
25 | |||
26 | $form->handleRequest($request); | ||
27 | |||
28 | if ($form->isValid()) { | ||
29 | $em = $this->getDoctrine()->getManager(); | ||
30 | $em->persist($config); | ||
31 | $em->flush(); | ||
32 | |||
33 | $this->get('session')->getFlashBag()->add( | ||
34 | 'notice', | ||
35 | 'Config saved' | ||
36 | ); | ||
37 | |||
38 | return $this->redirect($this->generateUrl('config')); | ||
39 | } | ||
40 | |||
41 | return $this->render('WallabagCoreBundle:Config:index.html.twig', array( | ||
42 | 'form' => $form->createView(), | ||
43 | )); | ||
44 | } | ||
45 | |||
46 | private function getConfig() | ||
47 | { | ||
48 | $config = $this->getDoctrine() | ||
49 | ->getRepository('WallabagCoreBundle:Config') | ||
50 | ->findOneByUser($this->getUser()); | ||
51 | |||
52 | if (!$config) { | ||
53 | $config = new Config($this->getUser()); | ||
54 | } | ||
55 | |||
56 | return $config; | ||
57 | } | ||
58 | } | ||