Browse Source

Evolution #176: Modération commentaire

bastien 12 years ago
parent
commit
269bccbfcc

+ 10 - 2
app/Resources/translations/userui.fr.yml View File

119
  
119
  
120
 element:
120
 element:
121
   report:
121
   report:
122
-    link_title:        Signaler cet élément
122
+    link_title:          Signaler cet élément
123
     confirm: 
123
     confirm: 
124
       sentence:          Signaler ce contenu comme inapproprié ?
124
       sentence:          Signaler ce contenu comme inapproprié ?
125
       yes:               Oui
125
       yes:               Oui
126
       no:                Non
126
       no:                Non
127
   proposition_tags:
127
   proposition_tags:
128
-    link_title:        Proposer des tags
128
+    link_title:        Proposer des tags
129
+    
130
+comment:
131
+  report:
132
+    link_title:          Signaler ce commentaire
133
+    confirm: 
134
+      sentence:          Signaler ce commentaire comme inapproprié ?
135
+      yes:               Oui
136
+      no:                Non

+ 78 - 0
src/Muzich/CommentBundle/Controller/CommentController.php View File

288
     
288
     
289
   }
289
   }
290
   
290
   
291
+  /**
292
+   * Signalement d'un commentaire
293
+   * 
294
+   * @param int $element_id
295
+   * @param date $date
296
+   * @param string $token
297
+   * @param string $dom_id
298
+   * @return Response 
299
+   */
300
+  public function alertAction($element_id, $date, $token)
301
+  {
302
+    if (($response = $this->mustBeConnected(true)))
303
+    {
304
+      return $response;
305
+    }
306
+    
307
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
308
+      ->findOneById($element_id)) || $this->getUser()->getPersonalHash() != $token)
309
+    {
310
+      return $this->jsonResponse(array(
311
+        'status' => 'error',
312
+        'errors' => array('NotFound')
313
+      ));
314
+    }
315
+    
316
+    // Création de l'objet de gestion des commentaires
317
+    $cm = new CommentsManager($element->getComments());
318
+    $cm->alertComment($this->getUserId(), $date);
319
+    $element->setComments($cm->get());
320
+    $element->setHasCommentReport($cm->hasCommentAlert());
321
+    
322
+    $this->getDoctrine()->getEntityManager()->persist($element);
323
+    $this->getDoctrine()->getEntityManager()->flush();
324
+    
325
+    return $this->jsonResponse(array(
326
+      'status' => 'success'
327
+    ));
328
+  }
329
+  
330
+  /**
331
+   * Signalement d'un commentaire
332
+   * 
333
+   * @param int $element_id
334
+   * @param date $date
335
+   * @param string $token
336
+   * @param string $dom_id
337
+   * @return Response 
338
+   */
339
+  public function unAlertAction($element_id, $date, $token)
340
+  {
341
+    if (($response = $this->mustBeConnected(true)))
342
+    {
343
+      return $response;
344
+    }
345
+    
346
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
347
+      ->findOneById($element_id)) || $this->getUser()->getPersonalHash() != $token)
348
+    {
349
+      return $this->jsonResponse(array(
350
+        'status' => 'error',
351
+        'errors' => array('NotFound')
352
+      ));
353
+    }
354
+    
355
+    // Création de l'objet de gestion des commentaires
356
+    $cm = new CommentsManager($element->getComments());
357
+    $cm->unAlertComment($this->getUserId(), $date);
358
+    $element->setComments($cm->get());
359
+    $element->setHasCommentReport($cm->hasCommentAlert());
360
+    
361
+    $this->getDoctrine()->getEntityManager()->persist($element);
362
+    $this->getDoctrine()->getEntityManager()->flush();
363
+    
364
+    return $this->jsonResponse(array(
365
+      'status' => 'success'
366
+    ));
367
+  }
368
+  
291
 }
369
 }

