Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5866 eleazar 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Mapper\QueryMapper;
14
use Laminas\Db\Sql\Select;
15
use LeadersLinked\Library\Functions;
16
use LeadersLinked\Mapper\SurveyTestMapper;
17
use LeadersLinked\Mapper\SurveyMapper;
18
use LeadersLinked\Mapper\SurveyFormMapper;
19
use LeadersLinked\Form\SurveyTestForm;
20
use LeadersLinked\Model\SurveyTest;
21
use LeadersLinked\Mapper\UserMapper;
22
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
23
use LeadersLinked\Library\SurveyReport;
7080 eleazar 24
use PhpOffice\PhpSpreadsheet\Spreadsheet;
25
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
26
use PhpOffice\PhpSpreadsheet\IOFactory;
5866 eleazar 27
 
28
class SurveyReportController extends AbstractActionController {
29
 
30
    /**
31
     *
32
     * @var AdapterInterface
33
     */
34
    private $adapter;
35
 
36
    /**
37
     *
38
     * @var AbstractAdapter
39
     */
40
    private $cache;
41
 
42
    /**
43
     *
44
     * @var  LoggerInterface
45
     */
46
    private $logger;
47
 
48
    /**
49
     *
50
     * @var array
51
     */
52
    private $config;
53
 
54
    /**
55
     *
56
     * @param AdapterInterface $adapter
57
     * @param AbstractAdapter $cache
58
     * @param LoggerInterface $logger
59
     * @param array $config
60
     */
61
    public function __construct($adapter, $cache, $logger, $config) {
62
        $this->adapter = $adapter;
63
        $this->cache = $cache;
64
        $this->logger = $logger;
65
        $this->config = $config;
66
    }
67
 
68
    public function indexAction() {
5911 eleazar 69
 
5866 eleazar 70
        $request = $this->getRequest();
71
        $currentUserPlugin = $this->plugin('currentUserPlugin');
72
        $currentCompany = $currentUserPlugin->getCompany();
73
        $currentUser = $currentUserPlugin->getUser();
74
 
6424 eleazar 75
        try{
5866 eleazar 76
        $request = $this->getRequest();
77
        if ($request->isGet()) {
78
 
79
            $headers = $request->getHeaders();
80
 
81
            $isJson = false;
82
            if ($headers->has('Accept')) {
83
                $accept = $headers->get('Accept');
84
 
85
                $prioritized = $accept->getPrioritized();
86
 
87
                foreach ($prioritized as $key => $value) {
88
                    $raw = trim($value->getRaw());
89
 
90
                    if (!$isJson) {
91
                        $isJson = strpos($raw, 'json');
92
                    }
93
                }
94
            }
95
 
96
            if ($isJson) {
5911 eleazar 97
 
5866 eleazar 98
                $search = $this->params()->fromQuery('search', []);
99
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
100
 
101
                $page = intval($this->params()->fromQuery('start', 1), 10);
102
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
103
                $order = $this->params()->fromQuery('order', []);
104
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
105
                $order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
106
 
6411 eleazar 107
                $fields = ['name'];
6416 eleazar 108
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
5866 eleazar 109
 
110
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
111
                    $order_direction = 'ASC';
112
                }
113
 
6411 eleazar 114
                $surveyMapper = SurveyMapper::getInstance($this->adapter);
6412 eleazar 115
                $paginator = $surveyMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
6423 eleazar 116
 
117
                $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
118
 
5866 eleazar 119
                $items = [];
120
                $records = $paginator->getCurrentItems();
6866 eleazar 121
 
5866 eleazar 122
                foreach ($records as $record) {
6423 eleazar 123
                    $surveyForm = $surveyFormMapper->fetchOne($record->form_id);
6451 eleazar 124
                    $params = [
125
 
126
                        'id' => $record->uuid,
127
                    ];
5866 eleazar 128
                    $item = [
129
                        'id' => $record->id,
6426 eleazar 130
                        'name' => $record->name,
6211 eleazar 131
                        'form' => $surveyForm->name,
6427 eleazar 132
                        'status' => $record->status,
5866 eleazar 133
                        'actions' => [
6496 eleazar 134
                            'link_report_all' => $this->url()->fromRoute('survey/report/all', ['survey_id' => $record->uuid]),
7021 eleazar 135
                            'link_report_csv' => $this->url()->fromRoute('survey/report/csv', ['survey_id' => $record->uuid]),
6496 eleazar 136
                            'link_overview' => $this->url()->fromRoute('survey/report/overview', ['survey_id' => $record->uuid])
5866 eleazar 137
                        ]
138
                    ];
139
 
140
                    array_push($items, $item);
141
                }
142
 
143
                return new JsonModel([
144
                    'success' => true,
145
                    'data' => [
146
                        'items' => $items,
147
                        'total' => $paginator->getTotalItemCount(),
148
                    ]
149
                ]);
5911 eleazar 150
            } else {
151
                $surveyMapper = SurveyMapper::getInstance($this->adapter);
152
                $survies = $surveyMapper->fetchAllByCompanyId($currentCompany->id);
153
 
5866 eleazar 154
                $form = new SurveyTestForm($this->adapter, $currentCompany->id);
155
 
156
                $this->layout()->setTemplate('layout/layout-backend');
157
                $viewModel = new ViewModel();
5933 eleazar 158
                $viewModel->setTemplate('leaders-linked/survey-report/index.phtml');
5866 eleazar 159
                $viewModel->setVariables([
5911 eleazar 160
                    'form'      => $form,
161
                    'survies' => $survies
5866 eleazar 162
                ]);
163
                return $viewModel;
164
            }
165
        } else {
166
            return new JsonModel([
167
                'success' => false,
168
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
169
            ]);
170
 
6424 eleazar 171
        }
172
        } catch (\Throwable $e) {
173
            $e->getMessage();
174
            return new JsonModel([
175
                'success' => false,
176
                'data' => $e
177
            ]);
5866 eleazar 178
        }
6212 eleazar 179
 
5866 eleazar 180
    }
