]>
Commit | Line | Data |
---|---|---|
7408a6cb KD |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
6 | use Symfony\Component\HttpFoundation\Request; | |
7 | use Symfony\Component\Routing\Annotation\Route; | |
8 | use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule; | |
9 | ||
10 | /** | |
11 | * IgnoreOriginInstanceRuleController controller. | |
12 | * | |
13 | * @Route("/ignore-origin-instance-rules") | |
14 | */ | |
15 | class IgnoreOriginInstanceRuleController extends Controller | |
16 | { | |
17 | /** | |
18 | * Lists all IgnoreOriginInstanceRule entities. | |
19 | * | |
20 | * @Route("/", name="ignore_origin_instance_rules_index", methods={"GET"}) | |
21 | */ | |
22 | public function indexAction() | |
23 | { | |
24 | $rules = $this->get('wallabag_core.ignore_origin_instance_rule_repository')->findAll(); | |
25 | ||
26 | return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:index.html.twig', [ | |
27 | 'rules' => $rules, | |
28 | ]); | |
29 | } | |
30 | ||
31 | /** | |
32 | * Creates a new ignore origin instance rule entity. | |
33 | * | |
34 | * @Route("/new", name="ignore_origin_instance_rules_new", methods={"GET", "POST"}) | |
35 | * | |
36 | * @return \Symfony\Component\HttpFoundation\Response | |
37 | */ | |
38 | public function newAction(Request $request) | |
39 | { | |
40 | $ignoreOriginInstanceRule = new IgnoreOriginInstanceRule(); | |
41 | ||
42 | $form = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); | |
43 | $form->handleRequest($request); | |
44 | ||
45 | if ($form->isSubmitted() && $form->isValid()) { | |
46 | $em = $this->getDoctrine()->getManager(); | |
47 | $em->persist($ignoreOriginInstanceRule); | |
48 | $em->flush(); | |
49 | ||
50 | $this->get('session')->getFlashBag()->add( | |
51 | 'notice', | |
52 | $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.added') | |
53 | ); | |
54 | ||
55 | return $this->redirectToRoute('ignore_origin_instance_rules_index'); | |
56 | } | |
57 | ||
58 | return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:new.html.twig', [ | |
59 | 'rule' => $ignoreOriginInstanceRule, | |
60 | 'form' => $form->createView(), | |
61 | ]); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Displays a form to edit an existing ignore origin instance rule entity. | |
66 | * | |
67 | * @Route("/{id}/edit", name="ignore_origin_instance_rules_edit", methods={"GET", "POST"}) | |
68 | * | |
69 | * @return \Symfony\Component\HttpFoundation\Response | |
70 | */ | |
71 | public function editAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) | |
72 | { | |
73 | $deleteForm = $this->createDeleteForm($ignoreOriginInstanceRule); | |
74 | $editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); | |
75 | $editForm->handleRequest($request); | |
76 | ||
77 | if ($editForm->isSubmitted() && $editForm->isValid()) { | |
78 | $em = $this->getDoctrine()->getManager(); | |
79 | $em->persist($ignoreOriginInstanceRule); | |
80 | $em->flush(); | |
81 | ||
82 | $this->get('session')->getFlashBag()->add( | |
83 | 'notice', | |
84 | $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.updated') | |
85 | ); | |
86 | ||
87 | return $this->redirectToRoute('ignore_origin_instance_rules_index'); | |
88 | } | |
89 | ||
90 | return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:edit.html.twig', [ | |
91 | 'rule' => $ignoreOriginInstanceRule, | |
92 | 'edit_form' => $editForm->createView(), | |
93 | 'delete_form' => $deleteForm->createView(), | |
94 | ]); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Deletes a site credential entity. | |
99 | * | |
100 | * @Route("/{id}", name="ignore_origin_instance_rules_delete", methods={"DELETE"}) | |
101 | * | |
102 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
103 | */ | |
104 | public function deleteAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) | |
105 | { | |
106 | $form = $this->createDeleteForm($ignoreOriginInstanceRule); | |
107 | $form->handleRequest($request); | |
108 | ||
109 | if ($form->isSubmitted() && $form->isValid()) { | |
110 | $this->get('session')->getFlashBag()->add( | |
111 | 'notice', | |
112 | $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.deleted') | |
113 | ); | |
114 | ||
115 | $em = $this->getDoctrine()->getManager(); | |
116 | $em->remove($ignoreOriginInstanceRule); | |
117 | $em->flush(); | |
118 | } | |
119 | ||
120 | return $this->redirectToRoute('ignore_origin_instance_rules_index'); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Creates a form to delete a ignore origin instance rule entity. | |
125 | * | |
126 | * @param IgnoreOriginInstanceRule $ignoreOriginInstanceRule The ignore origin instance rule entity | |
127 | * | |
128 | * @return \Symfony\Component\Form\Form The form | |
129 | */ | |
130 | private function createDeleteForm(IgnoreOriginInstanceRule $ignoreOriginInstanceRule) | |
131 | { | |
132 | return $this->createFormBuilder() | |
133 | ->setAction($this->generateUrl('ignore_origin_instance_rules_delete', ['id' => $ignoreOriginInstanceRule->getId()])) | |
134 | ->setMethod('DELETE') | |
135 | ->getForm() | |
136 | ; | |
137 | } | |
138 | } |