Kaynağa Gözat

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

bastien 13 yıl önce
ebeveyn
işleme
105728e723

+ 36 - 6
src/Muzich/CoreBundle/Command/RecalculateReputationCommand.php Dosyayı Görüntüle

7
 use Symfony\Component\Console\Input\InputInterface;
7
 use Symfony\Component\Console\Input\InputInterface;
8
 use Symfony\Component\Console\Input\InputOption;
8
 use Symfony\Component\Console\Input\InputOption;
9
 use Symfony\Component\Console\Output\OutputInterface;
9
 use Symfony\Component\Console\Output\OutputInterface;
10
+use Muzich\CoreBundle\Entity\EventArchive;
10
 
11
 
11
 class RecalculateReputationCommand extends ContainerAwareCommand
12
 class RecalculateReputationCommand extends ContainerAwareCommand
12
 {
13
 {
63
     {
64
     {
64
       $user_points = 0;
65
       $user_points = 0;
65
       
66
       
66
-      // On calcule pour les éléments
67
+      /*
68
+       * On calcule pour les éléments
69
+       */
67
       $elements = $em->createQuery(
70
       $elements = $em->createQuery(
68
         "SELECT e FROM MuzichCoreBundle:Element e"
71
         "SELECT e FROM MuzichCoreBundle:Element e"
69
         . " WHERE e.owner = :uid"
72
         . " WHERE e.owner = :uid"
78
         $element_points += $element->getPoints();
81
         $element_points += $element->getPoints();
79
       }
82
       }
80
       
83
       
81
-      // On calcule pour les favoris
84
+      /*
85
+       * On calcule pour les favoris
86
+       */
82
       $coef_element_fav = $this->getContainer()->getParameter('reputation_element_favorite_value');
87
       $coef_element_fav = $this->getContainer()->getParameter('reputation_element_favorite_value');
83
       $count_favs = 0;
88
       $count_favs = 0;
84
       $fav = $em->createQuery(
89
       $fav = $em->createQuery(
97
         }
102
         }
98
       }
103
       }
99
       
104
       
100
-      // Calcul pour les utilisateurs suivis
105
+      /*
106
+       * Calcul pour les utilisateurs suivis
107
+       */
101
       $coef_follow = $this->getContainer()->getParameter('reputation_element_follow_value');
108
       $coef_follow = $this->getContainer()->getParameter('reputation_element_follow_value');
102
       $count_follow = 0;
109
       $count_follow = 0;
103
       $fol = $em->createQuery(
110
       $fol = $em->createQuery(
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
       $user->setReputation($points);
153
       $user->setReputation($points);

+ 2 - 5
src/Muzich/CoreBundle/Controller/ElementController.php Dosyayı Görüntüle

6
 use Muzich\CoreBundle\ElementFactory\ElementManager;
6
 use Muzich\CoreBundle\ElementFactory\ElementManager;
7
 use Muzich\CoreBundle\Propagator\EventElement;
7
 use Muzich\CoreBundle\Propagator\EventElement;
8
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
8
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
9
-use Muzich\CoreBundle\Managers\EventArchiveManager;
10
-use Muzich\CoreBundle\Entity\EventArchive;
11
 
9
 
12
 class ElementController extends Controller
10
 class ElementController extends Controller
13
 {
11
 {
688
     $element->setHasTagProposition(false);
686
     $element->setHasTagProposition(false);
689
     $this->getDoctrine()->getEntityManager()->persist($element);
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
     $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
692
     $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
696
       ->findByElement($element->getId())
693
       ->findByElement($element->getId())

+ 17 - 0
src/Muzich/CoreBundle/Propagator/EventElement.php Dosyayı Görüntüle

9
 use Muzich\CoreBundle\Entity\Event;
9
 use Muzich\CoreBundle\Entity\Event;
10
 use Muzich\CoreBundle\Entity\User;
10
 use Muzich\CoreBundle\Entity\User;
11
 use Muzich\CoreBundle\Managers\CommentsManager;
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
  * Propagateur d'événement concernant les éléments
17
  * Propagateur d'événement concernant les éléments
136
     $this->container->get('doctrine')->getEntityManager()->persist($event);
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
 }