Browse Source

Evolution #113: Administration: Gestion des tags à modérer

bastien 13 years ago
parent
commit
27c8d96309

+ 174 - 2
src/Muzich/AdminBundle/Controller/ModerateController.php View File

@@ -2,8 +2,9 @@
2 2
 
3 3
 namespace Muzich\AdminBundle\Controller;
4 4
 
5
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
5
+use Muzich\CoreBundle\lib\Controller;
6 6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
+//use Muzich\CoreBundle\Util\TagLike;
7 8
 
8 9
 class ModerateController extends Controller
9 10
 {
@@ -29,8 +30,179 @@ class ModerateController extends Controller
29 30
   public function tagsAction()
30 31
   {
31 32
     // Récupération des tags
32
-    $tags = $this->getDoctrine()->getEntityManager('MuzichCoreBundle:Tag')
33
+    $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
33 34
       ->getToModerate();
35
+    
36
+    // TODO: Ajouter a chaque tag la liste des tags ressemblant
37
+    
38
+    return array(
39
+      'tags' => $tags
40
+    );
41
+  }
42
+  
43
+  public function tagAcceptAction($tag_id)
44
+  {
45
+    if ($this->getUser() == 'anon.')
46
+    {
47
+      if ($this->getRequest()->isXmlHttpRequest())
48
+      {
49
+        return $this->jsonResponse(array(
50
+          'status' => 'mustbeconnected'
51
+        ));
52
+      }
53
+      else
54
+      {
55
+        return $this->redirect($this->generateUrl('index'));
56
+      }
57
+    }
58
+    
59
+    if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
60
+      'id'         => $tag_id,
61
+      'tomoderate' => true
62
+    ))))
63
+    {
64
+      return $this->jsonResponse(array(
65
+        'status'  => 'error',
66
+        'message' => 'NotFound'
67
+      ));
68
+    }
69
+    
70
+    $tag->setTomoderate(false);
71
+    $tag->setPrivateids(null);
72
+    $this->getDoctrine()->getEntityManager()->persist($tag);
73
+    $this->getDoctrine()->getEntityManager()->flush();
74
+    
75
+    return $this->jsonResponse(array(
76
+      'status' => 'success'
77
+    ));
78
+  }
79
+  
80
+  public function tagRefuseAction($tag_id)
81
+  {
82
+    if ($this->getUser() == 'anon.')
83
+    {
84
+      if ($this->getRequest()->isXmlHttpRequest())
85
+      {
86
+        return $this->jsonResponse(array(
87
+          'status' => 'mustbeconnected'
88
+        ));
89
+      }
90
+      else
91
+      {
92
+        return $this->redirect($this->generateUrl('index'));
93
+      }
94
+    }
95
+    
96
+    if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
97
+      'id'         => $tag_id,
98
+      'tomoderate' => true
99
+    ))))
100
+    {
101
+      return $this->jsonResponse(array(
102
+        'status'  => 'error',
103
+        'message' => 'NotFound'
104
+      ));
105
+    }
106
+    
107
+    $this->getDoctrine()->getEntityManager()->remove($tag);
108
+    $this->getDoctrine()->getEntityManager()->flush();
109
+    
110
+    return $this->jsonResponse(array(
111
+      'status' => 'success'
112
+    ));
113
+  }
114
+  
115
+  /**
116
+   * Cette action est plus délicate, elle consiste a remplacer le tag en question
117
+   * par un autre.
118
+   *
119
+   * @param int $tag_id
120
+   * @param int $tag_new_id
121
+   * @return view 
122
+   */
123
+  public function tagReplaceAction($tag_id, $tag_new_id)
124
+  {
125
+    if ($this->getUser() == 'anon.')
126
+    {
127
+      if ($this->getRequest()->isXmlHttpRequest())
128
+      {
129
+        return $this->jsonResponse(array(
130
+          'status' => 'mustbeconnected'
131
+        ));
132
+      }
133
+      else
134
+      {
135
+        return $this->redirect($this->generateUrl('index'));
136
+      }
137
+    }
138
+    
139
+    $tag_array = json_decode($tag_new_id);
140
+    if (!array_key_exists(0, $tag_array))
141
+    {
142
+      return $this->jsonResponse(array(
143
+        'status'  => 'error',
144
+        'message' => 'netTagError'
145
+      ));
146
+    }
147
+    $tag_new_id = $tag_array[0];
148
+    
149
+    if (
150
+      !($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
151
+        'id'         => $tag_id,
152
+        'tomoderate' => true
153
+      )))
154
+      || !($new_tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneById($tag_new_id))
155
+    )
156
+    {
157
+      return $this->jsonResponse(array(
158
+        'status'  => 'error',
159
+        'message' => 'NotFound'
160
+      ));
161
+    }
162
+    
163
+    /*
164
+     * Trois cas de figures ou sont utilisés les tags
165
+     *  * Sur un élément
166
+     *  * Tag favori
167
+     *  * Tag d'un groupe
168
+     */
169
+    $em = $this->getDoctrine()->getEntityManager();
170
+    
171
+    $netags = array();
172
+    foreach ($elements = $this->getDoctrine()->getEntityManager()->createQuery("
173
+      SELECT e, t FROM MuzichCoreBundle:Element e
174
+      JOIN e.tags t
175
+      WHERE t.id  = :tid
176
+    ")
177
+      ->setParameter('tid', $tag_new_id)
178
+      ->getResult() as $element)
179
+    {
180
+      
181
+      // TODO: a faire ...
182
+//      foreach ($element->getTags() as $etag)
183
+//      {
184
+//        if ($etag->getId() != $tag->getId())
185
+//        {
186
+//          $netags[] = $etag;
187
+//        }
188
+//      }
189
+//      $netags[] = $new_tag;
190
+//      
191
+//      $element->setTags(array());
192
+//      $em->persist($element);
193
+//      $em->flush();
194
+//      
195
+//      $element->setTags($netags);
196
+//      $em->persist($element);
197
+//      $em->flush();
198
+    }
199
+    
200
+    $em->remove($tag);
201
+    $em->flush();
202
+    
203
+    return $this->jsonResponse(array(
204
+      'status' => 'success'
205
+    ));
34 206
   }
