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 |
|
|
|
151 |
'how_are_you_feel' => [],
|
|
|
152 |
'climate_on_your_organization' => [],
|
|
|
153 |
],
|
|
|
154 |
'points' => [
|
|
|
155 |
'how_are_you_feel' => [],
|
|
|
156 |
'climate_on_your_organization' => [],
|
|
|
157 |
],
|
|
|
158 |
'how_are_you_feel' => [
|
|
|
159 |
'average_points' => 0,
|
|
|
160 |
'average_users' => 0,
|
|
|
161 |
],
|
15540 |
efrain |
162 |
'climate_on_your_organization' => [
|
|
|
163 |
'average_points' => 0,
|
|
|
164 |
'average_users' => 0,
|
|
|
165 |
]
|
15544 |
efrain |
166 |
|
|
|
167 |
|
15540 |
efrain |
168 |
];
|
15544 |
efrain |
169 |
|
15540 |
efrain |
170 |
|
|
|
171 |
|
|
|
172 |
$how_are_you_feel_points = 0;
|
|
|
173 |
$how_are_you_feel_users = 0;
|
|
|
174 |
|
|
|
175 |
$climate_on_your_organization_points = 0;
|
|
|
176 |
$climate_on_your_organization_users = 0;
|
|
|
177 |
|
|
|
178 |
$count = 0;
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
182 |
do {
|
|
|
183 |
$count++;
|
|
|
184 |
$date = $dt->format('Y-m-d');
|
|
|
185 |
$label = $dt->format('d/m/Y');
|
|
|
186 |
|
15544 |
efrain |
187 |
array_push($data['labels'], $label);
|
|
|
188 |
|
15540 |
efrain |
189 |
|
15544 |
efrain |
190 |
$points = 0;
|
|
|
191 |
$users = 0;
|
15540 |
efrain |
192 |
foreach($how_are_you_feel as $record)
|
|
|
193 |
{
|
|
|
194 |
if($date == $record['date']) {
|
15544 |
efrain |
195 |
$points = $record['points'];
|
|
|
196 |
$users = $record['users'];
|
15540 |
efrain |
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
|
15544 |
efrain |
201 |
|
|
|
202 |
array_push($data['points']['how_are_you_feel'], $points);
|
|
|
203 |
array_push($data['users']['how_are_you_feel'], $users);
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
$how_are_you_feel_points += $points;
|
|
|
207 |
$how_are_you_feel_users += $users;
|
15540 |
efrain |
208 |
|
15544 |
efrain |
209 |
$points = 0;
|
|
|
210 |
$users = 0;
|
15540 |
efrain |
211 |
foreach($climate_on_your_organization as $record)
|
|
|
212 |
{
|
|
|
213 |
if($date == $record['date']) {
|
15544 |
efrain |
214 |
$points = $record['points'];
|
|
|
215 |
$users = $record['users'];
|
15540 |
efrain |
216 |
}
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
|
15544 |
efrain |
220 |
array_push($data['points']['climate_on_your_organization'], $points);
|
|
|
221 |
array_push($data['users']['climate_on_your_organization'], $users);
|
15540 |
efrain |
222 |
|
|
|
223 |
|
15544 |
efrain |
224 |
$climate_on_your_organization_points += $points;
|
|
|
225 |
$climate_on_your_organization_users += $users;
|
15540 |
efrain |
226 |
|
|
|
227 |
|
|
|
228 |
$dt->add(new \DateInterval('P1D'));
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
} while($date < $endDate);
|
|
|
232 |
|
|
|
233 |
$data['how_are_you_feel']['average_points'] = number_format($how_are_you_feel_points / $count, 2);
|
|
|
234 |
$data['how_are_you_feel']['average_users'] = number_format($how_are_you_feel_users / $count, 2);
|
|
|
235 |
|
|
|
236 |
$data['climate_on_your_organization']['average_points'] = number_format($climate_on_your_organization_points / $count, 2);
|
|
|
237 |
$data['climate_on_your_organization']['average_users'] = number_format($climate_on_your_organization_users / $count, 2);
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
return new JsonModel([
|
|
|
242 |
'success' => true,
|
|
|
243 |
'data' => $data,
|
|
|
244 |
]);
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
} else {
|
|
|
251 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
252 |
$viewModel = new ViewModel();
|
|
|
253 |
$viewModel->setTemplate('leaders-linked/daily-pulse-reports/overview.phtml');
|
|
|
254 |
return $viewModel ;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
} else {
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
return new JsonModel([
|
|
|
261 |
'success' => false,
|
|
|
262 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
263 |
]);
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public function overviewDownloadAction()
|
|
|
268 |
{
|
|
|
269 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
270 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
271 |
|
|
|
272 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
273 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
274 |
|
|
|
275 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
276 |
$company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentNetwork->id);
|
|
|
277 |
|
|
|
278 |
$request = $this->getRequest();
|
|
|
279 |
|
|
|
280 |
if($request->isGet())
|
|
|
281 |
{
|
|
|
282 |
|
|
|
283 |
$startDate = $this->params()->fromQuery('startDate');
|
|
|
284 |
if(empty($startDate)) {
|
|
|
285 |
$startDate = date('Y-m-d');
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
$endDate = $this->params()->fromQuery('endDate');
|
|
|
290 |
if(empty($startDate)) {
|
|
|
291 |
$endDate = date('Y-m-d');
|
|
|
292 |
}
|
|
|
293 |
|
15541 |
efrain |
294 |
//$startDate = '2023-03-01';
|
|
|
295 |
//$endDate = '2023-03-19';
|
15540 |
efrain |
296 |
|
|
|
297 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
298 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
|
|
299 |
|
|
|
300 |
if(!$dtStartDate || !$dtEndDate) {
|
|
|
301 |
$startDate = date('Y-m-d');
|
|
|
302 |
$endDate = date('Y-m-d');
|
|
|
303 |
} else {
|
|
|
304 |
|
|
|
305 |
if($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
|
|
306 |
$startDate = date('Y-m-d');
|
|
|
307 |
$endDate = date('Y-m-d');
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
$dailyPulseRecordMapper = DailyPulseRecordMapper::getInstance($this->adapter);
|
|
|
312 |
$how_are_you_feel = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_HOW_ARE_YOU_FEEL, $startDate, $endDate);
|
|
|
313 |
|
|
|
314 |
$climate_on_your_organization = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_CLIMATE_ON_YOUR_ORGANIZATION, $startDate, $endDate);
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
$data = [
|
15544 |
efrain |
319 |
'labels' => [],
|
|
|
320 |
'users' => [
|
|
|
321 |
|
|
|
322 |
'how_are_you_feel' => [],
|
|
|
323 |
'climate_on_your_organization' => [],
|
|
|
324 |
],
|
|
|
325 |
'points' => [
|
|
|
326 |
'how_are_you_feel' => [],
|
|
|
327 |
'climate_on_your_organization' => [],
|
|
|
328 |
],
|
15540 |
efrain |
329 |
'how_are_you_feel' => [
|
15544 |
efrain |
330 |
'average_points' => 0,
|
|
|
331 |
'average_users' => 0,
|
15540 |
efrain |
332 |
],
|
|
|
333 |
'climate_on_your_organization' => [
|
|
|
334 |
'average_points' => 0,
|
|
|
335 |
'average_users' => 0,
|
|
|
336 |
]
|
15544 |
efrain |
337 |
|
|
|
338 |
|
15540 |
efrain |
339 |
];
|
|
|
340 |
|
|
|
341 |
|
15544 |
efrain |
342 |
|
15540 |
efrain |
343 |
$how_are_you_feel_points = 0;
|
|
|
344 |
$how_are_you_feel_users = 0;
|
|
|
345 |
|
|
|
346 |
$climate_on_your_organization_points = 0;
|
|
|
347 |
$climate_on_your_organization_users = 0;
|
|
|
348 |
|
|
|
349 |
$count = 0;
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
353 |
do {
|
|
|
354 |
$count++;
|
|
|
355 |
$date = $dt->format('Y-m-d');
|
|
|
356 |
$label = $dt->format('d/m/Y');
|
|
|
357 |
|
15544 |
efrain |
358 |
array_push($data['labels'], $label);
|
|
|
359 |
|
15540 |
efrain |
360 |
|
15544 |
efrain |
361 |
$points = 0;
|
|
|
362 |
$users = 0;
|
15540 |
efrain |
363 |
foreach($how_are_you_feel as $record)
|
|
|
364 |
{
|
|
|
365 |
if($date == $record['date']) {
|
15544 |
efrain |
366 |
$points = $record['points'];
|
|
|
367 |
$users = $record['users'];
|
15540 |
efrain |
368 |
}
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
15544 |
efrain |
373 |
array_push($data['points']['how_are_you_feel'], $points);
|
|
|
374 |
array_push($data['users']['how_are_you_feel'], $users);
|
15540 |
efrain |
375 |
|
15544 |
efrain |
376 |
|
|
|
377 |
$how_are_you_feel_points += $points;
|
|
|
378 |
$how_are_you_feel_users += $users;
|
|
|
379 |
|
|
|
380 |
$points = 0;
|
|
|
381 |
$users = 0;
|
15540 |
efrain |
382 |
foreach($climate_on_your_organization as $record)
|
|
|
383 |
{
|
|
|
384 |
if($date == $record['date']) {
|
15544 |
efrain |
385 |
$points = $record['points'];
|
|
|
386 |
$users = $record['users'];
|
15540 |
efrain |
387 |
}
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
|
15544 |
efrain |
391 |
array_push($data['points']['climate_on_your_organization'], $points);
|
|
|
392 |
array_push($data['users']['climate_on_your_organization'], $users);
|
15540 |
efrain |
393 |
|
|
|
394 |
|
15544 |
efrain |
395 |
$climate_on_your_organization_points += $points;
|
|
|
396 |
$climate_on_your_organization_users += $users;
|
|
|
397 |
|
|
|
398 |
|
15540 |
efrain |
399 |
$dt->add(new \DateInterval('P1D'));
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
} while($date < $endDate);
|
|
|
403 |
|
|
|
404 |
$data['how_are_you_feel']['average_points'] = number_format($how_are_you_feel_points / $count, 2);
|
|
|
405 |
$data['how_are_you_feel']['average_users'] = number_format($how_are_you_feel_users / $count, 2);
|
|
|
406 |
|
|
|
407 |
$data['climate_on_your_organization']['average_points'] = number_format($climate_on_your_organization_points / $count, 2);
|
|
|
408 |
$data['climate_on_your_organization']['average_users'] = number_format($climate_on_your_organization_users / $count, 2);
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
$spreadsheet = new Spreadsheet();
|
|
|
415 |
$spreadsheet->getProperties()->setTitle('Pulso Diario');
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
|
419 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
420 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
421 |
|
|
|
422 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Desde:');
|
|
|
423 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', $dt->format('d/m/Y'));
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
427 |
$spreadsheet->getActiveSheet()->SetCellValue('C1', 'Hasta:');
|
|
|
428 |
$spreadsheet->getActiveSheet()->SetCellValue('D1', $dt->format('d/m/Y'));
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
$spreadsheet->getActiveSheet()->SetCellValue('A3', 'Como te sientes hoy');
|
15544 |
efrain |
432 |
$spreadsheet->getActiveSheet()->setMergeCells(['A3', 'B3', 'C3', 'D3']);
|
15540 |
efrain |
433 |
$spreadsheet->getActiveSheet()->SetCellValue('A4', 'Puntos promedios');
|
|
|
434 |
$spreadsheet->getActiveSheet()->SetCellValue('B4', $data['how_are_you_feel']['average_points']);
|
|
|
435 |
$spreadsheet->getActiveSheet()->SetCellValue('C4', 'Usuarios promedios');
|
|
|
436 |
$spreadsheet->getActiveSheet()->SetCellValue('D4', $data['how_are_you_feel']['average_users']);
|
|
|
437 |
|
|
|
438 |
|
|
|
439 |
$spreadsheet->getActiveSheet()->SetCellValue('F3', 'Clima en su organización');
|
15544 |
efrain |
440 |
$spreadsheet->getActiveSheet()->setMergeCells(['F3', 'G3', 'H3', 'I3']);
|
15540 |
efrain |
441 |
$spreadsheet->getActiveSheet()->SetCellValue('F4', 'Puntos promedios');
|
|
|
442 |
$spreadsheet->getActiveSheet()->SetCellValue('G4', $data['climate_on_your_organization']['average_points']);
|
|
|
443 |
$spreadsheet->getActiveSheet()->SetCellValue('H4', 'Usuarios promedios');
|
|
|
444 |
$spreadsheet->getActiveSheet()->SetCellValue('I4', $data['climate_on_your_organization']['average_users']);
|
|
|
445 |
|
|
|
446 |
|
15544 |
efrain |
447 |
$spreadsheet->getActiveSheet()->SetCellValue('A6', 'Usuarios');
|
|
|
448 |
$spreadsheet->getActiveSheet()->setMergeCells(['A6', 'B6', 'C6']);
|
|
|
449 |
$spreadsheet->getActiveSheet()->SetCellValue('A7', 'Fecha');
|
|
|
450 |
$spreadsheet->getActiveSheet()->SetCellValue('B7', 'Puntos promedios');
|
|
|
451 |
$spreadsheet->getActiveSheet()->SetCellValue('C7', 'Cantidad de usuarios');
|
|
|
452 |
|
|
|
453 |
$row = 8;
|
|
|
454 |
$max = count($data['labels']);
|
|
|
455 |
|
|
|
456 |
for($i = 0; $i< $max; $i++)
|
15540 |
efrain |
457 |
{
|
15544 |
efrain |
458 |
$spreadsheet->getActiveSheet()->SetCellValue('A' . $row, $data['labels'][$i]);
|
|
|
459 |
$spreadsheet->getActiveSheet()->SetCellValue('B' . $row, $data['users']['how_are_you_feel'][$i]);
|
|
|
460 |
$spreadsheet->getActiveSheet()->SetCellValue('C' . $row, $data['users']['climate_on_your_organization'][$i]);
|
|
|
461 |
$row++;
|
15540 |
efrain |
462 |
}
|
15544 |
efrain |
463 |
|
15540 |
efrain |
464 |
|
15544 |
efrain |
465 |
$spreadsheet->getActiveSheet()->SetCellValue('F6', 'Puntos');
|
|
|
466 |
$spreadsheet->getActiveSheet()->setMergeCells(['F6', 'G6', 'H6']);
|
|
|
467 |
$spreadsheet->getActiveSheet()->SetCellValue('F7', 'Fecha');
|
|
|
468 |
$spreadsheet->getActiveSheet()->SetCellValue('G7', 'Puntos promedios');
|
|
|
469 |
$spreadsheet->getActiveSheet()->SetCellValue('H7', 'Cantidad de usuarios');
|
15540 |
efrain |
470 |
|
15544 |
efrain |
471 |
|
15540 |
efrain |
472 |
|
15544 |
efrain |
473 |
$row = 8;
|
|
|
474 |
$max = count($data['labels']);
|
|
|
475 |
|
|
|
476 |
for($i = 0; $i< $max; $i++)
|
15540 |
efrain |
477 |
{
|
15544 |
efrain |
478 |
$spreadsheet->getActiveSheet()->SetCellValue('F' . $row, $data['labels'][$i]);
|
|
|
479 |
$spreadsheet->getActiveSheet()->SetCellValue('G' . $row, $data['points']['how_are_you_feel'][$i]);
|
|
|
480 |
$spreadsheet->getActiveSheet()->SetCellValue('H' . $row, $data['points']['climate_on_your_organization'][$i]);
|
|
|
481 |
$row++;
|
15540 |
efrain |
482 |
}
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
$fileName = 'reporte_pulso_diario_' . date('d-m-Y-h-i-a', time()) . '.xls';
|
|
|
486 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_pulso_diario_' . time());
|
|
|
487 |
|
|
|
488 |
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
|
489 |
$writer->save($tempFilename);
|
|
|
490 |
|
|
|
491 |
$content = file_get_contents($tempFilename);
|
|
|
492 |
@unlink($tempFilename);
|
|
|
493 |
|
|
|
494 |
return new JsonModel([
|
|
|
495 |
'success' => true,
|
|
|
496 |
'data' => [
|
|
|
497 |
'content' => base64_encode($content),
|
|
|
498 |
'basename' => $fileName
|
|
|
499 |
|
|
|
500 |
]
|
|
|
501 |
]);
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
|
|
|
506 |
} else {
|
|
|
507 |
return new JsonModel([
|
|
|
508 |
'success' => false,
|
|
|
509 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
510 |
]);
|
|
|
511 |
}
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
|
|
|
515 |
}
|