Browse Source

Evolution #150: Reputation

bastien 13 years ago
parent
commit
1cfe34b694

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

@@ -54,7 +54,7 @@ class CommentController extends Controller
54 54
       )));
55 55
     }
56 56
     
57
-      
57
+    
58 58
     // On met a jour les commentaires
59 59
     $cm = new CommentsManager($element->getComments());
60 60
     $cm->add($this->getUser(), $comment);

+ 35 - 0
src/Muzich/CoreBundle/Actions/User/Reputation.php View File

@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Actions\User;
4
+
5
+use Muzich\CoreBundle\Entity\User;
6
+
7
+/**
8
+ * Description of Reputation
9
+ *
10
+ * @author bux
11
+ */
12
+class Reputation
13
+{
14
+  
15
+  /**
16
+   *
17
+   * @var User 
18
+   */
19
+  protected $user;
20
+  
21
+  public function __construct(User $user)
22
+  {
23
+    $this->user = $user;
24
+  }
25
+  
26
+  public function addPoints($points)
27
+  {
28
+    $this->user->setReputation($this->user->getReputation()+$points);
29
+  }
30
+  
31
+  public function removePoints($points)
32
+  {
33
+    $this->user->setReputation($this->user->getReputation()-$points);
34
+  }
35
+}

+ 7 - 0
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Controller;
4 4
 
5 5
 use Muzich\CoreBundle\lib\Controller;
6 6
 use Muzich\CoreBundle\ElementFactory\ElementManager;
7
+use Muzich\CoreBundle\Propagator\EventElementScore;
7 8
 
8 9
 class ElementController extends Controller
9 10
 {
@@ -369,6 +370,9 @@ class ElementController extends Controller
369 370
     }
370 371
     
371 372
     $element->addVoteGood($this->getUser()->getId());
373
+    $event = new EventElementScore($this->container);
374
+    $event->onePointAdded($element);
375
+    
372 376
     $this->getDoctrine()->getEntityManager()->persist($element);
373 377
     $this->getDoctrine()->getEntityManager()->flush();
374 378
     
@@ -416,6 +420,9 @@ class ElementController extends Controller
416 420
     }
417 421
     
418 422
     $element->removeVoteGood($this->getUser()->getId());
423
+    $event = new EventElementScore($this->container);
424
+    $event->onePointRemoved($element);
425
+    
419 426
     $this->getDoctrine()->getEntityManager()->persist($element);
420 427
     $this->getDoctrine()->getEntityManager()->flush();
421 428
     

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

@@ -119,6 +119,14 @@ class User extends BaseUser
119 119
   protected $country;
120 120
   
121 121
   /**
122
+   * Reputation
123
+   * 
124
+   * @ORM\Column(type="integer", nullable=true)
125
+   * @var int 
126
+   */
127
+  protected $reputation;
128
+  
129
+  /**
122 130
    * 
123 131
    */
124 132
   public function __construct()
@@ -364,6 +372,20 @@ class User extends BaseUser
364 372
     $this->country = $country;
365 373
   }
366 374
   
375
+  public function setReputation($reputation)
376
+  {
377
+    $this->reputation = $reputation;
378
+  }
379
+  
380
+  public function getReputation()
381
+  {
382
+    if ($this->reputation === null)
383
+    {
384
+      return 0;
385
+    }
386
+    return $this->reputation;
387
+  }
388
+  
367 389
   /*
368 390
    * 
369 391
    * 

+ 46 - 0
src/Muzich/CoreBundle/Propagator/EventElementScore.php View File

@@ -0,0 +1,46 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Propagator;
4
+
5
+use Muzich\CoreBundle\Propagator\EventPropagator;
6
+use Muzich\CoreBundle\Entity\Element;
7
+use Muzich\CoreBundle\Actions\User\Reputation as UserReputation;
8
+
9
+/**
10
+ * Description of EventElementScore
11
+ *
12
+ * @author bux
13
+ */
14
+class EventElementScore extends EventPropagator
15
+{  
16
+  /**
17
+   * Un point a été ajouté par quelqu'un a cet élément
18
+   * Conséquences:
19
+   *  * L'auteur du partage gagne x point de reputation
20
+   *
21
+   * @param Element $element 
22
+   */
23
+  public function onePointAdded(Element $element)
24
+  {
25
+    $ur = new UserReputation($element->getOwner());
26
+    $ur->addPoints(
27
+      $this->container->getParameter('reputation_element_point_value')
28
+    );
29
+  }
30
+  
31
+  /**
32
+   * Un point a été retiré par quelqu'un a cet élément
33
+   * Conséquences:
34
+   *  * L'auteur du partage perd x point de reputation
35
+   *
36
+   * @param Element $element 
37
+   */
38
+  public function onePointRemoved(Element $element)
39
+  {
40
+    $ur = new UserReputation($element->getOwner());
41
+    $ur->removePoints(
42
+      $this->container->getParameter('reputation_element_point_value')
43
+    );
44
+  }
45
+  
46
+}

+ 22 - 0
src/Muzich/CoreBundle/Propagator/EventPropagator.php View File

@@ -0,0 +1,22 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Propagator;
4
+
5
+use Symfony\Component\DependencyInjection\Container;
6
+
7
+/**
8
+ * Description of EventPropagator
9
+ *
10
+ * @author bux
11
+ */
12
+class EventPropagator
13
+{
14
+  protected $container;  
15
+  
16
+  public function __construct(Container $container)
17
+  {
18
+    $this->container = $container;
19
+  }
20
+}
21
+
22
+?>