Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 810 | Rev 4093 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
/**
3
 *
4
 * Controlador: Mis Perfiles
5
 *
6
 */
7
declare(strict_types=1);
8
 
9
namespace LeadersLinked\Controller;
10
 
11
use Laminas\Db\Adapter\AdapterInterface;
12
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
13
use Laminas\Mvc\Controller\AbstractActionController;
14
use Laminas\Log\LoggerInterface;
15
use Laminas\View\Model\ViewModel;
16
use Laminas\View\Model\JsonModel;
17
 
18
use LeadersLinked\Library\Functions;
19
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
20
use LeadersLinked\Library\Image;
21
 
22
use LeadersLinked\Mapper\CompanyLocationMapper;
23
use LeadersLinked\Form\CompanyProfileSocialNetworkForm;
24
use LeadersLinked\Form\CompanyProfileLocationForm;
25
use LeadersLinked\Form\CompanyProfileExtendedForm;
26
use LeadersLinked\Form\CompanyProfileImageForm;
27
use LeadersLinked\Form\CompanyProfileCoverForm;
768 geraldo 28
use LeadersLinked\Form\CompanyProfileHeaderForm;
29
use LeadersLinked\Form\CompanyProfileFooterForm;
1 www 30
 
31
use LeadersLinked\Form\CompanyProfileIndustryForm;
32
use LeadersLinked\Form\CompanyProfileCompanySizeForm;
33
use LeadersLinked\Form\CompanyProfileFoundationYearForm;
34
use LeadersLinked\Form\CompanyProfileWebsiteForm;
35
use LeadersLinked\Model\Location;
36
use LeadersLinked\Model\CompanyLocation;
37
use LeadersLinked\Model\CompanyUser;
38
 
39
use LeadersLinked\Mapper\LocationMapper;
40
use LeadersLinked\Mapper\CompanyFollowerMapper;
41
use LeadersLinked\Mapper\CompanyUserMapper;
42
use LeadersLinked\Mapper\CompanyMapper;
43
use LeadersLinked\Mapper\IndustryMapper;
44
use LeadersLinked\Mapper\CompanySizeMapper;
45
 