5911 eleazar 181
 
6496 eleazar 182
    public function overviewAction(){
183
        $request = $this->getRequest();
184
        $currentUserPlugin = $this->plugin('currentUserPlugin');
185
        $currentCompany = $currentUserPlugin->getCompany();
186
        $currentUser = $currentUserPlugin->getUser();
187
 
188
        $request = $this->getRequest();
189
        $uuid = $this->params()->fromRoute('survey_id');
190
 
191
        if (!$uuid) {
192
            $data = [
193
                'success' => false,
194
                'data' => 'ERROR_INVALID_PARAMETER'
195
            ];
196
 
197
            return new JsonModel($data);
198
        }
199
 
200
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
201
        $survey = $surveyMapper->fetchOneByUuid($uuid);
202
 
203
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
204
        $survey = $surveyMapper->fetchOneByUuid($uuid);
205
 
206
        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
207
        $surveyTests = $surveyTestMapper->fetchAllBySurveyId($survey->id);
208
 
209
        $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
210
        $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
211
 
212
        $sections = json_decode($surveyForm->content, true);
213
 
214
        $allTests = array_map(
215
            function($response) {
216
                return json_decode($response->content, true);
217
            },
218
            $surveyTests,
219
        );
220
 
221
        $averages = [];
222
 
223
        foreach($sections as $section) {
224
            foreach($section['questions'] as $question) {
225
                switch ($question['type']) {
226
                    case 'multiple':
227
                        $totals = [];
228
 
229
                        foreach($question['options'] as $option) {
230
                            $totals[$option['slug_option']] = 0;
231
                        }
232
 
233
                        foreach($question['options'] as $option) {
234
                            $totals[$option['slug_option']] = count(array_filter(
235
                                $allTests,
236
                                function ($test) use($option, $question) {
237
                                    return in_array($option['slug_option'], $test[$question['slug_question']]);
238
                                }
239
                            ));
240
                        }
241
 
242
                        $averages[$question['slug_question']] = $totals;
243
 
244
                        break;
245
 
246
                    case 'simple':
247
                        $totals = [];
248
 
249
                        foreach($question['options'] as $option) {
250
                            $totals[$option['slug_option']] = 0;
251
                        }
252
 
253
                        foreach ($allTests as $test) {
254
                            $totals[$test[$question['slug_question']]]++;
255
                        }
256
 
257
                        foreach($totals as $slug => $amount) {
258
                            $totals[$slug] = ($amount / count($allTests)) * 100;
259
                        }
260
 
261
                        $averages[$question['slug_question']] = $totals;
262
                    break;
263
 
264
                }
265
            }
266
        }
267
 
268
        $this->layout()->setTemplate('layout/layout-backend.phtml');
269
        $viewModel = new ViewModel();
270
        $viewModel->setTemplate('leaders-linked/survey-report/overview.phtml');
271
        $viewModel->setVariables([
6506 eleazar 272
            'sections' => $sections,
6524 eleazar 273
            'averages' => $averages,
6496 eleazar 274
        ]);
275
        return $viewModel ;
276
 
277
    }
