Browse Source

Evolution #146: Modération

bastien 13 years ago
parent
commit
fe16f5a69d

+ 7 - 1
app/Resources/translations/adminui.fr.yml View File

@@ -3,4 +3,10 @@ moderate:
3 3
   title:            Modération
4 4
   tags:
5 5
     title:          Tags
6
-    to_moderate:      %count% a modérer
6
+    to_moderate:      %count% a modérer
7
+  elements:
8
+    to_moderate:      %count% a modérer
9
+    title:          Elements
10
+    action:
11
+      delete:       Supprimer
12
+      clean:         Tout est ok

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

@@ -18,11 +18,14 @@ class ModerateController extends Controller
18 18
    */
19 19
   public function indexAction()
20 20
   {
21
-    $count_moderate = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
21
+    $count_tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
22
+      ->countToModerate();
23
+    $count_elements = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
22 24
       ->countToModerate();
23 25
     
24 26
     return array(
25
-      'count_moderate' => $count_moderate
27
+      'count_tags' => $count_tags,
28
+      'count_elements' => $count_elements
26 29
     );
27 30
   }
28 31
     
@@ -125,4 +128,91 @@ class ModerateController extends Controller
125 128
     
126 129
   }
127 130
   
131
+  /**
132
+   *
133
+   * @Template()
134
+   */
135
+  public function elementsAction()
136
+  {
137
+    // Récupération des elements
138
+    $elements = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
139
+      ->getToModerate();
140
+    
141
+    return array(
142
+      'elements' => $elements
143
+    );
144
+  }
145
+  
146
+  /**
147
+   * 
148
+   */
149
+  public function deleteElementAction($element_id)
150
+  {
151
+    if (($response = $this->mustBeConnected(true)))
152
+    {
153
+      return $response;
154
+    }
155
+    
156
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
157
+      ->findOneById($element_id))
158
+    )
159
+    {
160
+      return $this->jsonResponse(array(
161
+        'status' => 'error',
162
+        'errors' => array('NotFound')
163
+      ));
164
+    }
165
+    
166
+    $this->getDoctrine()->getEntityManager()->remove($element);
167
+    $this->getDoctrine()->getEntityManager()->flush();
168
+    
169
+    return $this->jsonResponse(array(
170
+      'status' => 'success'
171
+    ));
172
+  }
173
+  
174
+  public function cleanElementAction($element_id)
175
+  {
176
+    if (($response = $this->mustBeConnected(true)))
177
+    {
178
+      return $response;
179
+    }
180
+    
181
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
182
+      ->findOneById($element_id))
183
+    )
184
+    {
185
+      return $this->jsonResponse(array(
186
+        'status' => 'error',
187
+        'errors' => array('NotFound')
188
+      ));
189
+    }
190
+    
191
+    $user_ids = $element->getReportIds();
192
+    $element->setReportIds(null);
193
+    $element->setCountReport(null);
194
+    $this->getDoctrine()->getEntityManager()->persist($element);
195
+    
196
+    $users = $this->getDoctrine()->getEntityManager()
197
+      ->createQuery('
198
+        SELECT u FROM MuzichCoreBundle:User u
199
+        WHERE u.id IN (:uids)'
200
+      )
201
+      ->setParameter('uids', $user_ids)
202
+      ->getResult()
203
+    ;
204
+    
205
+    foreach ($users as $user)
206
+    {
207
+      $user->addBadReport();
208
+      $this->getDoctrine()->getEntityManager()->persist($user);
209
+    }
210
+    
211
+    $this->getDoctrine()->getEntityManager()->flush();
212
+    
213
+    return $this->jsonResponse(array(
214
+      'status' => 'success'
215
+    ));
216
+  }
217
+  
128 218
 }

+ 16 - 1
src/Muzich/AdminBundle/Resources/config/routing.yml View File

@@ -2,6 +2,8 @@ MuzichAdminBundle_moderate_index:
2 2
   pattern:  /admin/moderate
3 3
   defaults: { _controller: MuzichAdminBundle:Moderate:index }
4 4
 
5
+##
6
+
5 7
 MuzichAdminBundle_moderate_tags:
6 8
   pattern:  /admin/moderate/tags
7 9
   defaults: { _controller: MuzichAdminBundle:Moderate:tags }
@@ -17,4 +19,17 @@ MuzichAdminBundle_moderate_tags_refuse_tag:
17 19
 MuzichAdminBundle_moderate_tags_replace_tag:
18 20
   pattern:  /admin/moderate/tags/{tag_id}/replace/{tag_new_id}
19 21
   defaults: { _controller: MuzichAdminBundle:Moderate:tagReplace, tag_new_id: null }
20
-  
22
+  
23
+##
24
+
25
+moderate_elements_index:
26
+  pattern:  /admin/moderate/elements
27
+  defaults: { _controller: MuzichAdminBundle:Moderate:elements }
28
+  
29
+moderate_element_delete:
30
+  pattern:  /admin/moderate/element/delete/{element_id}
31
+  defaults: { _controller: MuzichAdminBundle:Moderate:deleteElement }
32
+  
33
+moderate_element_clean:
34
+  pattern:  /admin/moderate/element/clean/{element_id}
35
+  defaults: { _controller: MuzichAdminBundle:Moderate:cleanElement }

+ 41 - 0
src/Muzich/AdminBundle/Resources/views/Moderate/elements.html.twig View File

