Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16769 Rev 16817
Línea 8... Línea 8...
8
 
8
 
9
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
-
 
13
use LeadersLinked\Library\Functions;
-
 
14
use LeadersLinked\Mapper\SurveyMapper;
-
 
15
use LeadersLinked\Mapper\SurveyFormMapper;
-
 
16
use LeadersLinked\Mapper\SurveyJobDescriptionMapper;
-
 
17
use LeadersLinked\Mapper\SurveyIndustryMapper;
-
 
18
use LeadersLinked\Mapper\SurveySkillMapper;
-
 
19
use LeadersLinked\Mapper\SurveyLocationMapper;
-
 
20
use LeadersLinked\Mapper\SurveyLanguageMapper;
-
 
21
use LeadersLinked\Mapper\IndustryMapper;
-
 
22
use LeadersLinked\Mapper\JobDescriptionMapper;
-
 
23
use LeadersLinked\Mapper\LanguageMapper;
-
 
-
 
12
use Laminas\View\Model\JsonModel;
24
use LeadersLinked\Mapper\SkillMapper;
-
 
25
use LeadersLinked\Form\SurveyForm;
-
 
26
use LeadersLinked\Model\Survey;
-
 
27
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
-
 
28
use LeadersLinked\Model\SurveyJobDescription;
-
 
29
use LeadersLinked\Model\SurveySkill;
-
 
30
use LeadersLinked\Model\SurveyIndustry;
-
 
31
use LeadersLinked\Model\SurveyLanguage;
-
 
Línea 32... Línea 13...
32
use LeadersLinked\Model\SurveyLocation;
13
 
Línea 33... Línea 14...
33
 
14
 
34
class SurveyController extends AbstractActionController {
15
class SurveyController extends AbstractActionController {
Línea 82... Línea 63...
82
        $this->config       = $config;
63
        $this->config       = $config;
83
        $this->translator   = $translator;
64
        $this->translator   = $translator;
84
    }
65
    }
Línea 85... Línea 66...
85
 
66
 
86
    public function indexAction() {
-
 
87
        $request = $this->getRequest();
-
 
88
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
89
        $currentCompany = $currentUserPlugin->getCompany();
-
 
90
        $currentUser = $currentUserPlugin->getUser();
-
 
91
 
-
 
92
 
-
 
93
        $request = $this->getRequest();
-
 
94
        if ($request->isGet()) {
-
 
95
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
-
 
96
            if($sandbox) {
-
 
97
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
-
 
98
            } else {
-
 
99
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
-
 
100
            }
-
 
101
 
-
 
102
            $headers = $request->getHeaders();
-
 
103
 
-
 
104
            $isJson = false;
-
 
105
            if ($headers->has('Accept')) {
-
 
106
                $accept = $headers->get('Accept');
-
 
107
 
-
 
108
                $prioritized = $accept->getPrioritized();
-
 
109
 
-
 
110
                foreach ($prioritized as $key => $value) {
-
 
111
                    $raw = trim($value->getRaw());
-
 
112
 
-
 
113
                    if (!$isJson) {
-
 
114
                        $isJson = strpos($raw, 'json');
-
 
115
                    }
-
 
116
                }
-
 
117
            }
-
 
118
 
-
 
119
            if ($isJson) {
-
 
120
                $search = $this->params()->fromQuery('search', []);
-
 
121
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
-
 
122
 
-
 
123
                $start = intval($this->params()->fromQuery('start', 0), 10);
-
 
124
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
-
 
125
                $page =  intval($start / $records_x_page);
-
 
126
                $page++;
-
 
127
                
-
 
128
                $order = $this->params()->fromQuery('order', []);
-
 
129
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
-
 
130
                $order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
-
 
131
 
-
 
132
                $fields = ['name'];
-
 
133
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
-
 
134
 
-
 
135
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
-
 
136
                    $order_direction = 'ASC';
-
 
137
                }
-
 
138
 
-
 
139
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
-
 
140
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'survey/edit');
-
 
141
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'survey/delete');
-
 
142
            
-
 
143
                $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
144
                $paginator = $surveyMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
-
 
145
 
-
 
146
                $items = [];
-
 
147
                $records = $paginator->getCurrentItems();
-
 
148
 
-
 
149
                $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
-
 
150
                
-
 
151
                $forms = [];
-
 
152
                
-
 
