Completed
Push — develop ( 53d6fd...6e76b4 )
by greg
03:11
created

Cron::getEntryMapper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %
Metric Value
dl 8
loc 8
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace PlaygroundGame\Service;
4
5
use Zend\ServiceManager\ServiceManagerAwareInterface;
6
use Zend\ServiceManager\ServiceManager;
7
use PlaygroundGame\Options\ModuleOptions;
8
use PlaygroundGame\Mapper\GameInterface as GameMapperInterface;
9
10
class Cron extends Game implements ServiceManagerAwareInterface
11
{
12
    /**
13
     * @var GameMapperInterface
14
     */
15
    protected $gameMapper;
16
17
    /**
18
     * @var EntryMapperInterface
19
     */
20
    protected $entryMapper;
21
22
    /**
23
     * @var ServiceManager
24
     */
25
    protected $serviceManager;
26
27
    /**
28
     * @var UserServiceOptionsInterface
29
     */
30
    protected $options;
31
32
    public static function cronMail()
33
    {
34
        $configuration = require 'config/application.config.php';
35
        $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
36
        $sm = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($smConfig));
37
        $sm->setService('ApplicationConfig', $configuration);
38
        $sm->get('ModuleManager')->loadModules();
39
        $sm->get('Application')->bootstrap();
40
41
        $mailService = $sm->get('playgrounduser_message');
42
        $gameService = $sm->get('playgroundgame_quiz_service');
43
44
        $from    = "[email protected]";
45
        $subject = "sujet game";
46
47
        $to = "[email protected]";
48
49
        $game = $gameService->checkGame('qooqo');
50
51
        // On recherche les joueurs qui n'ont pas partagé leur qquiz après avoir joué
52
        // entry join user join game : distinct user et game et game_entry = 0 et updated_at <= jour-1 et > jour - 2
53
54
        $message = $mailService->createTextMessage(
55
            $from,
56
            $to,
57
            $subject,
58
            'playground-game/email/share_reminder',
59
            array('game' => $game)
60
        );
61
62
        $mailService->send($message);
63
    }
64
65
    public static function instantWinEmail()
66
    {
67
        $configuration = require 'config/application.config.php';
68
        $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
69
        $sm = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($smConfig));
70
        $sm->setService('ApplicationConfig', $configuration);
71
        $sm->get('ModuleManager')->loadModules();
72
        $sm->get('Application')->bootstrap();
73
74
        $mailService = $sm->get('playgrounduser_message');
75
        $gameService = $sm->get('playgroundgame_instantwin_service');
76
77
        $from    = "[email protected]";
78
        $subject = "Votre jeu Instant gagnant";
79
80
        // Je recherche les jeux instantwin en cours
81
        $games = $gameService->getActiveGames(false, 'instantwin');
82
83
        // Je recherche les joueurs qui ont deja joué une seule fois au jeu mais pas rejoué dans le laps autorisé
84
        $arrayUsers = array();
85
        foreach ($games as $game) {
86
            $limitScale = $game->getPlayLimitScale();
87
            $limitDate = $this->getLimitDate($limitScale);
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
88
            $entries = $gameService->getEntryMapper()->findPlayersWithOneEntryBy($game, $limitDate);
89
            foreach ($entries as $e) {
90
                $arrayUsers[$e->getUser()->getId()]['user'] = $e->getUser();
91
                $arrayUsers[$e->getUser()->getId()]['game'] = $game;
92
            }
93
        }
94
95
        // J'envoie un mail de relance
96
        foreach ($arrayUsers as $k => $entry) {
97
            $user = $entry['user'];
98
            $game = $entry['game'];
99
            $message = $mailService->createHtmlMessage(
100
                $from,
101
                $user->getEmail(),
102
                $subject,
103
                'playground-game/email/game_instantwin_reminder',
104
                array('game' => $game, 'user' => $user)
105
            );
106
            $mailService->send($message);
107
        }
108
    }
109
}
110