|
@@ -8,14 +8,15 @@ use Symfony\Component\Console\Input\InputInterface;
|
8
|
8
|
use Symfony\Component\Console\Input\InputOption;
|
9
|
9
|
use Symfony\Component\Console\Output\OutputInterface;
|
10
|
10
|
use Muzich\CoreBundle\Entity\EventArchive;
|
|
11
|
+use Muzich\CoreBundle\Entity\Element;
|
11
|
12
|
|
12
|
13
|
class RecalculateReputationCommand extends ContainerAwareCommand
|
13
|
14
|
{
|
14
|
15
|
protected function configure()
|
15
|
16
|
{
|
16
|
17
|
$this
|
17
|
|
- ->setName('users:reputation:recalculate')
|
18
|
|
- ->setDescription('Recalcul des scores de reputation')
|
|
18
|
+ ->setName('score:recalculate')
|
|
19
|
+ ->setDescription('Recalcul des scores')
|
19
|
20
|
->addOption('user', null, InputOption::VALUE_REQUIRED, 'username du compte a traiter')
|
20
|
21
|
// ->addArgument('sites', InputArgument::OPTIONAL, 'Liste exhaustive des site a traiter')
|
21
|
22
|
// ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
|
|
@@ -26,12 +27,24 @@ class RecalculateReputationCommand extends ContainerAwareCommand
|
26
|
27
|
{
|
27
|
28
|
$doctrine = $this->getContainer()->get('doctrine');
|
28
|
29
|
$em = $doctrine->getEntityManager();
|
29
|
|
-
|
|
30
|
+
|
30
|
31
|
$output->writeln('#');
|
31
|
|
- $output->writeln('## Script de recalcul des scores de reputation ##');
|
|
32
|
+ $output->writeln('## Script de recalcul des scores ##');
|
32
|
33
|
$output->writeln('#');
|
33
|
34
|
|
34
|
35
|
$output->writeln('<info>Début du traitement ...</info>');
|
|
36
|
+ $this->recalculateUserScores($input, $output);
|
|
37
|
+ $this->recalculateElementScores($input, $output);
|
|
38
|
+
|
|
39
|
+ $output->writeln('<info>Saving in database ...</info>');
|
|
40
|
+ $em->flush();
|
|
41
|
+ $output->writeln('<info>Terminé !</info>');
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ protected function recalculateUserScores(InputInterface $input, OutputInterface $output)
|
|
45
|
+ {
|
|
46
|
+ $doctrine = $this->getContainer()->get('doctrine');
|
|
47
|
+ $em = $doctrine->getEntityManager();
|
35
|
48
|
|
36
|
49
|
if (($username = $input->getOption('user')))
|
37
|
50
|
{
|
|
@@ -79,6 +92,8 @@ class RecalculateReputationCommand extends ContainerAwareCommand
|
79
|
92
|
foreach ($elements as $element)
|
80
|
93
|
{
|
81
|
94
|
$element_points += $element->getPoints();
|
|
95
|
+ // Point déjà ajoutés a l'user
|
|
96
|
+ $element_points -= ($element->getCountFavorited()*$this->getContainer()->getParameter('reputation_element_favorite_value'));
|
82
|
97
|
}
|
83
|
98
|
|
84
|
99
|
/*
|
|
@@ -153,9 +168,37 @@ class RecalculateReputationCommand extends ContainerAwareCommand
|
153
|
168
|
|
154
|
169
|
$user->setReputation($points);
|
155
|
170
|
$em->persist($user);
|
156
|
|
- $em->flush();
|
|
171
|
+ $output->writeln('<info>User "'.$user->getUsername().'": '.$points.' score</info>');
|
157
|
172
|
}
|
158
|
173
|
|
159
|
|
- $output->writeln('<info>Terminé !</info>');
|
160
|
174
|
}
|
|
175
|
+
|
|
176
|
+ protected function recalculateElementScores(InputInterface $input, OutputInterface $output)
|
|
177
|
+ {
|
|
178
|
+ $doctrine = $this->getContainer()->get('doctrine');
|
|
179
|
+ $em = $doctrine->getEntityManager();
|
|
180
|
+
|
|
181
|
+ $elements = $em->createQuery(
|
|
182
|
+ "SELECT element FROM MuzichCoreBundle:Element element"
|
|
183
|
+ )->getResult();
|
|
184
|
+
|
|
185
|
+ foreach ($elements as $element)
|
|
186
|
+ {
|
|
187
|
+ $element->setPoints($this->getElementScore($element));
|
|
188
|
+ $em->persist($element);
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ }
|
|
192
|
+
|
|
193
|
+ protected function getElementScore(Element $element)
|
|
194
|
+ {
|
|
195
|
+ $element_score = 0;
|
|
196
|
+
|
|
197
|
+ $element_score += (count($element->getVoteGoodIds())*$this->getContainer()->getParameter('reputation_element_point_value'));
|
|
198
|
+
|
|
199
|
+ $element_score += ($element->getCountFavorited()*$this->getContainer()->getParameter('reputation_element_favorite_value'));
|
|
200
|
+
|
|
201
|
+ return $element_score;
|
|
202
|
+ }
|
|
203
|
+
|
161
|
204
|
}
|