+ 9 - 1
src/Muzich/CommentBundle/Resources/config/routing.yml View File

13
   
13
   
14
 ajax_delete_comment:
14
 ajax_delete_comment:
15
   pattern: /ajax/comment/delete/{element_id}/{date}/{token}
15
   pattern: /ajax/comment/delete/{element_id}/{date}/{token}
16
-  defaults: { _controller: MuzichCommentBundle:Comment:delete }
16
+  defaults: { _controller: MuzichCommentBundle:Comment:delete }
17
+  
18
+ajax_alert_comment:
19
+  pattern: /ajax/comment/alert/{element_id}/{date}/{token}
20
+  defaults: { _controller: MuzichCommentBundle:Comment:alert }
21
+  
22
+ajax_unalert_comment:
23
+  pattern: /ajax/comment/unalert/{element_id}/{date}/{token}
24
+  defaults: { _controller: MuzichCommentBundle:Comment:unAlert }

+ 8 - 0
src/Muzich/CommentBundle/Resources/views/Comment/comment.html.twig View File

5
    {{ date_or_relative_date(comment.e, 'comment.edited') }}{% endif %})
5
    {{ date_or_relative_date(comment.e, 'comment.edited') }}{% endif %})
6
 </span>
6
 </span>
7
 
7
 
8
+{% if app.user.id != comment.u.i %}
9
+  <a title="{{ 'comment.report.link_title'|trans({}, 'userui') }}" 
10
+    class="comment_report" 
11
+    href="{{ path('ajax_alert_comment', {'element_id':element_id, 'date': comment.d, 'token':app.user.getPersonalHash}) }}">
12
+    <img src="{{ asset('bundles/muzichcore/img/1331832708_comment_alert.png') }}" alt="report" />
13
+  </a>
14
+{% endif %}
15
+
8
 {% if app.user.id == comment.u.i %}
16
 {% if app.user.id == comment.u.i %}
9
   <a title="{{ 'comment.edit.link'|trans({}, 'elements') }}" class="comment_edit_link" 
17
   <a title="{{ 'comment.edit.link'|trans({}, 'elements') }}" class="comment_edit_link" 
10
      href="{{ path('ajax_edit_comment', {'element_id': element_id, 'date':comment.d, 'token':app.user.getPersonalHash})  }}" style="display: none;"
18
      href="{{ path('ajax_edit_comment', {'element_id': element_id, 'date':comment.d, 'token':app.user.getPersonalHash})  }}" style="display: none;"

+ 17 - 17
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php View File

78
   {
78
   {
79
     if ($micro)
79
     if ($micro)
80
     {
80
     {
81
-      return date('Y-m-d H:i:s u', time() - 60 * 60 *24 * $ecal);
81
+      return date('Y-m-d H:i:s', time() - 60 * 60 *24 * $ecal).' '.substr(microtime(), 0, 10);
82
     }
82
     }
83
     return date('Y-m-d H:i:s', time() - 60 * 60 *24 * $ecal);
83
     return date('Y-m-d H:i:s', time() - 60 * 60 *24 * $ecal);
84
   }
84
   }
217
     $cm = new CommentsManager();
217
     $cm = new CommentsManager();
218
     $cm->add($joelle, "J'aime bien quand ça tape. Ca rapelle ".
218
     $cm->add($joelle, "J'aime bien quand ça tape. Ca rapelle ".
219
       "le grincement sinistre des volets de vieilles ".
219
       "le grincement sinistre des volets de vieilles ".
220
-      "maisons. D'ailleur j'ai repeint mon mur des shiots !", false, $this->dateD(180));
220
+      "maisons. D'ailleur j'ai repeint mon mur des shiots !", false, $this->dateD(180, true));
221
     
221
     
222
     $this->createElement('azyd_azylum_1', 'AZYD AZYLUM Live au Café Provisoire', 
222
     $this->createElement('azyd_azylum_1', 'AZYD AZYLUM Live au Café Provisoire', 
223
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
223
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
228
     );
228
     );