278
 
6447 eleazar 279
    public function allAction() {
5930 eleazar 280
        $request = $this->getRequest();
281
        $currentUserPlugin = $this->plugin('currentUserPlugin');
282
        $currentCompany = $currentUserPlugin->getCompany();
283
        $currentUser = $currentUserPlugin->getUser();
284
 
285
        $request = $this->getRequest();
6043 eleazar 286
        $uuid = $this->params()->fromRoute('survey_id');
5961 eleazar 287
 
5930 eleazar 288
 
289
 
290
        if (!$uuid) {
291
            $data = [
292
                'success' => false,
293
                'data' => 'ERROR_INVALID_PARAMETER'
294
            ];
295
 
296
            return new JsonModel($data);
297
        }
298
 
6039 eleazar 299
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
300
        $survey = $surveyMapper->fetchOneByUuid($uuid);
6044 eleazar 301
 
5965 eleazar 302
        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
6052 eleazar 303
        $surveyTests = $surveyTestMapper->fetchAllBySurveyId($survey->id);
5966 eleazar 304
 
6052 eleazar 305
        if (!$surveyTests) {
5930 eleazar 306
            $data = [
307
                'success' => false,
5961 eleazar 308
                'data' => 'ERROR_RECORD_NOT_FOUND'
5930 eleazar 309
            ];
310
 
311
            return new JsonModel($data);
312
        }
313
 
5965 eleazar 314
 
5930 eleazar 315
        if ($request->isGet()) {
316
            $hydrator = new ObjectPropertyHydrator();
317
 
318
            //get form data
319
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
5965 eleazar 320
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
5930 eleazar 321
 
322
            if ($surveyForm) {
323
 
6052 eleazar 324
                return $this->renderPDF($surveyForm, $surveyTests, $survey);
5930 eleazar 325
            } else {
326
 
327
                $data = [
328
                    'success' => false,
329
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
330
                ];
331
 
332
                return new JsonModel($data);
333
            }
334
        } else {
335
            $data = [
336
                'success' => false,
337
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
338
            ];
339
 
340
            return new JsonModel($data);
341
        }
342
 
343
        return new JsonModel($data);
344
    }
345
 
346
 
