Sfoglia il codice sorgente

Evolution #601: Admin: re-création: Implementation moderation commentaires

Sevajol Bastien 12 anni fa
parent
commit
9dfd3f04b7

+ 83 - 0
src/Muzich/AdminBundle/Controller/Moderate_comment/EditController.php Vedi File

@@ -0,0 +1,83 @@
1
+<?php
2
+
3
+namespace Muzich\AdminBundle\Controller\Moderate_comment;
4
+
5
+use Muzich\CoreBundle\lib\Controller as BaseController;
6
+use Muzich\CoreBundle\Managers\CommentsManager;
7
+use Symfony\Component\HttpFoundation\RedirectResponse;
8
+
9
+class EditController extends BaseController
10
+{
11
+  
12
+  protected function getElementContext($element_id)
13
+  {
14
+    $Element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
15
+      ->findOneById($element_id);
16
+    if (!$Element) {
17
+        throw new NotFoundHttpException("The Muzich\CoreBundle\Entity\Element with id $element_id can't be found");
18
+    }
19
+    return $Element;
20
+  }
21
+  
22
+  public function acceptAction($element_id, $date)
23
+  {
24
+    $element = $this->getElementContext($element_id); 
25
+    $cm = new CommentsManager($element->getComments());
26
+    // On nettoie le commentaire et on récupère les ids des "signaleurs"
27
+    $ids = $cm->cleanAlertsOnComment($date);
28
+    $element->setComments($cm->get());
29
+    $element->setCountCommentReport($cm->countCommentAlert());
30
+    
31
+    $this->getDoctrine()->getEntityManager()->persist($element);
32
+    
33
+    // On récupère les user qui ont signalés ce commentaire
34
+    $users = $this->getDoctrine()->getEntityManager()
35
+      ->createQuery('
36
+        SELECT u FROM MuzichCoreBundle:User u
37
+        WHERE u.id IN (:uids)'
38
+      )
39
+      ->setParameter('uids', $ids)
40
+      ->getResult()
41
+    ;
42
+    
43
+    // Pour chacun on augmente le compteur de signalements inutiles
44
+    foreach ($users as $user)
45
+    {
46
+      $user->addBadReport();
47
+      $this->getDoctrine()->getEntityManager()->persist($user);
48
+    }
49
+    
50
+    $this->getDoctrine()->getEntityManager()->flush();
51
+    
52
+    $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
53
+    return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" ));
54
+  }
55
+  
56
+  public function refuseAction($element_id, $date)
57
+  {
58
+    $element = $this->getElementContext($element_id); 
59
+    $cm = new CommentsManager($element->getComments());
60
+    $comment = $cm->get($cm->getIndexWithDate($date));
61
+    // On supprime le commentaire
62
+    $cm->deleteWithDate($date);
63
+    $element->setComments($cm->get());
64
+    $element->setCountCommentReport($cm->countCommentAlert());
65
+    
66
+    // On récupère l'auteur du commentaire pour lui incrémenté son compteur
67
+    // de contenu modéré
68
+    $user = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:User')
69
+      ->findOneBy(array(
70
+        'id' => $comment['u']['i']
71
+      ));
72
+    
73
+    $user->addModeratedCommentCount();
74
+    
75
+    $this->getDoctrine()->getEntityManager()->persist($user);
76
+    $this->getDoctrine()->getEntityManager()->persist($element);
77
+    $this->getDoctrine()->getEntityManager()->flush();
78
+    
79
+    $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
80
+    return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" ));
81
+  }
82
+  
83
+}

+ 42 - 0
src/Muzich/AdminBundle/Controller/Moderate_comment/ListController.php Vedi File

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace Muzich\AdminBundle\Controller\Moderate_comment;
4
+
5
+use Muzich\CoreBundle\lib\Controller as BaseController;
6
+use Muzich\CoreBundle\Managers\CommentsManager;
7
+
8
+class ListController extends BaseController
9
+{
10
+  
11
+  public function listAction()
12
+  {
13
+    return $this->render('MuzichAdminBundle:Moderate_commentList:list.html.twig', array(
14
+      'Comments' => $this->getComments()
15
+    ));
16
+  }
17
+  
18
+  protected function getComments()
19
+  {
20
+    $elements = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
21
+      ->getForCommentToModerate();
22
+    
23
+    $comments = array();
24
+    foreach ($elements as $element)
25
+    {
26
+      $cm = new CommentsManager($element->getComments());
27
+      foreach ($cm->getAlertedComments() as $comment)
28
+      {
29
+        $comments[] = array(
30
+          'element_id' => $element->getId(),
31
+          'username'   => $comment['u']['n'],
32
+          'comment'    => $comment['c'],
33
+          'date'       => $comment['d']
34
+        );
35
+      }
36
+      
37
+    }
38
+    
39
+    return $comments;
40
+  }
41
+  
42
+}

+ 1 - 1
src/Muzich/AdminBundle/Menu/MenuBuilder.php Vedi File

@@ -49,7 +49,7 @@ class MenuBuilder extends BaseMenu
49 49
   {
50 50
     $this->addNavLinkRoute($menu, 'Element', 'Muzich_AdminBundle_Moderate_element_list');
51 51
     $this->addNavLinkRoute($menu, 'Tag', 'Muzich_AdminBundle_Moderate_tag_list');
52
-    //$this->addNavLinkRoute($menu, 'Comment', 'Muzich_AdminBundle_Moderate_comment_list');
52
+    $this->addNavLinkRoute($menu, 'Comment', 'Muzich_AdminBundle_Moderate_comment_list');
53 53
   }
54 54
   