229
     
229
     
230
     $cm = new CommentsManager();
230
     $cm = new CommentsManager();
231
-    $cm->add($bux, "Je commenteuuh nanana 1", false, $this->dateD(180));
232
-    $cm->add($paul, "Je répond 2", false, $this->dateD(180));
233
-    $cm->add($bux, "Je répond 3", false, $this->dateD(179));
234
-    $cm->add($paul, "Je répond 4", false, $this->dateD(178));
235
-    $cm->add($bux, "Je répond 5", false, $this->dateD(177));
236
-    $cm->add($paul, "Je répond 6", false, $this->dateD(176));
237
-    $cm->add($bux, "Je répond 7", false, $this->dateD(175));
238
-    $cm->add($paul, "Je répond 8", false, $this->dateD(174));
239
-    $cm->add($bux, "Je répond 9", false, $this->dateD(173));
240
-    $cm->add($paul, "Je répond 10", false, $this->dateD(172));
241
-    $cm->add($bux, "Je répond 11", false, $this->dateD(161));
242
-    $cm->add($paul, "Je répond 12", false, $this->dateD(150));
243
-    $cm->add($bux, "Je répond 13", false, $this->dateD(140));
231
+    $cm->add($bux, "Je commenteuuh nanana 1", false, $this->dateD(180, true));
232
+    $cm->add($paul, "Je répond 2", false, $this->dateD(180, true));
233
+    $cm->add($bux, "Je répond 3", false, $this->dateD(179, true));
234
+    $cm->add($paul, "Je répond 4", false, $this->dateD(178, true));
235
+    $cm->add($bux, "Je répond 5", false, $this->dateD(177, true));
236
+    $cm->add($paul, "Je répond 6", false, $this->dateD(176, true));
237
+    $cm->add($bux, "Je répond 7", false, $this->dateD(175, true));
238
+    $cm->add($paul, "Je répond 8", false, $this->dateD(174, true));
239
+    $cm->add($bux, "Je répond 9", false, $this->dateD(173, true));
240
+    $cm->add($paul, "Je répond 10", false, $this->dateD(172, true));
241
+    $cm->add($bux, "Je répond 11", false, $this->dateD(161, true));
242
+    $cm->add($paul, "Je répond 12", false, $this->dateD(150, true));
243
+    $cm->add($bux, "Je répond 13", false, $this->dateD(140, true));
244
     
244
     
245
     $this->createElement('babylon_pression_1', 'Babylon Pression - Des Tasers et des Pauvres', 
245
     $this->createElement('babylon_pression_1', 'Babylon Pression - Des Tasers et des Pauvres', 
246
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
246
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
251
     );
251
     );
252
     
252
     
253
     $cm = new CommentsManager();
253
     $cm = new CommentsManager();
254
-    $cm->add($bux, "C'est trop bon hein ?", false, $this->dateD(180));
255
-    $cm->add($paul, "C'est pas mal en effet", false, $this->dateD(180));
254
+    $cm->add($bux, "C'est trop bon hein ?", false, $this->dateD(180, true));
255
+    $cm->add($paul, "C'est pas mal en effet", false, $this->dateD(180, true));
256
         
256
         
