Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16954 Rev 17167
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
Línea 23... Línea 24...
23
use LeadersLinked\Mapper\CompanyUserRoleMapper;
24
use LeadersLinked\Mapper\CompanyUserRoleMapper;
24
use LeadersLinked\Mapper\RoleMapper;
25
use LeadersLinked\Mapper\RoleMapper;
25
use LeadersLinked\Model\UserType;
26
use LeadersLinked\Model\UserType;
26
use LeadersLinked\Model\UserPassword;
27
use LeadersLinked\Model\UserPassword;
27
use PhpOffice\PhpSpreadsheet\IOFactory;
28
use PhpOffice\PhpSpreadsheet\IOFactory;
28
use LeadersLinked\Form\UserUploadForm;
29
use LeadersLinked\Form\User\UserUploadForm;
29
use LeadersLinked\Mapper\CompanyServiceMapper;
30
use LeadersLinked\Mapper\CompanyServiceMapper;
30
use LeadersLinked\Model\CompanyService;
31
use LeadersLinked\Model\CompanyService;
31
use LeadersLinked\Model\Role;
32
use LeadersLinked\Model\Role;
32
use LeadersLinked\Mapper\CompanyRoleMapper;
33
use LeadersLinked\Mapper\CompanyRoleMapper;
33
use LeadersLinked\Model\CompanyUserRole;
34
use LeadersLinked\Model\CompanyUserRole;
Línea 57... Línea 58...
57
    /**
58
    /**
58
     *
59
     *
59
     * @var \Laminas\Db\Adapter\AdapterInterface
60
     * @var \Laminas\Db\Adapter\AdapterInterface
60
     */
61
     */
61
    private $adapter;
62
    private $adapter;
62
    
63
 
63
    /**
64
    /**
64
     *
65
     *
65
     * @var \LeadersLinked\Cache\CacheInterface
66
     * @var \LeadersLinked\Cache\CacheInterface
66
     */
67
     */
67
    private $cache;
68
    private $cache;
68
    
69
 
69
    
70
 
70
    /**
71
    /**
71
     *
72
     *
72
     * @var \Laminas\Log\LoggerInterface
73
     * @var \Laminas\Log\LoggerInterface
73
     */
74
     */
74
    private $logger;
75
    private $logger;
75
    
76
 
76
    /**
77
    /**
77
     *
78
     *
78
     * @var array
79
     * @var array
79
     */
80
     */
80
    private $config;
81
    private $config;
81
    
82
 
82
    
83
 
83
    /**
84
    /**
84
     *
85
     *
85
     * @var \Laminas\Mvc\I18n\Translator
86
     * @var \Laminas\Mvc\I18n\Translator
86
     */
87
     */
87
    private $translator;
88
    private $translator;
88
    
89
 
89
    
90
 