35 207
   
36 208
 }

+ 12 - 0
src/Muzich/AdminBundle/Resources/config/routing.yml View File

@@ -5,4 +5,16 @@ MuzichAdminBundle_moderate_index:
5 5
 MuzichAdminBundle_moderate_tags:
6 6
   pattern:  /admin/moderate/tags
7 7
   defaults: { _controller: MuzichAdminBundle:Moderate:tags }
8
+  
9
+MuzichAdminBundle_moderate_tags_accept_tag:
10
+  pattern:  /admin/moderate/tags/{tag_id}/accept
11
+  defaults: { _controller: MuzichAdminBundle:Moderate:tagAccept }
12
+  
13
+MuzichAdminBundle_moderate_tags_refuse_tag:
14
+  pattern:  /admin/moderate/tags/{tag_id}/refuse
15
+  defaults: { _controller: MuzichAdminBundle:Moderate:tagRefuse }
16
+  
17
+MuzichAdminBundle_moderate_tags_replace_tag:
18
+  pattern:  /admin/moderate/tags/{tag_id}/replace/{tag_new_id}
19
+  defaults: { _controller: MuzichAdminBundle:Moderate:tagReplace, tag_new_id: null }
8 20
   

+ 2 - 2
src/Muzich/AdminBundle/Resources/views/Moderate/layout.html.twig View File

@@ -1,10 +1,10 @@
1 1
 {% extends 'MuzichCoreBundle::layout.html.twig' %}
2 2
 
3 3
 {% block css %}
4
-	
4
+	<link href="{{ asset('bundles/muzichmoderate/css/moderate.css') }}" rel="stylesheet" media="screen" type="text/css" />
5 5
 {% endblock %}
6 6
 {% block js %}
7
-  
7
+  <script src="{{ asset('bundles/muzichmoderate/js/moderate.js') }}" type="text/javascript"></script>
8 8
 {% endblock %}
9 9
 
10 10
 {% block main_content %}

+ 40 - 0
src/Muzich/AdminBundle/Resources/views/Moderate/tags.html.twig View File

