Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15079 | Rev 16766 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 15079 Rev 15444
Línea 11... Línea 11...
11
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Mapper\QueryMapper;
13
use LeadersLinked\Mapper\QueryMapper;
14
use Laminas\Db\Sql\Select;
14
use Laminas\Db\Sql\Select;
15
use LeadersLinked\Library\Functions;
15
use LeadersLinked\Library\Functions;
16
use LeadersLinked\Mapper\CompanyMapper;
-
 
17
use LeadersLinked\Mapper\CompanySelfEvaluationFormMapper;
16
use LeadersLinked\Mapper\SelfEvaluationFormMapper;
18
use LeadersLinked\Mapper\CompanySelfEvaluationTestMapper;
17
use LeadersLinked\Mapper\SelfEvaluationTestMapper;
19
use LeadersLinked\Form\CompanySelfEvaluationTestForm;
18
use LeadersLinked\Form\SelfEvaluation\SelfEvaluationTestForm;
20
use LeadersLinked\Model\CompanySelfEvaluationForm;
19
use LeadersLinked\Model\SelfEvaluationForm;
21
use LeadersLinked\Model\CompanySelfEvaluationTest;
20
use LeadersLinked\Model\SelfEvaluationTest;
22
use LeadersLinked\Mapper\UserMapper;
21
use LeadersLinked\Mapper\UserMapper;
23
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
22
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
24
use LeadersLinked\Library\SelfEvaluationPdf;
23
use LeadersLinked\Library\SelfEvaluationPdf;
25
use LeadersLinked\Mapper\CompanySelfEvaluationFormUserMapper;
-
 
26
use LeadersLinked\Model\Company;
24
use LeadersLinked\Model\Company;
Línea 27... Línea 25...
27
 
25
 