6052 eleazar 347
    public function renderPDF($surveyForm, $surveyTests, $survey) {
5930 eleazar 348
 
6052 eleazar 349
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $survey->uuid;
5930 eleazar 350
 
351
 
352
        if(file_exists($target_path)) {
353
            Functions::deleteFiles($target_path);
354
        } else {
355
            @mkdir($target_path, 0755, true);
356
        }
357
 
358
        // Set Data
359
        $headerFormName = utf8_decode($surveyForm->name);
6071 eleazar 360
        $headerSurveyName = utf8_decode('Informe de Encuesta: ' . trim($survey->name) . ' al ' . date("m-d-Y H:i:s", strtotime($survey->added_on)));
6052 eleazar 361
        $sections = json_decode($surveyForm->content, true);
362
 
6053 eleazar 363
        $allTests = array_map(
6052 eleazar 364
            function($response) {
365
                return json_decode($response->content, true);
366
            },
367
            $surveyTests,
368
        );
369
 
370
        $averages = [];
371
 
372
        foreach($sections as $section) {
373
            foreach($section['questions'] as $question) {
374
                switch ($question['type']) {
6054 eleazar 375
                    case 'multiple':
6056 eleazar 376
                        $totals = [];
377
 
378
                        foreach($question['options'] as $option) {
379
                            $totals[$option['slug_option']] = 0;
380
                        }
381
 
382
                        foreach($question['options'] as $option) {
6057 eleazar 383
                            $totals[$option['slug_option']] = count(array_filter(
6056 eleazar 384
                                $allTests,
6452 eleazar 385
                                function ($test) use($option, $question) {
6450 eleazar 386
                                    return in_array($option['slug_option'], $test[$question['slug_question']]);
6056 eleazar 387
                                }
388
                            ));
389
                        }
6084 eleazar 390
 
6056 eleazar 391
                        $averages[$question['slug_question']] = $totals;
392
 
393
                        break;
6449 eleazar 394
 
6052 eleazar 395
                    case 'simple':
6053 eleazar 396
                        $totals = [];
6052 eleazar 397
 
398
                        foreach($question['options'] as $option) {
6053 eleazar 399
                            $totals[$option['slug_option']] = 0;
6052 eleazar 400
                        }
401
 
6053 eleazar 402
                        foreach ($allTests as $test) {
403
                            $totals[$test[$question['slug_question']]]++;
6052 eleazar 404
                        }
405
 
6053 eleazar 406
                        foreach($totals as $slug => $amount) {
407
                            $totals[$slug] = ($amount / count($allTests)) * 100;
6052 eleazar 408
                        }
409
 
6084 eleazar 410
                        $averages[$question['slug_question']] = $totals;
6052 eleazar 411
                    break;
6071 eleazar 412
 
6052 eleazar 413
                }
414
            }
415
        }
416
 
5930 eleazar 417
        //Generate New PDF
5971 eleazar 418
        $pdf = new SurveyReport();
5930 eleazar 419
 
420
        $pdf->AliasNbPages();
421
        $pdf->AddPage();
422
 
423
        // Set header secundary
6071 eleazar 424
        $pdf->customHeader($headerFormName, $headerSurveyName);
5930 eleazar 425
 
6609 eleazar 426
        $countSection = 0;
427
 
6615 eleazar 428
        for ($i = 0; $i < count($sections); $i++) {
429
            if ($countSection > 1) {
430
                $countSection = 0;
431
                $pdf->AddPage();
432
                $pdf->customHeader($headerFormName, $headerUserName);
433
            }
434
            $section = $sections[$i];
6084 eleazar 435
 
436
            foreach ($section['questions'] as $question) {
6615 eleazar 437
 
6614 eleazar 438
                    switch ($question['type']) {
439
                        case 'simple':
440
                            $labels = [];
441
                            $values = [];
6039 eleazar 442
 
6614 eleazar 443
                            foreach($question['options'] as $option) {
444
                                $labels []= strip_tags($option['text']) . "\n(%.1f%%)";
6133 eleazar 445
 
6614 eleazar 446
                                $values []= $averages[$question['slug_question']][$option['slug_option']];
447
                            }
448
 
449
                            $filename = $target_path . DIRECTORY_SEPARATOR .  $question['slug_question'] . '.png';
6635 eleazar 450
                            $pdf->Cell(0,10,strip_tags(trim(str_replace(' ', ' ', html_entity_decode($question['text'])))),0,1);
6914 eleazar 451
                            $pdf->pieChart($labels, $values, '', $filename);
6614 eleazar 452
                            $pdf->SetFont('Arial', '', 12);
453
                            $pdf->Image($filename, 45, $pdf->getY(), 120);
454
                            $pdf->setY($pdf->getY() + 90);
6912 eleazar 455
 
6614 eleazar 456
 
457
                            break;
458
 
459
                        case 'multiple':
460
                            $labels = [];
461
                            $values = [];
462
 
463
                            foreach($question['options'] as $option) {
464
                                $labels []= strip_tags($option['text']);
465
 
466
                                $values []= $averages[$question['slug_question']][$option['slug_option']];
467
                            }
468
 
469
                            $filename = $target_path . DIRECTORY_SEPARATOR .  $question['slug_question'] . '.png';
470
                            $pdf->Cell(0,10,strip_tags($question['text']),0,1);
471
                            $pdf->barChart($labels, $values, '', $filename);
472
                            $pdf->SetFont('Arial', '', 12);
473
                            $pdf->Image($filename, 12, $pdf->getY());
474
                            $pdf->setY($pdf->getY() + (count($values) * 13) + 10);
475
 
476
                            break;
477
                    }
6615 eleazar 478
                $countSection++;
6084 eleazar 479
            }
6608 eleazar 480
 
6615 eleazar 481
 
5930 eleazar 482
        }
483
 
7021 eleazar 484
        return $pdf->Output();
485
    }
