aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php128
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php7
2 files changed, 130 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
new file mode 100644
index 00000000..68e034fa
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -0,0 +1,128 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Config;
9use Wallabag\CoreBundle\Entity\User;
10use Wallabag\CoreBundle\Form\Type\ConfigType;
11use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
12use Wallabag\CoreBundle\Form\Type\UserType;
13use Wallabag\CoreBundle\Form\Type\NewUserType;
14
15class ConfigController extends Controller
16{
17 /**
18 * @param Request $request
19 *
20 * @Route("/config", name="config")
21 */
22 public function indexAction(Request $request)
23 {
24 $em = $this->getDoctrine()->getManager();
25 $config = $this->getConfig();
26 $user = $this->getUser();
27
28 // handle basic config detail
29 $configForm = $this->createForm(new ConfigType(), $config);
30 $configForm->handleRequest($request);
31
32 if ($configForm->isValid()) {
33 $em->persist($config);
34 $em->flush();
35
36 $this->get('session')->getFlashBag()->add(
37 'notice',
38 'Config saved'
39 );
40
41 return $this->redirect($this->generateUrl('config'));
42 }
43
44 // handle changing password
45 $pwdForm = $this->createForm(new ChangePasswordType());
46 $pwdForm->handleRequest($request);
47
48 if ($pwdForm->isValid()) {
49 $user->setPassword($pwdForm->get('new_password')->getData());
50 $em->persist($user);
51 $em->flush();
52
53 $this->get('session')->getFlashBag()->add(
54 'notice',
55 'Password updated'
56 );
57
58 return $this->redirect($this->generateUrl('config'));
59 }
60
61 // handle changing user information
62 $userForm = $this->createForm(new UserType(), $user);
63 $userForm->handleRequest($request);
64
65 if ($userForm->isValid()) {
66 $em->persist($user);
67 $em->flush();
68
69 $this->get('session')->getFlashBag()->add(
70 'notice',
71 'Information updated'
72 );
73
74 return $this->redirect($this->generateUrl('config'));
75 }
76
77 // handle adding new user
78 $newUser = new User();
79 $newUserForm = $this->createForm(new NewUserType(), $newUser);
80 $newUserForm->handleRequest($request);
81
82 if ($newUserForm->isValid()) {
83 $em->persist($newUser);
84
85 $config = new Config($newUser);
86 $config->setTheme($this->container->getParameter('theme'));
87 $config->setItemsPerPage($this->container->getParameter('items_on_page'));
88 $config->setLanguage($this->container->getParameter('language'));
89
90 $em->persist($config);
91
92 $em->flush();
93
94 $this->get('session')->getFlashBag()->add(
95 'notice',
96 sprintf('User "%s" added', $newUser->getUsername())
97 );
98
99 return $this->redirect($this->generateUrl('config'));
100 }
101
102 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
103 'configForm' => $configForm->createView(),
104 'pwdForm' => $pwdForm->createView(),
105 'userForm' => $userForm->createView(),
106 'newUserForm' => $newUserForm->createView(),
107 ));
108 }
109
110 /**
111 * Retrieve config for the current user.
112 * If no config were found, create a new one.
113 *
114 * @return Wallabag\CoreBundle\Entity\Config
115 */
116 private function getConfig()
117 {
118 $config = $this->getDoctrine()
119 ->getRepository('WallabagCoreBundle:Config')
120 ->findOneByUser($this->getUser());
121
122 if (!$config) {
123 $config = new Config($this->getUser());
124 }
125
126 return $config;
127 }
128}
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 89677bef..81ab7788 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -7,7 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Service\Extractor; 9use Wallabag\CoreBundle\Service\Extractor;
10use Wallabag\CoreBundle\Helper\Url; 10use Wallabag\CoreBundle\Form\Type\EntryType;
11 11
12class EntryController extends Controller 12class EntryController extends Controller
13{ 13{
@@ -22,10 +22,7 @@ class EntryController extends Controller
22 { 22 {
23 $entry = new Entry($this->getUser()); 23 $entry = new Entry($this->getUser());
24 24
25 $form = $this->createFormBuilder($entry) 25 $form = $this->createForm(new EntryType(), $entry);
26 ->add('url', 'url')
27 ->add('save', 'submit')
28 ->getForm();
29 26
30 $form->handleRequest($request); 27 $form->handleRequest($request);
31 28