]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Controller/ConfigController.php
Implement simple config
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ConfigController.php
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 }