Procházet zdrojové kódy

Procédure de mise a jour d'un groupe.

bastien před 13 roky
rodič
revize
3bfb8bb539

+ 4 - 1
app/Resources/translations/flash.fr.yml Zobrazit soubor

@@ -12,4 +12,7 @@ resetting.flash.success: Le mot de passe a été réinitialisé avec succès
12 12
 group:
13 13
   create:
14 14
     success:      Le groupe a été créé avec succés
15
-    failure:      Un erreur est survenue lors de la création du groupe
15
+    failure:      Un erreur est survenue lors de la création du groupe
16
+  update:
17
+    success:      La mise a jour a été un succés
18
+    failure:      Une erreur est survenue lors de la mise a jour du groupe

+ 6 - 1
app/Resources/translations/groups.fr.yml Zobrazit soubor

@@ -3,4 +3,9 @@ nogroups:
3 3
   sentence:                     Vous n'avez créé aucun groupe.
4 4
   
5 5
 havegroups:
6
-  sentence:                     Vous administrez les groupes suivants:
6
+  sentence:                     "Vous administrez les groupes suivants:"
7
+    
8
+group:
9
+  edit:                         Modifier ce groupe
10
+  follow:                       Suivre
11
+  notfollow:                    Ne plus suivre

+ 4 - 0
app/Resources/translations/users.fr.yml Zobrazit soubor

@@ -0,0 +1,4 @@
1
+
2
+user:
3
+  follow:                       Suivre
4
+  notfollow:                    Ne plus suivre

+ 12 - 1
src/Muzich/CoreBundle/Entity/Group.php Zobrazit soubor

@@ -220,7 +220,7 @@ class Group
220 220
    *
221 221
    * @param User $owner
222 222
    */
223
-  public function setOwner(User $owner)
223
+  public function setOwner(User $owner = null)
224 224
   {
225 225
       $this->owner = $owner;
226 226
   }
@@ -265,6 +265,7 @@ class Group
265 265
     $GroupsTagsFavorites = new GroupsTagsFavorites();
266 266
     $GroupsTagsFavorites->setTag($tag);
267 267
     $GroupsTagsFavorites->setPosition(0);
268
+    $GroupsTagsFavorites->setGroup($this);
268 269
     $em->persist($GroupsTagsFavorites);
269 270
     $this->tags[] = $GroupsTagsFavorites;
270 271
   }
@@ -310,4 +311,14 @@ class Group
310 311
     }
311 312
   }
312 313
   
314
+  public function setTagsToIds()
315
+  {
316
+    $tags_id = array();
317
+    foreach ($this->getTags() as $tag_r)
318
+    {
319
+      $tags_id[] = $tag_r->getTag()->getId();
320
+    }
321
+    $this->tags = $tags_id;
322
+  }
323
+  
313 324
 }

+ 2 - 0
src/Muzich/CoreBundle/Repository/GroupRepository.php Zobrazit soubor

@@ -39,6 +39,8 @@ class GroupRepository extends EntityRepository
39 39
     return $this->getEntityManager()