257
     $this->createElement('ed_cox_1', 'Ed Cox - La fanfare des teuffeurs (Hardcordian)', 
257
     $this->createElement('ed_cox_1', 'Ed Cox - La fanfare des teuffeurs (Hardcordian)', 
258
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 
258
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 

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

195
    * @var int 
195
    * @var int 
196
    */
196
    */
197
   protected $points;
197
   protected $points;
198
+  
199
+  /**
200
+   * Booléen permettant de savoir si un des commentaires de cet élément
201
+   * a été signalé a la modération.
202
+   * 
203
+   * @ORM\Column(type="boolean", nullable = "true")
204
+   * @var type string
205
+   */
206
+  protected $has_comment_report = false;
198
 
207
 
199
   /**
208
   /**
200
    * Get id
209
    * Get id
519
     $this->tags_propositions = $propositions;
528
     $this->tags_propositions = $propositions;
520
   }
529
   }
521
   
530
   
531
+  public function getHasCommentReport()
532
+  {
533
+    if (is_null($this->has_comment_report))
534
+    {
535
+      return false;
536
+    }
537
+    return $this->has_comment_report;
538
+  }
539
+  
540
+  public function setHasCommentReport($has)
541
+  {
542
+    $this->has_comment_report = $has;
543
+  }
544
+  
522
   /**
545
   /**
523
    * Etablie des relation vers des tags.
546
    * Etablie des relation vers des tags.
524
    * (Supprime les anciens tags, au niveau de l'objet seulement)
547
    * (Supprime les anciens tags, au niveau de l'objet seulement)

+ 1 - 0
src/Muzich/CoreBundle/Extension/MyTwigExtension.php View File

115
     $date = str_replace(' ', '', $date);
115
     $date = str_replace(' ', '', $date);
116
     $date = str_replace('-', '', $date);
116
     $date = str_replace('-', '', $date);
117
     $date = str_replace(':', '', $date);
117
     $date = str_replace(':', '', $date);
118
+    $date = str_replace('.', '', $date);
118
     return $date;
119
     return $date;
119
   }
120
   }
120
   
121
   

+ 77 - 2
src/Muzich/CoreBundle/Managers/CommentsManager.php View File

37
   {
37
   {
38
     if (!$date)
38
     if (!$date)
39
     {
39
     {
40
-      $date = date('Y-m-d H:i:s u');
40
+      $date = date('Y-m-d H:i:s').' '.substr(microtime(), 0, 10);
41
     }
41
     }
42
     
42
     
43
     $this->comments[] = array(
43
     $this->comments[] = array(
46
         "s" => $user->getSlug(),
46
         "s" => $user->getSlug(),
47
         "n" => $user->getName()
47
         "n" => $user->getName()
48
       ),
48
       ),
49
+      "a" => array(),
49
       "f" => $follow,
50
       "f" => $follow,
50
       "d" => $date,
51
       "d" => $date,
51
       "c" => $comment
52
       "c" => $comment
91
             "s" => $user->getSlug(),
92
             "s" => $user->getSlug(),
92
             "n" => $user->getName()
93
             "n" => $user->getName()
93
           ),
94
           ),
94
-          "e" => date('Y-m-d H:i:s u'),
95
+          "a" => $comment['a'],
96
+          "e" => date('Y-m-d H:i:s').' '.substr(microtime(), 0, 10),
95
           "f" => $follow,
97
           "f" => $follow,
96
           "d" => $date,
98
           "d" => $date,
97
           "c" => $comment_c
99
           "c" => $comment_c
232
     return $ids;
234
     return $ids;
233
   }
235
   }
234
   
236
   
237
+  /**
238
+   * Signalement d'un commentaire par un utilisateur
239
+   *
240
+   * @param int $user_id id de l'user faisant le signalement
241
+   * @param date $date   date du commentaire
242
+   * 
243
+   * @return boolean
244
+   */
245
+  public function alertComment($user_id, $date)
246
+  {
247
+    foreach ($this->comments as $i => $comment)
248
+    {
249
+      if ($comment['d'] == $date)
250
+      {
251
+        if (!in_array($user_id, $comment['a']))
252
+        {
253
+          $comment['a'][] = $user_id;
254
+          $this->comments[$i] = $comment;
255
+          return true;
256
+        }
257
+      }
258
+    }
259
+    return false;
260
+  }
261
+  
262
+  /**
263
+   * Retrait du signalement d'un commentaire de la part d'un user.
264
+   * 
265
+   * @param type $user_id  id de l'user retirant son signalement
266
+   * @param date $date     date du commentaire
267
+   * @return boolean 
268
+   */
269
+  public function unAlertComment($user_id, $date)
270
+  {
271
+    foreach ($this->comments as $i => $comment)
272
+    {
273
+      if ($comment['d'] == $date)
274
+      {
275
+        if (in_array($user_id, $comment['a']))
276
+        {
277
+          foreach ($comment['a'] as $ii => $user_alert_id)
278
+          {
279
+            if ($user_alert_id == $user_id)
280
+            {
281
+              unset($comment['a'][$ii]);
282
+              $this->comments[$i] = $comment;
283
+              return true;
284
+            }
285
+          }
286
+        }
287
+        
288
+      }
289
+    }
290
+    return false;
291
+  }
292
+  
293
+  /**
294
+   * Permet de savoir si un ou plusieurs des commentaires ont été signalé.
295
+   * 
296
+   * @return boolean
297
+   */
298
+  public function hasCommentAlert()
299
+  {
300
+    foreach ($this->comments as $i => $comment)
301
+    {
302
+      if (count($comment['a']))
303
+      {
304
+        return true;
305
+      }
306
+    }
307
+    return false;
308
+  }
309
+  
235
 }
310
 }