@@ -0,0 +1,41 @@
1
+{% extends "MuzichAdminBundle:Moderate:layout.html.twig" %}
2
+
3
+{% block title %}{% endblock %}
4
+
5
+{% block content %}
6
+
7
+  <h2>{{ 'moderate.elements.title'|trans({}, 'adminui') }}</h2>
8
+    
9
+  <ul id="moderate_elements">
10
+    {% for element in elements %}
11
+      <li class="element" id="mod_element_{{ element.id }}">
12
+        
13
+        <div class="controls">
14
+          <a class="delete" href="{{ path('moderate_element_delete', {'element_id':element.id}) }}" >
15
+            {{ 'moderate.elements.action.delete'|trans({}, 'adminui') }}
16
+          </a>
17
+            -
18
+          <a class="clean" href="{{ path('moderate_element_clean', {'element_id':element.id}) }}" >
19
+             {{ 'moderate.elements.action.clean'|trans({}, 'adminui') }}
20
+          </a>
21
+        </div>
22
+        
23
+        <div class="element">
24
+          <ul>
25
+            <li><strong>Name</strong>: {{ element.name }}</li>
26
+            <li><strong>url</strong>: <a href="{{ element.url }}" target="_blank">{{ element.url }}</a></li>
27
+            {% if element.embed %}
28
+              {% autoescape false %}
29
+                <li>
30
+                  {{ element.embed }}
31
+                </li>
32
+              {% endautoescape %}
33
+            {% endif %}
34
+          </ul>
35
+        </div>
36
+        
37
+      </li>
38
+    {% endfor %}
39
+  </ul>
40
+
41
+{% endblock %}

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

@@ -11,9 +11,19 @@
11 11
   <ul>
12 12
     <li>
13 13
       <a href="{{ path('MuzichAdminBundle_moderate_tags') }}">
14
-        {{ 'moderate.tags.to_moderate'|trans({'%count%' : count_moderate}, 'adminui') }}
14
+        {{ 'moderate.tags.to_moderate'|trans({'%count%' : count_tags}, 'adminui') }}
15 15
       </a>
16 16
     </li>
17 17
   </ul>
18
-
18
+  
19
+  <h3>{{ 'moderate.elements.title'|trans({}, 'adminui') }}</h3>
20
+  
21
+  <ul>
22
+    <li>
23
+      <a href="{{ path('moderate_elements_index') }}">
24
+        {{ 'moderate.elements.to_moderate'|trans({'%count%' : count_elements}, 'adminui') }}
25
+      </a>
26
+    </li>
27
+  </ul>
28
+  
19 29
 {% endblock %}

+ 3 - 0
src/Muzich/CoreBundle/Managers/ElementReportManager.php View File

@@ -26,6 +26,9 @@ class ElementReportManager
26 26
   public function add(User $user)
27 27
   {
28 28
     $ids = $this->element->getReportIds();
29
+    
30
+    if ($ids === null){$ids = array();}
31
+    
29 32
     if (!in_array($user->getId(), $ids))
30 33
     {
31 34
       $ids[] = (string)$user->getId();

+ 19 - 0
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -277,4 +277,23 @@ class ElementRepository extends EntityRepository
277 277
       ->setMaxResults($limit)
278 278
     ;
279 279
   }  
280
+  
281
+  public function countToModerate()
282
+  {
283
+    return $this->getEntityManager()
284
+      ->createQuery("SELECT COUNT(e.id) FROM MuzichCoreBundle:Element e
285
+        WHERE e.count_report IS NOT NULL"
286
+      )->getSingleScalarResult()
287
+    ;
288
+  }
289
+  
290
+  public function getToModerate()
291
+  {
292
+    return $this->getEntityManager()
293
+      ->createQuery("SELECT e FROM MuzichCoreBundle:Element e
294
+        WHERE e.count_report  IS NOT NULL"
295
+      )->getResult()
296
+    ;
297
+  }  
298
+  
280 299
 }

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

@@ -7,4 +7,23 @@ ul#moderate_tags li.tag
7 7
 ul#moderate_tags li.tag span.name
8 8
 {
9 9
   width: 350px;
10
+}
11
+
12
+ul#moderate_elements
13
+{
14
+  margin-left: 0px;
15
+}
16
+
17
+ul#moderate_elements li.element
18
+{
19
+  list-style: none;
20
+  background-color: #f0f0f0;
21
+  margin-top: 25px;
22
+}
23
+
24
+ul#moderate_elements div.controls
25
+{
26
+  text-align: center;
27
+  font-size: 110%;
28
+  font-weight: bold;
10 29
 }

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

@@ -51,5 +51,35 @@ $(document).ready(function(){
51 51
       
52 52
     return false;
53 53
   });
54
+  
55
+  $('ul#moderate_elements li.element div.controls a.delete').live('click', function(){
56
+     li = $(this).parent('div.controls').parent('li.element');
57
+     $.getJSON($(this).attr('href'), function(response) {
58
+       if (response.status == 'success')
59
+       {
60
+         li.slideUp(500, function(){li.remove();});
61
+       }
62
+       else
63
+       {
64
+         alert(response.status);
65
+       }
66
+     });
67
+     return false;
68
+  });
69
+  
70
+  $('ul#moderate_elements li.element div.controls a.clean').live('click', function(){
71
+    li = $(this).parent('div.controls').parent('li.element');
72
+    $.getJSON($(this).attr('href'), function(response) {
73
+       if (response.status == 'success')
74
+       {
75
+         li.slideUp(500, function(){li.remove();});
76
+       }
77
+       else
78
+       {
79
+         alert(response.status);
80
+       }
81
+     });
82
+     return false;
83
+  });
54 84
    
55 85
 });