55 55
   public function createAdminMenu(Request $request)

+ 19 - 0
src/Muzich/AdminBundle/Resources/config/routing.yml Vedi File

@@ -39,3 +39,22 @@ Muzich_AdminBundle_Moderate_tag_refuse:
39 39
   defaults: { _controller:Muzich\AdminBundle\Controller\Moderate_tag\EditController::refuseAction }
40 40
   requirements:
41 41
     _method:  GET
42
+    
43
+Muzich_AdminBundle_Moderate_comment_list:
44
+  pattern:  /Moderate_comment/
45
+  defaults: { _controller:Muzich\AdminBundle\Controller\Moderate_comment\ListController::listAction }
46
+  requirements:
47
+    _method:  GET
48
+    
49
+Muzich_AdminBundle_Moderate_comment_accept:
50
+  pattern:  /Moderate_comment/{element_id}/{date}/accept
51
+  defaults: { _controller:Muzich\AdminBundle\Controller\Moderate_comment\EditController::acceptAction }
52
+  requirements:
53
+    _method:  GET
54
+    
55
+Muzich_AdminBundle_Moderate_comment_refuse:
56
+  pattern:  /Moderate_comment/{element_id}/{date}/refuse
57
+  defaults: { _controller:Muzich\AdminBundle\Controller\Moderate_comment\EditController::refuseAction }
58
+  requirements:
59
+    _method:  GET
60
+

+ 105 - 0
src/Muzich/AdminBundle/Resources/views/Moderate_commentList/list.html.twig Vedi File

@@ -0,0 +1,105 @@
1
+{% extends "AdmingeneratorGeneratorBundle::base_admin_assetic_less.html.twig" %}
2
+
3
+{% block stylesheets %}{{ parent() }}{% endblock %}
4
+
5
+{% block javascripts %}
6
+  {{ parent() }}
7
+  <script src="{{ asset("bundles/admingeneratorgenerator/js/admingenerator/general.js") }}"></script>
8
+{% endblock %}
9
+
10
+{% block title %}
11
+  {{ parent() }} - {% trans from "Admin" %}List for Comments{% endtrans %}
12
+{% endblock %}
13
+
14
+{% block body %}
15
+  
16
+  {% block page_title %}
17
+    <header>
18
+      <h1>{% trans from "Admin" %}List for Comments{% endtrans %}</h1>
19
+    </header>
20
+  {% endblock %}
21
+  
22
+  <div class="row-fluid">
23
+    <div class=" span9 ">
24
+
25
+      {% block list_scopes %}
26
+      {% endblock %}
27
+  
28
+      {% block list_nbresults %}
29
+      {% endblock %}
30
+      
31
+      {% block form_batch_actions %}
32
+      {% endblock %}
33
+  
34
+      <table class="table table-striped table-hover table-condensed">
35
+        {% block list_thead %}
36
+          <thead>
37
+            <tr class="list_thead">
38
+              
39
+              <th class="list_thead_column">
40
+                Username
41
+              </th>
42
+              
43
+              <th class="list_thead_column">
44
+                Comment
45
+              </th>
46
+              
47
+              <th class="actions">{% trans from "Admingenerator" %}list.header.actions{% endtrans %}</th>
48
+            </tr>
49
+          </thead>
50
+        {% endblock %}
51
+  
52
+      {% block list_tbody %}
53
+        <tbody>
54
+          {% if Comments|length > 0 %}
55
+  
56
+            {% for Comment in Comments %}
57
+            <tr class="list_trow">
58
+              {% block list_row %}
59
+                <td class="td_integer td_username">
60
+                  {% block list_td_column_id %}{{ Comment.username }}{% endblock %}
61
+                </td>
62
+                <td class="td_string td_comment">
63
+                  {% block list_td_column_name %}{{ Comment.comment }}{% endblock %}
64
+                </td>
65
+              {% endblock %}
66
+              {% block list_object_actions %}
67
+                <td class="actions">
68
+                  
69
+                  <a class="" href="{{ path("Muzich_AdminBundle_Moderate_comment_accept", { 'element_id': Comment.element_id, 'date' : Comment.date }) }}"
70
+                     data-confirm="{% trans from "Admingenerator" %}Sure to ACCEPT ?{% endtrans %}"
71
+                     rel="tooltip" data-original-title="{% trans from "Admingenerator" %}Accept{% endtrans %}">
72
+                    <i class="icon-asterisk"></i>
73
+                  </a>
74
+                  
75
+                                              
76
+                  <a class="" href="{{ path("Muzich_AdminBundle_Moderate_comment_refuse", { 'element_id': Comment.element_id, 'date' : Comment.date }) }}"
77
+                     data-confirm="{% trans from "Admingenerator" %}Sure to REFUSE ?{% endtrans %}"
78
+                     rel="tooltip" data-original-title="{% trans from "Admingenerator" %}Refuse{% endtrans %}">
79
+                    <i class="icon-asterisk"></i>
80
+                  </a>
81
+                
82
+                </td>
83
+              {% endblock %}
84
+  
85
+            </tr>
86
+          {% endfor %}
87
+  
88
+        {% else %}
89
+          <tr class="list_trow no_results_row">
90
+            <td colspan="5">{% trans from "Admingenerator" %}list.no.results{% endtrans %}</td>
91
+          </tr>
92
+        {% endif %}
93
+      </tbody>
94
+      {% endblock %}
95
+  
96
+      </table>
97
+      
98
+      <div class="form-actions">
99
+        {% block list_paginator %}
100
+        {% endblock %}
101
+      </div>
102
+  
103
+    </div>
104
+  </div>
105
+{% endblock %}