|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Controller\Frontend; |
|
4
|
|
|
|
|
5
|
|
|
class LotteryController extends GameController |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var gameService |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $gameService; |
|
11
|
|
|
|
|
12
|
|
|
public function playAction() |
|
13
|
|
|
{ |
|
14
|
|
|
$sg = $this->getGameService(); |
|
15
|
|
|
|
|
16
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
|
17
|
|
|
$channel = $this->getEvent()->getRouteMatch()->getParam('channel'); |
|
18
|
|
|
|
|
19
|
|
|
$game = $sg->checkGame($identifier); |
|
20
|
|
|
if (! $game || $game->isClosed()) { |
|
21
|
|
|
return $this->notFoundAction(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$redirectFb = $this->checkFbRegistration($this->zfcUserAuthentication()->getIdentity(), $game, $channel); |
|
|
|
|
|
|
25
|
|
|
if ($redirectFb) { |
|
26
|
|
|
return $redirectFb; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
|
|
30
|
|
View Code Duplication |
if (!$user && !$game->getAnonymousAllowed()) { |
|
|
|
|
|
|
31
|
|
|
$redirect = urlencode( |
|
32
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
33
|
|
|
$game->getClassType() . '/play', |
|
34
|
|
|
array('id' => $game->getIdentifier(), 'channel' => $channel), |
|
35
|
|
|
array('force_canonical' => true) |
|
36
|
|
|
) |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
return $this->redirect()->toUrl( |
|
40
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
41
|
|
|
'zfcuser/register', |
|
42
|
|
|
array('channel' => $channel) |
|
43
|
|
|
) . '?redirect='.$redirect |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$entry = $sg->play($game, $user); |
|
48
|
|
|
if (!$entry) { |
|
49
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
|
50
|
|
|
$this->flashMessenger()->addMessage('Vous avez déjà participé'); |
|
51
|
|
|
|
|
52
|
|
|
return $this->redirect()->toUrl( |
|
53
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
54
|
|
|
'lottery/result', |
|
55
|
|
|
array('id' => $identifier, 'channel' => $this->getEvent()->getRouteMatch()->getParam('channel')) |
|
56
|
|
|
) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// Every entry is eligible to draw |
|
61
|
|
|
$entry->setDrawable(true); |
|
62
|
|
|
$entry->setActive(false); |
|
63
|
|
|
$sg->getEntryMapper()->update($entry); |
|
64
|
|
|
|
|
65
|
|
|
return $this->redirect()->toUrl( |
|
66
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
67
|
|
|
$game->getClassType() . '/'. $game->nextStep($this->params('action')), |
|
68
|
|
|
array('id' => $identifier, 'channel' => $this->getEvent()->getRouteMatch()->getParam('channel')) |
|
69
|
|
|
) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function resultAction() |
|
74
|
|
|
{ |
|
75
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
|
76
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
|
|
77
|
|
|
$sg = $this->getGameService(); |
|
78
|
|
|
|
|
79
|
|
|
$statusMail = null; |
|
80
|
|
|
|
|
81
|
|
|
$game = $sg->checkGame($identifier); |
|
82
|
|
|
if (!$game || $game->isClosed()) { |
|
83
|
|
|
return $this->notFoundAction(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
|
87
|
|
|
$socialLinkUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
88
|
|
|
'lottery', |
|
89
|
|
|
array( |
|
90
|
|
|
'id' => $game->getIdentifier(), |
|
91
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
|
92
|
|
|
), |
|
93
|
|
|
array('force_canonical' => true) |
|
94
|
|
|
).'?key='.$secretKey; |
|
95
|
|
|
// With core shortener helper |
|
96
|
|
|
$socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$lastEntry = $sg->findLastInactiveEntry($game, $user); |
|
99
|
|
|
if (!$lastEntry) { |
|
100
|
|
|
return $this->redirect()->toUrl( |
|
101
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
102
|
|
|
'lottery', |
|
103
|
|
|
array( |
|
104
|
|
|
'id' => $game->getIdentifier(), |
|
105
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
|
106
|
|
|
), |
|
107
|
|
|
array('force_canonical' => true) |
|
108
|
|
|
) |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
View Code Duplication |
if (!$user && !$game->getAnonymousAllowed()) { |
|
|
|
|
|
|
113
|
|
|
$redirect = urlencode( |
|
114
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
115
|
|
|
'lottery/result', |
|
116
|
|
|
array('id' => $game->getIdentifier(), 'channel' => $channel) |
|
|
|
|
|
|
117
|
|
|
) |
|
118
|
|
|
); |
|
119
|
|
|
return $this->redirect()->toUrl( |
|
120
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
|
|
121
|
|
|
'zfcuser/register', |
|
122
|
|
|
array('channel' => $channel) |
|
123
|
|
|
) . '?redirect='.$redirect |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
|
128
|
|
|
$form->setAttribute('method', 'post'); |
|
129
|
|
|
|
|
130
|
|
|
if ($this->getRequest()->isPost()) { |
|
|
|
|
|
|
131
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
|
|
132
|
|
|
$form->setData($data); |
|
133
|
|
|
if ($form->isValid()) { |
|
134
|
|
|
$result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
|
135
|
|
|
if ($result) { |
|
136
|
|
|
$statusMail = true; |
|
137
|
|
|
$sg->addAnotherChance($game, $user, 1); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
// buildView must be before sendMail because it adds the game template path to the templateStack |
|
143
|
|
|
$viewModel = $this->buildView($game); |
|
144
|
|
|
|
|
145
|
|
|
$this->getGameService()->sendMail($game, $user, $lastEntry); |
|
146
|
|
|
|
|
147
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
|
|
148
|
|
|
'statusMail' => $statusMail, |
|
149
|
|
|
'form' => $form, |
|
150
|
|
|
'socialLinkUrl' => $socialLinkUrl, |
|
151
|
|
|
'secretKey' => $secretKey, |
|
152
|
|
|
)); |
|
153
|
|
|
|
|
154
|
|
|
return $viewModel; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
View Code Duplication |
public function fbshareAction() |
|
|
|
|
|
|
158
|
|
|
{ |
|
159
|
|
|
$sg = $this->getGameService(); |
|
160
|
|
|
$result = parent::fbshareAction(); |
|
161
|
|
|
$bonusEntry = false; |
|
162
|
|
|
|
|
163
|
|
|
if ($result->getVariable('success')) { |
|
164
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
|
165
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
|
|
166
|
|
|
$game = $sg->checkGame($identifier); |
|
167
|
|
|
$bonusEntry = $sg->addAnotherChance($game, $user, 1); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$response = $this->getResponse(); |
|
171
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
|
172
|
|
|
'success' => $result, |
|
173
|
|
|
'playBonus' => $bonusEntry |
|
174
|
|
|
))); |
|
175
|
|
|
|
|
176
|
|
|
return $response; |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
View Code Duplication |
public function fbrequestAction() |
|
|
|
|
|
|
180
|
|
|
{ |
|
181
|
|
|
$sg = $this->getGameService(); |
|
182
|
|
|
$result = parent::fbrequestAction(); |
|
183
|
|
|
$bonusEntry = false; |
|
184
|
|
|
|
|
185
|
|
|
if ($result->getVariable('success')) { |
|
186
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
|
187
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
|
|
188
|
|
|
$game = $sg->checkGame($identifier); |
|
189
|
|
|
$bonusEntry = $sg->addAnotherChance($game, $user, 1); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
$response = $this->getResponse(); |
|
193
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
|
194
|
|
|
'success' => $result, |
|
195
|
|
|
'playBonus' => $bonusEntry |
|
196
|
|
|
))); |
|
197
|
|
|
|
|
198
|
|
|
return $response; |
|
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
View Code Duplication |
public function tweetAction() |
|
|
|
|
|
|
202
|
|
|
{ |
|
203
|
|
|
$sg = $this->getGameService(); |
|
204
|
|
|
$result = parent::tweetAction(); |
|
205
|
|
|
$bonusEntry = false; |
|
206
|
|
|
|
|
207
|
|
|
if ($result->getVariable('success')) { |
|
208
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
|
209
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
|
|
210
|
|
|
$game = $sg->checkGame($identifier); |
|
211
|
|
|
$bonusEntry = $sg->addAnotherChance($game, $user, 1); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
$response = $this->getResponse(); |
|
215
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
|
216
|
|
|
'success' => $result, |
|
217
|
|
|
'playBonus' => $bonusEntry |
|
218
|
|
|
))); |
|
219
|
|
|
|
|
220
|
|
|
return $response; |
|
|
|
|
|
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
View Code Duplication |
public function googleAction() |
|
|
|
|
|
|
224
|
|
|
{ |
|
225
|
|
|
$sg = $this->getGameService(); |
|
226
|
|
|
$result = parent::googleAction(); |
|
227
|
|
|
$bonusEntry = false; |
|
228
|
|
|
|
|
229
|
|
|
if ($result->getVariable('success')) { |
|
230
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
|
231
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
|
|
232
|
|
|
$game = $sg->checkGame($identifier); |
|
233
|
|
|
$bonusEntry = $sg->addAnotherChance($game, $user, 1); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
$response = $this->getResponse(); |
|
237
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
|
238
|
|
|
'success' => $result, |
|
239
|
|
|
'playBonus' => $bonusEntry |
|
240
|
|
|
))); |
|
241
|
|
|
|
|
242
|
|
|
return $response; |
|
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function getGameService() |
|
246
|
|
|
{ |
|
247
|
|
|
if (!$this->gameService) { |
|
248
|
|
|
$this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service'); |
|
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
return $this->gameService; |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: