Quellcode durchsuchen

Evolution #673: Modération plus rapide/facile

Sevajol Bastien vor 11 Jahren
Ursprung
Commit
a3af1e6fad

+ 1 - 0
src/Muzich/AdminBundle/Controller/Admin_element/EditController.php Datei anzeigen

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

+ 1 - 0
src/Muzich/AdminBundle/Controller/Moderate_comment/EditController.php Datei anzeigen

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

+ 1 - 0
src/Muzich/AdminBundle/Controller/Moderate_element/EditController.php Datei anzeigen

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

+ 1 - 0
src/Muzich/AdminBundle/Controller/Moderate_tag/EditController.php Datei anzeigen

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

+ 126 - 0
src/Muzich/AdminBundle/Controller/Moderate_user/EditController.php Datei anzeigen

@@ -0,0 +1,126 @@
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 Datei anzeigen

@@ -12,7 +12,7 @@ builders:
12 12
   list:
13 13
     params:
14 14
       title: List for Users
15
-      display: [ id, username, email, reputation, enabled ]
15
+      display: [ id, username, email, reputation, bad_count, enabled ]
16 16
       actions:
17 17
         new: ~
18 18
       object_actions:
@@ -50,9 +50,15 @@ builders:
50 50
       display:
51 51
         "General": [ username, email, town, country ]
52 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 54
         "System": [ cgu_accepted, mail_newsletter, mail_partner ]
55 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 62
         list: ~
57 63
         new: ~
58 64
   delete: ~

+ 5 - 0
src/Muzich/AdminBundle/Resources/config/routing.yml Datei anzeigen

@@ -46,3 +46,8 @@ Muzich_AdminBundle_Moderate_comment_refuse:
46 46
   requirements:
47 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 Datei anzeigen

@@ -151,7 +151,7 @@ class Element
151 151
   /**
152 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 156
   protected $tags_propositions;
157 157
   

+ 29 - 0
src/Muzich/CoreBundle/Entity/User.php Datei anzeigen

@@ -134,6 +134,12 @@ class User extends BaseUser
134 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 143
    * Compteur de signalements inutiles
138 144
    * 
139 145
    * @ORM\Column(type="integer", nullable=true)
@@ -494,6 +500,7 @@ class User extends BaseUser
494 500
   public function setBadReportCount($count)
495 501
   {
496 502
     $this->bad_report_count = $count;
503
+    $this->updateBadCount();
497 504
   }
498 505
   
499 506
   public function addBadReport()
@@ -557,6 +564,7 @@ class User extends BaseUser
557 564
   public function setModeratedElementCount($count)
558 565
   {
559 566
     $this->moderated_element_count = $count;
567
+    $this->updateBadCount();
560 568
   }
561 569
   
562 570
   public function addModeratedElementCount()
@@ -576,6 +584,7 @@ class User extends BaseUser
576 584
   public function setModeratedTagCount($count)
577 585
   {
578 586
     $this->moderated_tag_count = $count;
587
+    $this->updateBadCount();
579 588
   }
580 589
   
581 590
   public function addModeratedTagCount()
@@ -595,6 +604,7 @@ class User extends BaseUser
595 604
   public function setModeratedCommentCount($count)
596 605
   {
597 606
     $this->moderated_comment_count = $count;
607
+    $this->updateBadCount();
598 608
   }
599 609
   
600 610
   public function addModeratedCommentCount()
@@ -1061,4 +1071,23 @@ class User extends BaseUser
1061 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 Datei anzeigen

@@ -16,7 +16,7 @@ class UserRepository extends EntityRepository
16 16
    * @param array $join
17 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 21
     $select = 'u';
22 22
     $join = '';