Browse Source

Evolution #183: Suivis des mauvais comportements

bastien 12 years ago
parent
commit
3350c306f2

+ 74 - 6
src/Muzich/AdminBundle/Controller/ModerateController.php View File

@@ -53,13 +53,24 @@ class ModerateController extends Controller
53 53
   
54 54
   public function tagAcceptAction($tag_id)
55 55
   {
56
-    if (($response = $this->mustBeConnected()))
56
+    if (($response = $this->mustBeConnected(true)))
57 57
     {
58 58
       return $response;
59 59
     }
60 60
     
61
+    if (!($tag = $doctrine->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
62
+      'id'         => $tag_id,
63
+      'tomoderate' => true
64
+    ))))
65
+    {
66
+      return $this->jsonResponse(array(
67
+        'status'  => 'error',
68
+        'message' => 'NotFound'
69
+      ));
70
+    }
71
+    
61 72
     $tagManager = new TagManager();
62
-    if (!$tagManager->moderateTag($this->getDoctrine(), $tag_id, true))
73
+    if (!$tagManager->moderateTag($this->getDoctrine(), $tag, true))
63 74
     {
64 75
       return $this->jsonResponse(array(
65 76
         'status'  => 'error',
@@ -74,13 +85,24 @@ class ModerateController extends Controller
74 85
   
75 86
   public function tagRefuseAction($tag_id)
76 87
   {
77
-    if (($response = $this->mustBeConnected()))
88
+    if (($response = $this->mustBeConnected(true)))
78 89
     {
79 90
       return $response;
80 91
     }
81 92
     
93
+    if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
94
+      'id'         => $tag_id,
95
+      'tomoderate' => true
96
+    ))))
97
+    {
98
+      return $this->jsonResponse(array(
99
+        'status'  => 'error',
100
+        'message' => 'NotFound'
101
+      ));
102
+    }
103
+    
82 104
     $tagManager = new TagManager();
83
-    if (!$tagManager->moderateTag($this->getDoctrine(), $tag_id, false))
105
+    if (!$tagManager->moderateTag($this->getDoctrine(), $tag, false))
84 106
     {
85 107
       return $this->jsonResponse(array(
86 108
         'status'  => 'error',
@@ -88,6 +110,29 @@ class ModerateController extends Controller
88 110
       ));
89 111
     }
90 112
     
113
+    // Tout c'est bien passé, on incremente ceci dit le compteur
114
+    // de tag refusés par la modération pour le ou les utilisateurs
115
+    // ayant fait la demande d'ajout
116
+    $uids = json_decode($tag->getPrivateids(), true);
117
+    
118
+    $users = $this->getDoctrine()->getEntityManager()
119
+      ->createQuery('
120
+        SELECT u FROM MuzichCoreBundle:User u
121
+        WHERE u.id IN (:uids)'
122
+      )
123
+      ->setParameter('uids', $uids)
124
+      ->getResult()
125
+    ;
126
+    
127
+    // Pour chacun on augmente le compteur
128
+    foreach ($users as $user)
129
+    {
130
+      $user->addModeratedTagCount();
131
+      $this->getDoctrine()->getEntityManager()->persist($user);
132
+    }
133
+    
134
+    $this->getDoctrine()->getEntityManager()->flush();
135
+    
91 136
     return $this->jsonResponse(array(
92 137
       'status' => 'success'
93 138
     ));
@@ -103,11 +148,22 @@ class ModerateController extends Controller
103 148
    */
104 149
   public function tagReplaceAction($tag_id, $tag_new_id)
105 150
   {
106
-    if (($response = $this->mustBeConnected()))
151
+    if (($response = $this->mustBeConnected(true)))
107 152
     {
108 153
       return $response;
109 154
     }
110 155
     
156
+    if (!($tag = $doctrine->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
157
+      'id'         => $tag_id,
158
+      'tomoderate' => true
159
+    ))))
160
+    {
161
+      return $this->jsonResponse(array(
162
+        'status'  => 'error',
163
+        'message' => 'NotFound'
164
+      ));
165
+    }
166
+    
111 167
     $tag_array = json_decode($tag_new_id);
112 168
     if (!array_key_exists(0, $tag_array))