153
                foreach ($records as $record) {
-
 
154
                   
-
 
155
                    if(isset($forms[$record->form_id])) {
-
 
156
                        
-
 
157
                        $surveyForm = $forms[$record->form_id]; 
-
 
158
                    } else {
-
 
159
                        $surveyForm = $surveyFormMapper->fetchOne($record->form_id);
-
 
160
                        $forms[$record->form_id] = $surveyForm;
-
 
161
                    }
-
 
162
                    
-
 
163
                    $dtSinceDate = \DateTime::createFromFormat('Y-m-d', $record->since_date);
-
 
164
                    $dtLastDate = \DateTime::createFromFormat('Y-m-d', $record->last_date);
-
 
165
                    
-
 
166
                    
-
 
167
                    
-
 
168
                    $item = [
-
 
169
                        'id' => $record->id,
-
 
170
                        'name' => $record->name,
-
 
171
                        'form' => $surveyForm->name,
-
 
172
                        'since_date' => $dtSinceDate->format('d/m/Y'),
-
 
173
                        'last_date' => $dtLastDate->format('d/m/Y'),
-
 
174
                        'status' => $record->status,
-
 
175
                        'actions' => [
-
 
176
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('survey/edit', ['id' => $record->uuid]) : '',
-
 
177
                            'link_delete' => $allowDelete  ? $this->url()->fromRoute('survey/delete', ['id' => $record->uuid]) : '',
-
 
178
                        ]
-
 
179
                    ];
-
 
180
 
-
 
181
                    array_push($items, $item);
-
 
182
                }
-
 
183
 
67
    public function indexAction() {
184
                return new JsonModel([
68
        return new JsonModel([
185
                    'success' => true,
-
 
186
                    'data' => [
69
            'success' => false,
187
                        'items' => $items,
-
 
188
                        'total' => $paginator->getTotalItemCount(),
-
 
189
                    ]
70
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
190
                ]);
-
 
Línea 191... Línea -...
191
            } else {
-
 
192
 
-
 
193
                $form = new SurveyForm($this->adapter, $currentCompany->id);
-
 
194
 
-
 
195
                $this->layout()->setTemplate('layout/layout-backend');
-
 
196
                $viewModel = new ViewModel();
-
 
197
                $viewModel->setTemplate('leaders-linked/survey/index.phtml');
-
 
198
                $viewModel->setVariable('form', $form);
-
 
199
                $viewModel->setVariable('google_map_key', $google_map_key);
-
 
200
                return $viewModel;
-
 
201
            }
-
 
202
        } else {
-
 
203
            return new JsonModel([
-
 
204
                'success' => false,
-
 
205
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
206
            ]);
71
        ]);
Línea 207... Línea -...
207
        }
-
 
208
    }
-
 
209
 
-
 
