1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Controller\Frontend; |
4
|
|
|
|
5
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
6
|
|
|
use Zend\View\Model\ViewModel; |
7
|
|
|
use Zend\View\Model\JsonModel; |
8
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
9
|
|
|
|
10
|
|
|
class HomeController extends AbstractActionController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \PlaygroundGame\Service\GameService |
14
|
|
|
*/ |
15
|
|
|
protected $gameService; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \PlaygroundCms\Service\Page |
19
|
|
|
*/ |
20
|
|
|
protected $pageService; |
21
|
|
|
|
22
|
|
|
protected $options; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
* @var ServiceManager |
27
|
|
|
*/ |
28
|
|
|
protected $serviceLocator; |
29
|
|
|
|
30
|
|
|
public function __construct(ServiceLocatorInterface $locator) |
31
|
|
|
{ |
32
|
|
|
$this->serviceLocator = $locator; |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getServiceLocator() |
36
|
|
|
{ |
37
|
|
|
return $this->serviceLocator; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function indexAction() |
41
|
|
|
{ |
42
|
|
|
$layoutViewModel = $this->layout(); |
43
|
|
|
|
44
|
|
|
$slider = new ViewModel(); |
45
|
|
|
$slider->setTemplate('playground-game/common/top_promo'); |
46
|
|
|
|
47
|
|
|
$sliderGames = $this->getGameService()->getActiveSliderGames(); |
48
|
|
|
$sliderPages = $this->getPageService()->getActiveSliderPages(); |
49
|
|
|
|
50
|
|
|
// I merge both types of articles and sort them in reverse order of their key |
51
|
|
|
// And as their key is some sort of... date !, It means I sort it in date reverse order ;) |
52
|
|
|
$sliderItems = array_merge($sliderGames, $sliderPages); |
53
|
|
|
|
54
|
|
|
krsort($sliderItems); |
55
|
|
|
|
56
|
|
|
$slider->setVariables(array('sliderItems' => $sliderItems)); |
57
|
|
|
|
58
|
|
|
$layoutViewModel->addChild($slider, 'slider'); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$games = $this->getGameService()->getActiveGames(true, '', ''); |
61
|
|
|
|
62
|
|
|
$pages = $this->getPageService()->getActivePages(); |
63
|
|
|
|
64
|
|
|
// I merge both types of articles and sort them in reverse order of their key |
65
|
|
|
// And as their key is some sort of... date !, It means I sort it in date reverse order ;) |
66
|
|
|
$items = array_merge($games, $pages); |
67
|
|
|
krsort($items); |
68
|
|
|
|
69
|
|
|
if (is_array($items)) { |
70
|
|
|
$paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($items)); |
71
|
|
|
$paginator->setItemCountPerPage(7); |
72
|
|
|
$paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p')); |
73
|
|
|
} else { |
74
|
|
|
$paginator = $items; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->layout()->setVariables( |
|
|
|
|
78
|
|
|
array( |
79
|
|
|
'sliderItems' => $sliderItems, |
80
|
|
|
) |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return new ViewModel( |
84
|
|
|
array( |
85
|
|
|
'items' => $paginator, |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function shareAction() |
91
|
|
|
{ |
92
|
|
|
$statusMail = null; |
93
|
|
|
|
94
|
|
|
$form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
95
|
|
|
$form->setAttribute('method', 'post'); |
96
|
|
|
|
97
|
|
|
// buildView must be before sendMail because it adds the game template path to the templateStack |
98
|
|
|
if ($this->getRequest()->isXmlHttpRequest()) { |
|
|
|
|
99
|
|
|
$viewModel = new JsonModel(); |
100
|
|
|
} else { |
101
|
|
|
$viewModel = new ViewModel(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
105
|
|
|
|
106
|
|
|
if ($this->getRequest()->isPost()) { |
|
|
|
|
107
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
108
|
|
|
$form->setData($data); |
109
|
|
|
if ($form->isValid()) { |
110
|
|
|
$subject = $this->serviceLocator->get('MvcTranslator')->translate( |
111
|
|
|
$this->getOptions()->getDefaultSubjectLine(), |
112
|
|
|
'playgroundgame' |
113
|
|
|
); |
114
|
|
|
$result = $this->getGameService()->sendShareMail($data, null, $user, null, 'share_game', $subject); |
115
|
|
|
if ($result) { |
116
|
|
|
$statusMail = true; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$viewModel->setVariables( |
122
|
|
|
[ |
123
|
|
|
'statusMail' => $statusMail, |
124
|
|
|
'form' => $form, |
125
|
|
|
] |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
return $viewModel; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getOptions() |
132
|
|
|
{ |
133
|
|
|
if (!$this->options) { |
134
|
|
|
$this->setOptions($this->getServiceLocator()->get('playgroundgame_module_options')); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $this->options; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function setOptions($options) |
141
|
|
|
{ |
142
|
|
|
$this->options = $options; |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getGameService() |
148
|
|
|
{ |
149
|
|
|
if (!$this->gameService) { |
150
|
|
|
$this->gameService = $this->getServiceLocator()->get('playgroundgame_game_service'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $this->gameService; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setGameService(\PlaygroundGame\Service\Game $gameService) |
157
|
|
|
{ |
158
|
|
|
$this->gameService = $gameService; |
|
|
|
|
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function getPageService() |
164
|
|
|
{ |
165
|
|
|
if (!$this->pageService) { |
166
|
|
|
$this->pageService = $this->getServiceLocator()->get('playgroundcms_page_service'); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $this->pageService; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function setPageService(\PlaygroundCms\Service\Page $pageService) |
173
|
|
|
{ |
174
|
|
|
$this->pageService = $pageService; |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..