40 40
       ->createQuery("
41 41
         SELECT g FROM MuzichCoreBundle:Group g
42
+        LEFT JOIN g.tags tr 
43
+        LEFT JOIN tr.tag t
42 44
         WHERE g.slug = :str
43 45
       ")
44 46
       ->setParameters(array(

+ 95 - 0
src/Muzich/GroupBundle/Controller/DefaultController.php Zobrazit soubor

@@ -82,4 +82,99 @@ class DefaultController extends Controller
82 82
     }
83 83
   }
84 84
   
85
+  /**
86
+   * 
87
+   * @Template()
88
+   */
89
+  public function editAction(Request $request, $slug)
90
+  {
91
+    $user = $this->getUser();
92
+    
93
+    try {
94
+      
95
+      $group = $this->getDoctrine()
96
+        ->getRepository('MuzichCoreBundle:Group')
97
+        ->findOneBySlug($slug)
98
+        ->getSingleResult()
99
+      ;
100
+      
101
+    } catch (\Doctrine\ORM\NoResultException $e) {
102
+        throw $this->createNotFoundException('Groupe introuvable.');
103
+    }
104
+    
105
+    if ($group->getOwner()->getId() != $user->getId())
106
+    {
107
+      throw $this->createNotFoundException('Vous n\'ête pas le créateur de ce groupe.');
108
+    }
109
+    
110
+    $group->setTagsToIds();
111
+    
112
+    $form = $this->createForm(
113
+      new GroupForm(), 
114
+      $group,
115
+      array('tags' => $this->getTagsArray())
116
+    );
117
+    
118
+    return array(
119
+      'group' => $group,
120
+      'form'  => $form->createView()        
121
+    );
122
+  }
123
+  
124
+  public function updateAction(Request $request, $slug)
125
+  {
126
+    $user = $this->getUser();
127
+    $em = $this->getDoctrine()->getEntityManager();
128
+    
129
+    try {
130
+      
131
+      $group = $this->getDoctrine()
132
+        ->getRepository('MuzichCoreBundle:Group')
133
+        ->findOneBySlug($slug)
134
+        ->getSingleResult()
135
+      ;
136
+      
137
+    } catch (\Doctrine\ORM\NoResultException $e) {
138
+        throw $this->createNotFoundException('Groupe introuvable.');
139
+    }
140
+    
141
+    if ($group->getOwner()->getId() != $user->getId())
142
+    {
143
+      throw $this->createNotFoundException('Vous n\'ête pas le créateur de ce groupe.');
144
+    }
145
+    
146
+    $group->setTagsToIds();
147
+    
148
+    $form = $this->createForm(
149
+      new GroupForm(), 
150
+      $group,
151
+      array('tags' => $this->getTagsArray())
152
+    );
153
+    
154
+    $form->bindRequest($request);
155
+    
156
+    if ($form->isValid())
157
+    {
158
+      $factory = new GroupManager($group, $em, $this->container);
159
+      $factory->proceedTags($group->getTags());
160
+      
161
+      $em->persist($group);
162
+      $em->flush();
163
+      
164
+      $this->setFlash('success', 'group.update.success');
165
+      return $this->redirect($this->generateUrl('show_group', array('slug' => $group->getSlug())));
166
+    }
167
+    else
168
+    {
169
+      $this->setFlash('error', 'group.update.failure');
170
+      
171
+      return $this->render(
172
+        'GroupBundle:Default:edit.html.twig', 
173
+         array(
174
+           'form_new' => $form->createView()
175
+         )
176
+      );
177
+    }
178
+  }
179
+  
85 180
 }

+ 12 - 4
src/Muzich/GroupBundle/Resources/config/routing.yml Zobrazit soubor

@@ -1,8 +1,16 @@
1 1
 
2 2
 groups_own_list:
3
-    pattern:  /my-groups
4
-    defaults: { _controller: MuzichGroupBundle:Default:myList }
3
+  pattern:  /my-groups
4
+  defaults: { _controller: MuzichGroupBundle:Default:myList }
5 5
 
6 6
 group_add:
7
-    pattern:   /my-groups/add
8
-    defaults: { _controller: MuzichGroupBundle:Default:add }
7
+  pattern:   /my-groups/add
8
+  defaults: { _controller: MuzichGroupBundle:Default:add }
9
+    
10
+group_edit:
11
+  pattern:   /group/{slug}/edit
12
+  defaults: { _controller: MuzichGroupBundle:Default:edit }
13
+    
14
+group_update:
15
+  pattern:   /group/{slug}/update
16
+  defaults: { _controller: MuzichGroupBundle:Default:update }

+ 16 - 0
src/Muzich/GroupBundle/Resources/views/Default/edit.html.twig Zobrazit soubor

@@ -0,0 +1,16 @@
1
+{% extends "MuzichGroupBundle::layout.html.twig" %}
2
+
3
+{% block title %}Edition du groupe {{ group.name }}{% endblock %}
4
+
5
+{% block content %}
6
+
7
+  <h2>Edition du groupe {{ group.name }}</h2>
8
+
9
+  <form action="{{ path('group_update', { 'slug': group.slug }) }}" method="post" {{ form_enctype(form) }}>
10
+    
11
+    {% include "MuzichGroupBundle:Form:form.html.twig" %}
12
+
13
+    <input type="submit" />
14
+  </form>
15
+
16
+{% endblock %}

+ 2 - 29
src/Muzich/GroupBundle/Resources/views/Default/myList.html.twig Zobrazit soubor

@@ -25,35 +25,8 @@
25 25
   <h2>Ajouter un groupe</h2>
26 26
 
27 27
   <form action="{{ path('group_add') }}" method="post" {{ form_enctype(form_new) }}>