46
class ProfileController extends AbstractActionController
47
{
48
    /**
49
     *
50
     * @var AdapterInterface
51
     */
52
    private $adapter;
53
 
54
 
55
    /**
56
     *
57
     * @var AbstractAdapter
58
     */
59
    private $cache;
60
 
61
    /**
62
     *
63
     * @var  LoggerInterface
64
     */
65
    private $logger;
66
 
67
 
68
    /**
69
     *
70
     * @var array
71
     */
72
    private $config;
73
 
74
    /**
75
     *
76
     * @param AdapterInterface $adapter
77
     * @param AbstractAdapter $cache
78
     * @param LoggerInterface $logger
79
     * @param array $config
80
     */
81
    public function __construct($adapter, $cache , $logger,  $config)
82
    {
83
        $this->adapter      = $adapter;
84
        $this->cache        = $cache;
85
        $this->logger       = $logger;
86
        $this->config       = $config;
87
 
88
    }
89
 
90
 
91
 
92
    /**
93
     * Presenta el perfil con las opciónes de edición de cada sección
94
     * @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
95
     */
96
    public function indexAction()
97
    {
98
        $currentUserPlugin = $this->plugin('currentUserPlugin');
99
        $currentUser = $currentUserPlugin->getUser();
100
        $currentCompany = $currentUserPlugin->getCompany();
101
 
102
 
103
        $request = $this->getRequest();
104
        if($request->isGet()) {
105
 
106
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
107
            if($sandbox) {
108
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
109
            } else {
110
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
111
            }
112
 
113
            $companyMapper = CompanyMapper::getInstance($this->adapter);
114
            $company = $companyMapper->fetchOne($currentCompany->id);
115
 
116
 
117
            $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
118
            $records = $companyLocationMapper->fetchAllLocationByCompanyId($company->id);
119
 
120
 
121
 
122
 
123
            $locations = [];
124
            foreach($records as $record)
125
            {
126
                $location =  [
127
                    'formatted_address'  => $record['formatted_address'],
128
                    'country' => $record['country'],
129
                    'is_main' => $record['is_main'],
130
                    'link_edit' => $this->url()->fromRoute('profile/location', [ 'operation' => 'edit', 'id' =>  $record['company_location_uuid'] ]),
131
                    'link_delete' => $this->url()->fromRoute('profile/location', ['operation' => 'delete', 'id' => $record['company_location_uuid'] ])
132
 
133
                ];
134
 
135
                array_push($locations, $location);
136
            }
137
 
138
            $industryMapper = IndustryMapper::getInstance($this->adapter);
139
            $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
140
 
141
            $formSocialNetwork = new CompanyProfileSocialNetworkForm();
142
            $formLocation = new CompanyProfileLocationForm();
143
            $formExtended = new CompanyProfileExtendedForm();
144
            $formFoundationYear = new CompanyProfileFoundationYearForm();
145
            $formWebsite = new CompanyProfileWebsiteForm();
146
            $formImage = new CompanyProfileImageForm($this->config);
147
            $formCover = new CompanyProfileCoverForm($this->config);
768 geraldo 148
            $formHeader = new CompanyProfileHeaderForm($this->config);
149
            $formFooter = new CompanyProfileFooterForm($this->config);
150
 
151
 
152
 
1 www 153
            $formCompanySize = new CompanyProfileCompanySizeForm($this->adapter);
154
            $formIndustry = new CompanyProfileIndustryForm($this->adapter);
155
 
156
            $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
157
            $follower = $companyFollowerMapper->getCountFollowers($currentCompany->id);
158
 
159
            $image_size_cover = $this->config['leaderslinked.image_sizes.company_cover_upload'];
160
            $image_size_profile = $this->config['leaderslinked.image_sizes.company_image_upload'];
1101 geraldo 161
            $image_size_header = $this->config['leaderslinked.image_sizes.company_header_pdf_upload'];
162
            $image_size_footer= $this->config['leaderslinked.image_sizes.company_footer_pdf_upload'];
1 www 163
 
164
 
165
            $industry = $industryMapper->fetchOne($company->industry_id);
166
            $companySize = $companySizeMapper->fetchOne($company->company_size_id);
167
 
168
 
169
            $this->layout()->setTemplate('layout/layout-backend');
170
            $viewModel = new ViewModel();
171
            $viewModel->setTemplate('leaders-linked/profile/index.phtml');
172
            $viewModel->setVariables([
173
                'google_map_key'        => $google_map_key,
174
                'follower'              => $follower,
175
                'company_id'            => $currentCompany->id,
176
                'company_name'          => $company->name,
177
                'company_uuid'          => $company->uuid,
178
                'name'                  => trim($company->name),
179
                'image'                 => $company->image,
180
                'cover'                 => $company->cover,
782 geraldo 181
                'header'                 => $company->header,
182
                'footer'                 => $company->footer,
1 www 183
                'overview'              => $company->description,
184
                'website'               => $company->website,
185
                'foundation_year'       => $company->foundation_year,
186
                'facebook'              => $company->facebook,
187
                'instagram'             => $company->instagram,
188
                'twitter'               => $company->twitter,
189
                'locations'             => $locations,
190
                'industry'              => $industry->name,
191
                'company_size'          => $companySize->name . ' ('.$companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee .')',
192
                'formLocation'          => $formLocation,
193
                'formSocialNetwork'     => $formSocialNetwork,
194
                'formExtended'          => $formExtended,
195
                'formImage'             => $formImage,
196
                'formCover'             => $formCover,
768 geraldo 197
                'formHeader'             => $formHeader,
198
                'formFooter'             => $formFooter,
1 www 199
                'formFoundationYear'    => $formFoundationYear,
200
                'formWebsite'           => $formWebsite,
201
                'formIndustry'          => $formIndustry,
202
                'formCompanySize'       => $formCompanySize,
203
                'image_size_cover'      => $image_size_cover,
204
                'image_size_profile'    => $image_size_profile,
781 geraldo 205
                'image_size_header'    => $image_size_header,
206
                'image_size_footer'    => $image_size_footer,
1 www 207
            ]);
208
            return $viewModel ;
209
 
210
        } else {
211
            $data = [
212
                'success' => false,
213
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
214
            ];
215
 
216
            return new JsonModel($data);
217
        }
218
 
219
        return new JsonModel($data);
220
    }
221
 
222
 
223
    /**
224
     *
225
     * Borrar un perfil excepto el público
226
     * @return \Laminas\View\Model\JsonModel
227
     */
228
    public function deleteAction()
229
    {
230
 
231
        $currentUserPlugin = $this->plugin('currentUserPlugin');
232
        $currentUser = $currentUserPlugin->getUser();
233
        $currentCompany = $currentUserPlugin->getCompany();
234
 
235
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
236
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $currentUser->id);
237
 
238
        if(!$companyUser || $companyUser->type != CompanyUser::CREATOR_YES) {
239
            $response = [
240
                'success' => false,
241
                'data' => 'ERROR_UNAUTHORIZED'
242
            ];
243
 
244
            return new JsonModel($response);
245
        }
246
 
247
 
248
        if($request->isPost()) {
249
            $companyMapper = CompanyMapper::getInstance($this->adapter);
250
            $result = $companyMapper->delete($companyUser->id);
251
            if($result) {
252
                $this->logger->info('Se borro la empresa : ' .  $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
253
 
254
                $data = [
255
                    'success' => true,
256
                    'data' => 'LABEL_RECORD_DELETED'
257
                ];
258
            } else {
259
 
260
                $data = [
261
                    'success'   => false,
262
                    'data'      => $companyUserMapper->getError()
263
                ];
264
 
265
                return new JsonModel($data);
266
            }
267
 
268
        } else {
269
            $data = [
270
                'success' => false,
271
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
272
            ];
273
 
274
            return new JsonModel($data);
275
        }
276
 
277
        return new JsonModel($data);
278
    }
279
 
280
 
281
 
282
    /**
283
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
284
     * @return \Laminas\View\Model\JsonModel
285
     */
286
    public function extendedAction()
287
    {
288
 
289
 
290
        $currentUserPlugin = $this->plugin('currentUserPlugin');
291
        $currentUser = $currentUserPlugin->getUser();
292
        $currentCompany = $currentUserPlugin->getCompany();
293
 
294
 
295
 
296
 
297
 
298
        $request = $this->getRequest();
299
        if($request->isGet()) {
300
            $companyMapper = CompanyMapper::getInstance($this->adapter);
301
            $company = $companyMapper->fetchOne($currentCompany->id);
302
 
303
            $data = [
304
                'success' => true,
305
                'data' => [
306
                    'description' => $company->description,
307
                ]
308
            ];
309
 
310
            return new JsonModel($data);
311
 
312
 
313
        } else if($request->isPost()) {
314
            $form = new CompanyProfileExtendedForm();
315
            $dataPost = $request->getPost()->toArray();
316
 
317
            $form->setData($dataPost);
318
 
319
            if($form->isValid()) {
320
                $companyMapper = CompanyMapper::getInstance($this->adapter);
321
                $company = $companyMapper->fetchOne($currentCompany->id);
322
 
323
                $dataPost = (array) $form->getData();
324
 
325
                $hydrator = new ObjectPropertyHydrator();
326
                $hydrator->hydrate($dataPost, $company);
327
 
328
                $companyMapper->updateExtended($company);
329
 
330
                $this->logger->info('Se actualizo las descripción de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
331
 
332
                return new JsonModel([
333
                    'success'   => true,
334
                    'data' => [
335
                        'description' => $company->description,
336
                    ]
337
                ]);
338
 
339
            } else {
340
                $messages = [];
341
                $form_messages = (array) $form->getMessages();
342
                foreach($form_messages  as $fieldname => $field_messages)
343
                {
344
                    $messages[$fieldname] = array_values($field_messages);
345
                }
346
 
347
                return new JsonModel([
348
                    'success'   => false,
349
                    'data'   => $messages
350
                ]);
351
            }
352
        }
353
 
354
 
355
        $data = [
356
            'success' => false,
357
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
358
        ];
359
 
360
 
361
        return new JsonModel($data);
362
    }
363
 
364
    /**
365
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
366
     * @return \Laminas\View\Model\JsonModel
367
     */
368
    public function websiteAction()
369
    {
370
        $currentUserPlugin = $this->plugin('currentUserPlugin');
371
        $currentUser = $currentUserPlugin->getUser();
372
        $currentCompany = $currentUserPlugin->getCompany();
373
 
374
        $request = $this->getRequest();
375
        if($request->isGet()) {
376
            $companyMapper = CompanyMapper::getInstance($this->adapter);
377
            $company = $companyMapper->fetchOne($currentCompany->id);
378
 
379
            $data = [
380
                'success' => true,
381
                'data' => [
382
                    'website' => $company->website,
383
                ]
384
            ];
385
 
386
            return new JsonModel($data);
387
 
388
 
389
        } else if($request->isPost()) {
390
 
391
 
392
            $form = new CompanyProfileWebsiteForm();
393
            $dataPost = $request->getPost()->toArray();
394
 
395
            $form->setData($dataPost);
396
 
397
            if($form->isValid()) {
398
                $companyMapper = CompanyMapper::getInstance($this->adapter);
399
                $company = $companyMapper->fetchOne($currentCompany->id);
400
 
401
                $dataPost = (array) $form->getData();
402
 
403
                $hydrator = new ObjectPropertyHydrator();
404
                $hydrator->hydrate($dataPost, $company);
405
 
406
                $companyMapper->updateWebsite($company);
407
 
408
                $this->logger->info('Se actualizo el website de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
409
 
410
                return new JsonModel([
411
                    'success'   => true,
412
                    'data' => [
413
                        'website' => $company->website,
414
                    ]
415
                ]);
416
 
417
            } else {
418
                $messages = [];
419
                $form_messages = (array) $form->getMessages();
420
                foreach($form_messages  as $fieldname => $field_messages)
421
                {
422
                    $messages[$fieldname] = array_values($field_messages);
423
                }
424
 
425
                return new JsonModel([
426
                    'success'   => false,
427
                    'data'   => $messages
428
                ]);
429
            }
430
        }
431
 
432
 
433
        $data = [
434
            'success' => false,
435
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
436
        ];
437
 
438
 
439
        return new JsonModel($data);
440
    }
441
 
442
    /**
443
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
444
     * @return \Laminas\View\Model\JsonModel
445
     */
446
    public function foundationYearAction()
447
    {
448
 
449
        $currentUserPlugin = $this->plugin('currentUserPlugin');
450
        $currentUser = $currentUserPlugin->getUser();
451
        $currentCompany = $currentUserPlugin->getCompany();
452
 
453
 
454
 
455
        $request = $this->getRequest();
456
        if($request->isGet()) {
457
            $companyMapper = CompanyMapper::getInstance($this->adapter);
458
            $company = $companyMapper->fetchOne($currentCompany->id);
459
 
460
            $data = [
461
                'success' => true,
462
                'data' => [
463
                    'foundation_year' => $company->foundation_year,
464
                ]
465
 
466
            ];
467
 
468
            return new JsonModel($data);
469
 
470
 
471
        } else if($request->isPost()) {
472
 
473
 
474
            $form = new CompanyProfileFoundationYearForm();
475
            $dataPost = $request->getPost()->toArray();
476
 
477
            $form->setData($dataPost);
478
 
479
            if($form->isValid()) {
480
                $companyMapper = CompanyMapper::getInstance($this->adapter);
481
                $company = $companyMapper->fetchOne($currentCompany->id);
482
 
483
                $dataPost = (array) $form->getData();
484
 
485
                $hydrator = new ObjectPropertyHydrator();
486
                $hydrator->hydrate($dataPost, $company);
487
 
488
                $companyMapper->updateFoundationYear($company);
489
 
490
                $this->logger->info('Se actualizo el año de fundación de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
491
 
492
                return new JsonModel([
493
                    'success'   => true,
494
                    'data' => $company->foundation_year,
495
                ]);
496
 
497
            } else {
498
                $messages = [];
499
                $form_messages = (array) $form->getMessages();
500
                foreach($form_messages  as $fieldname => $field_messages)
501
                {
502
                    $messages[$fieldname] = array_values($field_messages);
503
                }
504
 
505
                return new JsonModel([
506
                    'success'   => false,
507
                    'data'   => $messages
508
                ]);
509
            }
510
        }
511
 
512
 
513
        $data = [
514
            'success' => false,
515
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
516
        ];
517
 
518
 
519
        return new JsonModel($data);
520
    }
521
 
522
 
523
    /**
524
     * Actualización de la ubucación
525
     * @return \Laminas\View\Model\JsonModel
526
     */
527
    public function locationAction()
528
    {
529
        $currentUserPlugin = $this->plugin('currentUserPlugin');
530
        $currentUser = $currentUserPlugin->getUser();
531
        $currentCompany = $currentUserPlugin->getCompany();
532
 
533
        $operation = $this->params()->fromRoute('operation');
534
        if($operation == 'edit' || $operation == 'delete') {
535
            $id = $this->params()->fromRoute('id');
536
            if(! $id) {
537
                $response = [
538
                    'success' => false,
539
                    'data' => 'ERROR_INVALID_PARAMETER'
540
                ];
541
 
542
                return new JsonModel($response);
543
            }
544
        } else {
545
            $id = '';
546
        }
547
 
548
 
549
 
550
 
551
 
552
 
553
 
554
 
555
        $request = $this->getRequest();
556
        if($request->isPost()) {
557
            $companyMapper = CompanyMapper::getInstance($this->adapter);
558
            $company = $companyMapper->fetchOne($currentCompany->id);
559
 
560
            $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
561
 
562
 
563
            $companyLocation = null;
564
            if($id) {
565
                $companyLocation = $companyLocationMapper->fetchOneByUuid($id);
566
                if(!$companyLocation) {
567
                    $response = [
568
                        'success' => false,
569
                        'data' => 'ERROR_RECORD_NOT_FOUND'
570
                    ];
571
 
572
                    return new JsonModel($response);
573
                }
574
 
575
                if($companyLocation->company_id != $company->id) {
576
                    $response = [
577
                        'success' => false,
578
                        'data' => 'ERROR_UNAUTHORIZED'
579
                    ];
580
                    return new JsonModel($response);
581
                }
582
            }
583
 
584
            $locationMapper = LocationMapper::getInstance($this->adapter);
585
            $response = [];
586
 
587
 
588
 
589
            if($operation == 'delete' && $companyLocation ) {
590
 
591
                if($companyLocationMapper->delete($companyLocation->id)) {
592
                    $this->logger->info('Se borrar una ubicación de la empresa: ' . $company->name, ['user_id' => $currentUser->id,  'ip' => Functions::getUserIP()]);
593
                    $locationMapper->delete($companyLocation->location_id);
594
 
595
                } else {
596
                    $response = [
597
                        'success'   => false,
598
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
599
                    ];
600
                }
601
 
602
 
603
            } else {
604
                $form = new CompanyProfileLocationForm();
605
                $dataPost = $request->getPost()->toArray();
606
 
607
 
608
                $dataPost['is_main'] = isset($dataPost['is_main']) ? $dataPost['is_main'] : CompanyLocation::IS_MAIN_NO;
609
 
610
 
611
                $form->setData($dataPost);
612
 
613
                if($form->isValid()) {
614
 
615
                    if($operation == 'edit') {
616
                        $location = $locationMapper->fetchOne($companyLocation->location_id);
617
                    } else {
618
                        $location = new Location();
619
                    }
620
 
621
                    $dataPost = (array) $form->getData();
622
                    $hydrator = new ObjectPropertyHydrator();
623
                    $hydrator->hydrate($dataPost, $location);
624
 
625
                    if($operation == 'edit') {
626
 
627
 
628
                        $companyLocation->is_main = $dataPost['is_main'];
629
                        $companyLocationMapper->update($companyLocation);
630
 
631
 
632
                        $location = $locationMapper->update($location);
633
                        $this->logger->info('Se actualizo una ubicación de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
634
 
635
 
636
                    } else {
637
 
638
                        $result = $locationMapper->insert($location);
639
 
640
                        if($result) {
641
                            $companyLocation = new CompanyLocation();
642
                            $companyLocation->company_id = $currentCompany->id;
643
                            $companyLocation->location_id = $location->id;
644
                            $companyLocation->is_main = $dataPost['is_main'];
645
 
646
                            $companyLocationMapper->insert($companyLocation);
647
                            $this->logger->info('Se agrego una ubicación a la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
648
                        } else {
649
                            $response = [
650
                                'success'   => false,
651
                                'data' => 'ERROR_THERE_WAS_AN_ERROR'
652
                            ];
653
                        }
654
                    }
655
                } else {
656
                    return new JsonModel([
657
                        'success'   => false,
658
                        'data'   =>   'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
659
                    ]);
660
                }
661
            }
662
 
663
            if(!$response) {
664
                $records = $companyLocationMapper->fetchAllLocationByCompanyId($currentCompany->id);
665
 
666
 
667
                $locations = [];
668
                foreach($records as $record)
669
                {
670
                    $location =  [
671
                        'formatted_address'  => $record['formatted_address'],
672
                        'country' => $record['country'],
673
                        'is_main' => $record['is_main'],
674
                        'link_edit' => $this->url()->fromRoute('profile/location', ['id' => $company->uuid, 'operation' => 'edit', 'company_location_id' => $record['company_location_uuid'] ]),
675
                        'link_delete' => $this->url()->fromRoute('profile/location', ['id' => $company->uuid, 'operation' => 'delete', 'company_location_id' => $record['company_location_uuid'] ])
676
 
677
                    ];
678
 
679
                    array_push($locations, $location);
680
                }
681
 
682
                $response = [
683
                    'success' => true,
684
                    'data' => $locations
685
                ];
686
 
687
 
688
            }
689
 
690
            return new JsonModel($response);
691
 
692
        } else if($request->isGet() && $operation == 'edit') {
693
 
694
 
695
 
696
            $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
697
            $companyLocation = $companyLocationMapper->fetchOneByUuid($id);
698
 
699
 
700
 
701
            if(!$companyLocation) {
702
                $response = [
703
                    'success' => false,
704
                    'data' => 'ERROR_RECORD_NOT_FOUND'
705
                ];
706
 
707
                return new JsonModel($response);
708
            }
709
 
710
            if($companyLocation->company_id != $currentCompany->id) {
711
                $response = [
712
                    'success' => false,
713
                    'data' => 'ERROR_UNAUTHORIZED'
714
                ];
715
                return new JsonModel($response);
716
            }
717
 
718
            $locationMapper = LocationMapper::getInstance($this->adapter);
719
            $location = $locationMapper->fetchOne($companyLocation->location_id);
720
 
721
            $hydrator = new ObjectPropertyHydrator();
722
            $data = $hydrator->extract($location);
723
 
724
            $data['is_main'] = $companyLocation->is_main;
725
 
726
            $response = [
727
                'success' => true,
728
                'data' =>  $data
729
            ];
730
 
731
            return new JsonModel($response);
732
 
733
        }
734
 
735
        $response = [
736
            'success' => false,
737
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
738
        ];
739
 
740
 
741
        return new JsonModel($response);
742
    }
743
 
744
    /**
745
     * Actualización de las redes sociales
746
     * @return \Laminas\View\Model\JsonModel
747
     */
748
    public function socialNetworkAction()
749
    {
750
 
751
 
752
        $currentUserPlugin = $this->plugin('currentUserPlugin');
753
        $currentUser = $currentUserPlugin->getUser();
754
        $currentCompany = $currentUserPlugin->getCompany();
755
 
756
 
757
 
758
        $request = $this->getRequest();
759
        if($request->isGet()) {
760
            $companyMapper = CompanyMapper::getInstance($this->adapter);
761
            $company = $companyMapper->fetchOne($currentCompany->id);
762
 
763
            $data = [
764
                'success' => true,
765
                'data' => [
766
                    'facebook' => $company->facebook,
767
                    'instagram' => $company->instagram,
768
                    'twitter' => $company->twitter
769
                ]
770
            ];
771
 
772
            return new JsonModel($data);
773
 
774
 
775
        } else if($request->isPost()) {
776
 
777
            $form = new CompanyProfileSocialNetworkForm();
778
            $dataPost = $request->getPost()->toArray();
779
 
780
            $form->setData($dataPost);
781
 
782
            if($form->isValid()) {
783
                $companyMapper = CompanyMapper::getInstance($this->adapter);
784
                $company = $companyMapper->fetchOne($currentCompany->id);
785
 
786
                $this->logger->info('Se actualizaron las redes sociales de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
787
 
788
                $dataPost = (array) $form->getData();
789
 
790
                $hydrator = new ObjectPropertyHydrator();
791
                $hydrator->hydrate($dataPost, $company);
792
 
793
                $companyMapper->updateSocialNetwork($company);
794
                return new JsonModel([
795
                    'success'   => true,
796
                    'data' => [
797
                        'facebook' => $company->facebook,
798
                        'instagram' => $company->instagram,
799
                        'twitter' => $company->twitter
800
                    ]
801
                ]);
802
 
803
            } else {
804
                $messages = [];
805
                $form_messages = (array) $form->getMessages();
806
                foreach($form_messages  as $fieldname => $field_messages)
807
                {
808
                    $messages[$fieldname] = array_values($field_messages);
809
                }
810
 
811
                return new JsonModel([
812
                    'success'   => false,
813
                    'data'   => $messages
814
                ]);
815
            }
816
        }
817
 
818
 
819
        $data = [
820
            'success' => false,
821
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
822
        ];
823
 
824
 
825
        return new JsonModel($data);
826
    }
827
 
828
 
829
 
830
    /**
831
     * Cambio de la imagen del image del perfil
832
     * @return \Laminas\View\Model\JsonModel
833
     */
834
    public function imageAction()
835
    {
836
        $currentUserPlugin = $this->plugin('currentUserPlugin');
837
        $currentUser = $currentUserPlugin->getUser();
838
        $currentCompany = $currentUserPlugin->getCompany();
839
 
840
        $operation  = $this->params()->fromRoute('operation');
841
 
842
 
843
 
844
 
845
 
846
        $request = $this->getRequest();
847
        if($request->isPost()) {
848
            $companyMapper = CompanyMapper::getInstance($this->adapter);
849
            $company = $companyMapper->fetchOne($currentCompany->id);
850
 
851
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
852
 
853
            if($operation == 'delete') {
854
                $this->logger->info('Se borro la imagen de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
855
 
856
                if($company->image) {
857
 
858
                    if(!Image::delete($target_path, $company->image)) {
859
                        return new JsonModel([
860
                            'success'   => false,
861
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
862
                        ]);
863
                    }
864
 
865
 
866
                }
867
 
868
                $company->image = '';
869
                if(!$companyMapper->updateImage($company)) {
870
                    return new JsonModel([
871
                        'success'   => false,
872
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
873
                    ]);
874
                }
875
 
876
            } else {
877
                $form = new CompanyProfileImageForm($this->config);
878
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
879
 
880
                $form->setData($data);
881
 
882
                if($form->isValid()) {
883
 
884
                    $files = $request->getFiles()->toArray();
885
                    if(!empty($files['image']['error'])) {
886
 
887
                        return new JsonModel([
888
                            'success'   => false,
889
                            'data'   =>  'ERROR_UPLOAD_FILE'
890
                        ]);
891
 
892
 
893
                    }
894
 
895
 
896
                    if($company->image) {
897
 
898
                        if(!Image::delete($target_path, $company->image)) {
899
                            return new JsonModel([
900
                                'success'   => false,
901
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
902
                            ]);
903
                        }
904
 
905
 
906
                    }
907
 
908
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_image_size']);
909
                    $source             = $files['image']['tmp_name'];
910
                    $target_filename    = 'company-image-' . uniqid() . '.png';
911
                    $crop_to_dimensions = true;
912
 
913
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
914
                        return new JsonModel([
915
                            'success'   => false,
916
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
917
                        ]);
918
                    }
919
 
920
 
921
                    $company->image = $target_filename;
922
                    if(!$companyMapper->updateImage($company)) {
923
                        return new JsonModel([
924
                            'success'   => false,
925
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
926
                        ]);
927
                    }
928
 
929
                    $this->logger->info('Se actualizo la imagen de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
930
 
931
                } else {
932
                    $messages = [];
933
                    $form_messages = (array) $form->getMessages();
934
                    foreach($form_messages  as $fieldname => $field_messages)
935
                    {
936
                        $messages[$fieldname] = array_values($field_messages);
937
                    }
938
 
939
                    return new JsonModel([
940
                        'success'   => false,
941
                        'data'   => $messages
942
                    ]);
943
                }
944
            }
945
            return new JsonModel([
946
                'success'   => true,
947
                'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image])
948
 
949
            ]);
950
        }
951
 
952
 
953
        $data = [
954
            'success' => false,
955
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
956
        ];
957
 
958
 
959
        return new JsonModel($data);
960
    }
961
 
962
    /**
963
     * Cambio de la imagen de fondo superior (cover) del perfil
964
     * @return \Laminas\View\Model\JsonModel
965
     */
966
    public function coverAction()
967
    {
968
        $operation          = $this->params()->fromRoute('operation');
969
 
970
 
971
        $currentUserPlugin = $this->plugin('currentUserPlugin');
972
        $currentUser = $currentUserPlugin->getUser();
973
        $currentCompany = $currentUserPlugin->getCompany();
974
 
975
 
976
 
977
 
978
        $request = $this->getRequest();
979
        if($request->isPost()) {
980
 
981
            $companyMapper = CompanyMapper::getInstance($this->adapter);
982
            $company = $companyMapper->fetchOne($currentCompany->id);
983
 
984
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
985
 
986
 
987
 
988
            if($operation == 'delete') {
989
                if($company->cover) {
990
 
991
                    if(!Image::delete($target_path, $company->cover)) {
992
                        return new JsonModel([
993
                            'success'   => false,
994
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
995
                        ]);
996
                    }
997
                }
998
 
999
                $this->logger->info('Se borro el cover de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1000
                $company->cover = '';
1001
                if(!$companyMapper->updateCover($company)) {
1002
                    return new JsonModel([
1003
                        'success'   => false,
1004
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1005
                    ]);
1006
                }
1007
 
1008
            } else {
1009
                $form = new CompanyProfileCoverForm($this->config);
1010
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1011
 
1012
                $form->setData($data);
1013
 
1014
                if($form->isValid()) {
1015
 
1016
 
1017
                    $files = $request->getFiles()->toArray();
1018
                    if(!empty($files['cover']['error'])) {
1019
 
1020
                        return new JsonModel([
1021
                            'success'   => false,
1022
                            'data'   =>  'ERROR_UPLOAD_FILE'
1023
                        ]);
1024
 
1025
 
1026
                    }
1027
 
1028
                    if($company->cover) {
1029
 
1030
                        if(!Image::delete($target_path, $company->cover)) {
1031
                            return new JsonModel([
1032
                                'success'   => false,
1033
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1034
                            ]);
1035
                        }
1036
                    }
1037
 
1038
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_size']);
1039
                    $source             = $files['cover']['tmp_name'];
1040
                    $target_filename    = 'company-cover-' . uniqid() . '.png';
1041
                    $crop_to_dimensions = false;
1042
 
1043
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1044
                        return new JsonModel([
1045
                            'success'   => false,
1046
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1047
                        ]);
1048
                    }
1049
 
1050
 
1051
                    $company->cover = $target_filename;
1052
                    if(!$companyMapper->updateCover($company)) {
1053
                        return new JsonModel([
1054
                            'success'   => false,
1055
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1056
                        ]);
1057
                    }
1058
 
1059
 
1060
 
1061
 
1062
                    $this->logger->info('Se actualizo el cover  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1063
 
1064
                } else {
1065
                    $messages = [];
1066
                    $form_messages = (array) $form->getMessages();
1067
                    foreach($form_messages  as $fieldname => $field_messages)
1068
                    {
1069
                        $messages[$fieldname] = array_values($field_messages);
1070
                    }
1071
 
1072
                    return new JsonModel([
1073
                        'success'   => false,
1074
                        'data'   => $messages
1075
                    ]);
1076
                }
1077
            }
1078
            return new JsonModel([
1079
                'success'   => true,
1080
                'data' => $this->url()->fromRoute('storage', ['type' => 'company-cover', 'code' => $company->uuid, 'filename' => $company->cover])
1081
 
1082
            ]);
1083
        }
1084
 
1085
 
1086
        $data = [
1087
            'success' => false,
1088
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1089
        ];
1090
 
1091
 
1092
        return new JsonModel($data);
1093
    }
768 geraldo 1094
 
1095
 
1096
 
1097
     /**
1098
     * Cambio de la imagen de de la cabecera de los reportes
1099
     * @return \Laminas\View\Model\JsonModel
1100
     */
1101
    public function headerAction()
1102
    {
1103
        $operation = $this->params()->fromRoute('operation');
1104
 
1105
 
1106
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1107
        $currentUser = $currentUserPlugin->getUser();
1108
        $currentCompany = $currentUserPlugin->getCompany();
1109
 
1110
 
1111
 
1112
 
1113
        $request = $this->getRequest();
1114
        if($request->isPost()) {
1115
 
1116
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1117
            $company = $companyMapper->fetchOne($currentCompany->id);
1118
 
1119
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1120
 
1121
 
1122
 
1123
            if($operation == 'delete') {
1124
                if($company->header) {
1125
 
1126
                    if(!Image::delete($target_path, $company->header)) {
1127
                        return new JsonModel([
1128
                            'success'   => false,
1129
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1130
                        ]);
1131
                    }
1132
                }
1133
 
1134
                $this->logger->info('Se borro el header  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1135
                $company->header = '';
1136
                if(!$companyMapper->updateHeader($company)) {
1137
                    return new JsonModel([
1138
                        'success'   => false,
1139
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1140
                    ]);
1141
                }
1142
 
1143
            } else {
1144
                $form = new CompanyProfileHeaderForm($this->config);
1145
                $data   = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1146
 
1147
                $form->setData($data);
1148
 
1149
                if($form->isValid()) {
1150
 
1151
 
1152
                    $files = $request->getFiles()->toArray();
1153
                    if(!empty($files['header']['error'])) {
1154
 
1155
                        return new JsonModel([
1156
                            'success'   => false,
1157
                            'data'   =>  'ERROR_UPLOAD_FILE'
1158
                        ]);
1159
 
1160
 
1161
                    }
1162
 
1163
                    if($company->header) {
1164
 
1165
                        if(!Image::delete($target_path, $company->header)) {
1166
                            return new JsonModel([
1167
                                'success'   => false,
1168
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1169
                            ]);
1170
                        }
1171
                    }
1172
 
1101 geraldo 1173
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_header_pdf_size']);
768 geraldo 1174
                    $source             = $files['header']['tmp_name'];
1175
                    $target_filename    = 'company-header-' . uniqid() . '.png';
1176
                    $crop_to_dimensions = false;
1177
 
1178
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1179
                        return new JsonModel([
1180
                            'success'   => false,
1181
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1182
                        ]);
1183
                    }
1184
 
1185
 
1186
                    $company->header = $target_filename;
1187
                    if(!$companyMapper->updateHeader($company)) {
1188
                        return new JsonModel([
1189
                            'success'   => false,
1190
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1191
                        ]);
1192
                    }
1193
 
1194
 
1195
                    $this->logger->info('Se actualizo el header  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1196
 
1197
                } else {
1198
                    $messages = [];
1199
                    $form_messages = (array) $form->getMessages();
1200
                    foreach($form_messages  as $fieldname => $field_messages)
1201
                    {
1202
                        $messages[$fieldname] = array_values($field_messages);
1203
                    }
1204
 
1205
                    return new JsonModel([
1206
                        'success'   => false,
1207
                        'data'   => $messages
1208
                    ]);
1209
                }
1210
            }
1211
            return new JsonModel([
1212
                'success'   => true,
810 geraldo 1213
                'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->header])
768 geraldo 1214
 
1215
            ]);
1216
        }
1217
 
1218
 
1219
        $data = [
1220
            'success' => false,
1221
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1222
        ];
1223
 
1224
 
1225
        return new JsonModel($data);
1226
    }
1227
 
1228
 
1229
     /**
1230
     * Cambio de la imagen de de la cabecera de los reportes
1231
     * @return \Laminas\View\Model\JsonModel
1232
     */
1233
    public function footerAction()
1234
    {
1235
        $operation          = $this->params()->fromRoute('operation');
1236
 
1237
 
1238
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1239
        $currentUser = $currentUserPlugin->getUser();
1240
        $currentCompany = $currentUserPlugin->getCompany();
1241
 
1242
 
1243
 
1244
 
1245
        $request = $this->getRequest();
1246
        if($request->isPost()) {
1247
 
1248
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1249
            $company = $companyMapper->fetchOne($currentCompany->id);
1250
 
1251
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1252
 
1253
 
1254
 
1255
            if($operation == 'delete') {
1256
                if($company->footer) {
1257
 
1258
                    if(!Image::delete($target_path, $company->footer)) {
1259
                        return new JsonModel([
1260
                            'success'   => false,
1261
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1262
                        ]);
1263
                    }
1264
                }
1265
 
1266
                $this->logger->info('Se borro el footer  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1267
                $company->footer = '';
1268
                if(!$companyMapper->updateFooter($company)) {
1269
                    return new JsonModel([
1270
                        'success'   => false,
1271
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1272
                    ]);
1273
                }
1274
 
1275
            } else {
1276
                $form = new CompanyProfileFooterForm($this->config);
1277
                $data   = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1278
 
1279
                $form->setData($data);
1280
 
1281
                if($form->isValid()) {
1282
 
1283
 
1284
                    $files = $request->getFiles()->toArray();
1285
                    if(!empty($files['footer']['error'])) {
1286
 
1287
                        return new JsonModel([
1288
                            'success'   => false,
1289
                            'data'   =>  'ERROR_UPLOAD_FILE'
1290
                        ]);
1291
 
1292
 
1293
                    }
1294
 
1295
                    if($company->footer) {
1296
 
1297
                        if(!Image::delete($target_path, $company->footer)) {
1298
                            return new JsonModel([
1299
                                'success'   => false,
1300
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1301
                            ]);
1302
                        }
1303
                    }
1304
 
1101 geraldo 1305
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_footer_pdf_size']);
768 geraldo 1306
                    $source             = $files['footer']['tmp_name'];
1307
                    $target_filename    = 'company-footer-' . uniqid() . '.png';
1308
                    $crop_to_dimensions = false;
1309
 
1310
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1311
                        return new JsonModel([
1312
                            'success'   => false,
1313
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1314
                        ]);
1315
                    }
1316
 
1317
 
1318
                    $company->footer = $target_filename;
1319
                    if(!$companyMapper->updateFooter($company)) {
1320
                        return new JsonModel([
1321
                            'success'   => false,
1322
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1323
                        ]);
1324
                    }
1325
 
1326
 
1327
 
1328
 
1329
                    $this->logger->info('Se actualizo el footer  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1330
 
1331
                } else {
1332
                    $messages = [];
1333
                    $form_messages = (array) $form->getMessages();
1334
                    foreach($form_messages  as $fieldname => $field_messages)
1335
                    {
1336
                        $messages[$fieldname] = array_values($field_messages);
1337
                    }
1338
 
1339
                    return new JsonModel([
1340
                        'success'   => false,
1341
                        'data'   => $messages
1342
                    ]);
1343
                }
1344
            }
1345
            return new JsonModel([
1346
                'success'   => true,
810 geraldo 1347
                'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->footer])
768 geraldo 1348
 
1349
            ]);
1350
        }
1351
 
1352
 
1353
        $data = [
1354
            'success' => false,
1355
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1356
        ];
1357
 
1358
 
1359
        return new JsonModel($data);
1360
    }
1 www 1361
 
1362
    /**
1363
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
1364
     * @return \Laminas\View\Model\JsonModel
1365
     */
1366
    public function industryAction()
1367
    {
1368
 
1369
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1370
        $currentUser = $currentUserPlugin->getUser();
1371
        $currentCompany = $currentUserPlugin->getCompany();
1372
 
1373
 
1374
 
1375
 
1376
 
1377
 
1378
        $request = $this->getRequest();
1379
        if($request->isGet()) {
1380
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1381
            $company = $companyMapper->fetchOne($currentCompany->id);
1382
 
1383
            $industryMapper = IndustryMapper::getInstance($this->adapter);
1384
            $industry = $industryMapper->fetchOne($company->industry_id);
1385
 
1386
            $data = [
1387
                'success' => true,
1388
                'data' => [
1389
                    'industry_id' => $industry->uuid,
1390
                ]
1391
            ];
1392
 
1393
            return new JsonModel($data);
1394
 
1395
 
1396
        } else if($request->isPost()) {
1397
 
1398
 
1399
            $form = new CompanyProfileIndustryForm($this->adapter);
1400
            $dataPost = $request->getPost()->toArray();
1401
 
1402
            $form->setData($dataPost);
1403
 
1404
            if($form->isValid()) {
1405
                $companyMapper = CompanyMapper::getInstance($this->adapter);
1406
                $company = $companyMapper->fetchOne($currentCompany->id);
1407
 
1408
                $dataPost = (array) $form->getData();
1409
 
1410
                $industryMapper = IndustryMapper::getInstance($this->adapter);
1411
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
1412
 
1413
                $company->industry_id = $industry->id;
1414
                $companyMapper->updateIndustry($company);
1415
 
1416
                $this->logger->info('Se actualizo la industria de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1417
 
1418
                $industryMapper = IndustryMapper::getInstance($this->adapter);
1419
                $industry = $industryMapper->fetchOne($company->industry_id);
1420
 
1421
                return new JsonModel([
1422
                    'success'   => true,
1423
                    'data' =>  $industry->name,
1424
 
1425
                ]);
1426
 
1427
            } else {
1428
                $messages = [];
1429
                $form_messages = (array) $form->getMessages();
1430
                foreach($form_messages  as $fieldname => $field_messages)
1431
                {
1432
                    $messages[$fieldname] = array_values($field_messages);
1433
                }
1434
 
1435
                return new JsonModel([
1436
                    'success'   => false,
1437
                    'data'   => $messages
1438
                ]);
1439
            }
1440
        }
1441
 
1442
 
1443
        $data = [
1444
            'success' => false,
1445
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1446
        ];
1447
 
1448
 
1449
        return new JsonModel($data);
1450
    }
1451
 
1452
    /**
1453
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
1454
     * @return \Laminas\View\Model\JsonModel
1455
     */
1456
    public function companySizeAction()
1457
    {
1458
 
1459
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1460
        $currentUser = $currentUserPlugin->getUser();
1461
        $currentCompany = $currentUserPlugin->getCompany();
1462
 
1463
 
1464
 
1465
 
1466
        $request = $this->getRequest();
1467
        if($request->isGet()) {
1468
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1469
            $company = $companyMapper->fetchOne($currentCompany->id);
1470
 
1471
            $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
1472
            $companySize = $companySizeMapper->fetchOne($company->company_size_id);
1473
 
1474
            $data = [
1475
                'success' => true,
1476
                'data' => [
1477
                    'company_size_id' => $companySize->uuid
1478
                ]
1479
            ];
1480
 
1481
            return new JsonModel($data);
1482
 
1483
 
1484
        } else if($request->isPost()) {
1485
 
1486
 
1487
            $form = new CompanyProfileCompanySizeForm($this->adapter);
1488
            $dataPost = $request->getPost()->toArray();
1489
 
1490
            $form->setData($dataPost);
1491
 
1492
            if($form->isValid()) {
1493
                $companyMapper = CompanyMapper::getInstance($this->adapter);
1494
                $company = $companyMapper->fetchOne($currentCompany->id);
1495
 
1496
                $dataPost = (array) $form->getData();
1497
 
1498
                $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
1499
                $companySize = $companySizeMapper->fetchOneByUuid($dataPost['company_size_id']);
1500
 
1501
                $company->company_size_id = $companySize->id;
1502
                $companyMapper->updateIndustry($company);
1503
 
1504
                $this->logger->info('Se actualizo la industria de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1505
 
1506
                $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
1507
                $companySize = $companySizeMapper->fetchOne($company->company_size_id);
1508
 
1509
                return new JsonModel([
1510
                    'success'   => true,
1511
                    'data' => $companySize->name . ' (' . $companySize->minimum_no_of_employee .'-' . $companySize->maximum_no_of_employee . ')',
1512
 
1513
                ]);
1514
 
1515
            } else {
1516
                $messages = [];
1517
                $form_messages = (array) $form->getMessages();
1518
                foreach($form_messages  as $fieldname => $field_messages)
1519
                {
1520
                    $messages[$fieldname] = array_values($field_messages);
1521
                }
1522
 
1523
                return new JsonModel([
1524
                    'success'   => false,
1525
                    'data'   => $messages
1526
                ]);
1527
            }
1528
        }
1529
 
1530
 
1531
        $data = [
1532
            'success' => false,
1533
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1534
        ];
1535
 
1536
 
1537
        return new JsonModel($data);
1538
    }
1539
}