486
 
487
    public function csvAction() {
488
        $request = $this->getRequest();
489
        $currentUserPlugin = $this->plugin('currentUserPlugin');
490
        $currentCompany = $currentUserPlugin->getCompany();
491
        $currentUser = $currentUserPlugin->getUser();
492
 
493
        $request = $this->getRequest();
494
        $uuid = $this->params()->fromRoute('survey_id');
495
 
496
 
497
 
498
        if (!$uuid) {
499
            $data = [
500
                'success' => false,
501
                'data' => 'ERROR_INVALID_PARAMETER'
502
            ];
503
 
504
            return new JsonModel($data);
505
        }
506
 
507
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
508
        $survey = $surveyMapper->fetchOneByUuid($uuid);
509
 
510
        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
511
        $surveyTests = $surveyTestMapper->fetchAllBySurveyId($survey->id);
512
 
513
        if (!$surveyTests) {
514
            $data = [
515
                'success' => false,
516
                'data' => 'ERROR_RECORD_NOT_FOUND'
517
            ];
518
 
519
            return new JsonModel($data);
520
        }
521
 
522
 
523
        if ($request->isGet()) {
524
            $hydrator = new ObjectPropertyHydrator();
525
 
526
            //get form data
527
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
528
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
529
 
530
            if ($surveyForm) {
531
 
532
                return $this->csvRender($surveyForm, $surveyTests, $survey);
533
            } else {
534
 
535
                $data = [
536
                    'success' => false,
537
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
538
                ];
539
 
540
                return new JsonModel($data);
541
            }
542
        } else {
543
            $data = [
544
                'success' => false,
545
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
546
            ];
547
 
548
            return new JsonModel($data);
549
        }
550
 
551
        return new JsonModel($data);
552
    }
553
 
554
 
555
    public function csvRender($surveyForm, $surveyTests, $survey)
