Proyectos de Subversion LeadersLinked - Backend

Rev

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