28
-    {{ form_errors(form_new) }}
29
-
30
-    <div class="field">
31
-      {{ form_label(form_new.name, 'name'|trans({}, 'groupform')) }}
32
-      {{ form_errors(form_new.name) }}
33
-      {{ form_widget(form_new.name) }}
34
-    </div>
35
-        
36
-    <div class="field">
37
-      {{ form_label(form_new.description, 'description'|trans({}, 'groupform')) }}
38
-      {{ form_errors(form_new.description) }}
39
-      {{ form_widget(form_new.description) }}
40
-    </div>
41
-      
42
-      <i>{{ 'openhelp'|trans({}, 'groupform') }}</i>
43
-      
44
-    <div class="field">
45
-      {{ form_label(form_new.open, 'open'|trans({}, 'groupform')) }}
46
-      {{ form_errors(form_new.open) }}
47
-      {{ form_widget(form_new.open) }}
48
-    </div>
49
-      
50
-    <div class="field">
51
-      {{ form_label(form_new.tags, 'tags'|trans({}, 'groupform')) }}
52
-      {{ form_errors(form_new.tags) }}
53
-      {{ form_widget(form_new.tags) }}
54
-    </div>
55
-
56
-    {{ form_rest(form_new) }}
28
+    
29
+    {% include "MuzichGroupBundle:Form:form.html.twig" with { 'form': form_new } %}
57 30
 
58 31
     <input type="submit" />
59 32
   </form>

+ 29 - 0
src/Muzich/GroupBundle/Resources/views/Form/form.html.twig Zobrazit soubor

@@ -0,0 +1,29 @@
1
+{{ form_errors(form) }}
2
+
3
+<div class="field">
4
+  {{ form_label(form.name, 'name'|trans({}, 'groupform')) }}
5
+  {{ form_errors(form.name) }}
6
+  {{ form_widget(form.name) }}
7
+</div>
8
+
9
+<div class="field">
10
+  {{ form_label(form.description, 'description'|trans({}, 'groupform')) }}
11
+  {{ form_errors(form.description) }}
12
+  {{ form_widget(form.description) }}
13
+</div>
14
+
15
+  <i>{{ 'openhelp'|trans({}, 'groupform') }}</i>
16
+
17
+<div class="field">
18
+  {{ form_label(form.open, 'open'|trans({}, 'groupform')) }}
19
+  {{ form_errors(form.open) }}
20
+  {{ form_widget(form.open) }}
21
+</div>
22
+
23
+<div class="field">
24
+  {{ form_label(form.tags, 'tags'|trans({}, 'groupform')) }}
25
+  {{ form_errors(form.tags) }}
26
+  {{ form_widget(form.tags) }}
27
+</div>
28
+
29
+{{ form_rest(form) }}

+ 1 - 0
src/Muzich/HomeBundle/Controller/ShowController.php Zobrazit soubor

@@ -58,6 +58,7 @@ class ShowController extends Controller
58 58
     
59 59
     return array(
60 60
       'group'       => $group,
61
+      'his_group'   => ($group->getOwner()->getId() == $user->getId()) ? true : false,
61 62
       'elements'    => $this->getShowedEntityElements($group->getId(), 'Group'),
62 63
       'following'   => $user->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
63 64
       'user'        => $user

+ 16 - 6
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig Zobrazit soubor

@@ -4,13 +4,23 @@
4 4
 
5 5
 {% block content %}
6 6
 
7
-  <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': user.personalHash }) }}" class="follow_link following" >
8
-    {% if following %}
9
-      Ne plus suivre
10
-    {% else %}
11
-      Suivre
7
+  <span class="follow_link following">
8
+  
9
+    {% if his_group %}
10
+      <a href="{{ path('group_edit', { 'slug': group.slug }) }}" >
11
+        {{ 'group.edit'|trans({}, 'groups') }}
12
+      </a> |
12 13
     {% endif %}
13
-  </a>
14
+
15
+    <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': user.personalHash }) }}" >
16
+      {% if following %}
17
+        {{ 'group.notfollow'|trans({}, 'groups') }}
18
+      {% else %}
19
+        {{ 'group.follow'|trans({}, 'groups') }}
20
+      {% endif %}
21
+    </a>
22
+    
23
+  </span>
14 24
     
15 25
   <h2>{{ group.name }}</h2>
16 26
   

+ 11 - 7
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig Zobrazit soubor

@@ -3,14 +3,18 @@
3 3
 {% block title %}{% endblock %}
4 4
 
5 5
 {% block content %}
6
+
7
+  <span class="follow_link following">
8
+    
9
+    <a href="{{ path('follow', { 'type': 'user', 'id': viewed_user.id, 'token': user.personalHash }) }}" class="follow_link following" >
10
+      {% if following %}
11
+        {{ 'user.notfollow'|trans({}, 'users') }}
12
+      {% else %}
13
+        {{ 'users.follow'|trans({}, 'users') }}
14
+      {% endif %}
15
+    </a>
6 16
     
7
-  <a href="{{ path('follow', { 'type': 'user', 'id': viewed_user.id, 'token': user.personalHash }) }}" class="follow_link following" >
8
-    {% if following %}
9
-      Ne plus suivre
10
-    {% else %}
11
-      Suivre
12
-    {% endif %}
13
-  </a>
17
+  </span>
14 18
 
15 19
   <h2>{{ viewed_user.name }}</h2>
16 20