113 169
     {
@@ -119,7 +175,7 @@ class ModerateController extends Controller
119 175
     $tag_new_id = $tag_array[0];
120 176
     
121 177
     $tagManager = new TagManager();
122
-    if (!$tagManager->moderateTag($this->getDoctrine(), $tag_id, false, $tag_new_id))
178
+    if (!$tagManager->moderateTag($this->getDoctrine(), $tag, false, $tag_new_id))
123 179
     {
124 180
       return $this->jsonResponse(array(
125 181
         'status'  => 'error',
@@ -170,6 +226,7 @@ class ModerateController extends Controller
170 226
     
171 227
     $event = new EventElement($this->container);
172 228
     $event->elementRemoved($element);
229
+    $element->getOwner()->addModeratedElementCount();
173 230
 
174 231
     $this->getDoctrine()->getEntityManager()->persist($element->getOwner());
175 232
     $this->getDoctrine()->getEntityManager()->remove($element);
@@ -344,11 +401,22 @@ class ModerateController extends Controller
344 401
     }
345 402
     
346 403
     $cm = new CommentsManager($element->getComments());
404
+    $comment = $cm->get($cm->getIndexWithDate($date));
347 405
     // On supprime le commentaire
348 406
     $cm->deleteWithDate($date);
349 407
     $element->setComments($cm->get());
350 408
     $element->setCountCommentReport($cm->countCommentAlert());
351 409
     
410
+    // On récupère l'auteur du commentaire pour lui incrémenté son compteur
411
+    // de contenu modéré
412
+    $user = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:User')
413
+      ->findOneBy(array(
414
+        'id' => $comment['u']['i']
415
+      ));
416
+    
417
+    $user->addModeratedCommentCount();
418
+    
419
+    $this->getDoctrine()->getEntityManager()->persist($user);
352 420
     $this->getDoctrine()->getEntityManager()->persist($element);
353 421
     $this->getDoctrine()->getEntityManager()->flush();
354 422
     

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

@@ -113,6 +113,30 @@ class User extends BaseUser
113 113
    * @var int 
114 114
    */
115 115
   protected $bad_report_count;
116
+  
117
+  /**
118
+   * Compteur de contenus refusés par la modération
119
+   * 
120
+   * @ORM\Column(type="integer", nullable=true)
121
+   * @var int 
122
+   */
123
+  protected $moderated_element_count;
124
+  
125
+  /**
126
+   * Compteur de contenus refusés par la modération
127
+   * 
128
+   * @ORM\Column(type="integer", nullable=true)
129
+   * @var int 
130
+   */
131
+  protected $moderated_tag_count;
132
+  
133
+  /**
134
+   * Compteur de contenus refusés par la modération
135
+   * 
136
+   * @ORM\Column(type="integer", nullable=true)
137
+   * @var int 
138
+   */
139
+  protected $moderated_comment_count;
116 140
 
117 141
   /**
118 142
    * @ORM\Column(type="text", nullable=true)
@@ -438,6 +462,63 @@ class User extends BaseUser
438 462
     $this->events = $events;
439 463
   }
440 464
   
465
+  public function getModeratedElementCount()
466
+  {
467
+    if ($this->moderated_element_count === null)
468
+    {
469
+      return 0;
470
+    }
471
+    return $this->moderated_element_count;
472
+  }
473
+  
474
+  public function setModeratedElementCount($count)
475
+  {
476
+    $this->moderated_element_count = $count;
477
+  }
478
+  
479
+  public function addModeratedElementCount()
480
+  {
481
+    $this->setModeratedElementCount($this->getModeratedElementCount()+1);
482
+  }
483
+  
484
+  public function getModeratedTagCount()
485
+  {
486
+    if ($this->moderated_tag_count === null)
487
+    {
488
+      return 0;
489
+    }
490
+    return $this->moderated_tag_count;
491
+  }
492
+  
493
+  public function setModeratedTagCount($count)
494
+  {
495
+    $this->moderated_tag_count = $count;
496
+  }
497
+  
498
+  public function addModeratedTagCount()
499
+  {
500
+    $this->setModeratedTagCount($this->getModeratedTagCount()+1);
501
+  }
502
+  
503
+  public function getModeratedCommentCount()
504
+  {
505
+    if ($this->moderated_comment_count === null)
506
+    {
507
+      return 0;
508
+    }
509
+    return $this->moderated_comment_count;
510
+  }
511
+  
512
+  public function setModeratedCommentCount($count)
513
+  {
514
+    $this->moderated_comment_count = $count;
515
+  }
516
+  
517
+  public function addModeratedCommentCount()
518
+  {
519
+    $this->setModeratedCommentCount($this->getModeratedCommentCount()+1);
520
+  }
521
+  
441 522
   /*
442 523
    * 
443 524
    * 

+ 19 - 0
src/Muzich/CoreBundle/Managers/CommentsManager.php View File

@@ -173,6 +173,25 @@ class CommentsManager
173 173
   }
174 174
   
175 175
   /**
176
+   * Permet de récupérer l'index d'un commentaire dans le tableau de commentaires.
177
+   * Si le commentaire n'est pas trouvé on retourne null.
178
+   * 
179
+   * @param  string $date (Y-m-d H:i:s u)
180
+   * @return int 
181
+   */
182
+  public function getIndexWithDate($date)
183
+  {
184
+    foreach ($this->comments as $i => $comment)
185
+    {
186
+      if ($comment['d'] == $date)
187
+      {
188
+        return $i;
189
+      }
190
+    }
191
+    return null;
192
+  }
193
+  
194
+  /**
176 195
    * Retourne un commentaire en fonction de son index dans le tableau.
177 196
    * 
178 197
    * @return array

+ 2 - 5
src/Muzich/CoreBundle/Managers/TagManager.php View File

@@ -177,12 +177,9 @@ class TagManager
177 177
     $em->flush();
178 178
   }
179 179
   
180
-  public function moderateTag(Registry $doctrine, $tag_id, $accept, $replacing_id = null)
180
+  public function moderateTag(Registry $doctrine, Tag $tag, $accept, $replacing_id = null)
181 181
   {
182
-    if (($tag = $doctrine->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
183
-      'id'         => $tag_id,
184
-      'tomoderate' => true
185
-    ))))
182
+    if ($tag)
186 183
     {
187 184
       if ($accept)
188 185
       {