210
    public function addAction() {
-
 
211
        $request = $this->getRequest();
-
 
212
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
213
        $currentCompany = $currentUserPlugin->getCompany();
-
 
214
        $currentUser = $currentUserPlugin->getUser();
-
 
215
      
-
 
216
        $request = $this->getRequest();
-
 
217
 
-
 
218
        if ($request->isPost()) {
-
 
219
            
-
 
220
            $form = new SurveyForm($this->adapter, $currentCompany->id);
-
 
221
            
-
 
222
            $dataPost = $request->getPost()->toArray();
-
 
223
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : SurveyForm::STATUS_INACTIVE;           
-
 
224
 
-
 
225
            $form->setData($dataPost);
-
 
226
 
-
 
227
            if ($form->isValid()) {
-
 
228
                $dataPost = (array) $form->getData();
-
 
229
 
-
 
230
                $hydrator = new ObjectPropertyHydrator();
-
 
231
 
-
 
232
                $survey = new Survey();
-
 
233
                $hydrator->hydrate($dataPost, $survey);
-
 
234
 
-
 
235
                if (!$survey->status) {
-
 
236
                    $survey->status = Survey::STATUS_INACTIVE;
-
 
237
                }
-
 
238
                $survey->company_id = $currentCompany->id;
-
 
239
 
-
 
240
                $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
-
 
241
                $surveyForm = $surveyFormMapper->fetchOneByUuid($dataPost['form_id']);
-
 
242
                $survey->form_id = $surveyForm->id;
-
 
243
 
-
 
244
                $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
245
                //$result = $surveyMapper->insert($survey);
-
 
246
 
-
 
247
                if($surveyMapper->insert($survey)) {
-
 
248
                    $survey = $surveyMapper->fetchOne($survey->id);
-
 
249
 
-
 
250
                    if(!empty($dataPost['location_search'])){ 
-
 
251
                                                $record = new SurveyLocation();
-
 
252
                        $record->formatted_address = $dataPost['formatted_address'];
-
 
253
                        $record->city1 = $dataPost['city1'];
-
 
254
                        $record->city2 = $dataPost['city2'];
-
 
255
                        $record->address1 = $dataPost['address1'];
-
 
256
                        $record->address2 = $dataPost['address2'];
-
 
257
                        $record->country = $dataPost['country'];
-
 
258
                        $record->latitude = $dataPost['latitude'];
-
 
259
                        $record->longitude = $dataPost['longitude'];
-
 
260
                        $record->postal_code = $dataPost['postal_code'];
-
 
261
                        $record->state = $dataPost['state'];
-
 
262
                        $record->survey_id = $survey->id;
-
 
263
                        
-
 
264
                        $surveyLocationMapper = SurveyLocationMapper::getInstance($this->adapter);
-
 
265
                        $surveyLocationMapper->insert($record);
-
 
266
                    }
-
 
267
 
-
 
268
                    if(!empty($dataPost['job_description_id'])){ 
-
 
269
                        $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
270
                        $surveyJobDescriptionMapper = SurveyJobDescriptionMapper::getInstance($this->adapter);
-
 
271
 
-
 
272
                        foreach($dataPost['job_description_id'] as $jobDescriptionUuid) 
-
 
273
                        {
-
 
274
                            $jobDescription = $jobDescriptionMapper->fetchOneByUuid($jobDescriptionUuid);
-
 
275
                            if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
-
 
276
                                $record = new SurveyJobDescription();
-
 
277
                                $record->job_description_id = $jobDescription->id;
-
 
278
                                $record->survey_id = $survey->id;
-
 
279
 
-
 
280
                                $surveyJobDescriptionMapper->insert($record);
-
 
281
                            }
-
 
282
                        }
-
 
283
                    }
-
 
284
                    if(!empty($dataPost['skill_id'])){ 
-
 
285
                         $skillMapper = SkillMapper::getInstance($this->adapter);
-
 
286
                         $surveySkillMapper = SurveySkillMapper::getInstance($this->adapter);
-
 
287
 
-
 
288
                         foreach($dataPost['skill_id'] as $skillUuid) 
-
 
289
                         {
-
 
290
                             $skill = $skillMapper->fetchOneByUuid($skillUuid);
-
 
291
 
-
 
292
                             if($skill) {
-
 
293
                                $record = new SurveySkill();
-
 
294
                                $record->skill_id = $skill->id;
-
 
295
                                $record->survey_id = $survey->id;
-
 
296
 
-
 
297
                                $surveySkillMapper->insert($record);
-
 
298
                            }
-
 
299
                         }
-
 
300
                     }
-
 
301
 
-
 
302
                    if(!empty($dataPost['industry_id'])){ 
-
 
303
                         $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
304
                         $surveyIndustryMapper = SurveyIndustryMapper::getInstance($this->adapter);
-
 
305
 
-
 
306
                         foreach($dataPost['industry_id'] as $industryUuid) 
-
 
307
                         {
-
 
308
                             $industry = $industryMapper->fetchOneByUuid($industryUuid);
-
 
309
                             if($industry) {
-
 
310
                                 $record = new SurveyIndustry();
-
 
311
                                 $record->industry_id = $industry->id;
-
 
312
                                 $record->survey_id = $survey->id;
-
 
313
 
-
 
314
                                 $surveyIndustryMapper->insert($record);
-
 
315
                             }
-
 
316
                         }
-
 
317
                     }
-
 
318
 
-
 
319
                    if(!empty($dataPost['language_id'])){ 
-
 
320
                        $languageMapper = LanguageMapper::getInstance($this->adapter);
-
 
321
                        $surveyLanguageMapper = SurveyLanguageMapper::getInstance($this->adapter);
-
 
322
 
-
 
323
                        foreach($dataPost['language_id'] as $language_id) 
-
 
324
                        {
-
 
325
 
-
 
326
                            $language = $languageMapper->fetchOne($language_id);
-
 
327
                            if($language) {
-
 
328
                                $record = new SurveyLanguage();
-
 
329
                                $record->language_id = $language_id;
-
 
330
                                $record->survey_id = $survey->id;
-
 
331
 
-
 
332
                                $surveyLanguageMapper->insert($record);
-
 
333
                            }
-
 
334
                        }
-
 
335
                    }
-
 
336
 
-
 
337
                    $data = [
-
 
338
                        'success' => true,
-
 
339
                        'data' => 'LABEL_RECORD_ADDED'
-
 
340
                    ];
-
 
341
 
-
 
342
                } else {
-
 
343
                    $data = [
-
 
344
                        'success'   => false,
-
 
345
                        'data'      => $surveyMapper->getError()
-
 
346
                    ];
-
 
347
                }
-
 
348
                
-
 
349
             
-
 
350
                return new JsonModel($data);
-
 
351
            } else {
-
 
352
                $messages = [];
-
 
353
                $form_messages = (array) $form->getMessages();
-
 
354
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
355
 
-
 
356
                    $messages[$fieldname] = array_values($field_messages);
-
 
357
                }
-
 
358
 
-
 
359
                return new JsonModel([
-
 
360
                    'success' => false,
-
 
361
                    'data' => $messages
-
 
362
                ]);
-
 
363
            }
-
 
364
        } else {
-
 
365
            $data = [
-
 
366
                'success' => false,
-
 
367
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
368
            ];
-
 
369
 
-
 
370
            return new JsonModel($data);
-
 
371
        }
-
 
372
 
-
 
373
        return new JsonModel($data);
-
 
374
    }
-
 
375
 
-
 
