Browse Source

Evolution #162: Reputation: Prises en compte des autres facteurs

bastien 13 years ago
parent
commit
105728e723

+ 36 - 6
src/Muzich/CoreBundle/Command/RecalculateReputationCommand.php View File

@@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
7 7
 use Symfony\Component\Console\Input\InputInterface;
8 8
 use Symfony\Component\Console\Input\InputOption;
9 9
 use Symfony\Component\Console\Output\OutputInterface;
10
+use Muzich\CoreBundle\Entity\EventArchive;
10 11
 
11 12
 class RecalculateReputationCommand extends ContainerAwareCommand
12 13
 {
@@ -63,7 +64,9 @@ class RecalculateReputationCommand extends ContainerAwareCommand
63 64
     {
64 65
       $user_points = 0;
65 66
       
66
-      // On calcule pour les éléments
67
+      /*
68
+       * On calcule pour les éléments
69
+       */
67 70
       $elements = $em->createQuery(
68 71
         "SELECT e FROM MuzichCoreBundle:Element e"
69 72
         . " WHERE e.owner = :uid"
@@ -78,7 +81,9 @@ class RecalculateReputationCommand extends ContainerAwareCommand
78 81
         $element_points += $element->getPoints();
79 82
       }
80 83
       
81
-      // On calcule pour les favoris
84
+      /*
85
+       * On calcule pour les favoris
86
+       */
82 87
       $coef_element_fav = $this->getContainer()->getParameter('reputation_element_favorite_value');
83 88
       $count_favs = 0;
84 89
       $fav = $em->createQuery(
@@ -97,7 +102,9 @@ class RecalculateReputationCommand extends ContainerAwareCommand
97 102
         }
98 103
       }
99 104
       
100
-      // Calcul pour les utilisateurs suivis
105
+      /*
106
+       * Calcul pour les utilisateurs suivis
107
+       */
101 108
       $coef_follow = $this->getContainer()->getParameter('reputation_element_follow_value');
102 109
       $count_follow = 0;
103 110
       $fol = $em->createQuery(
@@ -115,9 +122,32 @@ class RecalculateReputationCommand extends ContainerAwareCommand
115 122
         }
116 123
       }
117 124
       
118
-      $points = ($element_points * $coef_element_point)
119
-        + ($count_favs * $coef_element_fav)
120
-        + ($count_follow * $coef_follow)
125
+      /*
126
+       *  Calcul pour les tags proposés sur des éléments
127
+       */
128
+      $coef_tag_prop = $this->getContainer()->getParameter('reputation_element_tags_element_prop_value');
129
+      
130
+      try {
131
+        
132
+        $count_tag_prop = $em->createQuery(
133
+          "SELECT a.count FROM MuzichCoreBundle:EventArchive a"
134
+          . " WHERE a.user = :uid AND a.type = :type"
135
+        )->setParameters(array(
136
+          'uid'  => $user->getId(),
137
+          'type' => EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
138
+        ))
139
+         ->getSingleScalarResult()      
140
+        ;
141
+        
142
+      } catch (\Doctrine\ORM\NoResultException $exc) {
143
+        $count_tag_prop = 0;
144
+      }
145
+
146
+      $points = 
147
+          ($element_points * $coef_element_point)
148
+        + ($count_favs     * $coef_element_fav)
149
+        + ($count_follow   * $coef_follow)
150
+        + ($count_tag_prop * $coef_tag_prop)
121 151
       ;
122 152
       
123 153
       $user->setReputation($points);

+ 2 - 5
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -6,8 +6,6 @@ use Muzich\CoreBundle\lib\Controller;
6 6
 use Muzich\CoreBundle\ElementFactory\ElementManager;
7 7
 use Muzich\CoreBundle\Propagator\EventElement;
8 8
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
9
-use Muzich\CoreBundle\Managers\EventArchiveManager;
10
-use Muzich\CoreBundle\Entity\EventArchive;
11 9
 
12 10
 class ElementController extends Controller
13 11
 {
@@ -688,9 +686,8 @@ class ElementController extends Controller
688 686
     $element->setHasTagProposition(false);
689 687
     $this->getDoctrine()->getEntityManager()->persist($element);
690 688
     
691
-    // On archive le fait que la proposition est été accepté
692
-    $eam = new EventArchiveManager($this->getDoctrine()->getEntityManager());
693
-    $eam->add($proposition->getUser(), EventArchive::PROP_TAGS_ELEMENT_ACCEPTED);
689
+    $event = new EventElement($this->container);
690
+    $event->tagsAccepteds($proposition);
694 691
     
695 692
     $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
696 693
       ->findByElement($element->getId())

+ 17 - 0
src/Muzich/CoreBundle/Propagator/EventElement.php View File

@@ -9,6 +9,9 @@ use Muzich\CoreBundle\Actions\User\Reputation as UserReputation;
9 9
 use Muzich\CoreBundle\Entity\Event;
10 10
 use Muzich\CoreBundle\Entity\User;
11 11
 use Muzich\CoreBundle\Managers\CommentsManager;
12
+use Muzich\CoreBundle\Entity\ElementTagsProposition;
13
+use Muzich\CoreBundle\Managers\EventArchiveManager;
14
+use Muzich\CoreBundle\Entity\EventArchive;
12 15
 
13 16
 /**
14 17
  * Propagateur d'événement concernant les éléments
@@ -136,4 +139,18 @@ class EventElement extends EventPropagator
136 139
     $this->container->get('doctrine')->getEntityManager()->persist($event);
137 140
   }
138 141
   
142
+  public function tagsAccepteds(ElementTagsProposition $proposition)
143
+  {
144
+    // On archive le fait que la proposition est été accepté
145
+    $eam = new EventArchiveManager($this->container->get('doctrine')->getEntityManager());
146
+    $eam->add($proposition->getUser(), EventArchive::PROP_TAGS_ELEMENT_ACCEPTED);
147
+    
148
+    // Et on donne des points a l'utilisateur
149
+    $ur = new UserReputation($proposition->getUser());
150
+    $ur->addPoints(
151
+      $this->container->getParameter('reputation_element_tags_element_prop_value')
152
+    );
153
+    $this->container->get('doctrine')->getEntityManager()->persist($proposition->getUser());
154
+  }
155
+  
139 156
 }