aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/GroupBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/GroupBundle')
-rw-r--r--src/Wallabag/GroupBundle/Controller/ManageController.php137
-rw-r--r--src/Wallabag/GroupBundle/Form/GroupType.php39
-rw-r--r--src/Wallabag/GroupBundle/Form/NewGroupType.php37
-rw-r--r--src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig44
-rw-r--r--src/Wallabag/GroupBundle/Resources/views/Manage/index.html.twig44
-rw-r--r--src/Wallabag/GroupBundle/Resources/views/Manage/new.html.twig37
6 files changed, 338 insertions, 0 deletions
diff --git a/src/Wallabag/GroupBundle/Controller/ManageController.php b/src/Wallabag/GroupBundle/Controller/ManageController.php
new file mode 100644
index 00000000..7015a465
--- /dev/null
+++ b/src/Wallabag/GroupBundle/Controller/ManageController.php
@@ -0,0 +1,137 @@
1<?php
2
3namespace Wallabag\GroupBundle\Controller;
4
5use Symfony\Component\HttpFoundation\Request;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Wallabag\GroupBundle\Entity\Group;
10
11/**
12 * Group controller.
13 */
14class ManageController extends Controller
15{
16 /**
17 * Lists all Group entities.
18 *
19 * @Route("/", name="group_index")
20 * @Method("GET")
21 */
22 public function indexAction()
23 {
24 $em = $this->getDoctrine()->getManager();
25
26 $groups = $em->getRepository('WallabagGroupBundle:Group')->findAll();
27
28 return $this->render('WallabagGroupBundle:Manage:index.html.twig', array(
29 'groups' => $groups,
30 ));
31 }
32
33 /**
34 * Creates a new Group entity.
35 *
36 * @Route("/new", name="group_new")
37 * @Method({"GET", "POST"})
38 */
39 public function newAction(Request $request)
40 {
41 $group = new Group('');
42
43 $form = $this->createForm('Wallabag\GroupBundle\Form\NewGroupType', $group);
44 $form->handleRequest($request);
45
46 if ($form->isSubmitted() && $form->isValid()) {
47 $em = $this->getDoctrine()->getManager();
48 $em->persist($group);
49 $em->flush();
50
51 $this->get('session')->getFlashBag()->add(
52 'notice',
53 $this->get('translator')->trans('flashes.group.notice.added', ['%name%' => $group->getName()])
54 );
55
56 return $this->redirectToRoute('group_edit', array('id' => $group->getId()));
57 }
58
59 return $this->render('WallabagGroupBundle:Manage:new.html.twig', array(
60 'group' => $group,
61 'form' => $form->createView(),
62 ));
63 }
64
65 /**
66 * Displays a form to edit an existing Group entity.
67 *
68 * @Route("/{id}/edit", name="group_edit")
69 * @Method({"GET", "POST"})
70 */
71 public function editAction(Request $request, Group $group)
72 {
73 $deleteForm = $this->createDeleteForm($group);
74 $editForm = $this->createForm('Wallabag\GroupBundle\Form\GroupType', $group);
75 $editForm->handleRequest($request);
76
77 if ($editForm->isSubmitted() && $editForm->isValid()) {
78 $em = $this->getDoctrine()->getManager();
79 $em->persist($group);
80 $em->flush();
81
82 $this->get('session')->getFlashBag()->add(
83 'notice',
84 $this->get('translator')->trans('flashes.group.notice.updated', ['%name%' => $group->getName()])
85 );
86
87 return $this->redirectToRoute('group_edit', array('id' => $group->getId()));
88 }
89
90 return $this->render('WallabagGroupBundle:Manage:edit.html.twig', array(
91 'group' => $group,
92 'edit_form' => $editForm->createView(),
93 'delete_form' => $deleteForm->createView(),
94 ));
95 }
96
97 /**
98 * Deletes a Group entity.
99 *
100 * @Route("/{id}", name="group_delete")
101 * @Method("DELETE")
102 */
103 public function deleteAction(Request $request, Group $group)
104 {
105 $form = $this->createDeleteForm($group);
106 $form->handleRequest($request);
107
108 if ($form->isSubmitted() && $form->isValid()) {
109 $this->get('session')->getFlashBag()->add(
110 'notice',
111 $this->get('translator')->trans('flashes.group.notice.deleted', ['%name%' => $group->getName()])
112 );
113
114 $em = $this->getDoctrine()->getManager();
115 $em->remove($group);
116 $em->flush();
117 }
118
119 return $this->redirectToRoute('group_index');
120 }
121
122 /**
123 * Creates a form to delete a Group entity.
124 *
125 * @param Group $group The Group entity
126 *
127 * @return \Symfony\Component\Form\Form The form
128 */
129 private function createDeleteForm(Group $group)
130 {
131 return $this->createFormBuilder()
132 ->setAction($this->generateUrl('group_delete', array('id' => $group->getId())))
133 ->setMethod('DELETE')
134 ->getForm()
135 ;
136 }
137}
diff --git a/src/Wallabag/GroupBundle/Form/GroupType.php b/src/Wallabag/GroupBundle/Form/GroupType.php
new file mode 100644
index 00000000..c2ad764b
--- /dev/null
+++ b/src/Wallabag/GroupBundle/Form/GroupType.php
@@ -0,0 +1,39 @@
1<?php
2
3namespace Wallabag\GroupBundle\Form;
4
5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\FormBuilderInterface;
7use Symfony\Component\OptionsResolver\OptionsResolver;
8use Symfony\Component\Form\Extension\Core\Type\SubmitType;
9use Symfony\Component\Form\Extension\Core\Type\TextType;
10
11class GroupType extends AbstractType
12{
13 /**
14 * @param FormBuilderInterface $builder
15 * @param array $options
16 */
17 public function buildForm(FormBuilderInterface $builder, array $options)
18 {
19 $builder
20 ->add('name', TextType::class, [
21 'required' => false,
22 'label' => 'group.form.name_label',
23 ])
24 ->add('save', SubmitType::class, [
25 'label' => 'group.form.save',
26 ])
27 ;
28 }
29
30 /**
31 * @param OptionsResolver $resolver
32 */
33 public function configureOptions(OptionsResolver $resolver)
34 {
35 $resolver->setDefaults(array(
36 'data_class' => 'Wallabag\GroupBundle\Entity\Group',
37 ));
38 }
39}
diff --git a/src/Wallabag/GroupBundle/Form/NewGroupType.php b/src/Wallabag/GroupBundle/Form/NewGroupType.php
new file mode 100644
index 00000000..29b20fe0
--- /dev/null
+++ b/src/Wallabag/GroupBundle/Form/NewGroupType.php
@@ -0,0 +1,37 @@
1<?php
2
3namespace Wallabag\GroupBundle\Form;
4
5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\Extension\Core\Type\SubmitType;
7use Symfony\Component\Form\Extension\Core\Type\TextType;
8use Symfony\Component\Form\FormBuilderInterface;
9use Symfony\Component\OptionsResolver\OptionsResolver;
10
11class NewGroupType extends AbstractType
12{
13 public function buildForm(FormBuilderInterface $builder, array $options)
14 {
15 $builder
16 ->add('name', TextType::class, [
17 'required' => true,
18 'label' => 'group.form.name_label',
19 ])
20 ->add('save', SubmitType::class, [
21 'label' => 'group.form.save',
22 ])
23 ;
24 }
25
26 public function configureOptions(OptionsResolver $resolver)
27 {
28 $resolver->setDefaults([
29 'data_class' => 'Wallabag\GroupBundle\Entity\Group',
30 ]);
31 }
32
33 public function getBlockPrefix()
34 {
35 return 'new_group';
36 }
37}
diff --git a/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig b/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig
new file mode 100644
index 00000000..7de68c35
--- /dev/null
+++ b/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig
@@ -0,0 +1,44 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{{ 'group.page_title'|trans }}{% endblock %}
4
5{% block content %}
6
7 <div class="row">
8 <div class="col s12">
9 <div class="card-panel">
10 <div class="row">
11 <div class="input-field col s12">
12 <h4>{{ 'group.edit_group'|trans }}</h4>
13
14 <div id="set6" class="col s12">
15 {{ form_start(edit_form) }}
16 {{ form_errors(edit_form) }}
17
18 <div class="row">
19 <div class="input-field col s12">
20 {{ form_label(edit_form.name) }}
21 {{ form_errors(edit_form.name) }}
22 {{ form_widget(edit_form.name) }}
23 </div>
24 </div>
25
26 <br/>
27
28 {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
29 {{ form_widget(edit_form._token) }}
30 </form>
31 <p>
32 {{ form_start(delete_form) }}
33 <button onclick="return confirm('{{ 'group.form.delete_confirm'|trans|escape('js') }}')" type="submit" class="btn waves-effect waves-light red">{{ 'group.form.delete'|trans }}</button>
34 {{ form_end(delete_form) }}
35 </p>
36 <p><a class="waves-effect waves-light btn blue-grey" href="{{ path('group_index') }}">{{ 'group.form.back_to_list'|trans }}</a></p>
37 </div>
38 </div>
39 </div>
40 </div>
41 </div>
42 </div>
43
44{% endblock %}
diff --git a/src/Wallabag/GroupBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/GroupBundle/Resources/views/Manage/index.html.twig
new file mode 100644
index 00000000..ce2a4556
--- /dev/null
+++ b/src/Wallabag/GroupBundle/Resources/views/Manage/index.html.twig
@@ -0,0 +1,44 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{{ 'group.page_title'|trans }}{% endblock %}
4
5{% block content %}
6
7 <div class="row">
8 <div class="col s12">
9 <div class="card-panel">
10 <div class="row">
11 <div class="input-field col s12">
12 <p class="help">{{ 'group.description'|trans|raw }}</p>
13
14 <table class="bordered">
15 <thead>
16 <tr>
17 <th>{{ 'group.form.name_label'|trans }}</th>
18 <th>{{ 'group.form.roles_label'|trans }}</th>
19 <th>{{ 'group.list.actions'|trans }}</th>
20 </tr>
21 </thead>
22 <tbody>
23 {% for group in groups %}
24 <tr>
25 <td>{{ group.name }}</td>
26 <td></td>
27 <td>
28 <a href="{{ path('group_edit', { 'id': group.id }) }}">{{ 'group.list.edit_action'|trans }}</a>
29 </td>
30 </tr>
31 {% endfor %}
32 </tbody>
33 </table>
34 <br />
35 <p>
36 <a href="{{ path('group_new') }}" class="waves-effect waves-light btn">{{ 'group.list.create_new_one'|trans }}</a>
37 </p>
38 </div>
39 </div>
40 </div>
41 </div>
42 </div>
43
44{% endblock %}
diff --git a/src/Wallabag/GroupBundle/Resources/views/Manage/new.html.twig b/src/Wallabag/GroupBundle/Resources/views/Manage/new.html.twig
new file mode 100644
index 00000000..3f1c2ad5
--- /dev/null
+++ b/src/Wallabag/GroupBundle/Resources/views/Manage/new.html.twig
@@ -0,0 +1,37 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{{ 'group.page_title'|trans }}{% endblock %}
4
5{% block content %}
6
7 <div class="row">
8 <div class="col s12">
9 <div class="card-panel">
10 <div class="row">
11 <div class="input-field col s12">
12 <h4>{{ 'group.new_group'|trans }}</h4>
13
14 <div id="set6" class="col s12">
15 {{ form_start(form) }}
16 {{ form_errors(form) }}
17
18 <div class="row">
19 <div class="input-field col s12">
20 {{ form_label(form.name) }}
21 {{ form_errors(form.name) }}
22 {{ form_widget(form.name) }}
23 </div>
24 </div>
25
26 {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
27 {{ form_rest(form) }}
28 </form>
29 <p><a class="waves-effect waves-light btn blue-grey" href="{{ path('group_index') }}">{{ 'group.form.back_to_list'|trans }}</a></p>
30 </div>
31 </div>
32 </div>
33 </div>
34 </div>
35 </div>
36
37{% endblock %}