90
    /**
91
    /**
91
     *
92
     *
92
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
93
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
93
     * @param \LeadersLinked\Cache\CacheInterface $cache
94
     * @param \LeadersLinked\Cache\CacheInterface $cache
94
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
95
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
Línea 101... Línea 102...
101
        $this->cache        = $cache;
102
        $this->cache        = $cache;
102
        $this->logger       = $logger;
103
        $this->logger       = $logger;
103
        $this->config       = $config;
104
        $this->config       = $config;
104
        $this->translator   = $translator;
105
        $this->translator   = $translator;
105
    }
106
    }
106
    
107
 
107
    public function indexAction()
108
    public function indexAction()
108
    {
109
    {
109
        $currentUserPlugin = $this->plugin('currentUserPlugin');
110
        $currentUserPlugin = $this->plugin('currentUserPlugin');
110
        $currentUser = $currentUserPlugin->getUser();
111
        $currentUser = $currentUserPlugin->getUser();
111
        $currentCompany = $currentUserPlugin->getCompany();
112
        $currentCompany = $currentUserPlugin->getCompany();
112
        
113
 
113
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
114
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
114
        $currentNetwork = $currentNetworkPlugin->getNetwork();
115
        $currentNetwork = $currentNetworkPlugin->getNetwork();
115
        
116
 
116
        
117
 
117
        $request = $this->getRequest();
118
        $request = $this->getRequest();
118
        
119
 
119
        if($request->isGet())
120
        if ($request->isGet())
120
        
121
 
121
            
122
 
122
            $headers  = $request->getHeaders();
123
            $headers  = $request->getHeaders();
123
            
124
 
124
            $isJson = false;
125
        $isJson = false;
125
            if($headers->has('Accept')) {
126
        if ($headers->has('Accept')) {
126
                $accept = $headers->get('Accept');
127
            $accept = $headers->get('Accept');
127
                
128
 
128
                $prioritized = $accept->getPrioritized();
129
            $prioritized = $accept->getPrioritized();
129
                
130
 
130
                foreach($prioritized as $key => $value) {
131
            foreach ($prioritized as $key => $value) {
131
                    $raw = trim($value->getRaw());
132
                $raw = trim($value->getRaw());
132
                    
133
 
133
                    if(!$isJson) {
134
                if (!$isJson) {
134
                        $isJson = strpos($raw, 'json');
135
                    $isJson = strpos($raw, 'json');
135
                    }
-
 
136
                    
-
 
137
                }
136
                }
138
            }
137
            }
-
 
138
        }
139
            
139
 
140
            if($isJson) {
140
        if ($isJson) { {
141
            {
-
 
142
                $network_id = $this->params()->fromQuery('network_id');
141
                $network_id = $this->params()->fromQuery('network_id');
143
                if($currentUser->is_super_user == User::IS_SUPER_USER_YES) {
142
                if ($currentUser->is_super_user == User::IS_SUPER_USER_YES) {
144
                    
143
 
145
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
144
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
146
                    $network = $networkMapper->fetchOneByUuid($network_id);
145
                    $network = $networkMapper->fetchOneByUuid($network_id);
147
                    if(!$network) {
146
                    if (!$network) {
148
                        $network = $currentNetwork;
147
                        $network = $currentNetwork;
149
                    }
148
                    }
150
                } else {
149
                } else {
151
                    $network = $currentNetwork;
150
                    $network = $currentNetwork;
152
                    
-
 
153
                }
151
                }
154
                
152
 
155
                
153
 
Línea 156... Línea 154...
156
 
154
 
157
                $search = $this->params()->fromQuery('search', []);
155
                $search = $this->params()->fromQuery('search', []);
158
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
156
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
159
                
157
 
160
                //$page               = intval($this->params()->fromQuery('start', 1), 10);
158
                //$page               = intval($this->params()->fromQuery('start', 1), 10);
161
                //$records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
159
                //$records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
162
                
160
 
163
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
161
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
164
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
162
                $page               = (intval($this->params()->fromQuery('start', 1), 10) / $records_x_page) + 1;
165
                
163
 
166
                $order =  $this->params()->fromQuery('order', []);
164
                $order =  $this->params()->fromQuery('order', []);
167
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
165
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
168
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
166
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
169
    
167
 
170
                $fields =  ['first_name', 'last_name', 'email'];
168
                $fields =  ['first_name', 'last_name', 'email'];
171
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
169
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
172
                
170
 
173
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
171
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
174
                    $order_direction = 'ASC';
172
                    $order_direction = 'ASC';
175
                }
-
 
Línea -... Línea 173...
-
 
173
                }
176
                
174
 
177
 
175
 
178
                if($currentCompany) {
176
                if ($currentCompany) {
179
                    $companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
177
                    $companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
180
                    
178
 
181
                    $roles = []; 
179
                    $roles = [];
182
                    $roleMapper = RoleMapper::getInstance($this->adapter);
180
                    $roleMapper = RoleMapper::getInstance($this->adapter);
183
                    $records = $roleMapper->fetchAll(); 
-
 
184
                    foreach ($records as $record)
181
                    $records = $roleMapper->fetchAll();
185
                    {
182
                    foreach ($records as $record) {
186
                        $roles[ $record->id ] = $record->name;
183
                        $roles[$record->id] = $record->name;
187
                    }
184
                    }
188
            
185
 
189
                    
186
 
190
                    //Usuarios cuando el nivel es empresa
187
                    //Usuarios cuando el nivel es empresa
191
                    
188
 
192
                    $acl = $this->getEvent()->getViewModel()->getVariable('acl');
189
                    $acl = $this->getEvent()->getViewModel()->getVariable('acl');
193
                    $allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
190
                    $allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
194
                    $allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
191
                    $allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
195
                    
192
 
196
                    $allowAccept    = $acl->isAllowed($currentUser->usertype_id, 'users/accept') ? 1 : 0;
193
                    $allowAccept    = $acl->isAllowed($currentUser->usertype_id, 'users/accept') ? 1 : 0;
197
                    $allowCancel    = $acl->isAllowed($currentUser->usertype_id, 'users/cancel') ? 1 : 0;
194
                    $allowCancel    = $acl->isAllowed($currentUser->usertype_id, 'users/cancel') ? 1 : 0;
198
                    $allowReject    = $acl->isAllowed($currentUser->usertype_id, 'users/reject') ? 1 : 0;
-
 
Línea -... Línea 195...
-
 
195
                    $allowReject    = $acl->isAllowed($currentUser->usertype_id, 'users/reject') ? 1 : 0;
199
                    $allowEdit     = $acl->isAllowed($currentUser->usertype_id, 'users/edit') ? 1 : 0;
196
                    $allowEdit     = $acl->isAllowed($currentUser->usertype_id, 'users/edit') ? 1 : 0;
200
                    
197
 
201
 
198
 
202
                    
199
 
203
                    $status = Functions::sanitizeFilterString($this->params()->fromQuery('status'));
200
                    $status = Functions::sanitizeFilterString($this->params()->fromQuery('status'));
204
                    if(!in_array($status, [
201
                    if (!in_array($status, [
205
                        CompanyUser::STATUS_ACCEPTED,
202
                        CompanyUser::STATUS_ACCEPTED,
206
                        CompanyUser::STATUS_ADMIN_WILL_ADD,
203
                        CompanyUser::STATUS_ADMIN_WILL_ADD,
207
                        CompanyUser::STATUS_CANCELLED,
204
                        CompanyUser::STATUS_CANCELLED,
208
                        CompanyUser::STATUS_PENDING,
205
                        CompanyUser::STATUS_PENDING,
209
                        CompanyUser::STATUS_REJECTED,
206
                        CompanyUser::STATUS_REJECTED,
210
                        CompanyUser::STATUS_SENT,
207
                        CompanyUser::STATUS_SENT,
211
                    ])) { 
208
                    ])) {
212
                        $status = '';
209
                        $status = '';
213
                    }
210
                    }
214
                    
211
 
215
                    
212
 
216
                    
213
 
217
                    $userMapper = UserMapper::getInstance($this->adapter);
214
                    $userMapper = UserMapper::getInstance($this->adapter);
218
                    $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
215
                    $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
219
                    
216
 
220
                    $paginator = $userMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $status,   $page, $records_x_page, $order_field, $order_direction);
217
                    $paginator = $userMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $status,   $page, $records_x_page, $order_field, $order_direction);
221
                    
218
 
222
                    $items = [];
219
                    $items = [];
223
                    $records = $paginator->getCurrentItems();
-
 
224
                    
220
                    $records = $paginator->getCurrentItems();
225
                    foreach($records as $record)
221
 
226
                    {
222
                    foreach ($records as $record) {
227
                        
223
 
228
                        $actions = []; 
224
                        $actions = [];
229
                        $actions['link_profile'] = 'https://'. $network->main_hostname . '/profile/view/' . $record['uuid'];
225
                        $actions['link_profile'] = 'https://' . $network->main_hostname . '/profile/view/' . $record['uuid'];
230
                        
226
 
231
                        
227
 
232
                        
228
 
233
                        
-
 
234
                        $details = []; 
229
 
235
                        switch ($record['status'])
230
                        $details = [];
236
                        {
231
                        switch ($record['status']) {
237
                            
232
 
238
                            case CompanyUser::STATUS_PENDING :
233
                            case CompanyUser::STATUS_PENDING:
239
                                $details['status']  = 'LABEL_PENDING';
234
                                $details['status']  = 'LABEL_PENDING';
240
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
235
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
241
                                $actions['link_reject'] = $allowReject ? $this->url()->fromRoute('users/reject', ['id' => $record['uuid']]) : '';
236
                                $actions['link_reject'] = $allowReject ? $this->url()->fromRoute('users/reject', ['id' => $record['uuid']]) : '';
242
                                break;
237
                                break;
243
                                
238
 
244
                            case CompanyUser::STATUS_ACCEPTED : 
239
                            case CompanyUser::STATUS_ACCEPTED:
245
                                $details['status']  = 'LABEL_ACCEPTED';
240
                                $details['status']  = 'LABEL_ACCEPTED';
246
                                if($record['creator'] == CompanyUser::CREATOR_NO) { 
241
                                if ($record['creator'] == CompanyUser::CREATOR_NO) {
247
                                    $actions['link_edit'] = $allowEdit ? $this->url()->fromRoute('users/edit', ['id' => $record['uuid']]) : '';
242
                                    $actions['link_edit'] = $allowEdit ? $this->url()->fromRoute('users/edit', ['id' => $record['uuid']]) : '';
248
                                    
243
 
249
                                    
244
 
250
                                    
245
 
251
                                    $actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('users/cancel', ['id' => $record['uuid']]) : '';
246
                                    $actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('users/cancel', ['id' => $record['uuid']]) : '';
252
                                } 
247
                                }
253
                                
248
 
254
                                break;
249
                                break;
255
                                
250
 
256
                            case CompanyUser::STATUS_ADMIN_WILL_ADD : 
251
                            case CompanyUser::STATUS_ADMIN_WILL_ADD:
257
                                $details['status']  = 'LABEL_ADMIN_WILL_ADD';
252
                                $details['status']  = 'LABEL_ADMIN_WILL_ADD';
258
                                $actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('users/cancel', ['id' => $record['uuid']]) : '';
253
                                $actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('users/cancel', ['id' => $record['uuid']]) : '';
259
                                $actions['link_edit'] = $allowEdit ? $this->url()->fromRoute('users/edit', ['id' => $record['uuid']]) : '';
254
                                $actions['link_edit'] = $allowEdit ? $this->url()->fromRoute('users/edit', ['id' => $record['uuid']]) : '';
260
                                
255
 
261
                                break;
256
                                break;
262
                                
257
 
263
                            case CompanyUser::STATUS_SENT :
258
                            case CompanyUser::STATUS_SENT:
264
                                $details['status']  = 'LABEL_INVITED';
259
                                $details['status']  = 'LABEL_INVITED';
265
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
260
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
266
                                $actions['link_reject'] = $allowReject ? $this->url()->fromRoute('users/reject', ['id' => $record['uuid']]) : '';
261
                                $actions['link_reject'] = $allowReject ? $this->url()->fromRoute('users/reject', ['id' => $record['uuid']]) : '';
267
                                break;
262
                                break;
268
                                
263
 
269
                            case CompanyUser::STATUS_REJECTED :
264
                            case CompanyUser::STATUS_REJECTED:
270
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
265
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
271
                                $details['status']  = 'LABEL_REJECTED';
266
                                $details['status']  = 'LABEL_REJECTED';
272
                                break;
267
                                break;
273
                                
268
 
274
                            case CompanyUser::STATUS_CANCELLED :
269
                            case CompanyUser::STATUS_CANCELLED:
275
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
270
                                $actions['link_accept'] = $allowAccept ? $this->url()->fromRoute('users/accept', ['id' => $record['uuid']]) : '';
276
                                $details['status']  = 'LABEL_CANCELLED';
271
                                $details['status']  = 'LABEL_CANCELLED';
277
                                break;
272
                                break;
278
                                
273
 
279
                            default : 
-
 
280
                                $details['status']  = '';
274
                            default:
281
                                break;
275
                                $details['status']  = '';
282
                                
276
                                break;
283
                        }
277
                        }
284
                        
278
 
285
                        $totalOtherCompanies = $companyUserMapper->fetchCountOtherCompaniesByCompanyIdAndUserId($currentCompany->id, $record['id']);
279
                        $totalOtherCompanies = $companyUserMapper->fetchCountOtherCompaniesByCompanyIdAndUserId($currentCompany->id, $record['id']);
286
                        if(!$totalOtherCompanies) {
280
                        if (!$totalOtherCompanies) {
287
                        
281
 
288
                            $actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record['uuid'] ]) : '';
282
                            $actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record['uuid']]) : '';
289
                            if($record['blocked'] == User::BLOCKED_YES ) {
283
                            if ($record['blocked'] == User::BLOCKED_YES) {
290
                                $actions['link_unblock'] = $allowUnblock ? $this->url()->fromRoute('users/unblock', ['id' => $record['uuid'] ]) : '';
284
                                $actions['link_unblock'] = $allowUnblock ? $this->url()->fromRoute('users/unblock', ['id' => $record['uuid']]) : '';
291
                            } 
285
                            }
292
                        }
286
                        }
293
                        
287
 
294
                        if($record['blocked'] == User::BLOCKED_YES ) {
288
                        if ($record['blocked'] == User::BLOCKED_YES) {
295
                            $details['blocked'] = 'LABEL_YES';
289
                            $details['blocked'] = 'LABEL_YES';
296
                        } else if($record['blocked'] == User::BLOCKED_NO ) {
290
                        } else if ($record['blocked'] == User::BLOCKED_NO) {
297
                            $details['blocked'] = 'LABEL_NO';
291
                            $details['blocked'] = 'LABEL_NO';
298
                        }
-
 
299
                        if($record['email_verified'] == User::EMAIL_VERIFIED_YES ) {
292
                        }
300
                            $details['email_verified'] = 'LABEL_YES';
293
                        if ($record['email_verified'] == User::EMAIL_VERIFIED_YES) {
301
                            
294
                            $details['email_verified'] = 'LABEL_YES';
302
                        } else if($record['email_verified'] == User::EMAIL_VERIFIED_NO ) {
295
                        } else if ($record['email_verified'] == User::EMAIL_VERIFIED_NO) {
303
                            $details['email_verified'] = 'LABEL_NO';
296
                            $details['email_verified'] = 'LABEL_NO';
304
                        }
297
                        }
305
                        $details['login_attempt'] = $record['login_attempt'];
298
                        $details['login_attempt'] = $record['login_attempt'];
306
                        
299
 
307
                        
300
 
308
                        $company_user_roles = $companyUserRoleMapper->fetchAllByCompanyIdAndUserId($currentCompany->id, $record['id']);
301
                        $company_user_roles = $companyUserRoleMapper->fetchAllByCompanyIdAndUserId($currentCompany->id, $record['id']);
309
                        
302
 
310
                        $details['roles'] = [];
303
                        $details['roles'] = [];
311
                        
304
 
312
                        if($record['creator'] == CompanyUser::CREATOR_YES) {
305
                        if ($record['creator'] == CompanyUser::CREATOR_YES) {
313
                            $details['roles'][] = 'LABEL_ALL_PERMITS';
306
                            $details['roles'][] = 'LABEL_ALL_PERMITS';
314
                            $details['creator'] = 'LABEL_YES' ;
307
                            $details['creator'] = 'LABEL_YES';
315
                        }  else { 
-
 
316
                            $details['creator'] = 'LABEL_NO'; 
308
                        } else {
317
                            foreach($company_user_roles as $company_user_role)
309
                            $details['creator'] = 'LABEL_NO';
318
                            {
-
 
319
                                $role = $roles[ $company_user_role->role_id ];
310
                            foreach ($company_user_roles as $company_user_role) {
320
                                $details['roles'][] = $role;
311
                                $role = $roles[$company_user_role->role_id];
321
                                
312
                                $details['roles'][] = $role;
322
                            }
313
                            }
323
                        } 
314
                        }
324
                        
-
 
Línea -... Línea 315...
-
 
315
 
325
                       
316
 
326
                        $details['backend'] = $record['backend'] == CompanyUser::BACKEND_YES ? 'LABEL_YES' : 'LABEL_NO';
317
                        $details['backend'] = $record['backend'] == CompanyUser::BACKEND_YES ? 'LABEL_YES' : 'LABEL_NO';
327
                        
318
 
328
 
319
 
329
                        
320
 
330
                        
321
 
331
                        
322
 
332
                        
323
 
333
                        $item = [
324
                        $item = [
334
                            'first_name' => $record['first_name'] ,
325
                            'first_name' => $record['first_name'],
335
                            'last_name' => $record['last_name'],
326
                            'last_name' => $record['last_name'],
336
                            'email' => $record['email'],
327
                            'email' => $record['email'],
337
                            'details' => $details,
328
                            'details' => $details,
338
                            'actions' =>  $actions ,
329
                            'actions' =>  $actions,
339
                       ];
330
                        ];
340
                        
331
 
341
                        array_push($items, $item);
332
                        array_push($items, $item);
342
                    }
333
                    }
343
                } else {
334
                } else {
344
                    //Usuario cuando el nivel es administrador
335
                    //Usuario cuando el nivel es administrador
345
                    
336
 
346
          
337
 
347
                    
338
 
348
                    $acl = $this->getEvent()->getViewModel()->getVariable('acl');
339
                    $acl = $this->getEvent()->getViewModel()->getVariable('acl');
349
                    $allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
340
                    $allowUnblock = $acl->isAllowed($currentUser->usertype_id, 'users/unblock');
350
                    $allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
341
                    $allowChangePassword = $acl->isAllowed($currentUser->usertype_id, 'users/change-password');
351
                    $allowChangeType   = $acl->isAllowed($currentUser->usertype_id, 'users/change-type') ? 1 : 0;
342
                    $allowChangeType   = $acl->isAllowed($currentUser->usertype_id, 'users/change-type') ? 1 : 0;
352
                    
343
 
353
                    
344
 
354
                    
345
 
355
                    $userMapper = UserMapper::getInstance($this->adapter);
346
                    $userMapper = UserMapper::getInstance($this->adapter);
356
                    $paginator = $userMapper->fetchAllDataTableByNetworkId($network->id, $search, $page, $records_x_page, $order_field, $order_direction);
347
                    $paginator = $userMapper->fetchAllDataTableByNetworkId($network->id, $search, $page, $records_x_page, $order_field, $order_direction);
357
                    
348
 
358
                    $items = [];
-
 
359
                    $records = $paginator->getCurrentItems();
349
                    $items = [];
360
                    
350
                    $records = $paginator->getCurrentItems();
361
                    foreach($records as $record)
351
 
362
                    {
352
                    foreach ($records as $record) {
363
                        $actions = [];
353
                        $actions = [];
364
                        
354
 
365
                        if($currentNetwork->id == $record->network_id) {
355
                        if ($currentNetwork->id == $record->network_id) {
366
                        
356
 
367
                            $actions['link_profile'] = 'https://'. $network->main_hostname . '/profile/view/' . $record->uuid;
357
                            $actions['link_profile'] = 'https://' . $network->main_hostname . '/profile/view/' . $record->uuid;
368
                        } else {
358
                        } else {
369
                            $actions['link_profile'] = '';
359
                            $actions['link_profile'] = '';
370
                        }
360
                        }
371
                        
361
 
372
                        $details = [] ;
362
                        $details = [];
373
                        if($record->status == User::STATUS_ACTIVE ) {
363
                        if ($record->status == User::STATUS_ACTIVE) {
374
                            $details['status'] = 'LABEL_ACTIVE';
364
                            $details['status'] = 'LABEL_ACTIVE';
375
                        } else if($record->status == User::STATUS_INACTIVE ) {
365
                        } else if ($record->status == User::STATUS_INACTIVE) {
376
                            $details['status'] = 'LABEL_INACTIVE';  
366
                            $details['status'] = 'LABEL_INACTIVE';
377
                        }
367
                        }
378
                        if($record->blocked == User::BLOCKED_YES ) {
368
                        if ($record->blocked == User::BLOCKED_YES) {
379
                            $details['blocked'] = 'LABEL_YES';
369
                            $details['blocked'] = 'LABEL_YES';
380
                        } else if($record->blocked == User::BLOCKED_NO ) {
370
                        } else if ($record->blocked == User::BLOCKED_NO) {
381
                            $details['blocked'] = 'LABEL_NO';
-
 
382
                        }
371
                            $details['blocked'] = 'LABEL_NO';
383
                        if($record->email_verified == User::EMAIL_VERIFIED_YES ) {
372
                        }
384
                            $details['email_verified'] = 'LABEL_YES';
373
                        if ($record->email_verified == User::EMAIL_VERIFIED_YES) {
385
                            
374
                            $details['email_verified'] = 'LABEL_YES';
386
                        } else if($record->email_verified == User::EMAIL_VERIFIED_NO ) {
375
                        } else if ($record->email_verified == User::EMAIL_VERIFIED_NO) {
387
                            $details['email_verified'] = 'LABEL_NO';
376
                            $details['email_verified'] = 'LABEL_NO';
388
                        }
377
                        }
389
                        
378
 
390
                        if($record->usertype_id == UserType::ADMIN) {
379
                        if ($record->usertype_id == UserType::ADMIN) {
391
                            $details['user_type'] = 'LABEL_ADMINISTRATOR';
380
                            $details['user_type'] = 'LABEL_ADMINISTRATOR';
392
                        } else   if($record->usertype_id == UserType::USER) {
381
                        } else   if ($record->usertype_id == UserType::USER) {
393
                            $details['user_type'] = 'LABEL_USER';
382
                            $details['user_type'] = 'LABEL_USER';
394
                        }
383
                        }
395
                        
384
 
396
                        $details['login_attempt'] = $record->login_attempt;
385
                        $details['login_attempt'] = $record->login_attempt;
397
                        
386
 
398
                        
387
 
399
                        $actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record->uuid ]) : '';
388
                        $actions['link_change_password'] = $allowChangePassword ? $this->url()->fromRoute('users/change-password', ['id' => $record->uuid]) : '';
400
                        $actions['link_unblock'] = $allowUnblock && $record->blocked == User::BLOCKED_YES ? $this->url()->fromRoute('users/unblock', ['id' => $record->uuid ]) : '';
389
                        $actions['link_unblock'] = $allowUnblock && $record->blocked == User::BLOCKED_YES ? $this->url()->fromRoute('users/unblock', ['id' => $record->uuid]) : '';
401
                        $actions['link_change_type'] =  $record->is_super_user == User::IS_SUPER_USER_NO && $allowChangeType ? $this->url()->fromRoute('users/change-type', ['id' => $record->uuid ]) : '';
390
                        $actions['link_change_type'] =  $record->is_super_user == User::IS_SUPER_USER_NO && $allowChangeType ? $this->url()->fromRoute('users/change-type', ['id' => $record->uuid]) : '';
402
                        
391
 
403
                        
392
 
404
                        $item = [
393
                        $item = [
405
                            'first_name' => $record->first_name,
394
                            'first_name' => $record->first_name,
406
                            'last_name' => $record->last_name,
395
                            'last_name' => $record->last_name,
407
                            'email' => $record->email,
396
                            'email' => $record->email,
408
                            'details' => $details,
397
                            'details' => $details,
409
                            'actions' => $actions
398
                            'actions' => $actions
410
                         ];
399
                        ];
411
                        
400
 
412
                        array_push($items, $item);
401
                        array_push($items, $item);
413
                    }
402
                    }
414
                }
403
                }
415
            }
404
            }
416
            
405
 
417
            return new JsonModel([
406
            return new JsonModel([
418
                'success' => true,
407
                'success' => true,
419
                'data' => [
408
                'data' => [
420
                    'items' => $items,
-
 
421
                    'total' => $paginator->getTotalItemCount(),
-
 
422
                ]
-
 
423
            ]);
-
 
424
                
409
                    'items' => $items,
425
 
410
                    'total' => $paginator->getTotalItemCount(),
426
            
411
                ]
427
        }
412
            ]);
428
        else if($request->isGet()) {
413
        } else if ($request->isGet()) {
429
            $this->layout()->setTemplate('layout/layout-backend');
414
            $this->layout()->setTemplate('layout/layout-backend');
430
            $viewModel = new ViewModel();
415
            $viewModel = new ViewModel();
431
            
416
 
432
            
417
 
433
            $networks = [];
418
            $networks = [];
434
            $networkMapper = NetworkMapper::getInstance($this->adapter);
419
            $networkMapper = NetworkMapper::getInstance($this->adapter);
435
            
-
 
436
            if($currentUser->is_super_user == User::IS_SUPER_USER_YES) {
420
 
437
                $records = $networkMapper->fetchAll();
421
            if ($currentUser->is_super_user == User::IS_SUPER_USER_YES) {
438
                foreach($records as $record) 
-
 
439
                {
422
                $records = $networkMapper->fetchAll();
440
                    $networks[ $record->uuid ] = $record->name;
423
                foreach ($records as $record) {
441
                }
-
 
442
                
424
                    $networks[$record->uuid] = $record->name;
443
            } else {
425
                }
444
                $networks[ $currentNetwork->uuid ] = $currentNetwork->name;
426
            } else {
445
            
427
                $networks[$currentNetwork->uuid] = $currentNetwork->name;
446
            }
428
            }
447
            
429
 
448
            
430
 
449
            $formFilter = new NetworkDataForm($networks);
431
            $formFilter = new NetworkDataForm($networks);
450
            $formUploadUsers = new UserUploadForm();
432
            $formUploadUsers = new UserUploadForm();
451
            $formChangePassword = new ChangePasswordForm();
433
            $formChangePassword = new ChangePasswordForm();
452
            $formChangeType = new ChangeTypeForm();
434
            $formChangeType = new ChangeTypeForm();
453
            
-
 
454
            $company = $currentUserPlugin->getCompany();
435
 
455
            if($company) {
436
            $company = $currentUserPlugin->getCompany();
456
                $viewModel->setTemplate('leaders-linked/users/company.phtml');
437
            if ($company) {
457
                 
438
                $viewModel->setTemplate('leaders-linked/users/company.phtml');
458
            } else { 
439
            } else {
459
                $viewModel->setTemplate('leaders-linked/users/index.phtml');
440
                $viewModel->setTemplate('leaders-linked/users/index.phtml');
460
            }
441
            }
461
            $viewModel->setVariables([
442
            $viewModel->setVariables([
462
                'formUploadUsers' => $formUploadUsers,
443
                'formUploadUsers' => $formUploadUsers,
463
                'formChangePassword' => $formChangePassword,
444
                'formChangePassword' => $formChangePassword,
464
                'formChangeType' => $formChangeType,
-
 
465
                'formFilter' => $formFilter
445
                'formChangeType' => $formChangeType,
466
            ] );
446
                'formFilter' => $formFilter
467
            return $viewModel ;
447
            ]);
468
      
448
            return $viewModel;
469
        } else {
449
        } else {
Línea 692... Línea 672...
692
            return new JsonModel($data);
672
            return new JsonModel($data);
693
        }
673
        }
Línea 694... Línea 674...
694
        
674
        
695
        return new JsonModel($data);
675
        return new JsonModel($data);
696
    }*/