556
    {
7026 eleazar 557
        $sections = json_decode($surveyForm->content, true);
7020 eleazar 558
 
7088 eleazar 559
        $spreadsheet = new Spreadsheet();
560
        $sheet = $spreadsheet->getActiveSheet();
561
 
7025 eleazar 562
        $allTests = array_map(
563
            function($response) {
564
                return json_decode($response->content, true);
565
            },
566
            $surveyTests,
567
        );
568
 
569
        $averages = [];
570
 
571
        foreach($sections as $section) {
572
            foreach($section['questions'] as $question) {
573
                switch ($question['type']) {
574
                    case 'multiple':
575
                        $totals = [];
576
 
577
                        foreach($question['options'] as $option) {
578
                            $totals[$option['slug_option']] = 0;
579
                        }
580
 
581
                        foreach($question['options'] as $option) {
582
                            $totals[$option['slug_option']] = count(array_filter(
583
                                $allTests,
584
                                function ($test) use($option, $question) {
585
                                    return in_array($option['slug_option'], $test[$question['slug_question']]);
586
                                }
587
                            ));
588
                        }
589
 
590
                        $averages[$question['slug_question']] = $totals;
591
 
592
                        break;
593
 
594
                    case 'simple':
595
                        $totals = [];
596
 
597
                        foreach($question['options'] as $option) {
598
                            $totals[$option['slug_option']] = 0;
599
                        }
600
 
601
                        foreach ($allTests as $test) {
602
                            $totals[$test[$question['slug_question']]]++;
603
                        }
604
 
605
                        foreach($totals as $slug => $amount) {
606
                            $totals[$slug] = ($amount / count($allTests)) * 100;
607
                        }
608
 
609
                        $averages[$question['slug_question']] = $totals;
610
                    break;
611
 
612
                }
613
            }
614
        }
615
 
7101 eleazar 616
        $row = 1;
617
 
7025 eleazar 618
        for ($i = 0; $i < count($sections); $i++) {
619
            $section = $sections[$i];
620
 
7096 eleazar 621
           for($j = 0; $j < count($section['questions']); $j++) {
7099 eleazar 622
                $question = $section['questions'][$j];
7095 eleazar 623
 
7101 eleazar 624
                if (!in_array($question['type'], ['simple', 'multiple'])){
625
                    continue;
626
                }
627
                $sheet->setCellValueByColumnAndRow(1, $row++, strip_tags($question['text']));
628
 
7028 eleazar 629
                switch ($question['type']) {
7032 eleazar 630
                    case 'simple':
7102 eleazar 631
                        for($k = 0; $k < count($question['options']); $k++) {
632
                            $option = $question['options'][$k];
7101 eleazar 633
                            $sheet->setCellValueByColumnAndRow(1, $row, strip_tags($option['text']));
634
                            $sheet->setCellValueByColumnAndRow(2, $row, round($averages[$question['slug_question']][$option['slug_option']], 2) . '%');
635
                            $row++;
7032 eleazar 636
                        }
7025 eleazar 637
 
7032 eleazar 638
                        break;
7025 eleazar 639
 
7032 eleazar 640
                    case 'multiple':
7102 eleazar 641
                        for($k = 0; $k < count($question['options']); $k++) {
642
                            $option = $question['options'][$k];
7101 eleazar 643
                            $sheet->setCellValueByColumnAndRow(1, $row, strip_tags($option['text']));
644
                            $sheet->setCellValueByColumnAndRow(2, $row,$averages[$question['slug_question']][$option['slug_option']]);
645
                            $row++;
7032 eleazar 646
                        }
7025 eleazar 647
 
7032 eleazar 648
                        break;
649
                }
7025 eleazar 650
            }
651
 
652
 
653
        }
654
 
7020 eleazar 655
        header('Content-Description: File Transfer');
7088 eleazar 656
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
657
        header('Content-Disposition: attachment; filename=report.xls');
7020 eleazar 658
        header('Content-Transfer-Encoding: binary');
659
        header('Expires: 0');
660
        header('Cache-Control: must-revalidate');
661
        header('Pragma: public');
662
 
7088 eleazar 663
        $writer = new Xlsx($spreadsheet);
664
 
7020 eleazar 665
        ob_clean();
666
        flush();
7088 eleazar 667
        $writer->save('php://output');
7020 eleazar 668
        return;
5930 eleazar 669
    }
5866 eleazar 670
}