15540 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\View\Model\ViewModel;
|
|
|
11 |
use Laminas\View\Model\JsonModel;
|
|
|
12 |
use LeadersLinked\Library\Functions;
|
|
|
13 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
14 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
15 |
use LeadersLinked\Mapper\DailyPulseEmojiMapper;
|
|
|
16 |
use LeadersLinked\Form\DailyPulse\DailyPulseAddEmojiForm;
|
|
|
17 |
use LeadersLinked\Form\DailyPulse\DailyPulseEditEmojiForm;
|
|
|
18 |
use LeadersLinked\Model\DailyPulseEmoji;
|
|
|
19 |
use LeadersLinked\Library\Image;
|
|
|
20 |
use LeadersLinked\Mapper\DailyPulseRecordMapper;
|
|
|
21 |
use LeadersLinked\Model\DailyPulseRecord;
|
|
|
22 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
23 |
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
24 |
|
|
|
25 |
class DailyPulseReportsController extends AbstractActionController
|
|
|
26 |
{
|
|
|
27 |
/**
|
|
|
28 |
*
|
|
|
29 |
* @var AdapterInterface
|
|
|
30 |
*/
|
|
|
31 |
private $adapter;
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
*
|
|
|
36 |
* @var AbstractAdapter
|
|
|
37 |
*/
|
|
|
38 |
private $cache;
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
*
|
|
|
42 |
* @var LoggerInterface
|
|
|
43 |
*/
|
|
|
44 |
private $logger;
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
*
|
|
|
49 |
* @var array
|
|
|
50 |
*/
|
|
|
51 |
private $config;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @param AdapterInterface $adapter
|
|
|
56 |
* @param AbstractAdapter $cache
|
|
|
57 |
* @param LoggerInterface $logger
|
|
|
58 |
* @param array $config
|
|
|
59 |
*/
|
|
|
60 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
61 |
{
|
|
|
62 |
$this->adapter = $adapter;
|
|
|
63 |
$this->cache = $cache;
|
|
|
64 |
$this->logger = $logger;
|
|
|
65 |
$this->config = $config;
|
|
|
66 |
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public function indexAction()
|
|
|
70 |
{
|
|
|
71 |
return new JsonModel([
|
|
|
72 |
'success' => false,
|
|
|
73 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
74 |
]);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public function overviewAction()
|
|
|
78 |
{
|
|
|
79 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
80 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
81 |
|
|
|
82 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
83 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
84 |
|
|
|
85 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
86 |
$company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentNetwork->id);
|
|
|
87 |
|
|
|
88 |
$request = $this->getRequest();
|
|
|
89 |
if($request->isGet()) {
|
|
|
90 |
|
|
|
91 |
$headers = $request->getHeaders();
|
|
|
92 |
|
|
|
93 |
$isJson = false;
|
|
|
94 |
if($headers->has('Accept')) {
|
|
|
95 |
$accept = $headers->get('Accept');
|
|
|
96 |
|
|
|
97 |
$prioritized = $accept->getPrioritized();
|
|
|
98 |
|
|
|
99 |
foreach($prioritized as $key => $value) {
|
|
|
100 |
$raw = trim($value->getRaw());
|
|
|
101 |
|
|
|
102 |
if(!$isJson) {
|
|
|
103 |
$isJson = strpos($raw, 'json');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|
15544 |
efrain |
109 |
// $isJson = true;
|
15540 |
efrain |
110 |
if($isJson) {
|
|
|
111 |
|
|
|
112 |
$startDate = $this->params()->fromQuery('startDate');
|
|
|
113 |
if(empty($startDate)) {
|
|
|
114 |
$startDate = date('Y-m-d');
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
$endDate = $this->params()->fromQuery('endDate');
|
|
|
119 |
if(empty($startDate)) {
|
|
|
120 |
$endDate = date('Y-m-d');
|
|
|
121 |
}
|
|
|
122 |
|
15541 |
efrain |
123 |
//$startDate = '2023-03-01';
|
|
|
124 |
//$endDate = '2023-03-19';
|
15540 |
efrain |
125 |
|
|
|
126 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
127 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
|
|
128 |
|
|
|
129 |
if(!$dtStartDate || !$dtEndDate) {
|
|
|
130 |
$startDate = date('Y-m-d');
|
|
|
131 |
$endDate = date('Y-m-d');
|
|
|
132 |
} else {
|
|
|
133 |
|
|
|
134 |
if($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
|
|
135 |
$startDate = date('Y-m-d');
|
|
|
136 |
$endDate = date('Y-m-d');
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
$dailyPulseRecordMapper = DailyPulseRecordMapper::getInstance($this->adapter);
|
|
|
141 |
$how_are_you_feel = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_HOW_ARE_YOU_FEEL, $startDate, $endDate);
|
|
|
142 |
|
|
|
143 |
$climate_on_your_organization = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_CLIMATE_ON_YOUR_ORGANIZATION, $startDate, $endDate);
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
$data = [
|
15544 |
efrain |
148 |
'labels' => [],
|
|
|
149 |
'users' => [
|
|
|
150 |
'how_are_you_feel' => [],
|
|
|
151 |
'climate_on_your_organization' => [],
|
|
|
152 |
],
|
|
|
153 |
'points' => [
|
|
|
154 |
'how_are_you_feel' => [],
|
|
|
155 |
'climate_on_your_organization' => [],
|
|
|
156 |
],
|
15545 |
efrain |
157 |
'average' => [
|
|
|
158 |
'how_are_you_feel' => [],
|
|
|
159 |
'climate_on_your_organization' => [],
|
|
|
160 |
],
|
15544 |
efrain |
161 |
'how_are_you_feel' => [
|
|
|
162 |
'average_points' => 0,
|
|
|
163 |
'average_users' => 0,
|
|
|
164 |
],
|
15540 |
efrain |
165 |
'climate_on_your_organization' => [
|
|
|
166 |
'average_points' => 0,
|
|
|
167 |
'average_users' => 0,
|
|
|
168 |
]
|
15544 |
efrain |
169 |
|
|
|
170 |
|
15540 |
efrain |
171 |
];
|
15544 |
efrain |
172 |
|
15540 |
efrain |
173 |
|
|
|
174 |
|
|
|
175 |
$how_are_you_feel_points = 0;
|
|
|
176 |
$how_are_you_feel_users = 0;
|
|
|
177 |
|
|
|
178 |
$climate_on_your_organization_points = 0;
|
|
|
179 |
$climate_on_your_organization_users = 0;
|
|
|
180 |
|
|
|
181 |
$count = 0;
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
185 |
do {
|
|
|
186 |
$count++;
|
|
|
187 |
$date = $dt->format('Y-m-d');
|
|
|
188 |
$label = $dt->format('d/m/Y');
|
|
|
189 |
|
15544 |
efrain |
190 |
array_push($data['labels'], $label);
|
|
|
191 |
|
15540 |
efrain |
192 |
|
15544 |
efrain |
193 |
$points = 0;
|
|
|
194 |
$users = 0;
|
15540 |
efrain |
195 |
foreach($how_are_you_feel as $record)
|
|
|
196 |
{
|
|
|
197 |
if($date == $record['date']) {
|
15544 |
efrain |
198 |
$points = $record['points'];
|
|
|
199 |
$users = $record['users'];
|
15540 |
efrain |
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
|
15544 |
efrain |
204 |
|
|
|
205 |
array_push($data['points']['how_are_you_feel'], $points);
|
|
|
206 |
array_push($data['users']['how_are_you_feel'], $users);
|
15545 |
efrain |
207 |
array_push($data['average']['how_are_you_feel'], $users ? $points / $users : 0);
|
15544 |
efrain |
208 |
|
|
|
209 |
|
|
|
210 |
$how_are_you_feel_points += $points;
|
|
|
211 |
$how_are_you_feel_users += $users;
|
15540 |
efrain |
212 |
|
15544 |
efrain |
213 |
$points = 0;
|
|
|
214 |
$users = 0;
|
15540 |
efrain |
215 |
foreach($climate_on_your_organization as $record)
|
|
|
216 |
{
|
|
|
217 |
if($date == $record['date']) {
|
15544 |
efrain |
218 |
$points = $record['points'];
|
|
|
219 |
$users = $record['users'];
|
15540 |
efrain |
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
|
15544 |
efrain |
224 |
array_push($data['points']['climate_on_your_organization'], $points);
|
|
|
225 |
array_push($data['users']['climate_on_your_organization'], $users);
|
15545 |
efrain |
226 |
array_push($data['average']['climate_on_your_organization'], $users ? $points / $users : 0);
|
15540 |
efrain |
227 |
|
|
|
228 |
|
15544 |
efrain |
229 |
$climate_on_your_organization_points += $points;
|
|
|
230 |
$climate_on_your_organization_users += $users;
|
15540 |
efrain |
231 |
|
|
|
232 |
|
|
|
233 |
$dt->add(new \DateInterval('P1D'));
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
} while($date < $endDate);
|
|
|
237 |
|
|
|
238 |
$data['how_are_you_feel']['average_points'] = number_format($how_are_you_feel_points / $count, 2);
|
|
|
239 |
$data['how_are_you_feel']['average_users'] = number_format($how_are_you_feel_users / $count, 2);
|
|
|
240 |
|
|
|
241 |
$data['climate_on_your_organization']['average_points'] = number_format($climate_on_your_organization_points / $count, 2);
|
|
|
242 |
$data['climate_on_your_organization']['average_users'] = number_format($climate_on_your_organization_users / $count, 2);
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
return new JsonModel([
|
|
|
247 |
'success' => true,
|
|
|
248 |
'data' => $data,
|
|
|
249 |
]);
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
} else {
|
|
|
256 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
257 |
$viewModel = new ViewModel();
|
|
|
258 |
$viewModel->setTemplate('leaders-linked/daily-pulse-reports/overview.phtml');
|
|
|
259 |
return $viewModel ;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
} else {
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
return new JsonModel([
|
|
|
266 |
'success' => false,
|
|
|
267 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
268 |
]);
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
public function overviewDownloadAction()
|
|
|
273 |
{
|
|
|
274 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
275 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
276 |
|
|
|
277 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
278 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
279 |
|
|
|
280 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
281 |
$company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentNetwork->id);
|
|
|
282 |
|
|
|
283 |
$request = $this->getRequest();
|
|
|
284 |
|
|
|
285 |
if($request->isGet())
|
|
|
286 |
{
|
|
|
287 |
|
|
|
288 |
$startDate = $this->params()->fromQuery('startDate');
|
|
|
289 |
if(empty($startDate)) {
|
|
|
290 |
$startDate = date('Y-m-d');
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
$endDate = $this->params()->fromQuery('endDate');
|
|
|
295 |
if(empty($startDate)) {
|
|
|
296 |
$endDate = date('Y-m-d');
|
|
|
297 |
}
|
|
|
298 |
|
15541 |
efrain |
299 |
//$startDate = '2023-03-01';
|
|
|
300 |
//$endDate = '2023-03-19';
|
15540 |
efrain |
301 |
|
|
|
302 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
303 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
|
|
304 |
|
|
|
305 |
if(!$dtStartDate || !$dtEndDate) {
|
|
|
306 |
$startDate = date('Y-m-d');
|
|
|
307 |
$endDate = date('Y-m-d');
|
|
|
308 |
} else {
|
|
|
309 |
|
|
|
310 |
if($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
|
|
311 |
$startDate = date('Y-m-d');
|
|
|
312 |
$endDate = date('Y-m-d');
|
|
|
313 |
}
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
$dailyPulseRecordMapper = DailyPulseRecordMapper::getInstance($this->adapter);
|
|
|
317 |
$how_are_you_feel = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_HOW_ARE_YOU_FEEL, $startDate, $endDate);
|
|
|
318 |
|
|
|
319 |
$climate_on_your_organization = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_CLIMATE_ON_YOUR_ORGANIZATION, $startDate, $endDate);
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
$data = [
|
15544 |
efrain |
324 |
'labels' => [],
|
15545 |
efrain |
325 |
'average' => [
|
|
|
326 |
'how_are_you_feel' => [],
|
|
|
327 |
'climate_on_your_organization' => [],
|
|
|
328 |
],
|
15544 |
efrain |
329 |
'users' => [
|
|
|
330 |
'how_are_you_feel' => [],
|
|
|
331 |
'climate_on_your_organization' => [],
|
|
|
332 |
],
|
|
|
333 |
'points' => [
|
|
|
334 |
'how_are_you_feel' => [],
|
|
|
335 |
'climate_on_your_organization' => [],
|
|
|
336 |
],
|
15540 |
efrain |
337 |
'how_are_you_feel' => [
|
15544 |
efrain |
338 |
'average_points' => 0,
|
|
|
339 |
'average_users' => 0,
|
15540 |
efrain |
340 |
],
|
|
|
341 |
'climate_on_your_organization' => [
|
|
|
342 |
'average_points' => 0,
|
|
|
343 |
'average_users' => 0,
|
|
|
344 |
]
|
15544 |
efrain |
345 |
|
|
|
346 |
|
15540 |
efrain |
347 |
];
|
|
|
348 |
|
|
|
349 |
|
15544 |
efrain |
350 |
|
15540 |
efrain |
351 |
$how_are_you_feel_points = 0;
|
|
|
352 |
$how_are_you_feel_users = 0;
|
|
|
353 |
|
|
|
354 |
$climate_on_your_organization_points = 0;
|
|
|
355 |
$climate_on_your_organization_users = 0;
|
|
|
356 |
|
|
|
357 |
$count = 0;
|
|
|
358 |
|
|
|
359 |
|
|
|
360 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
361 |
do {
|
|
|
362 |
$count++;
|
|
|
363 |
$date = $dt->format('Y-m-d');
|
|
|
364 |
$label = $dt->format('d/m/Y');
|
|
|
365 |
|
15544 |
efrain |
366 |
array_push($data['labels'], $label);
|
|
|
367 |
|
15540 |
efrain |
368 |
|
15544 |
efrain |
369 |
$points = 0;
|
|
|
370 |
$users = 0;
|
15540 |
efrain |
371 |
foreach($how_are_you_feel as $record)
|
|
|
372 |
{
|
|
|
373 |
if($date == $record['date']) {
|
15544 |
efrain |
374 |
$points = $record['points'];
|
|
|
375 |
$users = $record['users'];
|
15540 |
efrain |
376 |
}
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
15544 |
efrain |
381 |
array_push($data['points']['how_are_you_feel'], $points);
|
|
|
382 |
array_push($data['users']['how_are_you_feel'], $users);
|
15545 |
efrain |
383 |
array_push($data['average']['how_are_you_feel'], $users ? $points / $users : 0);
|
15540 |
efrain |
384 |
|
15544 |
efrain |
385 |
|
|
|
386 |
$how_are_you_feel_points += $points;
|
|
|
387 |
$how_are_you_feel_users += $users;
|
|
|
388 |
|
|
|
389 |
$points = 0;
|
|
|
390 |
$users = 0;
|
15540 |
efrain |
391 |
foreach($climate_on_your_organization as $record)
|
|
|
392 |
{
|
|
|
393 |
if($date == $record['date']) {
|
15544 |
efrain |
394 |
$points = $record['points'];
|
|
|
395 |
$users = $record['users'];
|
15540 |
efrain |
396 |
}
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
|
15544 |
efrain |
400 |
array_push($data['points']['climate_on_your_organization'], $points);
|
|
|
401 |
array_push($data['users']['climate_on_your_organization'], $users);
|
15545 |
efrain |
402 |
array_push($data['average']['climate_on_your_organization'], $users ? $points / $users : 0);
|
15540 |
efrain |
403 |
|
|
|
404 |
|
15544 |
efrain |
405 |
$climate_on_your_organization_points += $points;
|
|
|
406 |
$climate_on_your_organization_users += $users;
|
|
|
407 |
|
|
|
408 |
|
15540 |
efrain |
409 |
$dt->add(new \DateInterval('P1D'));
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
} while($date < $endDate);
|
|
|
413 |
|
|
|
414 |
$data['how_are_you_feel']['average_points'] = number_format($how_are_you_feel_points / $count, 2);
|
|
|
415 |
$data['how_are_you_feel']['average_users'] = number_format($how_are_you_feel_users / $count, 2);
|
|
|
416 |
|
|
|
417 |
$data['climate_on_your_organization']['average_points'] = number_format($climate_on_your_organization_points / $count, 2);
|
|
|
418 |
$data['climate_on_your_organization']['average_users'] = number_format($climate_on_your_organization_users / $count, 2);
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
$spreadsheet = new Spreadsheet();
|
|
|
425 |
$spreadsheet->getProperties()->setTitle('Pulso Diario');
|
|
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
|
429 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
430 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
431 |
|
|
|
432 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Desde:');
|
|
|
433 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', $dt->format('d/m/Y'));
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
437 |
$spreadsheet->getActiveSheet()->SetCellValue('C1', 'Hasta:');
|
|
|
438 |
$spreadsheet->getActiveSheet()->SetCellValue('D1', $dt->format('d/m/Y'));
|
|
|
439 |
|
|
|
440 |
|
|
|
441 |
$spreadsheet->getActiveSheet()->SetCellValue('A3', 'Como te sientes hoy');
|
15544 |
efrain |
442 |
$spreadsheet->getActiveSheet()->setMergeCells(['A3', 'B3', 'C3', 'D3']);
|
15540 |
efrain |
443 |
$spreadsheet->getActiveSheet()->SetCellValue('A4', 'Puntos promedios');
|
|
|
444 |
$spreadsheet->getActiveSheet()->SetCellValue('B4', $data['how_are_you_feel']['average_points']);
|
|
|
445 |
$spreadsheet->getActiveSheet()->SetCellValue('C4', 'Usuarios promedios');
|
|
|
446 |
$spreadsheet->getActiveSheet()->SetCellValue('D4', $data['how_are_you_feel']['average_users']);
|
|
|
447 |
|
|
|
448 |
|
|
|
449 |
$spreadsheet->getActiveSheet()->SetCellValue('F3', 'Clima en su organización');
|
15544 |
efrain |
450 |
$spreadsheet->getActiveSheet()->setMergeCells(['F3', 'G3', 'H3', 'I3']);
|
15540 |
efrain |
451 |
$spreadsheet->getActiveSheet()->SetCellValue('F4', 'Puntos promedios');
|
|
|
452 |
$spreadsheet->getActiveSheet()->SetCellValue('G4', $data['climate_on_your_organization']['average_points']);
|
|
|
453 |
$spreadsheet->getActiveSheet()->SetCellValue('H4', 'Usuarios promedios');
|
|
|
454 |
$spreadsheet->getActiveSheet()->SetCellValue('I4', $data['climate_on_your_organization']['average_users']);
|
|
|
455 |
|
|
|
456 |
|
15544 |
efrain |
457 |
$spreadsheet->getActiveSheet()->SetCellValue('A6', 'Usuarios');
|
|
|
458 |
$spreadsheet->getActiveSheet()->setMergeCells(['A6', 'B6', 'C6']);
|
|
|
459 |
$spreadsheet->getActiveSheet()->SetCellValue('A7', 'Fecha');
|
|
|
460 |
$spreadsheet->getActiveSheet()->SetCellValue('B7', 'Puntos promedios');
|
|
|
461 |
$spreadsheet->getActiveSheet()->SetCellValue('C7', 'Cantidad de usuarios');
|
|
|
462 |
|
|
|
463 |
$row = 8;
|
|
|
464 |
$max = count($data['labels']);
|
|
|
465 |
|
|
|
466 |
for($i = 0; $i< $max; $i++)
|
15540 |
efrain |
467 |
{
|
15544 |
efrain |
468 |
$spreadsheet->getActiveSheet()->SetCellValue('A' . $row, $data['labels'][$i]);
|
|
|
469 |
$spreadsheet->getActiveSheet()->SetCellValue('B' . $row, $data['users']['how_are_you_feel'][$i]);
|
|
|
470 |
$spreadsheet->getActiveSheet()->SetCellValue('C' . $row, $data['users']['climate_on_your_organization'][$i]);
|
|
|
471 |
$row++;
|
15540 |
efrain |
472 |
}
|
15544 |
efrain |
473 |
|
15540 |
efrain |
474 |
|
15544 |
efrain |
475 |
$spreadsheet->getActiveSheet()->SetCellValue('F6', 'Puntos');
|
|
|
476 |
$spreadsheet->getActiveSheet()->setMergeCells(['F6', 'G6', 'H6']);
|
|
|
477 |
$spreadsheet->getActiveSheet()->SetCellValue('F7', 'Fecha');
|
|
|
478 |
$spreadsheet->getActiveSheet()->SetCellValue('G7', 'Puntos promedios');
|
|
|
479 |
$spreadsheet->getActiveSheet()->SetCellValue('H7', 'Cantidad de usuarios');
|
15540 |
efrain |
480 |
|
15544 |
efrain |
481 |
|
15540 |
efrain |
482 |
|
15544 |
efrain |
483 |
$row = 8;
|
|
|
484 |
$max = count($data['labels']);
|
|
|
485 |
|
|
|
486 |
for($i = 0; $i< $max; $i++)
|
15540 |
efrain |
487 |
{
|
15544 |
efrain |
488 |
$spreadsheet->getActiveSheet()->SetCellValue('F' . $row, $data['labels'][$i]);
|
|
|
489 |
$spreadsheet->getActiveSheet()->SetCellValue('G' . $row, $data['points']['how_are_you_feel'][$i]);
|
|
|
490 |
$spreadsheet->getActiveSheet()->SetCellValue('H' . $row, $data['points']['climate_on_your_organization'][$i]);
|
|
|
491 |
$row++;
|
15540 |
efrain |
492 |
}
|
|
|
493 |
|
15545 |
efrain |
494 |
$spreadsheet->getActiveSheet()->SetCellValue('J6', 'Puntos promedios ( puntos / usuarios ) ');
|
|
|
495 |
$spreadsheet->getActiveSheet()->setMergeCells(['J6', 'K6', 'L6']);
|
|
|
496 |
$spreadsheet->getActiveSheet()->SetCellValue('J7', 'Fecha');
|
|
|
497 |
$spreadsheet->getActiveSheet()->SetCellValue('K7', 'Puntos promedios');
|
|
|
498 |
$spreadsheet->getActiveSheet()->SetCellValue('L7', 'Cantidad de usuarios');
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
$row = 8;
|
|
|
503 |
$max = count($data['labels']);
|
|
|
504 |
|
|
|
505 |
for($i = 0; $i< $max; $i++)
|
|
|
506 |
{
|
|
|
507 |
$spreadsheet->getActiveSheet()->SetCellValue('J' . $row, $data['labels'][$i]);
|
|
|
508 |
$spreadsheet->getActiveSheet()->SetCellValue('K' . $row, number_format($data['average']['how_are_you_feel'][$i], 2));
|
|
|
509 |
$spreadsheet->getActiveSheet()->SetCellValue('L' . $row, number_format($data['average']['climate_on_your_organization'][$i], 2));
|
|
|
510 |
$row++;
|
|
|
511 |
}
|
|
|
512 |
|
15540 |
efrain |
513 |
|
|
|
514 |
$fileName = 'reporte_pulso_diario_' . date('d-m-Y-h-i-a', time()) . '.xls';
|
|
|
515 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_pulso_diario_' . time());
|
|
|
516 |
|
|
|
517 |
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
|
518 |
$writer->save($tempFilename);
|
|
|
519 |
|
|
|
520 |
$content = file_get_contents($tempFilename);
|
|
|
521 |
@unlink($tempFilename);
|
|
|
522 |
|
|
|
523 |
return new JsonModel([
|
|
|
524 |
'success' => true,
|
|
|
525 |
'data' => [
|
|
|
526 |
'content' => base64_encode($content),
|
|
|
527 |
'basename' => $fileName
|
|
|
528 |
|
|
|
529 |
]
|
|
|
530 |
]);
|
|
|
531 |
|
|
|
532 |
|
|
|
533 |
|
|
|
534 |
|
|
|
535 |
} else {
|
|
|
536 |
return new JsonModel([
|
|
|
537 |
'success' => false,
|
|
|
538 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
539 |
]);
|
|
|
540 |
}
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
}
|