Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 780 | Rev 782 | 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,
781 geraldo 203
                'image_size_header'    => $image_size_header,
204
                'image_size_footer'    => $image_size_footer,
1 www 205
            ]);
206
            return $viewModel ;
207
 
208
        } else {
209
            $data = [
210
                'success' => false,
211
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
212
            ];
213
 
214
            return new JsonModel($data);
215
        }
216
 
217
        return new JsonModel($data);
218
    }
219
 
220
 
221
    /**
222
     *
223
     * Borrar un perfil excepto el público
224
     * @return \Laminas\View\Model\JsonModel
225
     */
226
    public function deleteAction()
227
    {
228
 
229
        $currentUserPlugin = $this->plugin('currentUserPlugin');
230
        $currentUser = $currentUserPlugin->getUser();
231
        $currentCompany = $currentUserPlugin->getCompany();
232
 
233
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
234
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $currentUser->id);
235
 
236
        if(!$companyUser || $companyUser->type != CompanyUser::CREATOR_YES) {
237
            $response = [
238
                'success' => false,
239
                'data' => 'ERROR_UNAUTHORIZED'
240
            ];
241
 
242
            return new JsonModel($response);
243
        }
244
 
245
 
246
        if($request->isPost()) {
247
            $companyMapper = CompanyMapper::getInstance($this->adapter);
248
            $result = $companyMapper->delete($companyUser->id);
249
            if($result) {
250
                $this->logger->info('Se borro la empresa : ' .  $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
251
 
252
                $data = [
253
                    'success' => true,
254
                    'data' => 'LABEL_RECORD_DELETED'
255
                ];
256
            } else {
257
 
258
                $data = [
259
                    'success'   => false,
260
                    'data'      => $companyUserMapper->getError()
261
                ];
262
 
263
                return new JsonModel($data);
264
            }
265
 
266
        } else {
267
            $data = [
268
                'success' => false,
269
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
270
            ];
271
 
272
            return new JsonModel($data);
273
        }
274
 
275
        return new JsonModel($data);
276
    }
277
 
278
 
279
 
280
    /**
281
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
282
     * @return \Laminas\View\Model\JsonModel
283
     */
284
    public function extendedAction()