676
    }*/
697
    
677
 
698
    public function unblockAction()
678
    public function unblockAction()
699
    {
679
    {
700
        $currentUserPlugin = $this->plugin('currentUserPlugin');
680
        $currentUserPlugin = $this->plugin('currentUserPlugin');
701
        $currentUser = $currentUserPlugin->getUser();
681
        $currentUser = $currentUserPlugin->getUser();
Línea 702... Línea 682...
702
        $request = $this->getRequest();
682
        $request = $this->getRequest();
703
 
683
 
704
        
684
 
705
        if($request->isPost()) {
685
        if ($request->isPost()) {
706
            
686
 
707
            $uuid = $this->params()->fromRoute('id');
687
            $uuid = $this->params()->fromRoute('id');
708
            if(!$uuid) {
688
            if (!$uuid) {
709
                return new JsonModel([
689
                return new JsonModel([
710
                    'success'   => false,
690
                    'success'   => false,
711
                    'data'      => 'ERROR_INVALID_PARAMETER'
691
                    'data'      => 'ERROR_INVALID_PARAMETER'
712
                ]);
692
                ]);
713
            }
693
            }
714
            
694
 
715
            $userMapper = UserMapper::getInstance($this->adapter);
695
            $userMapper = UserMapper::getInstance($this->adapter);
716
            $user = $userMapper->fetchOneByUuid($uuid);
696
            $user = $userMapper->fetchOneByUuid($uuid);
717
            
697
 
718
            if(!$user) {
698
            if (!$user) {
719
                return new JsonModel([
699
                return new JsonModel([
720
                    'success'   => false,
700
                    'success'   => false,
721
                    'data'      => 'ERROR_USER_NOT_FOUND'
701
                    'data'      => 'ERROR_USER_NOT_FOUND'
722
                ]);
702
                ]);
723
            }
703
            }
724
     
704
 
725
            if($user->blocked == User::BLOCKED_NO) {
705
            if ($user->blocked == User::BLOCKED_NO) {
726
                return new JsonModel([
706
                return new JsonModel([
727
                    'success'   => false,
707
                    'success'   => false,
728
                    'data'      => 'ERROR_USER_IS_NOT_BLOCKED'
708
                    'data'      => 'ERROR_USER_IS_NOT_BLOCKED'
Línea 729... Línea 709...
729
                ]);
709
                ]);
730
            }
710
            }
731
 
711
 
732
 
712
 
733
                
713
 
734
            $result = $userMapper->unblock($user);
714
            $result = $userMapper->unblock($user);
735
            if($result) {
715
            if ($result) {
736
                $this->logger->info('El usuario : ' . $user->email . ' ha sido desbloqueado ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
716
                $this->logger->info('El usuario : ' . $user->email . ' ha sido desbloqueado ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
737
                
717
 
738
                return new JsonModel([
718
                return new JsonModel([
739
                    'success'   => true,
719
                    'success'   => true,
740
                    'data'      => 'LABEL_USER_HAS_BEEN_UNBLOCKED',
720
                    'data'      => 'LABEL_USER_HAS_BEEN_UNBLOCKED',
741
                ]);
721
                ]);
742
            }  else {
722
            } else {
743
                
723
 
744
                return new JsonModel([
724
                return new JsonModel([
745
                    'success'   => false,
-
 
746
                    'data'      => $userMapper->getError()
-
 
747
                ]);
725
                    'success'   => false,
748
            }
726
                    'data'      => $userMapper->getError()
749
            
727
                ]);
750
            
728
            }
751
        }
729
        }
752
        
730
 
753
        
731
 
754
        
732
 
755
        return new JsonModel([
733
        return new JsonModel([
756
            'success' => false,
734
            'success' => false,
757
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
735
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
758
        ]);
736
        ]);
759
    }
737
    }
760
    
738
 
761
    public function emailVerifyAction()
739
    public function emailVerifyAction()
762
    {
740
    {
763
        $currentUserPlugin = $this->plugin('currentUserPlugin');
741
        $currentUserPlugin = $this->plugin('currentUserPlugin');
764
        $currentUser = $currentUserPlugin->getUser();
742
        $currentUser = $currentUserPlugin->getUser();
765
        $request = $this->getRequest();
743
        $request = $this->getRequest();
766
        
744
 
767
        
745
 
768
        if($request->isPost()) {
746
        if ($request->isPost()) {
769
            
747
 
770
            $uuid = $this->params()->fromRoute('id');
748
            $uuid = $this->params()->fromRoute('id');
771
            if(!$uuid) {
749
            if (!$uuid) {
772
                return new JsonModel([
750
                return new JsonModel([
773
                    'success'   => false,
751
                    'success'   => false,
774
                    'data'      => 'ERROR_INVALID_PARAMETER'
752
                    'data'      => 'ERROR_INVALID_PARAMETER'
775
                ]);
753
                ]);
776
            }
754
            }
777
            
755
 
778
            $userMapper = UserMapper::getInstance($this->adapter);
756
            $userMapper = UserMapper::getInstance($this->adapter);
779
            $user = $userMapper->fetchOneByUuid($uuid);
757
            $user = $userMapper->fetchOneByUuid($uuid);
780
            
758
 
781
            if(!$user) {
759
            if (!$user) {
782
                return new JsonModel([
760
                return new JsonModel([
783
                    'success'   => false,
761
                    'success'   => false,
784
                    'data'      => 'ERROR_USER_NOT_FOUND'
762
                    'data'      => 'ERROR_USER_NOT_FOUND'
785
                ]);
763
                ]);
786
            }
764
            }
787
            
765
 
788
            if($user->blocked == User::BLOCKED_NO) {
766
            if ($user->blocked == User::BLOCKED_NO) {
789
                return new JsonModel([
767
                return new JsonModel([
790
                    'success'   => false,
768
                    'success'   => false,
791
                    'data'      => 'ERROR_USER_IS_NOT_PENDING_FOR_EMAIL_VERIFY'
769
                    'data'      => 'ERROR_USER_IS_NOT_PENDING_FOR_EMAIL_VERIFY'
792
                ]);
770
                ]);
793
            }
771
            }
794
            
772
 
795
            
773
 
796
            
774
 
797
            $result = $userMapper->emailVerifyAndActive($user);
775
            $result = $userMapper->emailVerifyAndActive($user);
798
            if($result) {
776
            if ($result) {
799
                $this->logger->info('El usuario : ' . $user->email . ' ha sido desbloqueado ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
777
                $this->logger->info('El usuario : ' . $user->email . ' ha sido desbloqueado ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
800
                
778
 
801
                return new JsonModel([
779
                return new JsonModel([
802
                    'success'   => true,
780
                    'success'   => true,
803
                    'data'      => 'LABEL_USER_HAS_BEEN_UNBLOCKED',
781
                    'data'      => 'LABEL_USER_HAS_BEEN_UNBLOCKED',
804
                ]);
782
                ]);
805
            }  else {
783
            } else {
806
                
784
 
807
                return new JsonModel([
785
                return new JsonModel([
808
                    'success'   => false,
-
 
809
                    'data'      => $userMapper->getError()
-
 
810
                ]);
786
                    'success'   => false,
811
            }
787
                    'data'      => $userMapper->getError()
812
            
788
                ]);
813
            
789
            }
814
        }
790
        }
815
        
791
 
816
        
792
 
817
        
793
 
818
        return new JsonModel([
794
        return new JsonModel([
819
            'success' => false,
795
            'success' => false,
820
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
796
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
821
        ]);
797
        ]);
822
    }
798
    }
823
    
799
 
824
    public function changePasswordAction()
800
    public function changePasswordAction()
825
    {
801
    {
Línea 826... Línea 802...
826
        $currentUserPlugin = $this->plugin('currentUserPlugin');
802
        $currentUserPlugin = $this->plugin('currentUserPlugin');
827
        $currentUser = $currentUserPlugin->getUser();
803
        $currentUser = $currentUserPlugin->getUser();
828
        
804
 
829
        $request = $this->getRequest();
805
        $request = $this->getRequest();
830
 
806
 
831
        if($request->isGet()) {
807
        if ($request->isGet()) {
832
            $uuid = $this->params()->fromRoute('id');
808
            $uuid = $this->params()->fromRoute('id');
833
            if(!$uuid) {
809
            if (!$uuid) {
834
                return new JsonModel([
810
                return new JsonModel([
835
                    'success'   => false,
811
                    'success'   => false,
836
                    'data'      => 'ERROR_INVALID_PARAMETER'
812
                    'data'      => 'ERROR_INVALID_PARAMETER'
837
                ]);
813
                ]);
838
            }
814
            }
839
            
815
 
840
            $userMapper = UserMapper::getInstance($this->adapter);
816
            $userMapper = UserMapper::getInstance($this->adapter);
841
            $user = $userMapper->fetchOneByUuid($uuid);
817
            $user = $userMapper->fetchOneByUuid($uuid);
842
            
818
 
843
            
819
 
844
            
820
 
845
            if($user) {
821
            if ($user) {
Línea 855... Línea 831...
855
                return new JsonModel([
831
                return new JsonModel([
856
                    'success'   => false,
832
                    'success'   => false,
857
                    'data'      => 'ERROR_USER_NOT_FOUND'
833
                    'data'      => 'ERROR_USER_NOT_FOUND'
858
                ]);
834
                ]);
859
            }
835
            }
860
            
-
 
861
        }
836
        }
862
        
837
 
863
        if($request->isPost()) {
838
        if ($request->isPost()) {
864
            
839
 
865
            $uuid = $this->params()->fromRoute('id');
840
            $uuid = $this->params()->fromRoute('id');
866
            if(!$uuid) {
841
            if (!$uuid) {
867
                return new JsonModel([
842
                return new JsonModel([
868
                    'success'   => false,
843
                    'success'   => false,
869
                    'data'      => 'ERROR_INVALID_PARAMETER'
844
                    'data'      => 'ERROR_INVALID_PARAMETER'
870
                ]);
845
                ]);
871
            }
846
            }
872
            
847
 
873
            $userMapper = UserMapper::getInstance($this->adapter);
848
            $userMapper = UserMapper::getInstance($this->adapter);
874
            $user = $userMapper->fetchOneByUuid($uuid);
849
            $user = $userMapper->fetchOneByUuid($uuid);
875
            
850
 
876
            if(!$user) {
851
            if (!$user) {
877
                return new JsonModel([
852
                return new JsonModel([
878
                    'success'   => false,
853
                    'success'   => false,
879
                    'data'      => 'ERROR_USER_NOT_FOUND'
854
                    'data'      => 'ERROR_USER_NOT_FOUND'
880
                ]);
855
                ]);
881
            }
856
            }
882
            
857
 
883
            
858
 
884
            $dataPost = $request->getPost()->toArray();
859
            $dataPost = $request->getPost()->toArray();
885
            $form = new ChangePasswordForm();
860
            $form = new ChangePasswordForm();
886
            $form->setData($dataPost);
861
            $form->setData($dataPost);
887
            
862
 
888
            if($form->isValid()) {
863
            if ($form->isValid()) {
889
                
864
 
890
                
865
 
891
                
866
 
892
                $data = (array) $form->getData();
867
                $data = (array) $form->getData();
893
                $password = $data['password'];
868
                $password = $data['password'];
894
                
-
 
Línea -... Línea 869...
-
 
869
 
895
 
870
 
896
                
871
 
897
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
872
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
898
                $userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
873
                $userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
899
                
874
 
900
                $oldPassword = false;
875
                $oldPassword = false;
901
                foreach($userPasswords as $userPassword)
-
 
902
                {
876
                foreach ($userPasswords as $userPassword) {
903
                    if(password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password))
-
 
904
                    {
877
                    if (password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password)) {
905
                        $oldPassword = true;
878
                        $oldPassword = true;
906
                        break;
879
                        break;
907
                    }
880
                    }
908
                }
881
                }
909
                
882
 
910
                if($oldPassword) {
883
                if ($oldPassword) {
911
                    $this->logger->err('Cambio de contraseña del usuario - error contraseña ya utilizada anteriormente', ['user_id' =>  $currentUser->id, 'ip' => Functions::getUserIP()]);
884
                    $this->logger->err('Cambio de contraseña del usuario - error contraseña ya utilizada anteriormente', ['user_id' =>  $currentUser->id, 'ip' => Functions::getUserIP()]);
912
                    
885
 
913
                    return new JsonModel([
886
                    return new JsonModel([
914
                        'success'   => false,
887
                        'success'   => false,
915
                        'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
888
                        'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
916
                        
889
 
917
                    ]);
890
                    ]);
918
                } else {
891
                } else {
919
                    $password_hash = password_hash($password, PASSWORD_DEFAULT);
892
                    $password_hash = password_hash($password, PASSWORD_DEFAULT);
920
                    
893
 
921
                    
894
 
922
                    $result = $userMapper->updatePassword($user, $password_hash);
895
                    $result = $userMapper->updatePassword($user, $password_hash);
923
                    if($result) {
896
                    if ($result) {
924
                        $this->logger->info('Cambio de contraseña del usuario realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
897
                        $this->logger->info('Cambio de contraseña del usuario realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
925
                        
898
 
926
                        
899
 
927
                        return new JsonModel([
900
                        return new JsonModel([
928
                            'success'   => true,
901
                            'success'   => true,
929
                            'data'      => 'LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED'
902
                            'data'      => 'LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED'
930
                            
903
 
931
                        ]);
904
                        ]);
932
                    } else {
905
                    } else {
933
                        $this->logger->err('Cambio de contraseña del usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
906
                        $this->logger->err('Cambio de contraseña del usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
934
                        
907
 
935
                        return new JsonModel([
908
                        return new JsonModel([
936
                            'success'   => true,
909
                            'success'   => true,
937
                            'data'      => 'ERROR_THERE_WAS_AN_ERROR'
910
                            'data'      => 'ERROR_THERE_WAS_AN_ERROR'
938
                            
911
 
939
                        ]);
912
                        ]);
940
                    }
913
                    }
941
                }
-
 
942
                
914
                }
943
            } else {
915
            } else {
944
                $messages = [];
916
                $messages = [];
945
                
917
 
946
                $form_messages = (array) $form->getMessages();
918
                $form_messages = (array) $form->getMessages();
947
                foreach($form_messages  as $fieldname => $field_messages)
-
 
948
                {
919
                foreach ($form_messages  as $fieldname => $field_messages) {
949
                    $messages[$fieldname] = array_values($field_messages);
920
                    $messages[$fieldname] = array_values($field_messages);
950
                }
921
                }
951
                
922
 
952
                return new JsonModel([
923
                return new JsonModel([
953
                    'success'   => false,
924
                    'success'   => false,
954
                    'data'   => $messages
925
                    'data'   => $messages
955
                ]);
926
                ]);
956
            }
-
 
957
            
927
            }
958
        }
928
        }
959
        
929
 
960
        
930
 
961
        
931
 
962
        return new JsonModel([
932
        return new JsonModel([
963
            'success' => false,
933
            'success' => false,
964
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
934
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
965
        ]);
935
        ]);
966
    }
936
    }
967
    
937
 
968
    public function cancelAction()
938
    public function cancelAction()
969
    {
939
    {
970
        $currentUserPlugin = $this->plugin('currentUserPlugin');
940
        $currentUserPlugin = $this->plugin('currentUserPlugin');
971
        $currentUser = $currentUserPlugin->getUser();
941
        $currentUser = $currentUserPlugin->getUser();
972
        
942
 
973
        $currentCompany = $currentUserPlugin->getCompany(); 
943
        $currentCompany = $currentUserPlugin->getCompany();
974
        
944
 
975
        $request = $this->getRequest();
945
        $request = $this->getRequest();
976
        
946
 
977
        
947
 
978
        if($request->isPost()) {
948
        if ($request->isPost()) {
979
            
949
 
980
            $uuid = $this->params()->fromRoute('id');
950
            $uuid = $this->params()->fromRoute('id');
981
            if(!$uuid) {
951
            if (!$uuid) {
982
                return new JsonModel([
952
                return new JsonModel([
983
                    'success'   => false,
953
                    'success'   => false,
984
                    'data'      => 'ERROR_INVALID_PARAMETER'
954
                    'data'      => 'ERROR_INVALID_PARAMETER'
985
                ]);
955
                ]);
986
            }
956
            }
987
            
957
 
988
            $userMapper = UserMapper::getInstance($this->adapter);
958
            $userMapper = UserMapper::getInstance($this->adapter);
989
            $user = $userMapper->fetchOneByUuid($uuid);
959
            $user = $userMapper->fetchOneByUuid($uuid);
990
            
960
 
991
            if(!$user) {
961
            if (!$user) {
992
                return new JsonModel([
962
                return new JsonModel([
993
                    'success'   => false,
963
                    'success'   => false,
994
                    'data'      => 'ERROR_USER_COMPANY_NOT_FOUND'
964
                    'data'      => 'ERROR_USER_COMPANY_NOT_FOUND'
995
                ]);
965
                ]);
996
            }
966
            }
997
            
967
 
998
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
968
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
999
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id); 
969
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1000
            
970
 
1001
            if(!$companyUser) {
971
            if (!$companyUser) {
1002
                return new JsonModel([
972
                return new JsonModel([
1003
                    'success'   => false,
973
                    'success'   => false,
1004
                    'data'      => 'ERROR_USER_NOT_FOUND'
974
                    'data'      => 'ERROR_USER_NOT_FOUND'
1005
                ]);
975
                ]);
1006
            }
976
            }
1007
            
977
 
1008
            
978
 
1009
            if(!in_array($companyUser->status, [  CompanyUser::STATUS_ADMIN_WILL_ADD, CompanyUser::STATUS_ACCEPTED])) {
979
            if (!in_array($companyUser->status, [CompanyUser::STATUS_ADMIN_WILL_ADD, CompanyUser::STATUS_ACCEPTED])) {
1010
                return new JsonModel([
980
                return new JsonModel([
1011
                    'success'   => false,
981
                    'success'   => false,
1012
                    'data'      => 'ERROR_USER_COMPANY_WRONG_STATUS'
982
                    'data'      => 'ERROR_USER_COMPANY_WRONG_STATUS'
1013
                ]);
983
                ]);
1014
            }
984
            }
1015
            
985
 
1016
            $companyUser->status = CompanyUser::STATUS_CANCELLED;
986
            $companyUser->status = CompanyUser::STATUS_CANCELLED;
1017
            $result = $companyUserMapper->update($companyUser);
987
            $result = $companyUserMapper->update($companyUser);
1018
            if($result) {
988
            if ($result) {
1019
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido cancelada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
989
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido cancelada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1020
                
990
 
1021
                return new JsonModel([
991
                return new JsonModel([
1022
                    'success'   => true,
992
                    'success'   => true,
1023
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_CANCELLED',
993
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_CANCELLED',
1024
                ]);
994
                ]);
1025
            }  else {
995
            } else {
1026
                
996
 
1027
                return new JsonModel([
997
                return new JsonModel([
1028
                    'success'   => false,
998
                    'success'   => false,
1029
                    'data'      => $userMapper->getError()
999
                    'data'      => $userMapper->getError()
1030
                ]);
1000
                ]);
1031
            }
-
 
1032
            
-
 
1033
            
1001
            }
1034
        }
1002
        }
1035
        
1003
 
1036
        
1004
 
1037
        
1005
 
1038
        return new JsonModel([
1006
        return new JsonModel([
1039
            'success' => false,
1007
            'success' => false,
1040
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1008
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1041
        ]);
1009
        ]);
1042
    }
1010
    }
1043
    
1011
 
1044
    public function acceptAction()
1012
    public function acceptAction()
1045
    {
1013
    {
1046
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1014
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1047
        $currentUser = $currentUserPlugin->getUser();
1015
        $currentUser = $currentUserPlugin->getUser();
1048
        
1016
 
1049
        $currentCompany = $currentUserPlugin->getCompany();
1017
        $currentCompany = $currentUserPlugin->getCompany();
1050
        
1018
 
1051
        $request = $this->getRequest();
1019
        $request = $this->getRequest();
1052
        
1020
 
1053
        
1021
 
1054
        if($request->isPost()) {
1022
        if ($request->isPost()) {
1055
            
1023
 
1056
            $uuid = $this->params()->fromRoute('id');
1024
            $uuid = $this->params()->fromRoute('id');
1057
            if(!$uuid) {
1025
            if (!$uuid) {
1058
                return new JsonModel([
1026
                return new JsonModel([
1059
                    'success'   => false,
1027
                    'success'   => false,
1060
                    'data'      => 'ERROR_INVALID_PARAMETER'
1028
                    'data'      => 'ERROR_INVALID_PARAMETER'
1061
                ]);
1029
                ]);
1062
            }
1030
            }
1063
            
1031
 
1064
            $userMapper = UserMapper::getInstance($this->adapter);
1032
            $userMapper = UserMapper::getInstance($this->adapter);
1065
            $user = $userMapper->fetchOneByUuid($uuid);
1033
            $user = $userMapper->fetchOneByUuid($uuid);
1066
            
1034
 
1067
            if(!$user) {
1035
            if (!$user) {
1068
                return new JsonModel([
1036
                return new JsonModel([
1069
                    'success'   => false,
1037
                    'success'   => false,
1070
                    'data'      => 'ERROR_USER_NOT_FOUND'
1038
                    'data'      => 'ERROR_USER_NOT_FOUND'
1071
                ]);
1039
                ]);
1072
            }
1040
            }
1073
            
1041
 
1074
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1042
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1075
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1043
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1076
            
1044
 
1077
            if(!$companyUser) {
1045
            if (!$companyUser) {
1078
                return new JsonModel([
1046
                return new JsonModel([
1079
                    'success'   => false,
1047
                    'success'   => false,
1080
                    'data'      => 'ERROR_USER_NOT_FOUND'
1048
                    'data'      => 'ERROR_USER_NOT_FOUND'
1081
                ]);
1049
                ]);
1082
            }
1050
            }
-
 
1051
 
1083
            
1052
            if (
1084
            if($companyUser->status != CompanyUser::STATUS_PENDING
1053
                $companyUser->status != CompanyUser::STATUS_PENDING
1085
                && $companyUser->status != CompanyUser::STATUS_SENT
1054
                && $companyUser->status != CompanyUser::STATUS_SENT
1086
                && $companyUser->status != CompanyUser::STATUS_CANCELLED
1055
                && $companyUser->status != CompanyUser::STATUS_CANCELLED
-
 
1056
                && $companyUser->status != CompanyUser::STATUS_REJECTED
1087
                && $companyUser->status != CompanyUser::STATUS_REJECTED) {
1057
            ) {
1088
                return new JsonModel([
1058
                return new JsonModel([
1089
                    'success'   => false,
1059
                    'success'   => false,
1090
                    'data'      => 'ERROR_USER_COMPANY_WRONG_STATUS'
1060
                    'data'      => 'ERROR_USER_COMPANY_WRONG_STATUS'
1091
                ]);
1061
                ]);
1092
            }
1062
            }
1093
            
1063
 
1094
            $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1064
            $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1095
            $result = $companyUserMapper->update($companyUser);
1065
            $result = $companyUserMapper->update($companyUser);
1096
            if($result) {
1066
            if ($result) {
1097
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido aceptada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1067
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido aceptada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1098
                
1068
 
1099
                return new JsonModel([
1069
                return new JsonModel([
1100
                    'success'   => true,
1070
                    'success'   => true,
1101
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_ACCEPTED'
1071
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_ACCEPTED'
1102
                ]);
1072
                ]);
1103
            }  else {
1073
            } else {
1104
                
1074
 
1105
                return new JsonModel([
1075
                return new JsonModel([
1106
                    'success'   => false,
1076
                    'success'   => false,
1107
                    'data'      => $userMapper->getError()
1077
                    'data'      => $userMapper->getError()
1108
                ]);
1078
                ]);
1109
            }
-
 
1110
            
-
 
1111
            
1079
            }
1112
        }
1080
        }
1113
        
1081
 
1114
        
1082
 
1115
        
1083
 
1116
        return new JsonModel([
1084
        return new JsonModel([
1117
            'success' => false,
1085
            'success' => false,
1118
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1086
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1119
        ]);
1087
        ]);
1120
    }
1088
    }
1121
    
1089
 
1122
    public function rejectAction()
1090
    public function rejectAction()
1123
    {
1091
    {
1124
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1092
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1125
        $currentUser = $currentUserPlugin->getUser();
1093
        $currentUser = $currentUserPlugin->getUser();
1126
        
1094
 
1127
        $currentCompany = $currentUserPlugin->getCompany();
1095
        $currentCompany = $currentUserPlugin->getCompany();
1128
        
1096
 
1129
        $request = $this->getRequest();
1097
        $request = $this->getRequest();
1130
        
1098
 
1131
        
1099
 
1132
        if($request->isPost()) {
1100
        if ($request->isPost()) {
1133
            
1101
 
1134
            $uuid = $this->params()->fromRoute('id');
1102
            $uuid = $this->params()->fromRoute('id');
1135
            if(!$uuid) {
1103
            if (!$uuid) {
1136
                return new JsonModel([
1104
                return new JsonModel([
1137
                    'success'   => false,
1105
                    'success'   => false,
1138
                    'data'      => 'ERROR_INVALID_PARAMETER'
1106
                    'data'      => 'ERROR_INVALID_PARAMETER'
1139
                ]);
1107
                ]);
1140
            }
1108
            }
1141
            
1109
 
1142
            $userMapper = UserMapper::getInstance($this->adapter);
1110
            $userMapper = UserMapper::getInstance($this->adapter);
1143
            $user = $userMapper->fetchOneByUuid($uuid);
1111
            $user = $userMapper->fetchOneByUuid($uuid);
1144
            
1112
 
1145
            if(!$user) {
1113
            if (!$user) {
1146
                return new JsonModel([
1114
                return new JsonModel([
1147
                    'success'   => false,
1115
                    'success'   => false,
1148
                    'data'      => 'ERROR_USER_NOT_FOUND'
1116
                    'data'      => 'ERROR_USER_NOT_FOUND'
1149
                ]);
1117
                ]);
1150
            }
1118
            }
1151
            
1119
 
1152
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1120
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1153
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1121
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1154
            
1122
 
1155
            if(!$companyUser) {
1123
            if (!$companyUser) {
1156
                return new JsonModel([
1124
                return new JsonModel([
1157
                    'success'   => false,
1125
                    'success'   => false,
1158
                    'data'      => 'ERROR_USER_COMPANY_NOT_FOUND'
1126
                    'data'      => 'ERROR_USER_COMPANY_NOT_FOUND'
1159
                ]);
1127
                ]);
1160
            }
1128
            }
-
 
1129
 
1161
            
1130
            if (
1162
            if($companyUser->status != CompanyUser::STATUS_PENDING 
1131
                $companyUser->status != CompanyUser::STATUS_PENDING
-
 
1132
                && $companyUser->status != CompanyUser::STATUS_SENT
1163
                && $companyUser->status != CompanyUser::STATUS_SENT) {
1133
            ) {
1164
                return new JsonModel([
1134
                return new JsonModel([
1165
                    'success'   => false,
1135
                    'success'   => false,
1166
                    'data'      => 'ERROR_USER_COMPANY_WRONG_STATUS'
1136
                    'data'      => 'ERROR_USER_COMPANY_WRONG_STATUS'
1167
                ]);
1137
                ]);
1168
            }
1138
            }
1169
            
1139
 
1170
            $companyUser->status = CompanyUser::STATUS_REJECTED;
1140
            $companyUser->status = CompanyUser::STATUS_REJECTED;
1171
            $result = $companyUserMapper->update($companyUser);
1141
            $result = $companyUserMapper->update($companyUser);
1172
            if($result) {
1142
            if ($result) {
1173
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido rechazada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1143
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido rechazada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1174
                
1144
 
1175
                return new JsonModel([
1145
                return new JsonModel([
1176
                    'success'   => true,
1146
                    'success'   => true,
1177
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_REJECTED',
1147
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_REJECTED',
1178
                ]);
1148
                ]);
1179
            }  else {
1149
            } else {
1180
                
1150
 
1181
                return new JsonModel([
1151
                return new JsonModel([
1182
                    'success'   => false,
1152
                    'success'   => false,
1183
                    'data'      => $userMapper->getError()
1153
                    'data'      => $userMapper->getError()
1184
                ]);
1154
                ]);
1185
            }
-
 
1186
            
-
 
1187
            
1155
            }
1188
        }
1156
        }
1189
        
1157
 
1190
        
1158
 
1191
        
1159
 
1192
        return new JsonModel([
1160
        return new JsonModel([
1193
            'success' => false,
1161
            'success' => false,
1194
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1162
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1195
        ]);
1163
        ]);
1196
    }
1164
    }
1197
    
1165
 
1198
    public function inviteAction()
1166
    public function inviteAction()
1199
    {
1167
    {
1200
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1168
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1201
        $currentUser = $currentUserPlugin->getUser();
1169
        $currentUser = $currentUserPlugin->getUser();
1202
        
1170
 
1203
        
1171
 
1204
        
1172
 
1205
        $currentCompany = $currentUserPlugin->getCompany();
1173
        $currentCompany = $currentUserPlugin->getCompany();
1206
        
1174
 
1207
        $request = $this->getRequest();
1175
        $request = $this->getRequest();
1208
        
1176
 
1209
        if($request->isGet()) {
1177
        if ($request->isGet()) {
1210
            
1178
 
1211
            $search = Functions::sanitizeFilterString($this->params()->fromQuery('search')) ;
1179
            $search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
1212
            if(strlen($search) >= 3) {
1180
            if (strlen($search) >= 3) {
1213
                
1181
 
1214
                $userMapper = UserMapper::getInstance($this->adapter);
1182
                $userMapper = UserMapper::getInstance($this->adapter);
1215
                $records  = $userMapper->fetchAllSuggestForInvitationByCompanyId($currentCompany->id, $search);
1183
                $records  = $userMapper->fetchAllSuggestForInvitationByCompanyId($currentCompany->id, $search);
1216
                
1184
 
1217
                $users = []; 
1185
                $users = [];
1218
                foreach($records as $record)
-
 
1219
                {
1186
                foreach ($records as $record) {
1220
                    array_push($users, [
1187
                    array_push($users, [
1221
                        'value' => $record->uuid, 
1188
                        'value' => $record->uuid,
1222
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')' 
1189
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
1223
                        
1190
 
1224
                    ]);
1191
                    ]);
1225
                }
1192
                }
1226
                
1193
 
1227
                return new JsonModel([
1194
                return new JsonModel([
1228
                    'success' => true,
1195
                    'success' => true,
1229
                    'data' => $users
1196
                    'data' => $users
1230
                ]);
-
 
1231
                
-
 
1232
             
-
 
1233
                
-
 
1234
                
1197
                ]);
1235
            } else {
1198
            } else {
1236
                return new JsonModel([
1199
                return new JsonModel([
1237
                    'success' => true,
1200
                    'success' => true,
1238
                    'data' => [
-
 
1239
                        
-
 
1240
                    ]
1201
                    'data' => []
1241
                ]); 
1202
                ]);
1242
            } 
-
 
1243
            
-
 
1244
            
-
 
1245
            
-
 
1246
            
-
 
1247
            
-
 
1248
            
1203
            }
1249
        } else if($request->isPost()) {
1204
        } else if ($request->isPost()) {
1250
            
1205
 
1251
            $uuid = $this->params()->fromPost('id');
1206
            $uuid = $this->params()->fromPost('id');
1252
            if(!$uuid) {
1207
            if (!$uuid) {
1253
                return new JsonModel([
1208
                return new JsonModel([
1254
                    'success'   => false,
1209
                    'success'   => false,
1255
                    'data'      => 'ERROR_INVALID_PARAMETER'
1210
                    'data'      => 'ERROR_INVALID_PARAMETER'
1256
                ]);
1211
                ]);
1257
            }
1212
            }
1258
            
1213
 
1259
            $userMapper = UserMapper::getInstance($this->adapter);
1214
            $userMapper = UserMapper::getInstance($this->adapter);
1260
            $user = $userMapper->fetchOneByUuid($uuid);
1215
            $user = $userMapper->fetchOneByUuid($uuid);
1261
            
1216
 
1262
            if(!$user) {
1217
            if (!$user) {
1263
                return new JsonModel([
1218
                return new JsonModel([
1264
                    'success'   => false,
1219
                    'success'   => false,
1265
                    'data'      => 'ERROR_USER_NOT_FOUND'
1220
                    'data'      => 'ERROR_USER_NOT_FOUND'
1266
                ]);
1221
                ]);
1267
            }
1222
            }
1268
            
1223
 
1269
            if($user->status != User::STATUS_ACTIVE) {
1224
            if ($user->status != User::STATUS_ACTIVE) {
1270
                return new JsonModel([
1225
                return new JsonModel([
1271
                    'success'   => false,
1226
                    'success'   => false,
1272
                    'data'      => 'ERROR_USER_IS_INACTIVE'
1227
                    'data'      => 'ERROR_USER_IS_INACTIVE'
1273
                ]);
1228
                ]);
1274
            }
1229
            }
1275
            
1230
 
1276
            
1231
 
1277
            
1232
 
1278
            
1233
 
1279
            
1234
 
1280
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1235
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1281
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1236
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1282
            
1237
 
1283
            if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED) {
1238
            if ($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED) {
1284
                return new JsonModel([
1239
                return new JsonModel([
1285
                    'success'   => false,
1240
                    'success'   => false,
1286
                    'data'      => 'ERROR_USER_COMPANY_FOUND'
1241
                    'data'      => 'ERROR_USER_COMPANY_FOUND'
1287
                ]);
1242
                ]);
1288
            }
1243
            }
1289
            $networkMapper = NetworkMapper::getInstance($this->adapter);
1244
            $networkMapper = NetworkMapper::getInstance($this->adapter);
Línea 1290... Línea 1245...
1290
            $network = $networkMapper->fetchOne($currentUser->network_id);
1245
            $network = $networkMapper->fetchOne($currentUser->network_id);
1291
 
1246
 
1292
            
1247
 
1293
            if($companyUser) {
1248
            if ($companyUser) {
1294
                
1249
 
1295
                
1250
 
1296
                if($network->default == Network::DEFAULT_YES) {
1251
                if ($network->default == Network::DEFAULT_YES) {
1297
                    $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1252
                    $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1298
                } else {
1253
                } else {
1299
                    $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1254
                    $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1300
                }
-
 
1301
                $result = $companyUserMapper->update($companyUser);
1255
                }
Línea 1302... Línea 1256...
1302
                
1256
                $result = $companyUserMapper->update($companyUser);
1303
            } else {
1257
            } else {
1304
 
1258
 
1305
                
1259
 
1306
                $companyUser = new CompanyUser();
1260
                $companyUser = new CompanyUser();
1307
                $companyUser->company_id = $currentCompany->id;
1261
                $companyUser->company_id = $currentCompany->id;
1308
                $companyUser->backend = CompanyUser::BACKEND_NO;
1262
                $companyUser->backend = CompanyUser::BACKEND_NO;
1309
                $companyUser->creator = CompanyUser::CREATOR_NO;
1263
                $companyUser->creator = CompanyUser::CREATOR_NO;
1310
                $companyUser->owner = CompanyUser::OWNER_NO;
1264
                $companyUser->owner = CompanyUser::OWNER_NO;
1311
                
1265
 
1312
                if($network->default == Network::DEFAULT_YES) {
1266
                if ($network->default == Network::DEFAULT_YES) {
1313
                    $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1267
                    $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1314
                } else {
1268
                } else {
1315
                    $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1269
                    $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1316
                }
1270
                }
1317
                
1271
 
1318
                
1272
 
1319
                $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1273
                $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1320
                $companyUser->user_id = $user->id;
1274
                $companyUser->user_id = $user->id;
1321
                
1275
 
1322
                
1276
 
1323
                
-
 
1324
                $result = $companyUserMapper->insert($companyUser);
-
 
1325
            }
-
 
1326
           
-
 
Línea -... Línea 1277...
-
 
1277
 
1327
  
1278
                $result = $companyUserMapper->insert($companyUser);
-
 
1279
            }
-
 
1280
 
-
 
1281
 
1328
            
1282
 
1329
            if($result) {
1283
            if ($result) {
1330
 
1284
 
1331
                
1285
 
1332
                $notification = new Notification();
1286
                $notification = new Notification();
1333
                $notification->type     = Notification::TYPE_RECEIVE_INVITATION_COMPANY;
1287
                $notification->type     = Notification::TYPE_RECEIVE_INVITATION_COMPANY;
1334
                $notification->read     = Notification::NO;
1288
                $notification->read     = Notification::NO;
1335
                $notification->user_id  = $user->id;
1289
                $notification->user_id  = $user->id;
1336
                $notification->company_id = $currentCompany->id;
1290
                $notification->company_id = $currentCompany->id;
1337
                $notification->message  = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_COMPANY';
1291
                $notification->message  = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_COMPANY';
1338
                $notification->url      = 'company/view/' . $currentCompany->uuid;
1292
                $notification->url      = 'company/view/' . $currentCompany->uuid;
1339
                
1293
 
1340
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
1294
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
1341
                $notificationMapper->insert($notification);
1295
                $notificationMapper->insert($notification);
1342
                
1296
 
1343
                $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
-
 
1344
                $userNotification = $userNotificationMapper->fetchOne($user->id);
1297
                $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
1345
                
1298
                $userNotification = $userNotificationMapper->fetchOne($user->id);
1346
                if($userNotification && $userNotification->receive_invitation_company)
1299
 
1347
                {
1300
                if ($userNotification && $userNotification->receive_invitation_company) {
1348
                    $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
-
 
1349
                    $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_COMPANY, $currentUser->network_id);
1301
                    $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1350
                    
1302
                    $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_COMPANY, $currentUser->network_id);
1351
                    if($emailTemplate) 
1303
 
1352
                    {
1304
                    if ($emailTemplate) {
1353
                        $company_profile_url = 'https://'. $network->main_hostname . '/company/view/' . $currentCompany->uuid;
1305
                        $company_profile_url = 'https://' . $network->main_hostname . '/company/view/' . $currentCompany->uuid;
1354
                        
1306
 
1355
                        
1307
 
1356
                        $arrayCont = [
1308
                        $arrayCont = [
Línea 1362... Línea 1314...
1362
                            'group_name'            => '',
1314
                            'group_name'            => '',
1363
                            'content'               => '',
1315
                            'content'               => '',
1364
                            'code'                  => '',
1316
                            'code'                  => '',
1365
                            'link'                  => $company_profile_url,
1317
                            'link'                  => $company_profile_url,
1366
                        ];
1318
                        ];
1367
                        
1319
 
1368
                        $email = new QueueEmail($this->adapter);
1320
                        $email = new QueueEmail($this->adapter);
1369
                        $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1321
                        $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1370
                    }
1322
                    }
1371
                }
1323
                }
1372
                
1324
 
1373
                
1325
 
1374
                $this->logger->info('La empresa : ' . $currentCompany->name . ' envio al usuario : ' . $user->email . ' una invitación ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1326
                $this->logger->info('La empresa : ' . $currentCompany->name . ' envio al usuario : ' . $user->email . ' una invitación ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1375
                
1327
 
1376
                if($network->default == Network::DEFAULT_YES) {
1328
                if ($network->default == Network::DEFAULT_YES) {
1377
                    return new JsonModel([
1329
                    return new JsonModel([
1378
                        'success'   => true,
1330
                        'success'   => true,
1379
                        'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_CREATED',
1331
                        'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_CREATED',
1380
                    ]);
1332
                    ]);
1381
                } else {
1333
                } else {
1382
                    return new JsonModel([
1334
                    return new JsonModel([
1383
                        'success'   => true,
1335
                        'success'   => true,
1384
                        'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_INVITED_SENT',
1336
                        'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_INVITED_SENT',
1385
                    ]);
1337
                    ]);
1386
                }
1338
                }
1387
                
-
 
1388
                
-
 
1389
            }  else {
1339
            } else {
1390
                
1340
 
1391
                return new JsonModel([
1341
                return new JsonModel([
1392
                    'success'   => false,
1342
                    'success'   => false,
1393
                    'data'      => $userMapper->getError()
1343
                    'data'      => $userMapper->getError()
1394
                ]);
1344
                ]);
1395
            }
1345
            }
1396
            
-
 
1397
            
-
 
1398
        }
1346
        }
1399
        
1347
 
1400
        
1348
 
1401
        
1349
 
1402
        return new JsonModel([
1350
        return new JsonModel([
1403
            'success' => false,
1351
            'success' => false,
1404
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1352
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1405
        ]);
1353
        ]);
1406
    }
1354
    }
1407
    
1355
 
1408
    
1356
 
1409
    public function deleteAction()
1357
    public function deleteAction()
1410
    {
1358
    {
1411
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1359
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1412
        $currentUser = $currentUserPlugin->getUser();
1360
        $currentUser = $currentUserPlugin->getUser();
1413
        
1361
 
1414
        $currentCompany = $currentUserPlugin->getCompany();
1362
        $currentCompany = $currentUserPlugin->getCompany();
1415
        
1363
 
1416
        $request = $this->getRequest();
1364
        $request = $this->getRequest();
1417
        
1365
 
1418
        
1366
 
1419
        if($request->isPost()) {
1367
        if ($request->isPost()) {
1420
            
1368
 
1421
            $uuid = $this->params()->fromRoute('id');
1369
            $uuid = $this->params()->fromRoute('id');
1422
            if(!$uuid) {
1370
            if (!$uuid) {
1423
                return new JsonModel([
1371
                return new JsonModel([
1424
                    'success'   => false,
1372
                    'success'   => false,
1425
                    'data'      => 'ERROR_INVALID_PARAMETER'
1373
                    'data'      => 'ERROR_INVALID_PARAMETER'
1426
                ]);
1374
                ]);
1427
            }
1375
            }
1428
            
1376
 
1429
            $userMapper = UserMapper::getInstance($this->adapter);
1377
            $userMapper = UserMapper::getInstance($this->adapter);
1430
            $user = $userMapper->fetchOneByUuid($uuid);
1378
            $user = $userMapper->fetchOneByUuid($uuid);
1431
            
1379
 
1432
            if(!$user) {
1380
            if (!$user) {
1433
                return new JsonModel([
1381
                return new JsonModel([
1434
                    'success'   => false,
1382
                    'success'   => false,
1435
                    'data'      => 'ERROR_USER_NOT_FOUND'
1383
                    'data'      => 'ERROR_USER_NOT_FOUND'
1436
                    
1384
 
1437
                ]);
1385
                ]);
1438
            }
1386
            }
1439
            
1387
 
1440
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1388
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1441
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1389
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1442
            
1390
 
1443
            if($companyUser) {
1391
            if ($companyUser) {
1444
                return new JsonModel([
1392
                return new JsonModel([
1445
                    'success'   => false,
1393
                    'success'   => false,
1446
                    'data'      => 'ERROR_USER_COMPANY_NOT_FOUND'
1394
                    'data'      => 'ERROR_USER_COMPANY_NOT_FOUND'
1447
                ]);
1395
                ]);
1448
            }
1396
            }
1449
            
1397
 
1450
            
1398
 
1451
            if(!$currentCompany->internal) {
1399
            if (!$currentCompany->internal) {
1452
                return new JsonModel([
1400
                return new JsonModel([
1453
                    'success'   => false,
1401
                    'success'   => false,
1454
                    'data'      => 'ERROR_INTERNAL_COMPANY_ONLY'
1402
                    'data'      => 'ERROR_INTERNAL_COMPANY_ONLY'
1455
                ]);
1403
                ]);
1456
            }
1404
            }
Línea 1457... Línea 1405...
1457
 
1405
 
Línea 1458... Línea 1406...
1458
            
1406
 
1459
 
1407
 
1460
            $result = $companyUserMapper->delete($companyUser->id);
1408
            $result = $companyUserMapper->delete($companyUser->id);
1461
            if($result) {
1409
            if ($result) {
1462
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido eliminada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1410
                $this->logger->info('La relación del usuario : ' . $user->email . ' con la empresa : ' . $currentCompany->name  . ' ha sido eliminada ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1463
                
1411
 
1464
                return new JsonModel([
1412
                return new JsonModel([
1465
                    'success'   => true,
1413
                    'success'   => true,
1466
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_DELETED',
1414
                    'data'      => 'LABEL_USER_COMPANY_HAS_BEEN_DELETED',
1467
                ]);
1415
                ]);
1468
            }  else {
1416
            } else {
1469
                
1417
 
1470
                return new JsonModel([
1418
                return new JsonModel([
1471
                    'success'   => false,
1419
                    'success'   => false,
1472
                    'data'      => $userMapper->getError()
1420
                    'data'      => $userMapper->getError()
1473
                ]);
-
 
1474
            }
-
 
1475
            
1421
                ]);
1476
            
1422
            }
1477
        }
1423
        }
1478
        
1424
 
1479
        
1425
 
1480
        
1426
 
1481
        return new JsonModel([
1427
        return new JsonModel([
1482
            'success' => false,
1428
            'success' => false,
1483
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1429
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1484
        ]);
1430
        ]);
1485
    }
1431
    }
1486
    
1432
 
1487
    
1433
 
1488
    public function uploadAction()
1434
    public function uploadAction()
1489
    {
1435
    {
1490
        $request = $this->getRequest();
1436
        $request = $this->getRequest();
1491
        
1437
 
1492
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1438
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1493
        $currentNetwork    = $currentNetworkPlugin->getNetwork();
1439
        $currentNetwork    = $currentNetworkPlugin->getNetwork();
1494
        
1440
 
1495
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1441
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1496
        $currentUser    = $currentUserPlugin->getUser();
1442
        $currentUser    = $currentUserPlugin->getUser();
1497
        $currentCompany = $currentUserPlugin->getCompany();
1443
        $currentCompany = $currentUserPlugin->getCompany();
Línea 1498... Línea 1444...
1498
        
1444
 
1499
        $request    = $this->getRequest();
1445
        $request    = $this->getRequest();
1500
 
1446
 
1501
        if($request->isPost()) {
1447
        if ($request->isPost()) {
1502
            
1448
 
1503
            $step = Functions::sanitizeFilterString($this->params()->fromPost('step'));
1449
            $step = Functions::sanitizeFilterString($this->params()->fromPost('step'));
1504
            if($step == 'validation') {
1450
            if ($step == 'validation') {
1505
                $userMapper = UserMapper::getInstance($this->adapter);
1451
                $userMapper = UserMapper::getInstance($this->adapter);
1506
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1452
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1507
                
1453
 
1508
                $form = new  UserUploadForm();
1454
                $form = new  UserUploadForm();
1509
                $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1455
                $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1510
                
1456
 
1511
                $form->setData($dataPost);
1457
                $form->setData($dataPost);
1512
                
1458
 
1513
                if($form->isValid()) {
1459
                if ($form->isValid()) {
1514
                    
1460
 
1515
                    $file = $_FILES['file'];
1461
                    $file = $_FILES['file'];
1516
                    $tmp_filename = $file['tmp_name'];
1462
                    $tmp_filename = $file['tmp_name'];
1517
                    $final_filename =  'data/' . $file['name'];
1463
                    $final_filename =  'data/' . $file['name'];
1518
                    
1464
 
1519
                    if(!move_uploaded_file($tmp_filename, $final_filename)) {
1465
                    if (!move_uploaded_file($tmp_filename, $final_filename)) {
1520
                        return new JsonModel([
1466
                        return new JsonModel([
1521
                            'success' => false,
1467
                            'success' => false,
1522
                            'data' => 'ERROR_UPLOAD_FILE'
1468
                            'data' => 'ERROR_UPLOAD_FILE'
1523
                        ]);
1469
                        ]);
1524
                    }
1470
                    }
1525
                    
1471
 
1526
                    
1472
 
1527
                    $users = [];
1473
                    $users = [];
1528
                    
1474
 
1529
                    
1475
 
1530
                    $spreadsheet = IOFactory::load($final_filename);
1476
                    $spreadsheet = IOFactory::load($final_filename);
1531
                    $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
1477
                    $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
1532
                    
1478
 
1533
                    $emails = [];
-
 
1534
                    
1479
                    $emails = [];
1535
                    foreach($records as $record)
1480
 
1536
                    {
1481
                    foreach ($records as $record) {
1537
                        //A = Nombre 	B = Apellidos	C = Email 	D = contraseña
1482
                        //A = Nombre 	B = Apellidos	C = Email 	D = contraseña
1538
                        
1483
 
1539
                      
1484
 
1540
                        $first_name = Functions::sanitizeFilterString($record['A']);
1485
                        $first_name = Functions::sanitizeFilterString($record['A']);
1541
                        $last_name = Functions::sanitizeFilterString($record['B']);
1486
                        $last_name = Functions::sanitizeFilterString($record['B']);
1542
                        $email = trim(filter_var($record['C'], FILTER_SANITIZE_EMAIL));
1487
                        $email = trim(filter_var($record['C'], FILTER_SANITIZE_EMAIL));
1543
                     
1488
 
Línea 1544... Línea 1489...
1544
                        $password = Functions::sanitizeFilterString($record['D']);
1489
                        $password = Functions::sanitizeFilterString($record['D']);
1545
                        $isAdult = strtolower(Functions::sanitizeFilterString($record['E']));
1490
                        $isAdult = strtolower(Functions::sanitizeFilterString($record['E']));
1546
                        $country = strtolower(Functions::sanitizeFilterString($record['F']));
1491
                        $country = strtolower(Functions::sanitizeFilterString($record['F']));
1547
 
1492
 
1548
                        
1493
 
1549
                        if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ||  empty($password)) {
1494
                        if (empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ||  empty($password)) {
1550
                            continue;
1495
                            continue;
1551
                        }
1496
                        }
1552
                        
1497
 
1553
                        if(!in_array($email, $emails)) {
1498
                        if (!in_array($email, $emails)) {
1554
                            
1499
 
1555
                            $user = $userMapper->fetchOneByEmail($email);
1500
                            $user = $userMapper->fetchOneByEmail($email);
1556
                            
1501
 
1557
                            array_push($emails, $email);
1502
                            array_push($emails, $email);
Línea 1563... Línea 1508...
1563
                                'is_adult' => $isAdult,
1508
                                'is_adult' => $isAdult,
1564
                                'country' => $country,
1509
                                'country' => $country,
Línea 1565... Línea 1510...
1565
 
1510
 
1566
                            ]);
1511
                            ]);
1567
                        }
-
 
1568
                        
-
 
1569
                        
-
 
1570
                        
-
 
1571
                        
-
 
1572
                        
1512
                        }
1573
                    }
1513
                    }
1574
                    
1514
 
1575
                    $key = md5($currentUser->id . '-' . microtime(true));
1515
                    $key = md5($currentUser->id . '-' . microtime(true));
1576
                    $this->cache->setItem($key, serialize($users));
1516
                    $this->cache->setItem($key, serialize($users));
1577
                    
1517
 
1578
                    return new JsonModel([
1518
                    return new JsonModel([
1579
                        'success' => true,
1519
                        'success' => true,
1580
                        'data' => [
1520
                        'data' => [
1581
                            'key' => $key,
1521
                            'key' => $key,
1582
                            'items' => $users,
1522
                            'items' => $users,
1583
                        ]
1523
                        ]
1584
                    ]);
1524
                    ]);
1585
                    
1525
 
1586
                    @unlink($final_filename);
-
 
1587
                    
-
 
1588
                    
1526
                    @unlink($final_filename);
1589
                } else {
1527
                } else {
1590
                    $messages = [];
1528
                    $messages = [];
1591
                    $form_messages = (array) $form->getMessages();
1529
                    $form_messages = (array) $form->getMessages();
1592
                    foreach($form_messages  as $fieldname => $field_messages)
-
 
1593
                    {
1530
                    foreach ($form_messages  as $fieldname => $field_messages) {
1594
                        
1531
 
1595
                        $messages[$fieldname] = array_values($field_messages);
1532
                        $messages[$fieldname] = array_values($field_messages);
1596
                    }
1533
                    }
1597
                    
1534
 
1598
                    return new JsonModel([
1535
                    return new JsonModel([
1599
                        'success'   => false,
1536
                        'success'   => false,
1600
                        'data'   => $messages
1537
                        'data'   => $messages
1601
                    ]);
1538
                    ]);
1602
                }
1539
                }
1603
            } else if($step == 'process') {
1540
            } else if ($step == 'process') {
1604
                
1541
 
1605
                $key = Functions::sanitizeFilterString($this->params()->fromPost('key'));
1542
                $key = Functions::sanitizeFilterString($this->params()->fromPost('key'));
1606
                if(!$key) {
1543
                if (!$key) {
1607
                    return new JsonModel([
1544
                    return new JsonModel([
1608
                        'success' => false,
1545
                        'success' => false,
1609
                        'data' => 'ERROR_CACHE_KEY_EMPTY'
1546
                        'data' => 'ERROR_CACHE_KEY_EMPTY'
1610
                    ]);
1547
                    ]);
1611
                }
1548
                }
1612
                
1549
 
1613
                $value = $this->cache->getItem($key);
1550
                $value = $this->cache->getItem($key);
1614
                if(!$value) {
1551
                if (!$value) {
1615
                    
1552
 
1616
                    return new JsonModel([
1553
                    return new JsonModel([
1617
                        'success' => false,
1554
                        'success' => false,
1618
                        'data' => 'ERROR_CACHE_NOT_FOUND'
1555
                        'data' => 'ERROR_CACHE_NOT_FOUND'
1619
                    ]);
1556
                    ]);
1620
                }
1557
                }
1621
                
1558
 
1622
                $records = unserialize($value);
1559
                $records = unserialize($value);
1623
                if(!$records) {
1560
                if (!$records) {
1624
                    return new JsonModel([
1561
                    return new JsonModel([
1625
                        'success' => false,
1562
                        'success' => false,
1626
                        'data' => 'ERROR_CACHE_INVALID'
1563
                        'data' => 'ERROR_CACHE_INVALID'
1627
                    ]);
1564
                    ]);
1628
                }
1565
                }
1629
                
1566
 
1630
                $locationMapper = LocationMapper::getInstance($this->adapter);
1567
                $locationMapper = LocationMapper::getInstance($this->adapter);
1631
                $countryMapper = CountryMapper::getInstance($this->adapter);
1568
                $countryMapper = CountryMapper::getInstance($this->adapter);
1632
                
1569
 
1633
                
1570
 
1634
                $networkMapper = NetworkMapper::getInstance($this->adapter);
1571
                $networkMapper = NetworkMapper::getInstance($this->adapter);
1635
                $networkDefault = $networkMapper->fetchOneByDefault();
1572
                $networkDefault = $networkMapper->fetchOneByDefault();
1636
                
1573
 
1637
                $userMapper = UserMapper::getInstance($this->adapter);
1574
                $userMapper = UserMapper::getInstance($this->adapter);
1638
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1575
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
Línea 1639... Línea 1576...
1639
                
1576
 
1640
 
1577
 
1641
                $user_ids_in_default_network = [];
1578
                $user_ids_in_default_network = [];
1642
                
1579
 
1643
                
1580
 
1644
                $users_created = 0;
1581
                $users_created = 0;
1645
                $user_ids = [];
-
 
1646
                foreach($records as $record)
1582
                $user_ids = [];
1647
                {
1583
                foreach ($records as $record) {
1648
                    $first_name = $record['first_name'];
1584
                    $first_name = $record['first_name'];
1649
                    $last_name = $record['last_name'];
1585
                    $last_name = $record['last_name'];
1650
                    $password = $record['password'];
1586
                    $password = $record['password'];
1651
                    $email = $record['email'];
1587
                    $email = $record['email'];
1652
                    
1588
 
1653
                    
1589
 
1654
                    $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1590
                    $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1655
                    if(!$user) {
1591
                    if (!$user) {
1656
                        $password_hash = password_hash($password, PASSWORD_DEFAULT);
1592
                        $password_hash = password_hash($password, PASSWORD_DEFAULT);
1657
                        
1593
 
1658
                        $user = new User();
1594
                        $user = new User();
1659
                        $user->network_id = $currentNetwork->id;
1595
                        $user->network_id = $currentNetwork->id;
1660
                        $user->blocked = User::BLOCKED_NO;
1596
                        $user->blocked = User::BLOCKED_NO;
Línea 1665... Línea 1601...
1665
                        $user->password = $password_hash;
1601
                        $user->password = $password_hash;
1666
                        $user->login_attempt = 0;
1602
                        $user->login_attempt = 0;
1667
                        $user->usertype_id = UserType::USER;
1603
                        $user->usertype_id = UserType::USER;
1668
                        $user->status = User::STATUS_ACTIVE;
1604
                        $user->status = User::STATUS_ACTIVE;
1669
                        $user->is_adult = $record['is_adult'] == 'y' ? User::IS_ADULT_YES : User::IS_ADULT_NO;
1605
                        $user->is_adult = $record['is_adult'] == 'y' ? User::IS_ADULT_YES : User::IS_ADULT_NO;
1670
                        
1606
 
1671
                        $result = $userMapper->insert($user);
1607
                        $result = $userMapper->insert($user);
1672
                        if($result) {
1608
                        if ($result) {
1673
                            $users_created++;
1609
                            $users_created++;
1674
                            
1610
 
1675
                            $country_code = trim($record['country']);
1611
                            $country_code = trim($record['country']);
1676
                            
1612
 
1677
                            if($country_code) {
1613
                            if ($country_code) {
1678
                                $country = $countryMapper->fetchOneByCodeOrCountry($record['country']);
1614
                                $country = $countryMapper->fetchOneByCodeOrCountry($record['country']);
1679
                                if($country) {
1615
                                if ($country) {
1680
                                
1616
 
1681
                                    $location = new Location();
1617
                                    $location = new Location();
1682
                                    $location->formatted_address = $country->country;
1618
                                    $location->formatted_address = $country->country;
1683
                                    $location->country = $country->country;
1619
                                    $location->country = $country->country;
1684
                                    if($locationMapper->insert($location)) {
1620
                                    if ($locationMapper->insert($location)) {
1685
                                    
1621
 
1686
                                        $user->location_id = $location->id;
1622
                                        $user->location_id = $location->id;
1687
                                        $userMapper->updateLocation($user);
1623
                                        $userMapper->updateLocation($user);
1688
                                    }
1624
                                    }
1689
                                    
-
 
1690
                                }
1625
                                }
1691
                            } else {
1626
                            } else {
1692
                                $country_code = '';
1627
                                $country_code = '';
1693
                            }
1628
                            }
1694
                            
1629
 
1695
                            $userPassword = new UserPassword();
1630
                            $userPassword = new UserPassword();
1696
                            $userPassword->user_id = $user->id;
1631
                            $userPassword->user_id = $user->id;
1697
                            $userPassword->password = $password_hash;
1632
                            $userPassword->password = $password_hash;
1698
                            $userPasswordMapper->insert($userPassword);
1633
                            $userPasswordMapper->insert($userPassword);
1699
                            
1634
 
1700
                            
1635
 
1701
                            if($currentNetwork->default == Network::DEFAULT_YES) {
1636
                            if ($currentNetwork->default == Network::DEFAULT_YES) {
1702
                                array_push($user_ids_in_default_network, $user->id);
1637
                                array_push($user_ids_in_default_network, $user->id);
1703
                            } else {
1638
                            } else {
1704
                                
1639
 
1705
                                
1640
 
1706
                                
1641
 
1707
                                if($user->is_adult == User::IS_ADULT_YES) {
1642
                                if ($user->is_adult == User::IS_ADULT_YES) {
1708
                                    
1643
 
1709
                                    $userInDefaultNetwork = $userMapper->fetchOneByEmailAndNetworkId($user->email, $networkDefault->id);
1644
                                    $userInDefaultNetwork = $userMapper->fetchOneByEmailAndNetworkId($user->email, $networkDefault->id);
1710
                                    if($userInDefaultNetwork) {
1645
                                    if ($userInDefaultNetwork) {
1711
             
1646
 
1712
                                        array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
1647
                                        array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
1713
                                        
1648
 
1714
                                        if($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
1649
                                        if ($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
1715
                                            $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
1650
                                            $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
1716
                                            $userInDefaultNetwork->status != User::STATUS_ACTIVE;
1651
                                            $userInDefaultNetwork->status != User::STATUS_ACTIVE;
1717
                                            
1652
 
1718
                                            if(!$userMapper->update($userInDefaultNetwork)) {
1653
                                            if (!$userMapper->update($userInDefaultNetwork)) {
1719
                                                continue;
1654
                                                continue;
1720
                                            }
1655
                                            }
1721
                                        }
1656
                                        }
1722
                                        
-
 
1723
                                        
-
 
1724
                                    } else {
1657
                                    } else {
1725
                                        $userInDefaultNetwork = new User();
1658
                                        $userInDefaultNetwork = new User();
1726
                                        $userInDefaultNetwork->network_id = $networkDefault->id;
1659
                                        $userInDefaultNetwork->network_id = $networkDefault->id;
1727
                                        $userInDefaultNetwork->blocked = User::BLOCKED_NO;
1660
                                        $userInDefaultNetwork->blocked = User::BLOCKED_NO;
1728
                                        $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
1661
                                        $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
Línea 1733... Línea 1666...
1733
                                        $userInDefaultNetwork->login_attempt = 0;
1666
                                        $userInDefaultNetwork->login_attempt = 0;
1734
                                        $userInDefaultNetwork->usertype_id = UserType::USER;
1667
                                        $userInDefaultNetwork->usertype_id = UserType::USER;
1735
                                        $userInDefaultNetwork->status = User::STATUS_ACTIVE;
1668
                                        $userInDefaultNetwork->status = User::STATUS_ACTIVE;
1736
                                        $userInDefaultNetwork->is_adult = User::IS_ADULT_YES;
1669
                                        $userInDefaultNetwork->is_adult = User::IS_ADULT_YES;
1737
                                        $result = $userMapper->insert($userInDefaultNetwork);
1670
                                        $result = $userMapper->insert($userInDefaultNetwork);
1738
                                        if($result) {
1671
                                        if ($result) {
1739
                                            array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
1672
                                            array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
1740
                                            
1673
 
1741
                                            if($country) {
1674
                                            if ($country) {
1742
                                                
1675
 
1743
                                                $location = new Location();
1676
                                                $location = new Location();
1744
                                                $location->formatted_address = $country->country;
1677
                                                $location->formatted_address = $country->country;
1745
                                                $location->country = $country->country;
1678
                                                $location->country = $country->country;
1746
                                                if($locationMapper->insert($location)) {
1679
                                                if ($locationMapper->insert($location)) {
1747
                                                    
1680
 
1748
                                                    $userInDefaultNetwork->location_id = $location->id;
1681
                                                    $userInDefaultNetwork->location_id = $location->id;
1749
                                                    $userMapper->updateLocation($userInDefaultNetwork);
1682
                                                    $userMapper->updateLocation($userInDefaultNetwork);
1750
                                                }
1683
                                                }
1751
                                                
-
 
1752
                                            }
1684
                                            }
1753
                                            
1685
 
1754
                                            
1686
 
1755
                                            $userPassword = new UserPassword();
1687
                                            $userPassword = new UserPassword();
1756
                                            $userPassword->user_id = $userInDefaultNetwork->id;
1688
                                            $userPassword->user_id = $userInDefaultNetwork->id;
1757
                                            $userPassword->password = $password_hash;
1689
                                            $userPassword->password = $password_hash;
1758
                                            $userPasswordMapper->insert($userPassword);
1690
                                            $userPasswordMapper->insert($userPassword);
1759
                                        }
1691
                                        }
1760
                                        
-
 
1761
                                    }
1692
                                    }
1762
                                    
-
 
1763
                                    
-
 
1764
                                }
1693
                                }
1765
                                
-
 
1766
                                
-
 
1767
                            }
1694
                            }
1768
                            
-
 
1769
                            
-
 
1770
                            
-
 
1771
                            
-
 
1772
                            
-
 
1773
                            
-
 
1774
                        } else {
1695
                        } else {
1775
                            continue;
1696
                            continue;
1776
                        }
1697
                        }
1777
                    } else {
1698
                    } else {
1778
                        if($user->email_verified == User::EMAIL_VERIFIED_NO || $user->status != User::STATUS_ACTIVE) {
1699
                        if ($user->email_verified == User::EMAIL_VERIFIED_NO || $user->status != User::STATUS_ACTIVE) {
1779
                            $user->email_verified = User::EMAIL_VERIFIED_YES;
1700
                            $user->email_verified = User::EMAIL_VERIFIED_YES;
1780
                            $user->status != User::STATUS_ACTIVE;
1701
                            $user->status != User::STATUS_ACTIVE;
1781
                            
1702
 
1782
                            if(!$userMapper->update($user)) {
1703
                            if (!$userMapper->update($user)) {
1783
                                continue;
1704
                                continue;
1784
                            }
1705
                            }
1785
                        }
1706
                        }
1786
                    }
1707
                    }
1787
                    
1708
 
1788
                    array_push($user_ids, $user->id);
1709
                    array_push($user_ids, $user->id);
1789
                    
-
 
1790
                }
1710
                }
1791
                
1711
 
1792
                if($currentCompany) {
1712
                if ($currentCompany) {
1793
                
1713
 
1794
                    $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1714
                    $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1795
                    
1715
 
1796
                    $company_users_created = 0;
1716
                    $company_users_created = 0;
1797
                    
1717
 
1798
                    foreach($user_ids as $user_id)
1718
                    foreach ($user_ids as $user_id) {
1799
                    {
-
 
1800
                        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user_id);
1719
                        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user_id);
1801
                        if(!$companyUser) {
1720
                        if (!$companyUser) {
1802
                            
1721
 
1803
                            $companyUser = new CompanyUser(); 
1722
                            $companyUser = new CompanyUser();
1804
                            $companyUser->company_id = $currentCompany->id; 
1723
                            $companyUser->company_id = $currentCompany->id;
1805
                            $companyUser->user_id = $user_id; 
1724
                            $companyUser->user_id = $user_id;
1806
                            $companyUser->backend = CompanyUser::BACKEND_NO;
1725
                            $companyUser->backend = CompanyUser::BACKEND_NO;
1807
                            $companyUser->creator = CompanyUser::CREATOR_NO;
1726
                            $companyUser->creator = CompanyUser::CREATOR_NO;
1808
                            $companyUser->owner = CompanyUser::OWNER_NO; 
1727
                            $companyUser->owner = CompanyUser::OWNER_NO;
1809
                            
1728
 
1810
                            if($currentNetwork->default == Network::DEFAULT_YES) {
1729
                            if ($currentNetwork->default == Network::DEFAULT_YES) {
1811
                                $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1730
                                $companyUser->status = CompanyUser::STATUS_ADMIN_WILL_ADD;
1812
                            } else {
1731
                            } else {
1813
                                $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1732
                                $companyUser->status = CompanyUser::STATUS_ACCEPTED;
1814
                            }
1733
                            }
1815
                            
1734
 
1816
                            if($companyUserMapper->insert($companyUser)) {
1735
                            if ($companyUserMapper->insert($companyUser)) {
1817
                                $company_users_created++;
1736
                                $company_users_created++;
1818
                            }
1737
                            }
1819
                            
-
 
1820
                        }
1738
                        }
1821
                        
-
 
1822
                    }
1739
                    }
1823
                    
1740
 
1824
                    $this->logger->info('Se agregaron ' . $users_created . '  usuarios  la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1741
                    $this->logger->info('Se agregaron ' . $users_created . '  usuarios  la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1825
                    
-
 
1826
                    
-
 
1827
                    
-
 
1828
                } else {
1742
                } else {
1829
                    
1743
 
1830
                    $this->logger->info('Se agregaron ' . $users_created . ' usuarios a la red', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1744
                    $this->logger->info('Se agregaron ' . $users_created . ' usuarios a la red', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1831
                    
-
 
1832
                }
1745
                }
1833
                
1746
 
1834
                if($user_ids_in_default_network) {
1747
                if ($user_ids_in_default_network) {
1835
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
1748
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
1836
                    $companyToFollower = $companyMapper->fetchOneDefaultForFollowers();
1749
                    $companyToFollower = $companyMapper->fetchOneDefaultForFollowers();
1837
                    
1750
 
1838
                    $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
1751
                    $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
1839
                    
1752
 
1840
                    $userToConnection = $userMapper->fetchOneDefaultForConnection();
1753
                    $userToConnection = $userMapper->fetchOneDefaultForConnection();
1841
                    
1754
 
1842
                    
1755
 
1843
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1756
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1844
                    
1757
 
1845
                    foreach($user_ids_in_default_network as $user_id)
1758
                    foreach ($user_ids_in_default_network as $user_id) {
1846
                    {
-
 
1847
                        if($userToConnection) {
1759
                        if ($userToConnection) {
1848
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user_id, $userToConnection->id);
1760
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user_id, $userToConnection->id);
1849
                            if(!$connection) {
1761
                            if (!$connection) {
1850
                                $connection = new Connection();
1762
                                $connection = new Connection();
1851
                                $connection->request_from = $user_id;
1763
                                $connection->request_from = $user_id;
1852
                                $connection->request_to = $userToConnection->id;
1764
                                $connection->request_to = $userToConnection->id;
1853
                                $connection->status = Connection::STATUS_ACCEPTED;
1765
                                $connection->status = Connection::STATUS_ACCEPTED;
1854
                                
1766
 
1855
                                $connectionMapper->insert($connection);
1767
                                $connectionMapper->insert($connection);
1856
                            } else {
1768
                            } else {
1857
                                if($connection->status == Connection::STATUS_SENT) {
1769
                                if ($connection->status == Connection::STATUS_SENT) {
1858
                                    $connectionMapper->approve($connection);
1770
                                    $connectionMapper->approve($connection);
1859
                                }
1771
                                }
1860
                            }
1772
                            }
1861
                        }
1773
                        }
1862
                        
1774
 
1863
                        if($companyToFollower) {
1775
                        if ($companyToFollower) {
1864
                            $companyFollower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($companyToFollower->id, $user_id);
1776
                            $companyFollower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($companyToFollower->id, $user_id);
1865
                            if(!$companyFollower) {
1777
                            if (!$companyFollower) {
1866
                                $companyFollower = new CompanyFollower();
1778
                                $companyFollower = new CompanyFollower();
1867
                                $companyFollower->company_id = $companyToFollower->id; 
1779
                                $companyFollower->company_id = $companyToFollower->id;
1868
                                $companyFollower->follower_id = $user_id;
1780
                                $companyFollower->follower_id = $user_id;
1869
                                
1781
 
1870
                                $companyFollowerMapper->insert($companyFollower);
1782
                                $companyFollowerMapper->insert($companyFollower);
1871
                                
-
 
1872
                            }
1783
                            }
1873
                        }
1784
                        }
1874
                        
-
 
1875
                    }
1785
                    }
1876
                    
-
 
1877
                    
-
 
1878
                    
-
 
1879
                    
-
 
1880
                }
1786
                }
1881
                
1787
 
1882
                
1788
 
1883
                
1789
 
1884
                return new JsonModel([
1790
                return new JsonModel([
1885
                    'success' => true,
1791
                    'success' => true,
1886
                    'data' => [
1792
                    'data' => [
1887
                        'users_created' => $users_created
1793
                        'users_created' => $users_created
1888
                    ]
1794
                    ]
1889
                ]);
1795
                ]);
1890
                
-
 
1891
                
-
 
1892
                
-
 
1893
                
-
 
1894
            } else {
1796
            } else {
1895
                return new JsonModel([
1797
                return new JsonModel([
1896
                    'success' => false,
1798
                    'success' => false,
1897
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
1799
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
1898
                ]);
1800
                ]);
1899
            }
1801
            }
1900
            
-
 
1901
            
-
 
1902
            
-
 
1903
            
-
 
1904
        }
1802
        }
1905
        
1803
 
1906
        return new JsonModel([
1804
        return new JsonModel([
1907
            'success' => false,
1805
            'success' => false,
1908
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1806
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1909
        ]);
1807
        ]);
1910
    }
1808
    }