+ 3 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

46
     string_elementreport_confirm_sentence = "{{ 'element.report.confirm.sentence'|trans({}, 'userui') }}";
46
     string_elementreport_confirm_sentence = "{{ 'element.report.confirm.sentence'|trans({}, 'userui') }}";
47
     string_elementreport_confirm_yes = "{{ 'element.report.confirm.yes'|trans({}, 'userui') }}";
47
     string_elementreport_confirm_yes = "{{ 'element.report.confirm.yes'|trans({}, 'userui') }}";
48
     string_elementreport_confirm_no = "{{ 'element.report.confirm.no'|trans({}, 'userui') }}";
48
     string_elementreport_confirm_no = "{{ 'element.report.confirm.no'|trans({}, 'userui') }}";
49
+    string_commentreport_confirm_sentence = "{{ 'comment.report.confirm.sentence'|trans({}, 'userui') }}";
50
+    string_commentreport_confirm_yes = "{{ 'comment.report.confirm.yes'|trans({}, 'userui') }}";
51
+    string_commentreport_confirm_no = "{{ 'comment.report.confirm.no'|trans({}, 'userui') }}";
49
     
52
     
50
     url_index = "{{ path('index') }}";
53
     url_index = "{{ path('index') }}";
51
     url_search_tag = "{{ path('search_tag') }}";
54
     url_search_tag = "{{ path('search_tag') }}";

+ 29 - 0
web/bundles/muzichcore/js/muzich.js View File

1871
   /*
1871
   /*
1872
    * Proposition de tag sur un élément FIN
1872
    * Proposition de tag sur un élément FIN
1873
    */
1873
    */
1874
+  
1875
+  /*
1876
+    * Report / signalement d'un commentaire
1877
+    */
1878
+   
1879
+   $('a.comment_report').jConfirmAction({
1880
+    question : string_commentreport_confirm_sentence, 
1881
+    yesAnswer : string_commentreport_confirm_yes, 
1882
+    cancelAnswer : string_commentreport_confirm_no,
1883
+    onYes: function(link){
1884
+      
1885
+      $.getJSON(link.attr('href'), function(response){
1886
+        
1887
+        if (response.status == 'mustbeconnected')
1888
+        {
1889
+          $(location).attr('href', url_index);
1890
+        }
1891
+      });
1892
+      
1893
+      $('div.question').fadeOut();
1894
+      return false;
1895
+    },
1896
+    onOpen: function(link){
1897
+      
1898
+    },
1899
+    onClose: function(link){
1900
+      
1901
+    }
1902
+  });
1874
 
1903
 
1875
 });
1904
 });