aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-11 21:01:30 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-11 21:01:30 +0200
commite4cf672ccf61689ba28c2e89fc55f83167800b18 (patch)
tree5dc22c97797bdcdd0a3d2a7e182410f04a748c1e /src/Wallabag/CoreBundle/Controller
parente57df5611fe82ce61a71d51c762ee9296f18c3ac (diff)
parentdbe94e73a9eaf3acb250812913b0303b35d01a2e (diff)
downloadwallabag-e4cf672ccf61689ba28c2e89fc55f83167800b18.tar.gz
wallabag-e4cf672ccf61689ba28c2e89fc55f83167800b18.tar.zst
wallabag-e4cf672ccf61689ba28c2e89fc55f83167800b18.zip
Merge remote-tracking branch 'origin/master' into 2.2
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/DeveloperController.php101
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php25
2 files changed, 21 insertions, 105 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php
deleted file mode 100644
index f3492b74..00000000
--- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php
+++ /dev/null
@@ -1,101 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Component\HttpFoundation\Request;
7use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8use Wallabag\ApiBundle\Entity\Client;
9use Wallabag\CoreBundle\Form\Type\ClientType;
10
11class DeveloperController extends Controller
12{
13 /**
14 * List all clients and link to create a new one.
15 *
16 * @Route("/developer", name="developer")
17 *
18 * @return \Symfony\Component\HttpFoundation\Response
19 */
20 public function indexAction()
21 {
22 $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll();
23
24 return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [
25 'clients' => $clients,
26 ]);
27 }
28
29 /**
30 * Create a client (an app).
31 *
32 * @param Request $request
33 *
34 * @Route("/developer/client/create", name="developer_create_client")
35 *
36 * @return \Symfony\Component\HttpFoundation\Response
37 */
38 public function createClientAction(Request $request)
39 {
40 $em = $this->getDoctrine()->getManager();
41 $client = new Client();
42 $clientForm = $this->createForm(ClientType::class, $client);
43 $clientForm->handleRequest($request);
44
45 if ($clientForm->isValid()) {
46 $client->setAllowedGrantTypes(['token', 'authorization_code', 'password', 'refresh_token']);
47 $em->persist($client);
48 $em->flush();
49
50 $this->get('session')->getFlashBag()->add(
51 'notice',
52 $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()])
53 );
54
55 return $this->render('@WallabagCore/themes/common/Developer/client_parameters.html.twig', [
56 'client_id' => $client->getPublicId(),
57 'client_secret' => $client->getSecret(),
58 'client_name' => $client->getName(),
59 ]);
60 }
61
62 return $this->render('@WallabagCore/themes/common/Developer/client.html.twig', [
63 'form' => $clientForm->createView(),
64 ]);
65 }
66
67 /**
68 * Remove a client.
69 *
70 * @param Client $client
71 *
72 * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client")
73 *
74 * @return \Symfony\Component\HttpFoundation\RedirectResponse
75 */
76 public function deleteClientAction(Client $client)
77 {
78 $em = $this->getDoctrine()->getManager();
79 $em->remove($client);
80 $em->flush();
81
82 $this->get('session')->getFlashBag()->add(
83 'notice',
84 $this->get('translator')->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()])
85 );
86
87 return $this->redirect($this->generateUrl('developer'));
88 }
89
90 /**
91 * Display developer how to use an existing app.
92 *
93 * @Route("/developer/howto/first-app", name="developer_howto_firstapp")
94 *
95 * @return \Symfony\Component\HttpFoundation\Response
96 */
97 public function howtoFirstAppAction()
98 {
99 return $this->render('@WallabagCore/themes/common/Developer/howto_app.html.twig');
100 }
101}
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index 623a6146..5acc6852 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -63,10 +63,12 @@ class TagController extends Controller
63 $entry->removeTag($tag); 63 $entry->removeTag($tag);
64 $em = $this->getDoctrine()->getManager(); 64 $em = $this->getDoctrine()->getManager();
65 $em->flush(); 65 $em->flush();
66 if (count($tag->getEntries()) == 0) { 66
67 // remove orphan tag in case no entries are associated to it
68 if (count($tag->getEntries()) === 0) {
67 $em->remove($tag); 69 $em->remove($tag);
70 $em->flush();
68 } 71 }
69 $em->flush();
70 72
71 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); 73 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
72 74
@@ -84,10 +86,25 @@ class TagController extends Controller
84 { 86 {
85 $tags = $this->getDoctrine() 87 $tags = $this->getDoctrine()
86 ->getRepository('WallabagCoreBundle:Tag') 88 ->getRepository('WallabagCoreBundle:Tag')
87 ->findAllTagsWithEntries($this->getUser()->getId()); 89 ->findAllTags($this->getUser()->getId());
90
91 $flatTags = [];
92
93 foreach ($tags as $key => $tag) {
94 $nbEntries = $this->getDoctrine()
95 ->getRepository('WallabagCoreBundle:Entry')
96 ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']);
97
98 $flatTags[] = [
99 'id' => $tag['id'],
100 'label' => $tag['label'],
101 'slug' => $tag['slug'],
102 'nbEntries' => $nbEntries,
103 ];
104 }
88 105
89 return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ 106 return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
90 'tags' => $tags, 107 'tags' => $flatTags,
91 ]); 108 ]);
92 } 109 }
93 110