Browse Source

Evolution #99: Supprimer son groupe

bastien 13 years ago
parent
commit
6c2475a9bb

+ 3 - 1
app/Resources/translations/groups.fr.yml View File

8
 group:
8
 group:
9
   edit:                         Modifier ce groupe
9
   edit:                         Modifier ce groupe
10
   follow:                       Suivre
10
   follow:                       Suivre
11
-  notfollow:                    Ne plus suivre
11
+  notfollow:                    Ne plus suivre
12
+  remove:
13
+    link:                       Supprimer le groupe

+ 1 - 1
src/Muzich/CoreBundle/Entity/FollowGroup.php View File

34
    * Groupe suivis
34
    * Groupe suivis
35
    * 
35
    * 
36
    * @ORM\ManyToOne(targetEntity="Group", inversedBy="followers")
36
    * @ORM\ManyToOne(targetEntity="Group", inversedBy="followers")
37
-   * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
37
+   * @ORM\JoinColumn(name="group_id", referencedColumnName="id", onDelete="CASCADE")
38
    */
38
    */
39
   protected $group;
39
   protected $group;
40
   
40
   

+ 1 - 1
src/Muzich/CoreBundle/Entity/GroupsTagsFavorites.php View File

26
    * Cet attribut contient l'objet Group lié
26
    * Cet attribut contient l'objet Group lié
27
    * 
27
    * 
28
    * @ORM\ManyToOne(targetEntity="Group", inversedBy="tags")
28
    * @ORM\ManyToOne(targetEntity="Group", inversedBy="tags")
29
-   * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
29
+   * @ORM\JoinColumn(name="group_id", referencedColumnName="id", onDelete="CASCADE")
30
    */
30
    */
31
   protected $group;
31
   protected $group;
32
   
32
   

+ 18 - 0
src/Muzich/CoreBundle/lib/Controller.php View File

241
     }
241
     }
242
   }
242
   }
243
   
243
   
244
+  /**
245
+   * Retourne un Group en fonction du id passé
246
+   * 
247
+   * @param string $slug
248
+   * @return Group 
249
+   */
250
+  protected function findGroupWithId($id)
251
+  {
252
+    try {
253
+      return $this->getDoctrine()
254
+        ->getRepository('MuzichCoreBundle:Group')
255
+        ->findOneById($id)
256
+      ;      
257
+    } catch (\Doctrine\ORM\NoResultException $e) {
258
+        throw $this->createNotFoundException('Groupe introuvable.');
259
+    }
260
+  }
261
+  
244
   protected function getSearchForm($search_object)
262
   protected function getSearchForm($search_object)
245
   {
263
   {
246
     return $this->createForm(
264
     return $this->createForm(

+ 35 - 1
src/Muzich/GroupBundle/Controller/DefaultController.php View File

183
     }
183
     }
184
   }
184
   }
185
   
185
   
186
-}
186
+  public function deleteAction($group_id, $token)
187
+  {
188
+    $user = $this->getUser();
189
+    if ($user->getPersonalHash() != $token)
190
+    {
191
+      throw $this->createNotFoundException('Accès non autorisé.');
192
+    }
193
+    
194
+    $group = $this->findGroupWithId($group_id);
195
+    
196
+    if ($user->getId() != $group->getOwner()->getId())
197
+    {
198
+      throw $this->createNotFoundException('Accès non autorisé.');
199
+    }
200
+    
201
+    $em = $this->getDoctrine()->getEntityManager();
202
+    
203
+    // Il faudra le faire avec doctrine:
204
+    $elements = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
205
+      ->findBy(array('group' => $group->getId()))
206
+    ;
207
+    
208
+    foreach ($elements as $element)
209
+    {
210
+      $element->setGroup(null);
211
+      $em->persist($element);
212
+    }
213
+      
214
+    $em->remove($group);
215
+    $em->flush();
216
+    
217
+    return $this->redirect($this->container->get('request')->headers->get('referer'));
218
+  }
219
+  
220
+}

+ 4 - 0
src/Muzich/GroupBundle/Resources/config/routing.yml View File

14
 group_update:
14
 group_update:
15
   pattern:   /group/{slug}/update
15
   pattern:   /group/{slug}/update
16
   defaults: { _controller: MuzichGroupBundle:Default:update }
16
   defaults: { _controller: MuzichGroupBundle:Default:update }
17
+
18
+group_delete:
19
+  pattern:   /group/{group_id}/delete/{token}
20
+  defaults: { _controller: MuzichGroupBundle:Default:delete }

+ 8 - 0
src/Muzich/GroupBundle/Resources/views/Default/myList.html.twig View File

15
     <ul class="inline">
15
     <ul class="inline">
16
     {% for group in groups %} 
16
     {% for group in groups %} 
17
       <li>
17
       <li>
18
+        
18
         <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>
19
         <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>
20
+        
21
+        <a title="{{ 'group.remove.link'|trans({}, 'groups') }}" class="group_remove_link" 
22
+          href="{{ path('group_delete', {'group_id' : group.id, 'token': app.user.personalHash})  }}"
23
+        >
24
+          <img src="{{ asset('bundles/muzichcore/img/1327168960_fileclose.png') }}" alt="delete" />
25
+        </a>
26
+        
19
       </li>
27
       </li>
20
     {% endfor %}
28
     {% endfor %}
21
     </ul>
29
     </ul>

+ 1 - 1
src/Muzich/GroupBundle/Resources/views/Form/form.html.twig View File

26
   'form_name'     : form_name
26
   'form_name'     : form_name
27
 } %}
27
 } %}
28
 
28
 
29
-{{ fform_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
29
+{{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
30
 
30
 
31
 {{ form_rest(form) }}
31
 {{ form_rest(form) }}

+ 13 - 1
web/bundles/muzichcore/js/muzich.js View File

617
   $('ul.tagbox li.input input[type="text"]').formDefaults();
617
   $('ul.tagbox li.input input[type="text"]').formDefaults();
618
  
618
  
619
   ////////////////// FIN TAG PROMPT ///////////////
619
   ////////////////// FIN TAG PROMPT ///////////////
620
-
620
+ 
621
+  // Suppression d'un element
622
+  $('a.group_remove_link').jConfirmAction({
623
+    question : "Supprimer ce groupe ?", 
624
+    yesAnswer : "Oui", 
625
+    cancelAnswer : "Non",
626
+    onYes: function(link){
627
+      window.location = link.attr('href');
628
+      return false;
629
+    },
630
+    onOpen: function(){},
631
+    onClose: function(){}
632
+  });
621
    
633
    
622
  });
634
  });