Línea 28... Línea 26...
28
class SelfEvaluationReviewController extends AbstractActionController {
26
class SelfEvaluationReviewController extends AbstractActionController {
Línea 98... Línea 96...
98
 
96
 
Línea 99... Línea 97...
99
                $queryMapper = QueryMapper::getInstance($this->adapter);
97
                $queryMapper = QueryMapper::getInstance($this->adapter);
100
 
98
 
101
                $select = $queryMapper->getSql()->select();
99
                $select = $queryMapper->getSql()->select();
102
                $select->columns(['uuid', 'status', 'user_id', 'added_on']);
100
                $select->columns(['uuid', 'status', 'user_id', 'added_on']);
103
                $select->from(['test' => CompanySelfEvaluationTestMapper::_TABLE]);
101
                $select->from(['test' => SelfEvaluationTestMapper::_TABLE]);
Línea 104... Línea 102...
104
                $select->join(['form' => CompanySelfEvaluationFormMapper::_TABLE], 'test.form_id = form.id', ['name', 'language']);
102
                $select->join(['form' => SelfEvaluationFormMapper::_TABLE], 'test.form_id = form.id', ['name', 'language']);
105
                $select->join(['user' => UserMapper::_TABLE], 'test.user_id = user.id', ['first_name', 'last_name'], Select::JOIN_LEFT_OUTER);
103
                $select->join(['user' => UserMapper::_TABLE], 'test.user_id = user.id', ['first_name', 'last_name'], Select::JOIN_LEFT_OUTER);
Línea 106... Línea 104...
106
 
104
 
107
                $select->where->equalTo('form.status', CompanySelfEvaluationForm::STATUS_ACTIVE);
105
                $select->where->equalTo('form.status', SelfEvaluationForm::STATUS_ACTIVE);
108
                $select->where->notEqualTo('test.status', CompanySelfEvaluationTest::STATUS_DRAFT);
106
                $select->where->notEqualTo('test.status', SelfEvaluationTest::STATUS_DRAFT);
Línea 122... Línea 120...
122
                $records = $queryMapper->fetchAll($select);
120
                $records = $queryMapper->fetchAll($select);
123
                $items = [];
121
                $items = [];
Línea 124... Línea 122...
124
 
122
 
125
                foreach ($records as $record) {
123
                foreach ($records as $record) {
126
                    switch ($record['language']) {
124
                    switch ($record['language']) {
127
                        case CompanySelfEvaluationForm::LANGUAGE_ENGLISH :
125
                        case SelfEvaluationForm::LANGUAGE_ENGLISH :
128
                            $language = 'LABEL_ENGLISH';
126
                            $language = 'LABEL_ENGLISH';
Línea 129... Línea 127...
129
                            break;
127
                            break;
130
 
128
 
131
                        case CompanySelfEvaluationForm::LANGUAGE_SPANISH :
129
                        case SelfEvaluationForm::LANGUAGE_SPANISH :
Línea 132... Línea 130...
132
                            $language = 'LABEL_SPANISH';
130
                            $language = 'LABEL_SPANISH';
133
                            break;
131
                            break;
134
 
132
 
135
                        default :
133
                        default :
Línea 136... Línea 134...
136
                            $language = '';
134
                            $language = '';
Línea 137... Línea 135...
137
                            break;
135
                            break;
138
                    }
136
                    }
139
 
137
 
Línea 140... Línea 138...
140
                    switch ($record['status']) {
138
                    switch ($record['status']) {
141
 
139
 
142
                        case CompanySelfEvaluationTest::STATUS_COMPLETED :
140
                        case SelfEvaluationTest::STATUS_COMPLETED :
Línea 143... Línea 141...
143
                            $status = 'LABEL_COMPLETED';
141
                            $status = 'LABEL_COMPLETED';
144
                            break;
142
                            break;
145
 
143
 
Línea 146... Línea 144...
146
                        case CompanySelfEvaluationTest::STATUS_PENDING :
144
                        case SelfEvaluationTest::STATUS_PENDING :
Línea 162... Línea 160...
162
                        'user' => $record['first_name'] . ' ' . $record['last_name'],
160
                        'user' => $record['first_name'] . ' ' . $record['last_name'],
163
                        'language' => $language,
161
                        'language' => $language,
164
                        'status' => $status,
162
                        'status' => $status,
165
                        'added_on' => $record['added_on'],
163
                        'added_on' => $record['added_on'],
166
                        'actions' => [
164
                        'actions' => [
167
                            'link_edit' => $record['status'] != CompanySelfEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('self-evaluation/reviews/edit', ['id' => $record['uuid']]) : '',
165
                            'link_edit' => $record['status'] != SelfEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('self-evaluation/reviews/edit', ['id' => $record['uuid']]) : '',
168
                            'link_report' => $record['status'] == CompanySelfEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('self-evaluation/reviews/report', ['id' => $record['uuid']]) : '',
166
                            'link_report' => $record['status'] == SelfEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('self-evaluation/reviews/report', ['id' => $record['uuid']]) : '',
169
                        ]
167
                        ]
170
                    ];
168
                    ];
Línea 171... Línea 169...
171
 
169
 
172
                    array_push($items, $item);
170
                    array_push($items, $item);
Línea 179... Línea 177...
179
                        'total' => count($items),
177
                        'total' => count($items),
180
                    ]
178
                    ]
181
                ]);
179
                ]);
182
            } else {
180
            } else {
Línea 183... Línea 181...
183
 
181
 
Línea 184... Línea 182...
184
                $form = new CompanySelfEvaluationTestForm();
182
                $form = new SelfEvaluationTestForm();
185
 
183
 
186
                $this->layout()->setTemplate('layout/layout-backend');
184
                $this->layout()->setTemplate('layout/layout-backend');
187
                $viewModel = new ViewModel();
185
                $viewModel = new ViewModel();
Línea 215... Línea 213...
215
            ];
213
            ];
Línea 216... Línea 214...
216
 
214
 
