|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Zend\ServiceManager\ServiceManagerAwareInterface; |
|
6
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
7
|
|
|
use PlaygroundGame\Mapper\GameInterface as GameMapperInterface; |
|
8
|
|
|
|
|
9
|
|
|
class Cron extends Game implements ServiceManagerAwareInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var GameMapperInterface |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $gameMapper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var EntryMapperInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $entryMapper; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var ServiceManager |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $serviceManager; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var UserServiceOptionsInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $options; |
|
30
|
|
|
|
|
31
|
|
|
public static function cronMail() |
|
32
|
|
|
{ |
|
33
|
|
|
$configuration = require 'config/application.config.php'; |
|
34
|
|
|
$smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array(); |
|
35
|
|
|
$sm = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($smConfig)); |
|
36
|
|
|
$sm->setService('ApplicationConfig', $configuration); |
|
37
|
|
|
$sm->get('ModuleManager')->loadModules(); |
|
38
|
|
|
$sm->get('Application')->bootstrap(); |
|
39
|
|
|
|
|
40
|
|
|
$mailService = $sm->get('playgrounduser_message'); |
|
41
|
|
|
$gameService = $sm->get('playgroundgame_quiz_service'); |
|
42
|
|
|
|
|
43
|
|
|
$from = "[email protected]"; |
|
44
|
|
|
$subject = "sujet game"; |
|
45
|
|
|
|
|
46
|
|
|
$to = "[email protected]"; |
|
47
|
|
|
|
|
48
|
|
|
$game = $gameService->checkGame('qooqo'); |
|
49
|
|
|
|
|
50
|
|
|
// On recherche les joueurs qui n'ont pas partagé leur qquiz après avoir joué |
|
51
|
|
|
// entry join user join game : distinct user et game et game_entry = 0 et updated_at <= jour-1 et > jour - 2 |
|
52
|
|
|
|
|
53
|
|
|
$message = $mailService->createTextMessage( |
|
54
|
|
|
$from, |
|
55
|
|
|
$to, |
|
56
|
|
|
$subject, |
|
57
|
|
|
'playground-game/email/share_reminder', |
|
58
|
|
|
array('game' => $game) |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$mailService->send($message); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function instantWinEmail() |
|
65
|
|
|
{ |
|
66
|
|
|
$configuration = require 'config/application.config.php'; |
|
67
|
|
|
$smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array(); |
|
68
|
|
|
$sm = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($smConfig)); |
|
69
|
|
|
$sm->setService('ApplicationConfig', $configuration); |
|
70
|
|
|
$sm->get('ModuleManager')->loadModules(); |
|
71
|
|
|
$sm->get('Application')->bootstrap(); |
|
72
|
|
|
|
|
73
|
|
|
$mailService = $sm->get('playgrounduser_message'); |
|
74
|
|
|
$gameService = $sm->get('playgroundgame_instantwin_service'); |
|
75
|
|
|
|
|
76
|
|
|
$from = "[email protected]"; |
|
77
|
|
|
$subject = "Votre jeu Instant gagnant"; |
|
78
|
|
|
|
|
79
|
|
|
// Je recherche les jeux instantwin en cours |
|
80
|
|
|
$games = $gameService->getActiveGames(false, 'instantwin'); |
|
81
|
|
|
|
|
82
|
|
|
// Je recherche les joueurs qui ont deja joué une seule fois au jeu mais pas rejoué dans le laps autorisé |
|
83
|
|
|
$arrayUsers = array(); |
|
84
|
|
|
foreach ($games as $game) { |
|
85
|
|
|
$limitScale = $game->getPlayLimitScale(); |
|
86
|
|
|
$limitDate = $gameService->getLimitDate($limitScale); |
|
87
|
|
|
$entries = $gameService->getEntryMapper()->findPlayersWithOneEntryBy($game, $limitDate); |
|
88
|
|
|
foreach ($entries as $e) { |
|
89
|
|
|
$arrayUsers[$e->getUser()->getId()]['user'] = $e->getUser(); |
|
90
|
|
|
$arrayUsers[$e->getUser()->getId()]['game'] = $game; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
// J'envoie un mail de relance |
|
95
|
|
|
foreach ($arrayUsers as $k => $entry) { |
|
96
|
|
|
$user = $entry['user']; |
|
97
|
|
|
$game = $entry['game']; |
|
98
|
|
|
$message = $mailService->createHtmlMessage( |
|
99
|
|
|
$from, |
|
100
|
|
|
$user->getEmail(), |
|
101
|
|
|
$subject, |
|
102
|
|
|
'playground-game/email/game_instantwin_reminder', |
|
103
|
|
|
array('game' => $game, 'user' => $user) |
|
104
|
|
|
); |
|
105
|
|
|
$mailService->send($message); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|