Proyectos de Subversion LeadersLinked - Backend

Rev

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