285
    {
286
 
287
 
288
        $currentUserPlugin = $this->plugin('currentUserPlugin');
289
        $currentUser = $currentUserPlugin->getUser();
290
        $currentCompany = $currentUserPlugin->getCompany();
291
 
292
 
293
 
294
 
295
 
296
        $request = $this->getRequest();
297
        if($request->isGet()) {
298
            $companyMapper = CompanyMapper::getInstance($this->adapter);
299
            $company = $companyMapper->fetchOne($currentCompany->id);
300
 
301
            $data = [
302
                'success' => true,
303
                'data' => [
304
                    'description' => $company->description,
305
                ]
306
            ];
307
 
308
            return new JsonModel($data);
309
 
310
 
311
        } else if($request->isPost()) {
312
            $form = new CompanyProfileExtendedForm();
313
            $dataPost = $request->getPost()->toArray();
314
 
315
            $form->setData($dataPost);
316
 
317
            if($form->isValid()) {
318
                $companyMapper = CompanyMapper::getInstance($this->adapter);
319
                $company = $companyMapper->fetchOne($currentCompany->id);
320
 
321
                $dataPost = (array) $form->getData();
322
 
323
                $hydrator = new ObjectPropertyHydrator();
324
                $hydrator->hydrate($dataPost, $company);
325
 
326
                $companyMapper->updateExtended($company);
327
 
328
                $this->logger->info('Se actualizo las descripción de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
329
 
330
                return new JsonModel([
331
                    'success'   => true,
332
                    'data' => [
333
                        'description' => $company->description,
334
                    ]
335
                ]);
336
 
337
            } else {
338
                $messages = [];
339
                $form_messages = (array) $form->getMessages();
340
                foreach($form_messages  as $fieldname => $field_messages)
341
                {
342
                    $messages[$fieldname] = array_values($field_messages);
343
                }
344
 
345
                return new JsonModel([
346
                    'success'   => false,
347
                    'data'   => $messages
348
                ]);
349
            }
350
        }
351
 
352
 
353
        $data = [
354
            'success' => false,
355
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
356
        ];
357
 
358
 
359
        return new JsonModel($data);
360
    }
361
 
362
    /**
363
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
364
     * @return \Laminas\View\Model\JsonModel
365
     */
366
    public function websiteAction()
367
    {
368
        $currentUserPlugin = $this->plugin('currentUserPlugin');
369
        $currentUser = $currentUserPlugin->getUser();
370
        $currentCompany = $currentUserPlugin->getCompany();
371
 
372
        $request = $this->getRequest();
373
        if($request->isGet()) {
374
            $companyMapper = CompanyMapper::getInstance($this->adapter);
375
            $company = $companyMapper->fetchOne($currentCompany->id);
376
 
377
            $data = [
378
                'success' => true,
379
                'data' => [
380
                    'website' => $company->website,
381
                ]
382
            ];
383
 
384
            return new JsonModel($data);
385
 
386
 
387
        } else if($request->isPost()) {
388
 
389
 
390
            $form = new CompanyProfileWebsiteForm();
391
            $dataPost = $request->getPost()->toArray();
392
 
393
            $form->setData($dataPost);
394
 
395
            if($form->isValid()) {
396
                $companyMapper = CompanyMapper::getInstance($this->adapter);
397
                $company = $companyMapper->fetchOne($currentCompany->id);
398
 
399
                $dataPost = (array) $form->getData();
400
 
401
                $hydrator = new ObjectPropertyHydrator();
402
                $hydrator->hydrate($dataPost, $company);
403
 
404
                $companyMapper->updateWebsite($company);
405
 
406
                $this->logger->info('Se actualizo el website de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
407
 
408
                return new JsonModel([
409
                    'success'   => true,
410
                    'data' => [
411
                        'website' => $company->website,
412
                    ]
413
                ]);
414
 
415
            } else {
416
                $messages = [];
417
                $form_messages = (array) $form->getMessages();
418
                foreach($form_messages  as $fieldname => $field_messages)
419
                {
420
                    $messages[$fieldname] = array_values($field_messages);
421
                }
422
 
423
                return new JsonModel([
424
                    'success'   => false,
425
                    'data'   => $messages
426
                ]);
427
            }
428
        }
429
 
430
 
431
        $data = [
432
            'success' => false,
433
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
434
        ];
435
 
436
 
437
        return new JsonModel($data);
438
    }
439
 
440
    /**
441
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
442
     * @return \Laminas\View\Model\JsonModel
443
     */
444
    public function foundationYearAction()
445
    {
446
 
447
        $currentUserPlugin = $this->plugin('currentUserPlugin');
448
        $currentUser = $currentUserPlugin->getUser();
449
        $currentCompany = $currentUserPlugin->getCompany();
450
 
451
 
452
 
453
        $request = $this->getRequest();
454
        if($request->isGet()) {
455
            $companyMapper = CompanyMapper::getInstance($this->adapter);
456
            $company = $companyMapper->fetchOne($currentCompany->id);
457
 
458
            $data = [
459
                'success' => true,
460
                'data' => [
461
                    'foundation_year' => $company->foundation_year,
462
                ]
463
 
464
            ];
465
 
466
            return new JsonModel($data);
467
 
468
 
469
        } else if($request->isPost()) {
470
 
471
 
472
            $form = new CompanyProfileFoundationYearForm();
473
            $dataPost = $request->getPost()->toArray();
474
 
475
            $form->setData($dataPost);
476
 
477
            if($form->isValid()) {
478
                $companyMapper = CompanyMapper::getInstance($this->adapter);
479
                $company = $companyMapper->fetchOne($currentCompany->id);
480
 
481
                $dataPost = (array) $form->getData();
482
 
483
                $hydrator = new ObjectPropertyHydrator();
484
                $hydrator->hydrate($dataPost, $company);
485
 
486
                $companyMapper->updateFoundationYear($company);
487
 
488
                $this->logger->info('Se actualizo el año de fundación de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
489
 
490
                return new JsonModel([
491
                    'success'   => true,
492
                    'data' => $company->foundation_year,
493
                ]);
494
 
495
            } else {
496
                $messages = [];
497
                $form_messages = (array) $form->getMessages();
498
                foreach($form_messages  as $fieldname => $field_messages)
499
                {
500
                    $messages[$fieldname] = array_values($field_messages);
501
                }
502
 
503
                return new JsonModel([
504
                    'success'   => false,
505
                    'data'   => $messages
506
                ]);
507
            }
508
        }
509
 
510
 
511
        $data = [
512
            'success' => false,
513
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
514
        ];
515
 
516
 
517
        return new JsonModel($data);
518
    }
519
 
520
 
521
    /**
522
     * Actualización de la ubucación
523
     * @return \Laminas\View\Model\JsonModel
524
     */
525
    public function locationAction()
526
    {
527
        $currentUserPlugin = $this->plugin('currentUserPlugin');
528
        $currentUser = $currentUserPlugin->getUser();
529
        $currentCompany = $currentUserPlugin->getCompany();
530
 
531
        $operation = $this->params()->fromRoute('operation');
532
        if($operation == 'edit' || $operation == 'delete') {
533
            $id = $this->params()->fromRoute('id');
534
            if(! $id) {
535
                $response = [
536
                    'success' => false,
537
                    'data' => 'ERROR_INVALID_PARAMETER'
538
                ];
539
 
540
                return new JsonModel($response);
541
            }
542
        } else {
543
            $id = '';
544
        }
545
 
546
 
547
 
548
 
549
 
550
 
551
 
552
 
553
        $request = $this->getRequest();
554
        if($request->isPost()) {
555
            $companyMapper = CompanyMapper::getInstance($this->adapter);
556
            $company = $companyMapper->fetchOne($currentCompany->id);
557
 
558
            $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
559
 
560
 
561
            $companyLocation = null;
562
            if($id) {
563
                $companyLocation = $companyLocationMapper->fetchOneByUuid($id);
564
                if(!$companyLocation) {
565
                    $response = [
566
                        'success' => false,
567
                        'data' => 'ERROR_RECORD_NOT_FOUND'
568
                    ];
569
 
570
                    return new JsonModel($response);
571
                }
572
 
573
                if($companyLocation->company_id != $company->id) {
574
                    $response = [
575
                        'success' => false,
576
                        'data' => 'ERROR_UNAUTHORIZED'
577
                    ];
578
                    return new JsonModel($response);
579
                }
580
            }
581
 
582
            $locationMapper = LocationMapper::getInstance($this->adapter);
583
            $response = [];
584
 
585
 
586
 
587
            if($operation == 'delete' && $companyLocation ) {
588
 
589
                if($companyLocationMapper->delete($companyLocation->id)) {
590
                    $this->logger->info('Se borrar una ubicación de la empresa: ' . $company->name, ['user_id' => $currentUser->id,  'ip' => Functions::getUserIP()]);
591
                    $locationMapper->delete($companyLocation->location_id);
592
 
593
                } else {
594
                    $response = [
595
                        'success'   => false,
596
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
597
                    ];
598
                }
599
 
600
 
601
            } else {
602
                $form = new CompanyProfileLocationForm();
603
                $dataPost = $request->getPost()->toArray();
604
 
605
 
606
                $dataPost['is_main'] = isset($dataPost['is_main']) ? $dataPost['is_main'] : CompanyLocation::IS_MAIN_NO;
607
 
608
 
609
                $form->setData($dataPost);
610
 
611
                if($form->isValid()) {
612
 
613
                    if($operation == 'edit') {
614
                        $location = $locationMapper->fetchOne($companyLocation->location_id);
615
                    } else {
616
                        $location = new Location();
617
                    }
618
 
619
                    $dataPost = (array) $form->getData();
620
                    $hydrator = new ObjectPropertyHydrator();
621
                    $hydrator->hydrate($dataPost, $location);
622
 
623
                    if($operation == 'edit') {
624
 
625
 
626
                        $companyLocation->is_main = $dataPost['is_main'];
627
                        $companyLocationMapper->update($companyLocation);
628
 
629
 
630
                        $location = $locationMapper->update($location);
631
                        $this->logger->info('Se actualizo una ubicación de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
632
 
633
 
634
                    } else {
635
 
636
                        $result = $locationMapper->insert($location);
637
 
638
                        if($result) {
639
                            $companyLocation = new CompanyLocation();
640
                            $companyLocation->company_id = $currentCompany->id;
641
                            $companyLocation->location_id = $location->id;
642
                            $companyLocation->is_main = $dataPost['is_main'];
643
 
644
                            $companyLocationMapper->insert($companyLocation);
645
                            $this->logger->info('Se agrego una ubicación a la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
646
                        } else {
647
                            $response = [
648
                                'success'   => false,
649
                                'data' => 'ERROR_THERE_WAS_AN_ERROR'
650
                            ];
651
                        }
652
                    }
653
                } else {
654
                    return new JsonModel([
655
                        'success'   => false,
656
                        'data'   =>   'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
657
                    ]);
658
                }
659
            }
660
 
661
            if(!$response) {
662
                $records = $companyLocationMapper->fetchAllLocationByCompanyId($currentCompany->id);
663
 
664
 
665
                $locations = [];
666
                foreach($records as $record)
667
                {
668
                    $location =  [
669
                        'formatted_address'  => $record['formatted_address'],
670
                        'country' => $record['country'],
671
                        'is_main' => $record['is_main'],
672
                        'link_edit' => $this->url()->fromRoute('profile/location', ['id' => $company->uuid, 'operation' => 'edit', 'company_location_id' => $record['company_location_uuid'] ]),
673
                        'link_delete' => $this->url()->fromRoute('profile/location', ['id' => $company->uuid, 'operation' => 'delete', 'company_location_id' => $record['company_location_uuid'] ])
674
 
675
                    ];
676
 
677
                    array_push($locations, $location);
678
                }
679
 
680
                $response = [
681
                    'success' => true,
682
                    'data' => $locations
683
                ];
684
 
685
 
686
            }
687
 
688
            return new JsonModel($response);
689
 
690
        } else if($request->isGet() && $operation == 'edit') {
691
 
692
 
693
 
694
            $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
695
            $companyLocation = $companyLocationMapper->fetchOneByUuid($id);
696
 
697
 
698
 
699
            if(!$companyLocation) {
700
                $response = [
701
                    'success' => false,
702
                    'data' => 'ERROR_RECORD_NOT_FOUND'
703
                ];
704
 
705
                return new JsonModel($response);
706
            }
707
 
708
            if($companyLocation->company_id != $currentCompany->id) {
709
                $response = [
710
                    'success' => false,
711
                    'data' => 'ERROR_UNAUTHORIZED'
712
                ];
713
                return new JsonModel($response);
714
            }
715
 
716
            $locationMapper = LocationMapper::getInstance($this->adapter);
717
            $location = $locationMapper->fetchOne($companyLocation->location_id);
718
 
719
            $hydrator = new ObjectPropertyHydrator();
720
            $data = $hydrator->extract($location);
721
 
722
            $data['is_main'] = $companyLocation->is_main;
723
 
724
            $response = [
725
                'success' => true,
726
                'data' =>  $data
727
            ];
728
 
729
            return new JsonModel($response);
730
 
731
        }
732
 
733
        $response = [
734
            'success' => false,
735
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
736
        ];
737
 
738
 
739
        return new JsonModel($response);
740
    }
741
 
742
    /**
743
     * Actualización de las redes sociales
744
     * @return \Laminas\View\Model\JsonModel
745
     */
746
    public function socialNetworkAction()
747
    {
748
 
749
 
750
        $currentUserPlugin = $this->plugin('currentUserPlugin');
751
        $currentUser = $currentUserPlugin->getUser();
752
        $currentCompany = $currentUserPlugin->getCompany();
753
 
754
 
755
 
756
        $request = $this->getRequest();
757
        if($request->isGet()) {
758
            $companyMapper = CompanyMapper::getInstance($this->adapter);
759
            $company = $companyMapper->fetchOne($currentCompany->id);
760
 
761
            $data = [
762
                'success' => true,
763
                'data' => [
764
                    'facebook' => $company->facebook,
765
                    'instagram' => $company->instagram,
766
                    'twitter' => $company->twitter
767
                ]
768
            ];
769
 
770
            return new JsonModel($data);
771
 
772
 
773
        } else if($request->isPost()) {
774
 
775
            $form = new CompanyProfileSocialNetworkForm();
776
            $dataPost = $request->getPost()->toArray();
777
 
778
            $form->setData($dataPost);
779
 
780
            if($form->isValid()) {
781
                $companyMapper = CompanyMapper::getInstance($this->adapter);
782
                $company = $companyMapper->fetchOne($currentCompany->id);
783
 
784
                $this->logger->info('Se actualizaron las redes sociales de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
785
 
786
                $dataPost = (array) $form->getData();
787
 
788
                $hydrator = new ObjectPropertyHydrator();
789
                $hydrator->hydrate($dataPost, $company);
790
 
791
                $companyMapper->updateSocialNetwork($company);
792
                return new JsonModel([
793
                    'success'   => true,
794
                    'data' => [
795
                        'facebook' => $company->facebook,
796
                        'instagram' => $company->instagram,
797
                        'twitter' => $company->twitter
798
                    ]
799
                ]);
800
 
801
            } else {
802
                $messages = [];
803
                $form_messages = (array) $form->getMessages();
804
                foreach($form_messages  as $fieldname => $field_messages)
805
                {
806
                    $messages[$fieldname] = array_values($field_messages);
807
                }
808
 
809
                return new JsonModel([
810
                    'success'   => false,
811
                    'data'   => $messages
812
                ]);
813
            }
814
        }
815
 
816
 
817
        $data = [
818
            'success' => false,
819
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
820
        ];
821
 
822
 
823
        return new JsonModel($data);
824
    }
825
 
826
 
827
 
828
    /**
829
     * Cambio de la imagen del image del perfil
830
     * @return \Laminas\View\Model\JsonModel
831
     */
832
    public function imageAction()
833
    {
834
        $currentUserPlugin = $this->plugin('currentUserPlugin');
835
        $currentUser = $currentUserPlugin->getUser();
836
        $currentCompany = $currentUserPlugin->getCompany();
837
 
838
        $operation  = $this->params()->fromRoute('operation');
839
 
840
 
841
 
842
 
843
 
844
        $request = $this->getRequest();
845
        if($request->isPost()) {
846
            $companyMapper = CompanyMapper::getInstance($this->adapter);
847
            $company = $companyMapper->fetchOne($currentCompany->id);
848
 
849
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
850
 
851
            if($operation == 'delete') {
852
                $this->logger->info('Se borro la imagen de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
853
 
854
                if($company->image) {
855
 
856
                    if(!Image::delete($target_path, $company->image)) {
857
                        return new JsonModel([
858
                            'success'   => false,
859
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
860
                        ]);
861
                    }
862
 
863
 
864
                }
865
 
866
                $company->image = '';
867
                if(!$companyMapper->updateImage($company)) {
868
                    return new JsonModel([
869
                        'success'   => false,
870
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
871
                    ]);
872
                }
873
 
874
            } else {
875
                $form = new CompanyProfileImageForm($this->config);
876
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
877
 
878
                $form->setData($data);
879
 
880
                if($form->isValid()) {
881
 
882
                    $files = $request->getFiles()->toArray();
883
                    if(!empty($files['image']['error'])) {
884
 
885
                        return new JsonModel([
886
                            'success'   => false,
887
                            'data'   =>  'ERROR_UPLOAD_FILE'
888
                        ]);
889
 
890
 
891
                    }
892
 
893
 
894
                    if($company->image) {
895
 
896
                        if(!Image::delete($target_path, $company->image)) {
897
                            return new JsonModel([
898
                                'success'   => false,
899
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
900
                            ]);
901
                        }
902
 
903
 
904
                    }
905
 
906
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_image_size']);
907
                    $source             = $files['image']['tmp_name'];
908
                    $target_filename    = 'company-image-' . uniqid() . '.png';
909
                    $crop_to_dimensions = true;
910
 
911
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
912
                        return new JsonModel([
913
                            'success'   => false,
914
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
915
                        ]);
916
                    }
917
 
918
 
919
                    $company->image = $target_filename;
920
                    if(!$companyMapper->updateImage($company)) {
921
                        return new JsonModel([
922
                            'success'   => false,
923
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
924
                        ]);
925
                    }
926
 
927
                    $this->logger->info('Se actualizo la imagen de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
928
 
929
                } else {
930
                    $messages = [];
931
                    $form_messages = (array) $form->getMessages();
932
                    foreach($form_messages  as $fieldname => $field_messages)
933
                    {
934
                        $messages[$fieldname] = array_values($field_messages);
935
                    }
936
 
937
                    return new JsonModel([
938
                        'success'   => false,
939
                        'data'   => $messages
940
                    ]);
941
                }
942
            }
943
            return new JsonModel([
944
                'success'   => true,
945
                'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image])
946
 
947
            ]);
948
        }
949
 
950
 
951
        $data = [
952
            'success' => false,
953
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
954
        ];
955
 
956
 
957
        return new JsonModel($data);
958
    }
959
 
960
    /**
961
     * Cambio de la imagen de fondo superior (cover) del perfil
962
     * @return \Laminas\View\Model\JsonModel
963
     */
964
    public function coverAction()
965
    {
966
        $operation          = $this->params()->fromRoute('operation');
967
 
968
 
969
        $currentUserPlugin = $this->plugin('currentUserPlugin');
970
        $currentUser = $currentUserPlugin->getUser();
971
        $currentCompany = $currentUserPlugin->getCompany();
972
 
973
 
974
 
975
 
976
        $request = $this->getRequest();
977
        if($request->isPost()) {
978
 
979
            $companyMapper = CompanyMapper::getInstance($this->adapter);
980
            $company = $companyMapper->fetchOne($currentCompany->id);
981
 
982
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
983
 
984
 
985
 
986
            if($operation == 'delete') {
987
                if($company->cover) {
988
 
989
                    if(!Image::delete($target_path, $company->cover)) {
990
                        return new JsonModel([
991
                            'success'   => false,
992
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
993
                        ]);
994
                    }
995
                }
996
 
997
                $this->logger->info('Se borro el cover de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
998
                $company->cover = '';
999
                if(!$companyMapper->updateCover($company)) {
1000
                    return new JsonModel([
1001
                        'success'   => false,
1002
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1003
                    ]);
1004
                }
1005
 
1006
            } else {
1007
                $form = new CompanyProfileCoverForm($this->config);
1008
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1009
 
1010
                $form->setData($data);
1011
 
1012
                if($form->isValid()) {
1013
 
1014
 
1015
                    $files = $request->getFiles()->toArray();
1016
                    if(!empty($files['cover']['error'])) {
1017
 
1018
                        return new JsonModel([
1019
                            'success'   => false,
1020
                            'data'   =>  'ERROR_UPLOAD_FILE'
1021
                        ]);
1022
 
1023
 
1024
                    }
1025
 
1026
                    if($company->cover) {
1027
 
1028
                        if(!Image::delete($target_path, $company->cover)) {
1029
                            return new JsonModel([
1030
                                'success'   => false,
1031
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1032
                            ]);
1033
                        }
1034
                    }
1035
 
1036
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_size']);
1037
                    $source             = $files['cover']['tmp_name'];
1038
                    $target_filename    = 'company-cover-' . uniqid() . '.png';
1039
                    $crop_to_dimensions = false;
1040
 
1041
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1042
                        return new JsonModel([
1043
                            'success'   => false,
1044
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1045
                        ]);
1046
                    }
1047
 
1048
 
1049
                    $company->cover = $target_filename;
1050
                    if(!$companyMapper->updateCover($company)) {
1051
                        return new JsonModel([
1052
                            'success'   => false,
1053
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1054
                        ]);
1055
                    }
1056
 
1057
 
1058
 
1059
 
1060
                    $this->logger->info('Se actualizo el cover  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1061
 
1062
                } else {
1063
                    $messages = [];
1064
                    $form_messages = (array) $form->getMessages();
1065
                    foreach($form_messages  as $fieldname => $field_messages)
1066
                    {
1067
                        $messages[$fieldname] = array_values($field_messages);
1068
                    }
1069
 
1070
                    return new JsonModel([
1071
                        'success'   => false,
1072
                        'data'   => $messages
1073
                    ]);
1074
                }
1075
            }
1076
            return new JsonModel([
1077
                'success'   => true,
1078
                'data' => $this->url()->fromRoute('storage', ['type' => 'company-cover', 'code' => $company->uuid, 'filename' => $company->cover])
1079
 
1080
            ]);
1081
        }
1082
 
1083
 
1084
        $data = [
1085
            'success' => false,
1086
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1087
        ];
1088
 
1089
 
1090
        return new JsonModel($data);
1091
    }
768 geraldo 1092
 
1093
 
1094
 
1095
     /**
1096
     * Cambio de la imagen de de la cabecera de los reportes
1097
     * @return \Laminas\View\Model\JsonModel
1098
     */
1099
    public function headerAction()
1100
    {
1101
        $operation = $this->params()->fromRoute('operation');
1102
 
1103
 
1104
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1105
        $currentUser = $currentUserPlugin->getUser();
1106
        $currentCompany = $currentUserPlugin->getCompany();
1107
 
1108
 
1109
 
1110
 
1111
        $request = $this->getRequest();
1112
        if($request->isPost()) {
1113
 
1114
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1115
            $company = $companyMapper->fetchOne($currentCompany->id);
1116
 
1117
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1118
 
1119
 
1120
 
1121
            if($operation == 'delete') {
1122
                if($company->header) {
1123
 
1124
                    if(!Image::delete($target_path, $company->header)) {
1125
                        return new JsonModel([
1126
                            'success'   => false,
1127
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1128
                        ]);
1129
                    }
1130
                }
1131
 
1132
                $this->logger->info('Se borro el header  de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1133
                $company->header = '';
1134
                if(!$companyMapper->updateHeader($company)) {
1135
                    return new JsonModel([
1136
                        'success'   => false,
1137
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1138
                    ]);
1139
                }
1140
 
1141
            } else {
1142
                $form = new CompanyProfileHeaderForm($this->config);
1143
                $data   = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1144
 
1145
                $form->setData($data);
1146
 
1147
                if($form->isValid()) {
1148
 
1149
 
1150
                    $files = $request->getFiles()->toArray();
1151
                    if(!empty($files['header']['error'])) {
1152
 
1153
                        return new JsonModel([
1154
                            'success'   => false,
1155
                            'data'   =>  'ERROR_UPLOAD_FILE'
1156
                        ]);
1157
 
1158
 
1159
                    }
1160
 
1161
                    if($company->header) {
1162
 
1163
                        if(!Image::delete($target_path, $company->header)) {
1164
                            return new JsonModel([
1165
                                'success'   => false,
1166
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1167
                            ]);
1168
                        }
1169
                    }
1170
 
780 geraldo 1171
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_size']);
768 geraldo 1172
                    $source             = $files['header']['tmp_name'];
1173
                    $target_filename    = 'company-header-' . uniqid() . '.png';
1174
                    $crop_to_dimensions = false;
1175
 
1176
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1177
                        return new JsonModel([
1178
                            'success'   => false,
1179
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1180
                        ]);
1181
                    }
1182
 
1183
 
1184
                    $company->header = $target_filename;
1185
                    if(!$companyMapper->updateHeader($company)) {
1186
                        return new JsonModel([
1187
                            'success'   => false,
1188
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1189
                        ]);
1190
                    }
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,
1213
                'data' => $this->url()->fromRoute('storage', ['type' => 'company-header', 'code' => $company->uuid, 'filename' => $company->header])
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
 
780 geraldo 1305
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_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,
1347
                'data' => $this->url()->fromRoute('storage', ['type' => 'company-footer', 'code' => $company->uuid, 'filename' => $company->footer])
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
}