Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 14215 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 14215 Rev 15150
Línea 24... Línea 24...
24
use LeadersLinked\Mapper\SurveyMapper;
24
use LeadersLinked\Mapper\SurveyMapper;
25
use LeadersLinked\Mapper\SurveyFormMapper;
25
use LeadersLinked\Mapper\SurveyFormMapper;
26
use LeadersLinked\Form\SurveyTestForm;
26
use LeadersLinked\Form\SurveyTestForm;
27
use LeadersLinked\Model\SurveyTest;
27
use LeadersLinked\Model\SurveyTest;
28
use LeadersLinked\Library\UniqueSurveyReport;
28
use LeadersLinked\Library\UniqueSurveyReport;
-
 
29
use LeadersLinked\Model\Survey;
29
class SurveyTestController extends AbstractActionController {
30
class SurveyTestController extends AbstractActionController {
Línea 30... Línea 31...
30
 
31
 
31
    /**
32
    /**
32
     *
33
     *
Línea 130... Línea 131...
130
                $paginator = $surveyTestMapper->fetchAllDataTableBySurveyId($survey->id, $search, $page, $records_x_page, $order_field, $order_direction);
131
                $paginator = $surveyTestMapper->fetchAllDataTableBySurveyId($survey->id, $search, $page, $records_x_page, $order_field, $order_direction);
Línea 131... Línea 132...
131
                
132
                
132
                $items = [];
133
                $items = [];
Línea -... Línea 134...
-
 
134
                $records = $paginator->getCurrentItems();
-
 
135
                
-
 
136
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
-
 
137
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'survey/test/add');
-
 
138
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'survey/test/delete');
-
 
139
                $allowReport = $acl->isAllowed($currentUser->usertype_id, 'survey/test/report');
-
 
140
                
-
 
141
                
133
                $records = $paginator->getCurrentItems();
142
                
Línea 134... Línea 143...
134
                
143
                
135
                foreach ($records as $record) {
-
 
136
                   
-
 
137
                    $item = [
144
                foreach ($records as $record) {
138
                        'idOLD' => $record->id,
145
                   
139
                        'id' => $record->uuid,
146
                    $item = [
Línea 140... Línea 147...
140
                        'first_name' => $record->first_name,
147
                        'first_name' => $survey->identity == Survey::IDENTITY_YES ? $record->first_name : 'LABEL_SURVEY_ANONYMOUS',
141
                        'last_name' => $record->last_name,
148
                        'last_name' => $survey->identity == Survey::IDENTITY_YES ? $record->last_name : '',
142
                        'date' => $record->added_on,
149
                        'date' => $record->added_on,
143
                        
150
                        
144
                        'actions' => [
151
                        'actions' => [
Línea 145... Línea 152...
145
                            'link_delete' => $this->url()->fromRoute('survey/test/delete', ['id' => $record->id, 'survey_id' => $survey->uuid]),
152
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('survey/test/delete', ['id' => $record->id, 'survey_id' => $survey->uuid]) : '',
146
                            'link_report' => $this->url()->fromRoute('survey/test/report', ['uuid' => $record->uuid, 'survey_id' => $survey->uuid])
153
                            'link_report' => $allowReport ? $this->url()->fromRoute('survey/test/report', ['uuid' => $record->uuid, 'survey_id' => $survey->uuid]) : '',
Línea 147... Línea 154...
147
                        ]
154
                        ]
148
                    ];
155
                    ];
149
 
156
 
150
                    array_push($items, $item);
157
                    array_push($items, $item);
-
 
158
                }
151
                }
159
 
152
 
160
                return new JsonModel([
153
                return new JsonModel([
161
                    'success' => true,
154
                    'success' => true,
162
                    'data' => [
155
                    'data' => [
163
                        'items' => $items,
Línea 204... Línea 212...
204
 
212
 
205
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
213
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
Línea 206... Línea 214...
206
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
214
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
-
 
215
            
207
            
216
            $data = [
208
            $data = [
217
                'success' => true,
209
                'survey' => [
218
                'data' => [
210
                    'id' => $survey->uuid,
219
                    'id' => $survey->uuid,
211
                    'content' => $surveyForm->content ? json_decode($surveyForm->content) : [],
220
                    'content' => $surveyForm->content ? json_decode($surveyForm->content) : [],
-
 
221
                    'description' => $surveyForm->description,
212
                    'description' => $surveyForm->description,
222
                    'text' => $surveyForm->text,
213
                    'text' => $surveyForm->text,
223
                    'identity' => $survey->identity,
Línea 214... Línea 224...
214
                ],
224
                ],
Línea 410... Línea 420...
410
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
420
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
411
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
421
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
Línea 412... Línea 422...
412
 
422
 
Línea 413... Línea 423...
413
            if ($surveyForm) {
423
            if ($surveyForm) {
414
 
424
 
Línea 415... Línea 425...
415
                return $this->renderPDF($surveyForm, $surveyTest, $survey);
425
                return $this->renderPDF( $currentCompany, $surveyForm, $surveyTest, $survey);
416
            } else {
426
            } else {
417
 
427
 
Línea 432... Línea 442...
432
        }
442
        }
Línea 433... Línea 443...
433
 
443
 
434
        return new JsonModel($data);
444
        return new JsonModel($data);
Línea 435... Línea 445...
435
    }
445
    }
Línea -... Línea 446...
-
 
446
 
-
 
447
    public function renderPDF($company, $surveyForm, $surveyTest, $survey) {
-
 
448
 
-
 
449
        
-
 
450
        //Generate New PDF
-
 
451
        $pdf = new UniqueSurveyReport();
-
 
452
        
-
 
453
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
-
 
454
        
-
 
455
        $header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
-
 
456
        if(empty($header) || !file_exists($header)) {
-
 
457
            $header = $this->config['leaderslinked.images_default.company_pdf_header'];
-
 
458
        }
-
 
459
        
-
 
460
        $footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
-
 
461
        if(empty($footer) || !file_exists($footer)) {
-
 
462
            $footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
-
 
463
        }
-
 
464
        
436
 
465
        $pdf->header = $header;
Línea 437... Línea 466...
437
    public function renderPDF($surveyForm, $surveyTest, $survey) {
466
        $pdf->footer = $footer;
438
 
467
        
439
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $survey->uuid;
468
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $survey->uuid;
440
        
469
        
441
        
470
        
Línea 442... Línea 471...
442
        if(file_exists($target_path)) {
471
        if(file_exists($target_path)) {
443
            Functions::deleteFiles($target_path);
472
            Functions::deleteFiles($target_path);
444
        } else {
473
        } else {
445
            @mkdir($target_path, 0755, true);
474
            @mkdir($target_path, 0755, true);
446
        }
475
        }
447
        
476
        
448
        // Set Data
477
        // Set Data
449
        $headerFormName = utf8_decode($surveyForm->name);
-
 
450
        $headerSurveyName = utf8_decode('Informe de Encuesta: ' . trim($survey->name) . ' al ' . date("m-d-Y H:i:s", strtotime($survey->added_on)));
-
 
Línea 451... Línea 478...
451
        $sections = json_decode($surveyForm->content, true);
478
        $headerFormName = $this->cleanStringToPdf($surveyForm->name);
452
 
479
        $headerSurveyName = $this->cleanStringToPdf('Informe de Encuesta: ' . trim($survey->name) . ' al ' . date("m-d-Y H:i:s", strtotime($survey->added_on)));
Línea 453... Línea 480...
453
        $test = json_decode($surveyTest->content, true);
480
        $sections = json_decode($surveyForm->content, true);
Línea 477... Línea 504...
477
                        case 'simple':
504
                        case 'simple':
478
                            $options = [];
505
                            $options = [];
Línea 479... Línea 506...
479
 
506
 
480
                            foreach($question['options'] as $option) {
507
                            foreach($question['options'] as $option) {
481
                                $options []= [
508
                                $options []= [
482
                                    'text' => strip_tags($option['text']),
509
                                    'text' => $this->cleanStringToPdf($option['text']),
483
                                    'selected' => $option['slug_option'] == $test[$question['slug_question']],
510
                                    'selected' => $option['slug_option'] == $test[$question['slug_question']],
484
                                ];
511
                                ];
Línea 485... Línea 512...
485
                            }
512
                            }
Línea 486... Línea 513...
486
 
513
 
Línea 487... Línea 514...
487
                            $pdf->optionTable(strip_tags($question['text']), $options);
514
                            $pdf->optionTable($this->cleanStringToPdf($question['text']), $options);
488
                            
515
                            
Línea 489... Línea 516...
489
                            break;
516
                            break;
490
 
517
 
491
                        case 'multiple':
518
                        case 'multiple':
492
                            $options = [];
519
                            $options = [];
493
 
520
 
494
                            foreach($question['options'] as $option) {
521
                            foreach($question['options'] as $option) {
Línea 495... Línea 522...
495
                                $options []= [
522
                                $options []= [
Línea 496... Línea 523...
496
                                    'text' => strip_tags($option['text']),
523
                                    'text' => $this->cleanStringToPdf($option['text']),
497
                                    'selected' => in_array($option['slug_option'], $test[$question['slug_question']]),
524
                                    'selected' => in_array($option['slug_option'], $test[$question['slug_question']]),
498
                                ];
525
                                ];
Línea 499... Línea 526...
499
                            }
526
                            }
500
 
527
 
501
                            $pdf->optionTable(strip_tags($question['text']), $options);
528
                            $pdf->optionTable($this->cleanStringToPdf($question['text']), $options);
Línea 513... Línea 540...
513
            
540
            
Línea 514... Línea 541...
514
        }
541
        }
515
 
542
 
-
 
543
        return $pdf->Output();
-
 
544
    }
-
 
545
    
-
 
546
    private function cleanStringToPdf($s) 
-
 
547
    {
-
 
548
        
-
 
549
        $s = html_entity_decode($s);
-
 
550
        $detect = mb_detect_encoding($s); 
-
 
551
    
-
 
552
        if(strtoupper($detect) != 'UTF8') {
-
 
553
            
-
 
554
            $s = mb_convert_encoding($s, 'UTF8', $detect);
-
 
555
            
-
 
556
        }
-
 
557
 
-
 
558
        
Línea 516... Línea 559...
516
        return $pdf->Output();
559
        return strip_tags($s);