Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 4278 | Rev 6597 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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