Procházet zdrojové kódy

Evolution #146: Modération

bastien před 12 roky
rodič
revize
711e9eef77

+ 8 - 1
app/Resources/translations/userui.fr.yml Zobrazit soubor

@@ -100,4 +100,11 @@ system:
100 100
 date:
101 101
   instant:               a l'instant
102 102
   less_than_minute:      il y a moins d'une minute
103
- 
103
+ 
104
+element:
105
+  report:
106
+    link_title:        Signaler cet élément
107
+    confirm: 
108
+      sentence:          Signaler ce contenu comme inapproprié ?
109
+      yes:               Oui
110
+      no:                Non

+ 30 - 0
src/Muzich/CoreBundle/Controller/CoreController.php Zobrazit soubor

@@ -16,6 +16,7 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException;
16 16
 use Muzich\CoreBundle\Entity\Tag;
17 17
 use Muzich\CoreBundle\Managers\TagManager;
18 18
 use Muzich\CoreBundle\Entity\UsersTagsFavorites;
19
+use Muzich\CoreBundle\Managers\ElementReportManager;
19 20
 
20 21
 class CoreController extends Controller
21 22
 {
@@ -508,4 +509,33 @@ class CoreController extends Controller
508 509
     ));
509 510
   }
510 511
   
512
+  public function reportElementAction($element_id, $token)
513
+  {
514
+    if (($response = $this->mustBeConnected(true)))
515
+    {
516
+      return $response;
517
+    }
518
+    
519
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
520
+      ->findOneById($element_id)) 
521
+      || $this->getUser()->getPersonalHash() != $token)
522
+    {
523
+      return $this->jsonResponse(array(
524
+        'status' => 'error',
525
+        'errors' => array('NotFound')
526
+      ));
527
+    }
528
+    
529
+    $erm = new ElementReportManager($element);
530
+    $erm->add($this->getUser());
531
+    
532
+    $this->getDoctrine()->getEntityManager()->persist($element);
533
+    $this->getDoctrine()->getEntityManager()->flush();
534
+    
535
+    return $this->jsonResponse(array(
536
+      'status' => 'success'
537
+    ));
538
+    
539
+  }
540
+  
511 541
 }

+ 36 - 0
src/Muzich/CoreBundle/Entity/Element.php Zobrazit soubor

@@ -146,6 +146,22 @@ class Element
146 146
    * @var type string
147 147
    */
148 148
   protected $comments;
149
+  
150
+  /**
151
+   * Compteur de signalements
152
+   * 
153
+   * @ORM\Column(type="integer", nullable=true)
154
+   * @var int 
155
+   */
156
+  protected $count_report;
157
+  
158
+  /**
159
+   * array json des id users ayant reporté l'élément
160
+   * 
161
+   * @ORM\Column(type="text", nullable=true)
162
+   * @var string 
163
+   */
164
+  protected $report_ids;
149 165
 
150 166
   /**
151 167
    * Get id
@@ -416,6 +432,26 @@ class Element
416 432
     return json_decode($this->comments, true);
417 433
   }
418 434
   
435
+  public function getCountReport()
436
+  {
437
+    return $this->count_report;
438
+  }
439
+  
440
+  public function setCountReport($count)
441
+  {
442
+    $this->count_report = $count;
443
+  }
444
+  
445
+  public function getReportIds()
446
+  {
447
+    return json_decode($this->report_ids, true);
448
+  }
449
+  
450
+  public function setReportIds($report_ids)
451
+  {
452
+    $this->report_ids = json_encode($report_ids);
453
+  }
454
+  
419 455
   /**
420 456
    *
421 457
    * @param array $comments 

+ 23 - 0
src/Muzich/CoreBundle/Entity/User.php Zobrazit soubor

@@ -97,6 +97,14 @@ class User extends BaseUser
97 97
    * @ORM\OneToMany(targetEntity="Group", mappedBy="owner")
98 98
    */
99 99
   protected $groups_owned;
100
+  
101
+  /**
102
+   * Compteur de signalements inutiles
103
+   * 
104
+   * @ORM\Column(type="integer", nullable=true)
105
+   * @var int 
106
+   */
107
+  protected $bad_report_count;
100 108
 
