Browse Source

Evolution #673: Modération plus rapide/facile

Sevajol Bastien 11 years ago
parent
commit
a3af1e6fad

+ 1 - 0
src/Muzich/AdminBundle/Controller/Admin_element/EditController.php View File

7
 use Muzich\CoreBundle\Entity\Element;
7
 use Muzich\CoreBundle\Entity\Element;
8
 use Muzich\CoreBundle\Managers\ElementManager;
8
 use Muzich\CoreBundle\Managers\ElementManager;
9
 use Symfony\Component\HttpFoundation\RedirectResponse;
9
 use Symfony\Component\HttpFoundation\RedirectResponse;
10
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
 
11
 
11
 class EditController extends BaseEditController
12
 class EditController extends BaseEditController
12
 {
13
 {

+ 1 - 0
src/Muzich/AdminBundle/Controller/Moderate_comment/EditController.php View File

6
 use Muzich\CoreBundle\Managers\CommentsManager;
6
 use Muzich\CoreBundle\Managers\CommentsManager;
7
 use Symfony\Component\HttpFoundation\RedirectResponse;
7
 use Symfony\Component\HttpFoundation\RedirectResponse;
8
 use Symfony\Component\HttpFoundation\Response;
8
 use Symfony\Component\HttpFoundation\Response;
9
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
 
10
 
10
 class EditController extends BaseController
11
 class EditController extends BaseController
11
 {
12
 {

+ 1 - 0
src/Muzich/AdminBundle/Controller/Moderate_element/EditController.php View File

5
 use Admingenerated\MuzichAdminBundle\BaseModerate_elementController\EditController as BaseEditController;
5
 use Admingenerated\MuzichAdminBundle\BaseModerate_elementController\EditController as BaseEditController;
6
 use Muzich\CoreBundle\Propagator\EventElement;
6
 use Muzich\CoreBundle\Propagator\EventElement;
7
 use Symfony\Component\HttpFoundation\RedirectResponse;
7
 use Symfony\Component\HttpFoundation\RedirectResponse;
8
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8
 
9
 
9
 class EditController extends BaseEditController
10
 class EditController extends BaseEditController
10
 {
11
 {

+ 1 - 0
src/Muzich/AdminBundle/Controller/Moderate_tag/EditController.php View File

6
 use Muzich\CoreBundle\Managers\TagManager;
6
 use Muzich\CoreBundle\Managers\TagManager;
7
 use Symfony\Component\HttpFoundation\RedirectResponse;
7
 use Symfony\Component\HttpFoundation\RedirectResponse;
8
 use Symfony\Component\HttpFoundation\Response;
8
 use Symfony\Component\HttpFoundation\Response;
9
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
 
10
 
10
 class EditController extends BaseEditController
11
 class EditController extends BaseEditController
11
 {
12
 {

+ 126 - 0
src/Muzich/AdminBundle/Controller/Moderate_user/EditController.php View File

1
+<?php
2
+
3
+namespace Muzich\AdminBundle\Controller\Moderate_user;
4
+
5
+use Muzich\CoreBundle\lib\Controller as BaseController;
6
+use Symfony\Component\HttpFoundation\RedirectResponse;
7
+use Symfony\Component\HttpFoundation\Response;
8
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
+
10
+class EditController extends BaseController
11
+{
12
+  
13
+  protected function getUserContext($user_id)
14
+  {
15
+    $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
16
+      ->findOneById($user_id)->getSingleResult();
17
+    
18
+    if (!$user) {
19
+        throw new NotFoundHttpException("The Muzich\CoreBundle\Entity\User with id $user_id can't be found");
20
+    }
21
+    return $user;
22
+  }
23
+  
24
+  public function disableAndDeleteAllHisElementsAction($pk)
25
+  {
26
+    $user = $this->getUserContext($pk);
27
+    $user->setEnabled(false);
28
+    $this->persist($user);
29
+    foreach ($user->getElements() as $element)
30
+    {
31
+      $this->remove($element);
32
+    }
33
+    
34
+    try
35
+    {
36
+      $this->flush();
37
+      $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
38
+    }
39
+    catch (\Exception $e)
40
+    {
41
+      throw $e;
42
+      $this->get('session')->setFlash('error', $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
43
+    }
44
+    
45
+    return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Admin_user_show", array(
46
+      'pk' => $pk
47
+    )));
48
+  }
49
+  
50
+  public function acceptAction($element_id, $date)
51
+  {
52
+    $element = $this->getElementContext($element_id); 
53
+    $cm = new CommentsManager($element->getComments());
54
+    // On nettoie le commentaire et on récupère les ids des "signaleurs"
55
+    $ids = $cm->cleanAlertsOnComment($date);
56
+    $element->setComments($cm->get());
57
+    $element->setCountCommentReport($cm->countCommentAlert());
58
+    
59
+    $this->getDoctrine()->getEntityManager()->persist($element);
60
+    
61
+    // On récupère les user qui ont signalés ce commentaire
62
+    $users = $this->getDoctrine()->getEntityManager()
63
+      ->createQuery('
64
+        SELECT u FROM MuzichCoreBundle:User u
65
+        WHERE u.id IN (:uids)'
66
+      )
67
+      ->setParameter('uids', $ids)
68
+      ->getResult()
69
+    ;
70
+    
71
+    // Pour chacun on augmente le compteur de signalements inutiles
72
+    foreach ($users as $user)
73
+    {
74
+      $user->addBadReport();
75
+      $this->getDoctrine()->getEntityManager()->persist($user);
76
+    }
77
+    
78
+    $this->getDoctrine()->getEntityManager()->flush();
79
+    
80
+    if (!$this->getRequest()->isXmlHttpRequest())
81
+    {
82
+      $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
83
+      return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" ));
84
+    }
85
+    return $this->getJsonEmptyResponse();
86
+  }
87
+  
88
+  protected function getJsonEmptyResponse()
89
+  {
90
+    $response = new Response(json_encode(array()));
91
+    $response->headers->set('Content-Type', 'application/json; charset=utf-8');
92
+    return $response;
93
+  }
94
+  
95
+  public function refuseAction($element_id, $date)
96
+  {
97
+    $element = $this->getElementContext($element_id); 
98
+    $cm = new CommentsManager($element->getComments());
99
+    $comment = $cm->get($cm->getIndexWithDate($date));
100
+    // On supprime le commentaire
101
+    $cm->deleteWithDate($date);
102
+    $element->setComments($cm->get());
103
+    $element->setCountCommentReport($cm->countCommentAlert());
104
+    
105
+    // On récupère l'auteur du commentaire pour lui incrémenté son compteur
106
+    // de contenu modéré
107
+    $user = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:User')
108
+      ->findOneBy(array(
109
+        'id' => $comment['u']['i']
110
+      ));
111
+    
112
+    $user->addModeratedCommentCount();
113
+    
114
+    $this->getDoctrine()->getEntityManager()->persist($user);
115
+    $this->getDoctrine()->getEntityManager()->persist($element);
116
+    $this->getDoctrine()->getEntityManager()->flush();
117
+    
118
+    if (!$this->getRequest()->isXmlHttpRequest())
119
+    {
120
+      $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
121
+      return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" ));
122
+    }
123
+    return $this->getJsonEmptyResponse();
124
+  }
125
+  
126
+}

+ 8 - 2
src/Muzich/AdminBundle/Resources/config/Admin_user-generator.yml View File

12
   list:
12
   list:
13
     params:
13
     params:
14
       title: List for Users
14
       title: List for Users
15
-      display: [ id, username, email, reputation, enabled ]
15
+      display: [ id, username, email, reputation, bad_count, enabled ]
16
       actions:
16
       actions:
17
         new: ~
17
         new: ~
18
       object_actions:
18
       object_actions:
50
       display:
50
       display:
51
         "General": [ username, email, town, country ]
51
         "General": [ username, email, town, country ]
52
         "Resettings": [ email_requested, email_requested_datetime ]
52
         "Resettings": [ email_requested, email_requested_datetime ]
53
-        "Moderation": [ bad_report_count, moderated_element_count, moderated_tag_count, moderated_comment_count ]
53
+        "Moderation": [ enabled, bad_report_count, moderated_element_count, moderated_tag_count, moderated_comment_count ]
54
         "System": [ cgu_accepted, mail_newsletter, mail_partner ]
54
         "System": [ cgu_accepted, mail_newsletter, mail_partner ]
55
       actions:
55
       actions:
56
+        Disable_and_delete_elements:
57
+          route: Muzich_AdminBundle_Moderate_user_disable_and_delete_elements
58
+          params:
59
+            pk: "{{ User.id }}"
60
+          confirm: Sure to DISABLE user and DELETE ALL HIS ELEMENTS ?
61
+          icon: icon-trash
56
         list: ~
62
         list: ~
57
         new: ~
63
         new: ~
58
   delete: ~
64
   delete: ~

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

46
   requirements:
46
   requirements:
47
     _method:  GET
47
     _method:  GET
48
 
48
 
49
+Muzich_AdminBundle_Moderate_user_disable_and_delete_elements:
50
+  pattern:  /Moderate_user/{pk}/disable-and-delete-elements
51
+  defaults: { _controller:Muzich\AdminBundle\Controller\Moderate_user\EditController::disableAndDeleteAllHisElementsAction }
52
+  requirements:
53
+    _method:  GET

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

151
   /**
151
   /**
152
    * Propositions de tags
152
    * Propositions de tags
153
    * 
153
    * 
154
-   * @ORM\OneToMany(targetEntity="ElementTagsProposition", mappedBy="element")
154
+   * @ORM\OneToMany(targetEntity="ElementTagsProposition", mappedBy="element", cascade={"remove"})
155
    */
155
    */
156
   protected $tags_propositions;
156
   protected $tags_propositions;
157
   
157
   

+ 29 - 0
src/Muzich/CoreBundle/Entity/User.php View File

134
   protected $groups_owned;
134
   protected $groups_owned;
135
   
135
   
136
   /**
136
   /**
137
+   * @ORM\Column(type="integer", nullable=true)
138
+   * @var int 
139
+   */
140
+  protected $bad_count;
141
+  
142
+  /**
137
    * Compteur de signalements inutiles
143
    * Compteur de signalements inutiles
138
    * 
144
    * 
139
    * @ORM\Column(type="integer", nullable=true)
145
    * @ORM\Column(type="integer", nullable=true)
494
   public function setBadReportCount($count)
500
   public function setBadReportCount($count)
495
   {
501
   {
496
     $this->bad_report_count = $count;
502
     $this->bad_report_count = $count;
503
+    $this->updateBadCount();
497
   }
504
   }
498
   
505
   
499
   public function addBadReport()
506
   public function addBadReport()
557
   public function setModeratedElementCount($count)
564
   public function setModeratedElementCount($count)
558
   {
565
   {
559
     $this->moderated_element_count = $count;
566
     $this->moderated_element_count = $count;
567
+    $this->updateBadCount();
560
   }
568
   }
561
   
569
   
562
   public function addModeratedElementCount()
570
   public function addModeratedElementCount()
576
   public function setModeratedTagCount($count)
584
   public function setModeratedTagCount($count)
577
   {
585
   {
578
     $this->moderated_tag_count = $count;
586
     $this->moderated_tag_count = $count;
587
+    $this->updateBadCount();
579
   }
588
   }
580
   
589
   
581
   public function addModeratedTagCount()
590
   public function addModeratedTagCount()
595
   public function setModeratedCommentCount($count)
604
   public function setModeratedCommentCount($count)
596
   {
605
   {
597
     $this->moderated_comment_count = $count;
606
     $this->moderated_comment_count = $count;
607
+    $this->updateBadCount();
598
   }
608
   }
599
   
609
   
600
   public function addModeratedCommentCount()
610
   public function addModeratedCommentCount()
1061
     $this->setHelpTour($help_tour_status);
1071
     $this->setHelpTour($help_tour_status);
1062
   }
1072
   }
1063
   
1073
   
1074
+  public function getBadCount()
1075
+  {
1076
+    if (is_null($this->bad_count))
1077
+    {
1078
+      return 0;
1079
+    }
1080
+    
1081
+    return $this->bad_count;
1082
+  }
1083
+  
1084
+  public function updateBadCount()
1085
+  {
1086
+    $this->bad_count = $this->getBadReportCount()
1087
+      + $this->getModeratedCommentCount()
1088
+      + $this->getModeratedElementCount()
1089
+      + $this->getModeratedTagCount()
1090
+    ;
1091
+  }
1092
+  
1064
 }
1093
 }

+ 1 - 1
src/Muzich/CoreBundle/Repository/UserRepository.php View File

16
    * @param array $join
16
    * @param array $join
17
    * @return  Doctrine\ORM\Query
17
    * @return  Doctrine\ORM\Query
18
    */
18
    */
19
-  public function findOneById($user_id, $join_list)
19
+  public function findOneById($user_id, $join_list = array())
20
   {
20
   {
21
     $select = 'u';
21
     $select = 'u';
22
     $join = '';
22
     $join = '';