1911
    
1809
 
1912
    
1810
 
1913
    public function editAction()
1811
    public function editAction()
1914
    {
1812
    {
1915
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1813
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1916
        $currentUser = $currentUserPlugin->getUser();
1814
        $currentUser = $currentUserPlugin->getUser();
1917
        $currentCompany = $currentUserPlugin->getCompany();
1815
        $currentCompany = $currentUserPlugin->getCompany();
1918
        
1816
 
1919
        $request = $this->getRequest();
1817
        $request = $this->getRequest();
1920
        $uuid = $this->params()->fromRoute('id');
1818
        $uuid = $this->params()->fromRoute('id');
1921
        
1819
 
1922
        
1820
 
1923
        if(!$uuid) {
1821
        if (!$uuid) {
1924
            $data = [
1822
            $data = [
1925
                'success'   => false,
1823
                'success'   => false,
1926
                'data'   => 'ERROR_INVALID_PARAMETER'
1824
                'data'   => 'ERROR_INVALID_PARAMETER'
1927
            ];
1825
            ];
1928
            
1826
 
1929
            return new JsonModel($data);
1827
            return new JsonModel($data);
1930
        }
1828
        }
1931
        
1829
 
1932
        $userMapper = UserMapper::getInstance($this->adapter);
1830
        $userMapper = UserMapper::getInstance($this->adapter);
1933
        $user = $userMapper->fetchOneByUuid($uuid);
1831
        $user = $userMapper->fetchOneByUuid($uuid);
1934
        if(!$user) {
1832
        if (!$user) {
1935
            $data = [
1833
            $data = [
1936
                'success'   => false,
1834
                'success'   => false,
1937
                'data'   => 'ERROR_COMPANY_NOT_FOUND'
1835
                'data'   => 'ERROR_COMPANY_NOT_FOUND'
1938
            ];
1836
            ];
1939
            
1837
 
1940
            return new JsonModel($data);
1838
            return new JsonModel($data);
1941
        }
1839
        }
1942
        
1840
 
1943
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1841
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1944
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1842
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
1945
        if(!$companyUser) {
1843
        if (!$companyUser) {
1946
            return new JsonModel([
1844
            return new JsonModel([
1947
                'success'   => false,
1845
                'success'   => false,
1948
                'data'   => 'ERROR_COMPANY_USER_NOT_FOUND'
1846
                'data'   => 'ERROR_COMPANY_USER_NOT_FOUND'
1949
            ]);
1847
            ]);
1950
   
-
 
1951
        }
1848
        }
1952
        
1849
 
1953
        if($companyUser->status != CompanyUser::STATUS_ACCEPTED && $companyUser->status != CompanyUser::STATUS_ADMIN_WILL_ADD) {
1850
        if ($companyUser->status != CompanyUser::STATUS_ACCEPTED && $companyUser->status != CompanyUser::STATUS_ADMIN_WILL_ADD) {
1954
            return new JsonModel([
1851
            return new JsonModel([
1955
                'success'   => false,
1852
                'success'   => false,
1956
                'data'   => 'ERROR_COMPANY_USER_IS_NOT_ACTIVE'
1853
                'data'   => 'ERROR_COMPANY_USER_IS_NOT_ACTIVE'
1957
            ]);
1854
            ]);
1958
        }
1855
        }
1959
        
1856
 
1960
        
1857
 
1961
        
1858
 
1962
        
1859
 
1963
        if($request->isPost()) {
1860
        if ($request->isPost()) {
1964
            
1861
 
1965
            $companyRoleMapper = CompanyRoleMapper::getInstance($this->adapter);
1862
            $companyRoleMapper = CompanyRoleMapper::getInstance($this->adapter);
1966
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1863
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1967
            $companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
1864
            $companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
1968
            
1865
 
1969
            $backend = Functions::sanitizeFilterString($this->params()->fromPost('backend') );
1866
            $backend = Functions::sanitizeFilterString($this->params()->fromPost('backend'));
1970
            $companyUser->backend = $backend == CompanyUser::BACKEND_YES ? CompanyUser::BACKEND_YES : CompanyUser::BACKEND_NO; 
1867
            $companyUser->backend = $backend == CompanyUser::BACKEND_YES ? CompanyUser::BACKEND_YES : CompanyUser::BACKEND_NO;
1971
            $companyUserMapper->update($companyUser);
1868
            $companyUserMapper->update($companyUser);
1972
            
1869
 
1973
            
1870
 
1974
            $roleMapper = RoleMapper::getInstance($this->adapter);
1871
            $roleMapper = RoleMapper::getInstance($this->adapter);
1975
            $roles = $roleMapper->fetchAll();
1872
            $roles = $roleMapper->fetchAll();
1976
            
1873
 
1977
            
1874
 
1978
            foreach($roles as $role)
1875
            foreach ($roles as $role) {
1979
            {
-
 
1980
                $companyRole = $companyRoleMapper->fetchOneByCompanyIdAndRoleId($currentCompany->id, $role->id);
1876
                $companyRole = $companyRoleMapper->fetchOneByCompanyIdAndRoleId($currentCompany->id, $role->id);
1981
                if(!$companyRole) {
1877
                if (!$companyRole) {
1982
                    $companyUserRoleMapper->deleteByCompanyIdAndRoleId($currentCompany->id, $role->id); 
1878
                    $companyUserRoleMapper->deleteByCompanyIdAndRoleId($currentCompany->id, $role->id);
1983
                    continue;
1879
                    continue;
1984
                } 
1880
                }
1985
                
1881
 
1986
                $checked     = filter_var( $this->params()->fromPost('checked' . $role->id), FILTER_SANITIZE_NUMBER_INT);
1882
                $checked     = filter_var($this->params()->fromPost('checked' . $role->id), FILTER_SANITIZE_NUMBER_INT);
1987
                
1883
 
1988
        
1884
 
1989
                
1885
 
1990
                if($checked) {
1886
                if ($checked) {
1991
                    
1887
 
1992
                    $companyUserRole = $companyUserRoleMapper->fetchOneByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $role->id);
1888
                    $companyUserRole = $companyUserRoleMapper->fetchOneByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $role->id);
1993
                    if(!$companyUserRole) {
1889
                    if (!$companyUserRole) {
1994
                        
1890
 
1995
                        $companyUserRole = new CompanyUserRole(); 
1891
                        $companyUserRole = new CompanyUserRole();
1996
                        $companyUserRole->company_id = $currentCompany->id;
1892
                        $companyUserRole->company_id = $currentCompany->id;
1997
                        $companyUserRole->role_id = $role->id;
1893
                        $companyUserRole->role_id = $role->id;
1998
                        $companyUserRole->user_id = $user->id;
1894
                        $companyUserRole->user_id = $user->id;
1999
                        
1895
 
2000
                        $companyUserRoleMapper->insert($companyUserRole);
1896
                        $companyUserRoleMapper->insert($companyUserRole);
2001
                        
-
 
2002
                    }
1897
                    }
2003
                    
-
 
2004
                    
-
 
2005
                    
-
 
2006
                    
-
 
2007
                } else {
1898
                } else {
2008
      
1899
 
2009
                    $companyUserRoleMapper->deleteByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $role->id);
1900
                    $companyUserRoleMapper->deleteByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $role->id);
2010
                } 
1901
                }
2011
            }
1902
            }