376
    /*
-
 
377
    public function segmentAction() {
-
 
378
        $request = $this->getRequest();
-
 
379
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
380
        $currentCompany = $currentUserPlugin->getCompany();
-
 
381
        $currentUser = $currentUserPlugin->getUser();
-
 
382
 
-
 
383
        $request = $this->getRequest();
-
 
384
        $uuid = $this->params()->fromRoute('id');
-
 
385
 
-
 
386
 
-
 
387
        if (!$uuid) {
-
 
388
            $data = [
-
 
389
                'success' => false,
-
 
390
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
391
            ];
-
 
392
 
-
 
393
            return new JsonModel($data);
-
 
394
        }
-
 
395
 
-
 
396
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
397
        $survey = $surveyMapper->fetchOneByUuid($uuid);
-
 
398
        if (!$survey) {
-
 
399
            $data = [
-
 
400
                'success' => false,
-
 
401
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
402
            ];
-
 
403
 
-
 
404
            return new JsonModel($data);
-
 
405
        }
-
 
406
 
-
 
407
        if ($survey->company_id != $currentCompany->id) {
-
 
408
            return new JsonModel([
-
 
409
                'success' => false,
-
 
410
                'data' => 'ERROR_UNAUTHORIZED'
-
 
411
            ]);
-
 
412
        }
-
 
413
 
-
 
414
        if($request->isPost()){
-
 
415
            $form = new SurveySegmentedForm($this->adapter, $currentCompany->id);
-
 
416
            
-
 
417
            
-
 
418
            $dataPost = $request->getPost()->toArray();
-
 
419
            $form->setData($dataPost);
-
 
420
            
-
 
421
 
-
 
422
 
-
 
423
            if ($form->isValid()) {
-
 
424
                $dataPost = (array) $form->getData();
-
 
425
                
-
 
426
                if(!empty($dataPost['job_description_id'])){ 
-
 
427
                    $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
428
                    $surveyJobDescriptionMapper = SurveyJobDescriptionMapper::getInstance($this->adapter);
-
 
429
                    
-
 
430
                    foreach($dataPost['job_description_id'] as $jobDescriptionUuid) 
-
 
431
                    {
-
 
432
                        $jobDescription = $jobDescriptionMapper->fetchOneByUuid($jobDescriptionUuid);
-
 
433
                        if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
-
 
434
                            $record = new SurveyJobDescription();
-
 
435
                            $record->job_description_id = $jobDescription->id;
-
 
436
                            $record->survey_id = $survey->id;
-
 
437
                                   
-
 
438
                            $surveyJobDescriptionMapper->insert($record);
-
 
439
                        }
-
 
440
                    }
-
 
441
                }
-
 
442
                
-
 
443
 
-
 
444
                if(!empty($dataPost['skill_id'])){ 
-
 
445
                     $skillMapper = SkillMapper::getInstance($this->adapter);
-
 
446
                     $surveySkillMapper = SurveySkillMapper::getInstance($this->adapter);
-
 
447
                     
-
 
448
                     foreach($dataPost['skill_id'] as $skillUuid) 
-
 
449
                     {
-
 
450
                         $skill = $skillMapper->fetchOneByUuid($skillUuid);
-
 
451
                         
-
 
452
                         if($skill) {
-
 
453
                            $record = new SurveySkill();
-
 
454
                            $record->skill_id = $skill->id;
-
 
455
                            $record->survey_id = $survey->id;
-
 
456
                            
-
 
457
                            $surveySkillMapper->insert($record);
-
 
458
                         }
-
 
459
                     }
-
 
460
                 }
-
 
461
                 
-
 
462
                if(!empty($dataPost['industry_id'])){ 
-
 
463
                     
-
 
464
                     $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
465
                     $surveyIndustryMapper = SurveyIndustryMapper::getInstance($this->adapter);
-
 
466
                     
-
 
467
                     $ok = true;
-
 
468
                     
-
 
469
                     foreach($dataPost['industry_id'] as $industryUuid)
-
 
470
                     {
-
 
471
                         $industry = $industryMapper->fetchOneByUuid($industryUuid);
-
 
472
                         if($industry) {
-
 
473
                             $record = new SurveyIndustry();
-
 
474
                             $record->industry_id = $industry->id;
-
 
475
                             $record->survey_id = $survey->id;
-
 
476
                             
-
 
477
                             $surveyIndustryMapper->insert($record);
-
 
478
                          }
-
 
479
                     }
-
 
480
                 }
-
 
481
                 
-
 
482
            
-
 
483
                if(!empty($dataPost['language_id'])){ 
-
 
484
                    $languageMapper = LanguageMapper::getInstance($this->adapter);
-
 
485
                    $surveyLanguageMapper = SurveyLanguageMapper::getInstance($this->adapter);
-
 
486
                    
-
 
487
                    foreach($dataPost['language_id'] as $language_id) 
-
 
488
                    {
-
 
489
                        $language = $languageMapper->fetchOne($language_id);
-
 
490
                        if($language) {
-
 
491
                            $record = new SurveyLanguage();
-
 
492
                            $record->language_id = $language_id;
-
 
493
                            $record->survey_id = $survey->id;
-
 
494
                            
-
 
495
                            $surveyLanguageMapper->insert($record);
-
 
496
                        }
-
 
497
                    }
-
 
498
                 }
-
 
499
                 
-
 
500
                $data = [
-
 
501
                    'success' => true,
-
 
502
                    'data' => 'LABEL_RECORD_ADDED'
-
 
503
                ];
-
 
504
               // return new JsonModel($data); exit;
-
 
505
    
-
 
506
               // return new JsonModel($data);
-
 
507
            } else {
-
 
508
                $messages = [];
-
 
509
                $form_messages = (array) $form->getMessages();
-
 
510
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
511
 
-
 
512
                    $messages[$fieldname] = array_values($field_messages);
-
 
513
                }
-
 
514
 
-
 
515
                return new JsonModel([
-
 
516
                    'success' => false,
-
 
517
                    'data' => $messages
-
 
518
                ]);
-
 
519
            }
-
 
520
        } else {
-
 
521
            $data = [
-
 
522
                'success' => false,
-
 
523
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
524
            ];
-
 
525
 
-
 
526
            return new JsonModel($data);
-
 
527
        }
-
 
528
 
-
 
529
       return new JsonModel($data);
-
 
530
        
-
 
531
    }*/