217
            return new JsonModel($data);
215
            return new JsonModel($data);
Línea 218... Línea 216...
218
        }
216
        }
219
 
217
 
220
        $companySelfEvaluationTestMapper = CompanySelfEvaluationTestMapper::getInstance($this->adapter);
218
        $selfEvaluationTestMapper = SelfEvaluationTestMapper::getInstance($this->adapter);
221
        $companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneByUuid($uuid);
219
        $selfEvaluationTest = $selfEvaluationTestMapper->fetchOneByUuid($uuid);
222
        if (!$companySelfEvaluationTest) {
220
        if (!$selfEvaluationTest) {
223
            $data = [
221
            $data = [
224
                'success' => false,
222
                'success' => false,
Línea 225... Línea 223...
225
                'data' => 'ERROR_RECORD_NOT_FOUND'
223
                'data' => 'ERROR_RECORD_NOT_FOUND'
226
            ];
224
            ];
Línea 227... Línea 225...
227
 
225
 
228
            return new JsonModel($data);
226
            return new JsonModel($data);
229
        }
227
        }
230
 
228
 
Línea 231... Línea 229...
231
        if ($request->isPost()) {
229
        if ($request->isPost()) {
Línea 232... Línea 230...
232
            $form = new CompanySelfEvaluationTestForm();
230
            $form = new SelfEvaluationTestForm();
233
            $dataPost = $request->getPost()->toArray();
231
            $dataPost = $request->getPost()->toArray();
234
            $form->setData($dataPost);
232
            $form->setData($dataPost);
235
 
233
 
Línea 236... Línea 234...
236
            if ($form->isValid()) {
234
            if ($form->isValid()) {
Línea 237... Línea 235...
237
 
235
 
238
                $selfEvaluationTest = new CompanySelfEvaluationTest();
236
                $selfEvaluationTest = new SelfEvaluationTest();
239
                $selfEvaluationTest->status = CompanySelfEvaluationTest::STATUS_COMPLETED;
237
                $selfEvaluationTest->status = SelfEvaluationTest::STATUS_COMPLETED;
240
                $selfEvaluationTest->content = $dataPost['content'];
238
                $selfEvaluationTest->content = $dataPost['content'];
241
                $selfEvaluationTest->comments = $dataPost['comments'];
239
                $selfEvaluationTest->comments = $dataPost['comments'];
242
 
240
 
243
                $result = $companySelfEvaluationTestMapper->update($selfEvaluationTest, $companySelfEvaluationTest->id);
241
                $result = $selfEvaluationTestMapper->update($selfEvaluationTest, $selfEvaluationTest->id);
244
 
242
 
245
                if ($result) {
243
                if ($result) {
246
                    $data = [
244
                    $data = [
247
                        'success' => true,
245
                        'success' => true,
Línea 248... Línea 246...
248
                        'data' => 'LABEL_RECORD_UPDATED'
246
                        'data' => 'LABEL_RECORD_UPDATED'
249
                    ];
247
                    ];
Línea 269... Línea 267...
269
            }
267
            }
270
        } else if ($request->isGet()) {
268
        } else if ($request->isGet()) {
271
            $hydrator = new ObjectPropertyHydrator();
269
            $hydrator = new ObjectPropertyHydrator();
Línea 272... Línea 270...
272
 
270
 
273
            //get form data           
271
            //get form data           
274
            $companySelfEvaluationFormMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
272
            $selfEvaluationFormMapper = SelfEvaluationFormMapper::getInstance($this->adapter);
Línea 275... Línea 273...
275
            $companySelfEvaluationForm = $companySelfEvaluationFormMapper->fetchOne($companySelfEvaluationTest->form_id);
273
            $selfEvaluationForm = $selfEvaluationFormMapper->fetchOne($selfEvaluationTest->form_id);
276
 
274
 
277
            //get user data
275
            //get user data
Línea 278... Línea 276...
278
            $CompanyUserMapper = UserMapper::getInstance($this->adapter);
276
            $CompanyUserMapper = UserMapper::getInstance($this->adapter);
Línea 279... Línea 277...
279
            $userMapper = $CompanyUserMapper->fetchOne($companySelfEvaluationTest->user_id);
277
            $userMapper = $CompanyUserMapper->fetchOne($selfEvaluationTest->user_id);
280
 
278
 
281
            if ($companySelfEvaluationForm && $userMapper) {
279
            if ($selfEvaluationForm && $userMapper) {
282
 
280
 
283
                $data = [
281
                $data = [
284
                    'success' => true,
282
                    'success' => true,
285
                    'data' => [
283
                    'data' => [
286
                        'id' => $companySelfEvaluationTest->id,
284
                        'id' => $selfEvaluationTest->id,
287
                        'name' => $companySelfEvaluationForm->name,
285
                        'name' => $selfEvaluationForm->name,
288
                        'text' => $companySelfEvaluationForm->text,
286
                        'text' => $selfEvaluationForm->text,
289
                        'user' => $userMapper->first_name . ' ' . $userMapper->last_name,
287
                        'user' => $userMapper->first_name . ' ' . $userMapper->last_name,
290
                        'status' => $companySelfEvaluationTest->status,
288
                        'status' => $selfEvaluationTest->status,
Línea 291... Línea 289...
291
                        'comments' => $companySelfEvaluationTest->comments,
289
                        'comments' => $selfEvaluationTest->comments,
292
                        'content' => json_decode($companySelfEvaluationTest->content),
290
                        'content' => json_decode($selfEvaluationTest->content),
Línea 332... Línea 330...
332
            ];
330
            ];
Línea 333... Línea 331...
333
 
331
 
334
            return new JsonModel($data);
332
            return new JsonModel($data);
Línea 335... Línea 333...
335
        }
333
        }
336
 
334
 
337
        $companySelfEvaluationTestMapper = CompanySelfEvaluationTestMapper::getInstance($this->adapter);
335
        $selfEvaluationTestMapper = SelfEvaluationTestMapper::getInstance($this->adapter);
338
        $companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneByUuid($uuid);
336
        $selfEvaluationTest = $selfEvaluationTestMapper->fetchOneByUuid($uuid);
339
        if (!$companySelfEvaluationTest) {
337
        if (!$selfEvaluationTest) {
340
            $data = [
338
            $data = [
341
                'success' => false,
339
                'success' => false,
Línea 347... Línea 345...
347
 
345
 
348
        if ($request->isGet()) {
346
        if ($request->isGet()) {
Línea 349... Línea 347...
349
            $hydrator = new ObjectPropertyHydrator();
347
            $hydrator = new ObjectPropertyHydrator();
350
 
348
 
351
            //get form data           
349
            //get form data           
Línea 352... Línea 350...
352
            $companySelfEvaluationFormMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
350
            $selfEvaluationFormMapper = SelfEvaluationFormMapper::getInstance($this->adapter);
353
            $companySelfEvaluationForm = $companySelfEvaluationFormMapper->fetchOne($companySelfEvaluationTest->form_id);
351
            $selfEvaluationForm = $selfEvaluationFormMapper->fetchOne($selfEvaluationTest->form_id);
354
 
352
 
Línea 355... Línea 353...
355
            //get user data
353
            //get user data
Línea 356... Línea 354...
356
            $CompanyUserMapper = UserMapper::getInstance($this->adapter);
354
            $CompanyUserMapper = UserMapper::getInstance($this->adapter);
357
            $userMapper = $CompanyUserMapper->fetchOne($companySelfEvaluationTest->user_id);
355
            $userMapper = $CompanyUserMapper->fetchOne($selfEvaluationTest->user_id);
Línea 358... Línea 356...
358
 
356
 
359
            if ($companySelfEvaluationForm && $userMapper) {
357
            if ($selfEvaluationForm && $userMapper) {
360
 
358
 
Línea 381... Línea 379...
381
    }
379
    }
Línea 382... Línea 380...
382
 
380
 
383
    /**
381
    /**
384
     * Render Pdf document
382
     * Render Pdf document
385
     * @param Company $company
383
     * @param Company $company
386
     * @param CompanySelfEvaluationForm $companySelfEvaluationForm
384
     * @param SelfEvaluationForm $selfEvaluationForm
387
     * @param CompanySelfEvaluationTest $companySelfEvaluationTest
385
     * @param SelfEvaluationTest $selfEvaluationTest
388
     * @param UserMapper $userMapper
386
     * @param UserMapper $userMapper
389
     * @return mixed
387
     * @return mixed
390
     */
388
     */
Línea 391... Línea 389...
391
    public function renderPDF($company, $companySelfEvaluationForm, $companySelfEvaluationTest, $userMapper) {
389
    public function renderPDF($company, $selfEvaluationForm, $selfEvaluationTest, $userMapper) {
Línea 392... Línea 390...
392
 
390
 
393
        
391
        
394
        
392
        
Línea 406... Línea 404...
406
        
404
        
407
        
405
        
408
        
406
        
409
        
407
        
410
        // Set Data
408
        // Set Data
Línea 411... Línea 409...
411
        $headerFormName = utf8_decode($companySelfEvaluationForm->name);
409
        $headerFormName = utf8_decode($selfEvaluationForm->name);
412
        $headerUserName = utf8_decode('Informe de Auto-evaluación: ' . trim($userMapper->first_name . ' ' . $userMapper->last_name) . ' al ' . date("m-d-Y H:i:s", strtotime($companySelfEvaluationTest->added_on)));
410
        $headerUserName = utf8_decode('Informe de Auto-evaluación: ' . trim($userMapper->first_name . ' ' . $userMapper->last_name) . ' al ' . date("m-d-Y H:i:s", strtotime($selfEvaluationTest->added_on)));
Línea 492... Línea 490...
492
        $filenameGeneral = $target_path . DIRECTORY_SEPARATOR . 'general.png';
490
        $filenameGeneral = $target_path . DIRECTORY_SEPARATOR . 'general.png';
493
        $pdf->pieChart($labels, $values, '', $filenameGeneral);
491
        $pdf->pieChart($labels, $values, '', $filenameGeneral);
494
        $pdf->Image($filenameGeneral, 60, $pdf->getY(), 90);
492
        $pdf->Image($filenameGeneral, 60, $pdf->getY(), 90);
495
        $pdf->setY($pdf->getY() + 60);
493
        $pdf->setY($pdf->getY() + 60);
Línea 496... Línea 494...
496
 
494
 
Línea 497... Línea 495...
497
        if ($companySelfEvaluationTest->comments) {
495
        if ($selfEvaluationTest->comments) {
498
 
496
 
499
            $pdf->SetFont('Arial', 'B', 10);
497
            $pdf->SetFont('Arial', 'B', 10);
Línea 500... Línea 498...
500
            $pdf->Cell(190, 10, utf8_decode('Comentarios finales'), 0, 0, 'C');
498
            $pdf->Cell(190, 10, utf8_decode('Comentarios finales'), 0, 0, 'C');
501
            $pdf->setY($pdf->getY() + 10);
499
            $pdf->setY($pdf->getY() + 10);
502
 
500
 
503
            $pdf->SetFont('Arial', '', 8);
501
            $pdf->SetFont('Arial', '', 8);
Línea 504... Línea 502...
504
            $pdf->MultiCell(180, 8, utf8_decode($companySelfEvaluationTest->comments));
502
            $pdf->MultiCell(180, 8, utf8_decode($selfEvaluationTest->comments));
505
            $pdf->setY(60);
503
            $pdf->setY(60);