2012
            
1903
 
2013
            $this->logger->info('Se actualizo los roles del usuario : ' . $user->email . ' en la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1904
            $this->logger->info('Se actualizo los roles del usuario : ' . $user->email . ' en la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2014
            
1905
 
2015
            return new JsonModel([
1906
            return new JsonModel([
2016
                'success' => true,
1907
                'success' => true,
2017
                'data' => 'LABEL_RECORD_UPDATED'
1908
                'data' => 'LABEL_RECORD_UPDATED'
2018
            ]);
1909
            ]);
2019
            
-
 
2020
            
-
 
2021
        } else if ($request->isGet()) {
1910
        } else if ($request->isGet()) {
2022
            $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
1911
            $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
2023
            
1912
 
2024
            $roleMapper = RoleMapper::getInstance($this->adapter);
1913
            $roleMapper = RoleMapper::getInstance($this->adapter);
2025
            $records = $roleMapper->fetchAll();
1914
            $records = $roleMapper->fetchAll();
2026
            
-
 
Línea -... Línea 1915...
-
 
1915
 
2027
 
1916
 
2028
             
1917
 
2029
            $companyRoleMapper = CompanyRoleMapper::getInstance($this->adapter);
1918
            $companyRoleMapper = CompanyRoleMapper::getInstance($this->adapter);
2030
            $companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
1919
            $companyUserRoleMapper = CompanyUserRoleMapper::getInstance($this->adapter);
2031
            
1920
 
2032
            $roles = [];
1921
            $roles = [];
2033
            foreach($records as $record)
-
 
2034
            {
1922
            foreach ($records as $record) {
2035
                if($record->creator == Role::CREATOR_YES) {
1923
                if ($record->creator == Role::CREATOR_YES) {
2036
                    continue;
1924
                    continue;
2037
                }
1925
                }
2038
                
1926
 
2039
                if($record->service_id) {
1927
                if ($record->service_id) {
2040
                    $companyService = $companyServiceMapper->fetchOneByCompanyIdAndServiceId($currentCompany->id, $record->service_id);
1928
                    $companyService = $companyServiceMapper->fetchOneByCompanyIdAndServiceId($currentCompany->id, $record->service_id);
2041
                    if(!$companyService || $companyService->status == CompanyService::INACTIVE) {
1929
                    if (!$companyService || $companyService->status == CompanyService::INACTIVE) {
2042
                        continue;
1930
                        continue;
2043
                    }
-
 
2044
                    
1931
                    }
2045
                }
1932
                }
2046
                
1933
 
2047
               
1934
 
2048
                
1935
 
2049
                $companyRole = $companyRoleMapper->fetchOneByCompanyIdAndRoleId($currentCompany->id, $record->id);
1936
                $companyRole = $companyRoleMapper->fetchOneByCompanyIdAndRoleId($currentCompany->id, $record->id);
2050
                if(!$companyRole) {
1937
                if (!$companyRole) {
2051
                    continue;
1938
                    continue;
2052
                }
1939
                }
2053
                
1940
 
2054
                $companyUserRole  = $companyUserRoleMapper->fetchOneByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $record->id);
1941
                $companyUserRole  = $companyUserRoleMapper->fetchOneByCompanyIdAndUserIdAndRoleId($currentCompany->id, $user->id, $record->id);
2055
                
1942
 
2056
                
1943
 
2057
                $roles[ $record->id ] = [
1944
                $roles[$record->id] = [
2058
                    'id' => $record->id,
1945
                    'id' => $record->id,
2059
                    'name' => $record->name,
1946
                    'name' => $record->name,
2060
                    'fixed' => $record->creator == Role::CREATOR_YES ? true : false,
1947
                    'fixed' => $record->creator == Role::CREATOR_YES ? true : false,
2061
                    'checked' => $companyUserRole ? true : false,
1948
                    'checked' => $companyUserRole ? true : false,
2062
                ];
-
 
2063
                
-
 
2064
                
1949
                ];
2065
            }
-
 
Línea -... Línea 1950...
-
 
1950
            }
2066
            
1951
 
2067
 
1952
 
2068
            
1953
 
2069
            $data = [
1954
            $data = [
2070
                'success' => true,
1955
                'success' => true,
2071
                'data' => [
1956
                'data' => [
2072
                   'backend' => $companyUser->backend == CompanyUser::BACKEND_YES ? 1 : 0,
1957
                    'backend' => $companyUser->backend == CompanyUser::BACKEND_YES ? 1 : 0,
2073
                   'roles' => $roles,
1958
                    'roles' => $roles,
2074
                ] ,
1959
                ],
2075
            ];
1960
            ];
2076
            
1961
 
2077
            
1962
 
2078
            
1963
 
2079
            return new JsonModel($data);
1964
            return new JsonModel($data);
2080
        } else {
1965
        } else {
2081
            $data = [
1966
            $data = [
2082
                'success' => false,
1967
                'success' => false,
2083
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1968
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2084
            ];
1969
            ];
2085
            
1970
 
2086
            return new JsonModel($data);
1971
            return new JsonModel($data);
2087
        }