-
 
532
 
-
 
533
    public function editAction() {
-
 
534
        $request = $this->getRequest();
-
 
535
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
536
        $currentCompany = $currentUserPlugin->getCompany();
-
 
537
        $currentUser = $currentUserPlugin->getUser();
-
 
538
 
-
 
539
        $request = $this->getRequest();
-
 
540
        $uuid = $this->params()->fromRoute('id');
-
 
541
 
-
 
542
 
-
 
543
        if (!$uuid) {
-
 
544
            $data = [
-
 
545
                'success' => false,
-
 
546
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
547
            ];
-
 
548
 
-
 
549
            return new JsonModel($data);
-
 
550
        }
-
 
551
 
-
 
552
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
553
        $survey = $surveyMapper->fetchOneByUuid($uuid);
-
 
554
       
-
 
555
        if (!$survey) {
-
 
556
            $data = [
-
 
557
                'success' => false,
-
 
558
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
559
            ];
-
 
560
 
-
 
561
            return new JsonModel($data);
-
 
562
        }
-
 
563
 
-
 
564
        if ($survey->company_id != $currentCompany->id) {
-
 
565
            return new JsonModel([
-
 
566
                'success' => false,
-
 
567
                'data' => 'ERROR_UNAUTHORIZED'
-
 
568
            ]);
-
 
569
        }
-
 
570
 
-
 
571
 
-
 
572
        if ($request->isPost()) {
-
 
573
            $form = new SurveyForm($this->adapter, $currentCompany->id);
-
 
574
            $dataPost = $request->getPost()->toArray();
-
 
575
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : SurveyForm::STATUS_INACTIVE;
-
 
576
 
-
 
577
            $form->setData($dataPost);
-
 
578
 
-
 
579
            if ($form->isValid()) {
-
 
580
                $dataPost = (array) $form->getData();
-
 
581
               
-
 
582
                $hydrator = new ObjectPropertyHydrator();
-
 
583
                $hydrator->hydrate($dataPost, $survey);
-
 
584
 
-
 
585
                if (!$survey->status) {
-
 
586
                    $survey->status = Survey::STATUS_INACTIVE;
-
 
587
                }
-
 
588
               
-
 
589
                $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
-
 
590
                $surveyForm = $surveyFormMapper->fetchOneByUuid($dataPost['form_id']);
-
 
591
                $survey->form_id = $surveyForm->id;
-
 
592
                
-
 
593
                $result = $surveyMapper->update($survey);
-
 
594
                if($result){
-
 
595
                    $jobDescription = new SurveyJobDescription();
-
 
596
                    $skill = new SurveySkill();
-
 
597
                    $industry = new SurveyIndustry();
-
 
598
                    $language = new SurveyLanguage();
-
 
599
 
-
 
600
                    if(!empty($dataPost['location_search'])){ 
-
 
601
 
-
 
602
                        $surveyLocationMapper = SurveyLocationMapper::getInstance($this->adapter);
-
 
603
                        $surveyLocation = $surveyLocationMapper->fetchOneBySurveyId($survey->id);
-
 
604
 
-
 
605
                        if($surveyLocation) {
-
 
606
                            $surveyLocation->formatted_address = $dataPost['formatted_address'];
-
 
607
                            $surveyLocation->city1 = $dataPost['city1'];
-
 
608
                            $surveyLocation->city2 = $dataPost['city2'];
-
 
609
                            $surveyLocation->address1 = $dataPost['address1'];
-
 
610
                            $surveyLocation->address2 = $dataPost['address2'];
-
 
611
                            $surveyLocation->country = $dataPost['country'];
-
 
612
                            $surveyLocation->latitude = $dataPost['latitude'];
-
 
613
                            $surveyLocation->longitude = $dataPost['longitude'];
-
 
614
                            $surveyLocation->postal_code = $dataPost['postal_code'];
-
 
615
                            $surveyLocation->state = $dataPost['state'];
-
 
616
                            $surveyLocationMapper->update($surveyLocation);
-
 
617
                        } else {
-
 
618
                            $surveyLocation = new SurveyLocation();
-
 
619
                            $surveyLocation->formatted_address = $dataPost['formatted_address'];
-
 
620
                            $surveyLocation->city1 = $dataPost['city1'];
-
 
621
                            $surveyLocation->city2 = $dataPost['city2'];
-
 
622
                            $surveyLocation->address1 = $dataPost['address1'];
-
 
623
                            $surveyLocation->address2 = $dataPost['address2'];
-
 
624
                            $surveyLocation->country = $dataPost['country'];
-
 
625
                            $surveyLocation->latitude = $dataPost['latitude'];
-
 
626
                            $surveyLocation->longitude = $dataPost['longitude'];
-
 
627
                            $surveyLocation->postal_code = $dataPost['postal_code'];
-
 
628
                            $surveyLocation->state = $dataPost['state'];
-
 
629
                            $surveyLocation->survey_id = $survey->id;
-
 
630
                            $surveyLocationMapper->insert($surveyLocation);
-
 
631
                        }
-
 
632
                    }
-
 
633
 
-
 
634
                    if(!empty($dataPost['job_description_id'])){ 
-
 
635
                        $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
636
                        $surveyJobDescriptionMapper = SurveyJobDescriptionMapper::getInstance($this->adapter);
-
 
637
 
-
 
638
                        $surveyJobDescriptionMapper->deleteBySurveyId($survey->id);
-
 
639
 
-
 
640
                        foreach($dataPost['job_description_id'] as $jobDescriptionUuid) {
-
 
641
                        
-
 
642
                            $jobDescription = $jobDescriptionMapper->fetchOneByUuid($jobDescriptionUuid);
-
 
643
                            if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
-
 
644
                                $record = new SurveyJobDescription();
-
 
645
                                $record->job_description_id = $jobDescription->id;
-
 
646
                                $record->survey_id = $survey->id;
-
 
647
 
-
 
648
                                $surveyJobDescriptionMapper->insert($record);
-
 
649
                            }
-
 
650
                        }
-
 
651
 
-
 
652
                    }
-
 
653
 
-
 
654
 
-
 
655
                    if(!empty($dataPost['skill_id'])){ 
-
 
656
                         $skillMapper = SkillMapper::getInstance($this->adapter);
-
 
657
                         $surveySkillMapper = SurveySkillMapper::getInstance($this->adapter);
-
 
658
 
-
 
659
                         
-
 
660
                         $surveySkillMapper->deleteBySurveyId($survey->id);
-
 
661
                         
-
 
662
 
-
 
663
                         foreach($dataPost['skill_id'] as $skillUuid) {
-
 
664
                             $skill = $skillMapper->fetchOneByUuid($skillUuid);
-
 
665
                             if($skill) {
-
 
666
                                $record = new SurveySkill();
-
 
667
                                $record->skill_id = $skill->id;
-
 
668
                                $record->survey_id = $survey->id;
-
 
669
 
-
 
670
                                $surveySkillMapper->insert($record);
-
 
671
                            }
-
 
672
                         }
-
 
673
                    }
-
 
674
 
-
 
675
                    if(!empty($dataPost['industry_id'])){ 
-
 
676
                         $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
677
                         $surveyIndustryMapper = SurveyIndustryMapper::getInstance($this->adapter);
-
 
678
 
-
 
679
                         $surveyIndustryMapper->deleteBySurveyId($survey->id);
-
 
680
 
-
 
681
                         foreach($dataPost['industry_id'] as $industryUuid) {
-
 
682
                             $industry = $industryMapper->fetchOneByUuid($industryUuid);
-
 
683
 
-
 
684
                             if($industry) {
-
 
685
                                 $record = new SurveyIndustry();
-
 
686
                                 $record->industry_id = $industry->id;
-
 
687
                                 $record->survey_id = $survey->id;
-
 
688
 
-
 
689
                                 $surveyIndustryMapper->insert($record);
-
 
690
                                 
-
 
691
                             }
-
 
692
                         }
-
 
693
                    }
-
 
694
 
-
 
695
 
-
 
696
                    if(!empty($dataPost['language_id'])){ 
-
 
697
 
-
 
698
                        $surveyLanguageMapper = SurveyLanguageMapper::getInstance($this->adapter);
-
 
699
                        $surveyLanguageMapper->deleteBySurveyId($survey->id);
-
 
700
 
-
 
701
                        $languageMapper = LanguageMapper::getInstance($this->adapter);
-
 
702
                        
-
 
703
                        foreach($dataPost['language_id'] as $language_id) 
-
 
704
                        {
-
 
705
                            $language = $languageMapper->fetchOne($language_id);
-
 
706
                            if($language) {
-
 
707
                                $record = new SurveyLanguage();
-
 
708
                                $record->language_id = $language_id;
-
 
709
                                $record->survey_id = $survey->id;
-
 
710
 
-
 
711
 
-
 
712
                                $surveyLanguageMapper->insert($record);
-
 
713
                            }   
-
 
714
                        }
-
 
715
                     }
-
 
716
                }
-
 
717
      
-
 
718
 
-
 
719
                if ($result) {
-
 
720
                    $this->logger->info('Se edito la encuesta ' . $survey->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
721
                    $data = [
-
 
722
                        'success' => true,
-
 
723
                        'data' => 'LABEL_RECORD_UPDATED'
-
 
724
                    ];
-
 
725
                } else {
-
 
726
                    $data = [
-
 
727
                        'success' => false,
-
 
728
                        'data' => $surveyMapper->getError()
-
 
729
                    ];
-
 
730
                }
-
 
731
 
-
 
732
                return new JsonModel($data);
-
 
733
            } else {
-
 
734
                $messages = [];
-
 
735
                $form_messages = (array) $form->getMessages();
-
 
736
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
737
                    $messages[$fieldname] = array_values($field_messages);
-
 
738
                }
-
 
739
 
-
 
740
                return new JsonModel([
-
 
741
                    'success' => false,
-
 
742
                    'data' => $messages
-
 
743
                ]);
-
 
744
            }
-
 
745
        } else if ($request->isGet()) {
-
 
746
            $hydrator = new ObjectPropertyHydrator();
-
 
747
           
-
 
748
            $surveylenguageMapper = SurveyLanguageMapper::getInstance($this->adapter);
-
 
749
            $languages  = $surveylenguageMapper->fetchAllBySurveyId($survey->id);
-
 
750
            
-
 
751
            $lenguage = [];
-
 
752
            foreach($languages as $language)
-
 
753
            {
-
 
754
                array_push($lenguage, $language->language_id);
-
 
755
            }
-
 
756
 
-
 
757
            $surveySkillMapper = SurveySkillMapper::getInstance($this->adapter);
-
 
758
            $skills  = $surveySkillMapper->fetchAllBySurveyId($survey->id);
-
 
759
            
-
 
760
            $skilla = [];
-
 
761
            foreach($skills as $skill)
-
 
762
            {
-
 
763
                array_push($skilla, $skill->skill_id);
-
 
764
            }
-
 
765
            
-
 
766
 
-
 
767
            $skillMaster = [];
-
 
768
            foreach($skilla as $skillb)
-
 
769
            {
-
 
770
                $skillMapper = SkillMapper::getInstance($this->adapter);
-
 
771
                $skillm = $skillMapper->fetchOne($skillb);
-
 
772
                array_push($skillMaster, $skillm->uuid);
-
 
773
            }
-
 
774
 
-
 
775
            $SurveyJobDescriptionMapper = SurveyJobDescriptionMapper::getInstance($this->adapter);
-
 
776
            $SurveyJobDescriptions  = $SurveyJobDescriptionMapper->fetchAllBySurveyId($survey->id);
-
 
777
            
-
 
778
            $SurveyJobDescriptionA = [];
-
 
779
            foreach($SurveyJobDescriptions as $SurveyJobDescription)
-
 
780
            {
-
 
781
                array_push($SurveyJobDescriptionA, $SurveyJobDescription->job_description_id);
-
 
782
            }
-
 
783
           
-
 
784
            $SurveyJobDescriptionMaster = [];
-
 
785
            foreach($SurveyJobDescriptionA as $SurveyJobDescriptionB)
-
 
786
            {
-
 
787
                $JobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
788
                $JobDescriptionm = $JobDescriptionMapper->fetchOne($SurveyJobDescriptionB);
-
 
789
                array_push($SurveyJobDescriptionMaster, $JobDescriptionm->uuid);
-
 
790
            }
-
 
791
 
-
 
792
            $surveyIndustryMapper = SurveyIndustryMapper::getInstance($this->adapter);
-
 
793
            $industrys = $surveyIndustryMapper->fetchAllBySurveyId($survey->id);
-
 
794
            
-
 
795
            $industrya = [];
-
 
796
            foreach($industrys as $industry)
-
 
797
            {
-
 
798
                array_push($industrya, $industry->industry_id);
-
 
799
            }
-
 
800
            
-
 
801
 
-
 
802
            $industryMaster = [];
-
 
803
            foreach($industrya as $industryb)
-
 
804
            {
-
 
805
                $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
806
                $industrym = $industryMapper->fetchOne($industryb);
-
 
807
                array_push($industryMaster, $industrym->uuid);
-
 
808
            }
-
 
809
            
-
 
810
 
-
 
811
            $surveyLocationMapper = SurveyLocationMapper::getInstance($this->adapter);
-
 
812
            $surveyLocation  = $surveyLocationMapper->fetchOneBySurveyId($survey->id);
-
 
813
            
-
 
814
 
-
 
815
          
-
 
816
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
-
 
817
            $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
-
 
818
 
-
 
819
            $data = [
-
 
820
                'success' => true,
-
 
821
                'data' => [
-
 
822
                    'name' => $survey->name,
-
 
823
                    'form_id' => $surveyForm->uuid,
-
 
824
                    'target' => $survey->target,
-
 
825
                    'identity' => $survey->identity,
-
 
826
                    'since_date' => $survey->since_date,
-
 
827
                    'last_date' => $survey->last_date,
-
 
828
                    'status' => $survey->status, 
-
 
829
                    'lenguage_id' => $lenguage,
-
 
830
                    'skill_id' => $skillMaster,
-
 
831
                    'job_description_id' => $SurveyJobDescriptionMaster,
-
 
832
                    'industry_id' => $industryMaster,
-
 
833
                  
-
 
834
                    
-
 
835
                    'formatted_address' => $surveyLocation  ? $surveyLocation->formatted_address : '',
-
 
836
                    'city1' => $surveyLocation  ? $surveyLocation ->city1 : '',
-
 
837
                    'city2' => $surveyLocation  ? $surveyLocation ->city2 : '',
-
 
838
                    'address1' => $surveyLocation  ? $surveyLocation ->address1: '',
-
 
839
                    'address2' => $surveyLocation  ? $surveyLocation ->address2 : '',
-
 
840
                    'country' => $surveyLocation  ? $surveyLocation ->country : '',
-
 
841
                    'latitude' => $surveyLocation  ? $surveyLocation ->latitude : '',
-
 
842
                    'longitude' => $surveyLocation  ? $surveyLocation ->longitude : '',
-
 
843
                    'postal_code' => $surveyLocation  ? $surveyLocation ->postal_code : '',
-
 
844
                    'state' => $surveyLocation  ? $surveyLocation ->state : '',
-
 
845
  
-
 
846
 
-
 
847
                ]
-
 
848
            ];
-
 
849
 
-
 
850
            return new JsonModel($data);
-
 
851
        } else {
-
 
852
            $data = [
-
 
853
                'success' => false,
-
 
854
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
855
            ];
-
 
856
 
-
 
857
            return new JsonModel($data);
-
 
858
        }