101 109
   /**
102 110
    * 
@@ -309,6 +317,21 @@ class User extends BaseUser
309 317
     $this->email_requested = $email_requested;
310 318
   }
311 319
   
320
+  public function getBadReportCount()
321
+  {
322
+    return $this->bad_report_count;
323
+  }
324
+  
325
+  public function setBadReportCount($count)
326
+  {
327
+    $this->bad_report_count = $count;
328
+  }
329
+  
330
+  public function addBadReport()
331
+  {
332
+    $this->setBadReportCount($this->getBadReportCount()+1);
333
+  }
334
+  
312 335
   /*
313 336
    * 
314 337
    * 

+ 36 - 0
src/Muzich/CoreBundle/Managers/ElementReportManager.php Zobrazit soubor

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Managers;
4
+use Muzich\CoreBundle\Entity\Element;
5
+use Muzich\CoreBundle\Entity\User;
6
+
7
+/**
8
+ * @author bux
9
+ */
10
+class ElementReportManager
11
+{
12
+  
13
+  protected $element;
14
+  
15
+  public function __construct(Element $element)
16
+  {
17
+    $this->element = $element;
18
+  }
19
+  
20
+  /**
21
+   *
22
+   * @param \Muzich\CoreBundle\Entity\User $user
23
+   * @param String $comment
24
+   * @param String $date 
25
+   */
26
+  public function add(User $user)
27
+  {
28
+    $ids = $this->element->getReportIds();
29
+    if (!in_array($user->getId(), $ids))
30
+    {
31
+      $ids[] = (string)$user->getId();
32
+    }
33
+    $this->element->setReportIds($ids);
34
+  }
35
+  
36
+}

+ 4 - 1
src/Muzich/CoreBundle/Resources/config/routing.yml Zobrazit soubor

@@ -98,4 +98,7 @@ ajax_tag_add_to_favorites:
98 98
 ajax_set_element_group:
99 99
   pattern: /ajax/element/set-group/{element_id}/{group_id}/{token}
100 100
   defaults: { _controller: MuzichCoreBundle:Core:setElementGroup }
101
-  
101
+  
102
+ajax_report_element:
103
+  pattern: /ajax/element/report/{element_id}/{token}
104
+  defaults: { _controller: MuzichCoreBundle:Core:reportElement }

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig Zobrazit soubor

@@ -61,6 +61,12 @@
61 61
         <img src="{{ asset('bundles/muzichcore/img/1324917097_link.png') }}" alt="link" />
62 62
       </a>
63 63
       
64
+      <a title="{{ 'element.report.link_title'|trans({}, 'userui') }}" 
65
+        class="element_report" 
66
+        href="{{ path('ajax_report_element', {'element_id':element.id, 'token':app.user.getPersonalHash}) }}">
67
+        <img src="{{ asset('bundles/muzichcore/img/1331832708_comment_alert.png') }}" alt="report" />
68
+      </a>
69
+      
64 70
       {% if app.user.id == element.owner.id %}
65 71
         <a title="{{ 'element.edit.link'|trans({}, 'elements') }}" class="element_edit_link" 
66 72
            href="{{ path('element_edit', {'element_id' : element.id})  }}" style="display: none;"

+ 3 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig Zobrazit soubor

@@ -43,6 +43,9 @@
43 43
     string_tag_addtofav_confirm_sentence = "{{ 'element.tag.addtofav.confirm.sentence'|trans({}, 'elements') }}";
44 44
     string_tag_addtofav_confirm_yes = "{{ 'element.tag.addtofav.confirm.yes'|trans({}, 'elements') }}";
45 45
     string_tag_addtofav_confirm_no = "{{ 'element.tag.addtofav.confirm.no'|trans({}, 'elements') }}";
46
+    string_elementreport_confirm_sentence = "{{ 'element.report.confirm.sentence'|trans({}, 'userui') }}";
47
+    string_elementreport_confirm_yes = "{{ 'element.report.confirm.yes'|trans({}, 'userui') }}";
48
+    string_elementreport_confirm_no = "{{ 'element.report.confirm.no'|trans({}, 'userui') }}";
46 49
     
47 50
     url_index = "{{ path('index') }}";
48 51
     url_search_tag = "{{ path('search_tag') }}";

binární
web/bundles/muzichcore/img/1331832369_dialog-warning.png Zobrazit soubor


binární
web/bundles/muzichcore/img/1331832708_comment_alert.png Zobrazit soubor


+ 29 - 0
web/bundles/muzichcore/js/muzich.js Zobrazit soubor

@@ -1625,4 +1625,33 @@ $(document).ready(function(){
1625 1625
     return false;
1626 1626
   });
1627 1627
    
1628
+   /*
1629
+    * Report / signalement d'un élément
1630
+    */
1631
+   
1632
+   $('a.element_report').jConfirmAction({
1633
+    question : string_elementreport_confirm_sentence, 
1634
+    yesAnswer : string_elementreport_confirm_yes, 
1635
+    cancelAnswer : string_elementreport_confirm_no,
1636
+    onYes: function(link){
1637
+      
1638
+      $.getJSON(link.attr('href'), function(response){
1639
+        
1640
+        if (response.status == 'mustbeconnected')
1641
+        {
1642
+          $(location).attr('href', url_index);
1643
+        }
1644
+      });
1645
+      
1646
+      $('div.question').fadeOut();
1647
+      return false;
1648
+    },
1649
+    onOpen: function(link){
1650
+      
1651
+    },
1652
+    onClose: function(link){
1653
+      
1654
+    }
1655
+  });
1656
+   
1628 1657
  });