1972
        }
2088
        
1973
 
2089
        return new JsonModel($data);
1974
        return new JsonModel($data);
2090
    }
1975
    }
2091
    
1976
 
2092
    
1977
 
2093
    public function changeTypeAction()
1978
    public function changeTypeAction()
2094
    {
1979
    {
2095
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1980
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2096
        $currentUser = $currentUserPlugin->getUser();
1981
        $currentUser = $currentUserPlugin->getUser();
2097
        
1982
 
2098
        $request = $this->getRequest();
1983
        $request = $this->getRequest();
2099
        
1984
 
2100
        if($request->isGet()) {
1985
        if ($request->isGet()) {
2101
            $uuid = $this->params()->fromRoute('id');
1986
            $uuid = $this->params()->fromRoute('id');
2102
            if(!$uuid) {
1987
            if (!$uuid) {
2103
                return new JsonModel([
1988
                return new JsonModel([
2104
                    'success'   => false,
1989
                    'success'   => false,
2105
                    'data'      => 'ERROR_INVALID_PARAMETER'
1990
                    'data'      => 'ERROR_INVALID_PARAMETER'
2106
                ]);
1991
                ]);
2107
            }
1992
            }
2108
            
1993
 
2109
            $userMapper = UserMapper::getInstance($this->adapter);
1994
            $userMapper = UserMapper::getInstance($this->adapter);
2110
            $user = $userMapper->fetchOneByUuid($uuid);
1995
            $user = $userMapper->fetchOneByUuid($uuid);
2111
            
1996
 
2112
            
1997
 
2113
            
1998
 
2114
            if($user) {
1999
            if ($user) {
2115
                return new JsonModel([
2000
                return new JsonModel([
2116
                    'success'   => true,
2001
                    'success'   => true,
2117
                    'data'      => [
2002
                    'data'      => [
Línea 2122... Línea 2007...
2122
                return new JsonModel([
2007
                return new JsonModel([
2123
                    'success'   => false,
2008
                    'success'   => false,
2124
                    'data'      => 'ERROR_USER_NOT_FOUND'
2009
                    'data'      => 'ERROR_USER_NOT_FOUND'
2125
                ]);
2010
                ]);
2126
            }
2011
            }
2127
            
-
 
2128
        }
2012
        }
2129
        
2013
 
2130
        if($request->isPost()) {
2014
        if ($request->isPost()) {
2131
            
2015
 
2132
            $uuid = $this->params()->fromRoute('id');
2016
            $uuid = $this->params()->fromRoute('id');
2133
            if(!$uuid) {
2017
            if (!$uuid) {
2134
                return new JsonModel([
2018
                return new JsonModel([
2135
                    'success'   => false,
2019
                    'success'   => false,
2136
                    'data'      => 'ERROR_INVALID_PARAMETER'
2020
                    'data'      => 'ERROR_INVALID_PARAMETER'
2137
                ]);
2021
                ]);
2138
            }
2022
            }
2139
            
2023
 
2140
            $userMapper = UserMapper::getInstance($this->adapter);
2024
            $userMapper = UserMapper::getInstance($this->adapter);
2141
            $user = $userMapper->fetchOneByUuid($uuid);
2025
            $user = $userMapper->fetchOneByUuid($uuid);
2142
            
2026
 
2143
            if(!$user) {
2027
            if (!$user) {
2144
                return new JsonModel([
2028
                return new JsonModel([
2145
                    'success'   => false,
2029
                    'success'   => false,
2146
                    'data'      => 'ERROR_USER_NOT_FOUND'
2030
                    'data'      => 'ERROR_USER_NOT_FOUND'
2147
                ]);
2031
                ]);
2148
            }
2032
            }
2149
            
2033
 
2150
            
2034
 
2151
            $dataPost = $request->getPost()->toArray();
2035
            $dataPost = $request->getPost()->toArray();
2152
            $form = new ChangeTypeForm();
2036
            $form = new ChangeTypeForm();
2153
            $form->setData($dataPost);
2037
            $form->setData($dataPost);
2154
            
2038
 
2155
            if($form->isValid()) {
2039
            if ($form->isValid()) {
2156
                $dataPost = (array) $form->getData();
2040
                $dataPost = (array) $form->getData();
2157
                
2041
 
2158
                $result = $userMapper->updateUserTypeId($user, $dataPost['usertype_id']);
2042
                $result = $userMapper->updateUserTypeId($user, $dataPost['usertype_id']);
2159
                if($result) {
2043
                if ($result) {
2160
                    $this->logger->info('Cambio del tipo de usuario realizado por realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2044
                    $this->logger->info('Cambio del tipo de usuario realizado por realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2161
                        
2045
 
2162
                        
2046
 
2163
                    return new JsonModel([
2047
                    return new JsonModel([
2164
                        'success'   => true,
2048
                        'success'   => true,
2165
                        'data'      => 'LABEL_USER_CHANGE_TYPE_HAS_BEEN_UPDATED'
2049
                        'data'      => 'LABEL_USER_CHANGE_TYPE_HAS_BEEN_UPDATED'
2166
                            
2050
 
2167
                    ]);
2051
                    ]);
2168
                } else {
2052
                } else {
2169
                    $this->logger->err('Cambio del tipo de usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2053
                    $this->logger->err('Cambio del tipo de usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2170
                        
2054
 
2171
                    return new JsonModel([
2055
                    return new JsonModel([
2172
                        'success'   => true,
2056
                        'success'   => true,
2173
                        'data'      => 'ERROR_THERE_WAS_AN_ERROR'
2057
                        'data'      => 'ERROR_THERE_WAS_AN_ERROR'
2174
                            
-
 
2175
                    ]);
-
 
Línea -... Línea 2058...
-
 
2058
 
2176
 
2059
                    ]);
2177
                }
-
 
2178
                
2060
                }
2179
            } else {
2061
            } else {
2180
                $messages = [];
2062
                $messages = [];
2181
                
2063
 
2182
                $form_messages = (array) $form->getMessages();
2064
                $form_messages = (array) $form->getMessages();
2183
                foreach($form_messages  as $fieldname => $field_messages)
-
 
2184
                {
2065
                foreach ($form_messages  as $fieldname => $field_messages) {
2185
                    $messages[$fieldname] = array_values($field_messages);
2066
                    $messages[$fieldname] = array_values($field_messages);
2186
                }
2067
                }
2187
                
2068
 
2188
                return new JsonModel([
2069
                return new JsonModel([
2189
                    'success'   => false,
2070
                    'success'   => false,
2190
                    'data'   => $messages
2071
                    'data'   => $messages
2191
                ]);
2072
                ]);
2192
            }
-
 
2193
            
2073
            }
2194
        }
2074
        }
2195
        
2075
 
2196
        
2076
 
2197
        
2077
 
2198
        return new JsonModel([
2078
        return new JsonModel([
2199
            'success' => false,
2079
            'success' => false,
2200
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2080
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2201
        ]);
2081
        ]);
2202
    }
-
 
2203
    
-
 
2204
    
2082
    }