-
 
859
 
-
 
860
        return new JsonModel($data);
-
 
861
    }
-
 
862
 
-
 
863
    public function deleteAction() {
-
 
864
        $request = $this->getRequest();
-
 
865
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
866
        $currentCompany = $currentUserPlugin->getCompany();
-
 
867
        $currentUser = $currentUserPlugin->getUser();
-
 
868
 
-
 
869
        $request = $this->getRequest();
-
 
870
        $uuid = $this->params()->fromRoute('id');
-
 
871
 
-
 
872
        if (!$uuid) {
-
 
873
            $data = [
-
 
874
                'success' => false,
-
 
875
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
876
            ];
-
 
877
 
-
 
878
            return new JsonModel($data);
-
 
879
        }
-
 
880
 
-
 
881
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
882
        $survey = $surveyMapper->fetchOneByUuid($uuid);
-
 
883
        if (!$survey) {
-
 
884
            $data = [
-
 
885
                'success' => false,
-
 
886
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
887
            ];
-
 
888
 
-
 
889
            return new JsonModel($data);
-
 
890
        }
-
 
891
 
-
 
892
        if ($survey->company_id != $currentCompany->id) {
-
 
893
            return new JsonModel([
-
 
894
                'success' => false,
-
 
895
                'data' => 'ERROR_UNAUTHORIZED'
-
 
896
            ]);
-
 
897
        }
-
 
898
 
-
 
899
        if ($request->isPost()) {
-
 
900
 
-
 
901
            $result = $surveyMapper->delete($survey->id);
-
 
902
            if ($result) {
-
 
903
                $this->logger->info('Se borro la encuesta ' . $survey->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
904
 
-
 
905
                $data = [
-
 
906
                    'success' => true,
-
 
907
                    'data' => 'LABEL_RECORD_DELETED'
-
 
908
                ];
-
 
909
            } else {
-
 
910
 
-
 
911
                $data = [
-
 
912
                    'success' => false,
-
 
913
                    'data' => $surveyMapper->getError()
-
 
914
                ];
-
 
915
 
-
 
916
                return new JsonModel($data);
-
 
917
            }
-
 
918
        } else {
-
 
919
            $data = [
-
 
920
                'success' => false,
-
 
921
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
922
            ];
-
 
923
 
-
 
924
            return new JsonModel($data);
-
 
925
        }
-
 
Línea 926... Línea 72...
926
 
72