FacegameAchievementsCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace KI\UserBundle\Command;
4
5
use KI\UserBundle\Entity\Facegame;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
use KI\UserBundle\Event\AchievementCheckEvent;
13
use KI\UserBundle\Entity\Achievement;
14
15
class FacegameAchievementsCommand extends ContainerAwareCommand
16
{
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('upont:achievements:facegame')
21
            ->setDescription('Checks facegames for achievements')
22
        ;
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $em = $this->getContainer()->get('doctrine.orm.entity_manager');
28
29
        $query = $em->createQuery('SELECT fg FROM KIUserBundle:Facegame fg');
30
        $iterableResult = $query->iterate();
31
32
        /**
33
         * @var $facegame Facegame
34
         */
35
        foreach ($iterableResult as $row) {
36
            $facegame = $row[0];
37
            $user = $facegame->getUser();
38
39
            $achievementCheck = new AchievementCheckEvent(Achievement::GAME_PLAY, $user);
40
            $dispatcher = $this->getContainer()->get('event_dispatcher');
41
42
            $dispatcher->dispatch('upont.achievement', $achievementCheck);
43
44
            $promoUser = (int)$user->getPromo();
45
            $promoGame = (int)$facegame->getPromo();
46
47
            $wrongAnswers = $facegame->getWrongAnswers();
48
            $duration = $facegame->getDuration();
49
50
            if ($wrongAnswers == 0 && $promoGame == $promoUser - 1 && $duration < 60 * 1000) {
51
52
                $achievementCheck = new AchievementCheckEvent(Achievement::GAME_BEFORE, $user);
53
                $dispatcher->dispatch('upont.achievement', $achievementCheck);
54
55
            } else if ($wrongAnswers == 0 && $promoGame == $promoUser && $duration < 60 * 1000) {
56
57
                $achievementCheck = new AchievementCheckEvent(Achievement::GAME_SELF, $user);
58
                $dispatcher->dispatch('upont.achievement', $achievementCheck);
59
60 View Code Duplication
            } else if ($wrongAnswers == 0 && $promoGame == $promoUser + 1 && $duration < 60 * 1000) {
61
62
                $achievementCheck = new AchievementCheckEvent(Achievement::GAME_NEXT, $user);
63
                $dispatcher->dispatch('upont.achievement', $achievementCheck);
64
65
            }
66 View Code Duplication
            if ($wrongAnswers == 0 && $promoGame < $promoUser && $facegame->getHardcore() && $duration < 60 * 1000) {
67
68
                $achievementCheck = new AchievementCheckEvent(Achievement::GAME_OLD, $user);
69
                $dispatcher->dispatch('upont.achievement', $achievementCheck);
70
71
            }
72
73
            $em->detach($row[0]);
74
        }
75
    }
76
}
77