@@ -0,0 +1,40 @@
1
+{% extends "MuzichAdminBundle:Moderate:layout.html.twig" %}
2
+
3
+{% block title %}{% endblock %}
4
+
5
+{% block content %}
6
+
7
+  <h2>{{ 'moderate.tags.title'|trans({}, 'adminui') }}</h2>
8
+    
9
+  <ul id="moderate_tags">
10
+    {% for tag in tags %}
11
+      <li class="tag">
12
+        <a href="{{ path('MuzichAdminBundle_moderate_tags_accept_tag', {'tag_id' : tag.id}) }}" class="accept">
13
+         [V]
14
+        </a>
15
+        <a href="{{ path('MuzichAdminBundle_moderate_tags_refuse_tag', {'tag_id' : tag.id}) }}" class="refuse">
16
+         [X]
17
+        </a>
18
+        <a href="{{ path('MuzichAdminBundle_moderate_tags_replace_tag', {
19
+          'tag_id' : tag.id
20
+        }) }}" class="replace">
21
+         [R]
22
+        </a>
23
+        <span class="name">
24
+          {{ tag.name }}
25
+        </span>
26
+          
27
+        <form action="#" name="moderate_tag_{{ tag.id }}">
28
+          {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 
29
+            'form_name'     : 'moderate_tag_' ~ tag.id 
30
+          } %}
31
+            
32
+            <input type="hidden" class="tagBox_tags_ids" name="tagBox_tags_ids" />
33
+            
34
+        </form>
35
+          
36
+      </li>
37
+    {% endfor %}
38
+  </ul>
39
+
40
+{% endblock %}

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

@@ -34,7 +34,7 @@ class GroupsTagsFavorites
34 34
    * Cet attribut contient l'objet Tag lié
35 35
    * 
36 36
    * @ORM\ManyToOne(targetEntity="Tag", inversedBy="groups_favorites")
37
-   * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
37
+   * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="CASCADE")
38 38
    */
39 39
   protected $tag;
40 40
   

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

@@ -34,7 +34,7 @@ class UsersTagsFavorites
34 34
    * Cet attribut contient l'objet Tag lié
35 35
    * 
36 36
    * @ORM\ManyToOne(targetEntity="Tag", inversedBy="users_favorites")
37
-   * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
37
+   * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="CASCADE")
38 38
    */
39 39
   protected $tag;
40 40
   

+ 10 - 0
web/bundles/muzichmoderate/css/moderate.css View File

@@ -0,0 +1,10 @@
1
+
2
+ul#moderate_tags li.tag
3
+{
4
+  font-size: 115%;
5
+}
6
+
7
+ul#moderate_tags li.tag span.name
8
+{
9
+  width: 350px;
10
+}

+ 55 - 0
web/bundles/muzichmoderate/js/moderate.js View File

@@ -0,0 +1,55 @@
1
+$(document).ready(function(){
2
+   
3
+  $('ul#moderate_tags li.tag a.accept, ul#moderate_tags li.tag a.refuse').click(function(){
4
+    link = $(this);
5
+    $.getJSON($(this).attr('href'), function(response) {
6
+     
7
+      if (response.status == 'mustbeconnected')
8
+      {
9
+        $(location).attr('href', url_index);
10
+      }
11
+      
12
+      if (response.status == 'success')
13
+      {
14
+        link.parent('li').remove();
15
+      }
16
+      
17
+      if (response.status == 'error')
18
+      {
19
+        alert(response.message);
20
+      }
21
+      
22
+    });
23
+      
24
+    return false;
25
+  });
26
+  
27
+   
28
+  $('ul#moderate_tags li.tag a.replace').click(function(){
29
+    link = $(this);
30
+    
31
+    newtag = link.parent('li').find('input.tagBox_tags_ids').val();
32
+    
33
+    $.getJSON($(this).attr('href')+'/'+newtag, function(response) {
34
+     
35
+      if (response.status == 'mustbeconnected')
36
+      {
37
+        $(location).attr('href', url_index);
38
+      }
39
+      
40
+      if (response.status == 'error')
41
+      {
42
+        alert(response.message);
43
+      }
44
+      
45
+      if (response.status == 'success')
46
+      {
47
+        link.parent('li').remove();
48
+      }
49
+      
50
+    });
51
+      
52
+    return false;
53
+  });
54
+   
55
+});