Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 5205 Rev 5966
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 55... Línea 56...
55
    /**
56
    /**
56
     *
57
     *
57
     * @var AdapterInterface
58
     * @var AdapterInterface
58
     */
59
     */
59
    private $adapter;
60
    private $adapter;
60
    
61
 
61
    
62
 
62
    /**
63
    /**
63
     *
64
     *
64
     * @var AbstractAdapter
65
     * @var AbstractAdapter
65
     */
66
     */
66
    private $cache;
67
    private $cache;
67
    
68
 
68
    /**
69
    /**
69
     *
70
     *
70
     * @var  LoggerInterface
71
     * @var  LoggerInterface
71
     */
72
     */
72
    private $logger;
73
    private $logger;
73
    
74
 
74
    /**
75
    /**
75
     *
76
     *
76
     * @var array
77
     * @var array
77
     */
78
     */
78
    private $config;
79
    private $config;
79
    
80
 
80
    
81
 
81
    /**
82
    /**
82
     *
83
     *
83
     * @var array
84
     * @var array
84
     */
85
     */
85
    private $navigation;
86
    private $navigation;
86
    
87
 
87
    /**
88
    /**
88
     *
89
     *
89
     * @param AdapterInterface $adapter
90
     * @param AdapterInterface $adapter
90
     * @param AbstractAdapter $cache
91
     * @param AbstractAdapter $cache
91
     * @param LoggerInterface $logger
92
     * @param LoggerInterface $logger
92
     * @param array $config
93
     * @param array $config
93
     * @param array $navigation
94
     * @param array $navigation
94
     */
95
     */
95
    public function __construct($adapter, $cache , $logger, $config, $navigation)
96
    public function __construct($adapter, $cache, $logger, $config, $navigation)
96
    {
97
    {
97
        $this->adapter      = $adapter;
98
        $this->adapter      = $adapter;
98
        $this->cache        = $cache;
99
        $this->cache        = $cache;
99
        $this->logger       = $logger;
100
        $this->logger       = $logger;
100
        $this->config       = $config;
101
        $this->config       = $config;
101
        $this->navigation   = $navigation;
102
        $this->navigation   = $navigation;
102
    }
103
    }
103
    
104
 
104
    
105
 
105
    /**
106
    /**
106
     * Recuperamos las personas que pueda conocer
107
     * Recuperamos las personas que pueda conocer
107
     * tiene que enviarse un petición GET a la siguiente url: /helpers/people-you-may-know
108
     * tiene que enviarse un petición GET a la siguiente url: /helpers/people-you-may-know
108
     * retorna un json en caso de ser  positivo
109
     * retorna un json en caso de ser  positivo
109
     * [
110
     * [
Línea 124... Línea 125...
124
     * @return \Laminas\View\Model\JsonModel
125
     * @return \Laminas\View\Model\JsonModel
125
     */
126
     */
126
    public function peopleYouMayKnowAction()
127
    public function peopleYouMayKnowAction()
127
    {
128
    {
128
        $request = $this->getRequest();
129
        $request = $this->getRequest();
129
        if($request->isGet()) {
130
        if ($request->isGet()) {
130
            $currentUserPlugin = $this->plugin('currentUserPlugin');
131
            $currentUserPlugin = $this->plugin('currentUserPlugin');
131
            $currentUser = $currentUserPlugin->getUser();
132
            $currentUser = $currentUserPlugin->getUser();
132
    
133
 
133
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
134
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
134
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
135
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
135
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
136
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
Línea 136... Línea 137...
136
 
137
 
137
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
138
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
138
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
139
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
139
            
140
 
140
            /*Usuarios de la empresas donde trabajo o soy dueño */
141
            /*Usuarios de la empresas donde trabajo o soy dueño */
141
            $company_user_ids = [];
142
            $company_user_ids = [];
142
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
143
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
143
            
144
 
144
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
145
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
145
            foreach($records as $record)
-
 
146
            {
146
            foreach ($records as $record) {
147
                
147
 
148
                if($record->status != CompanyUser::STATUS_ACCEPTED) {
148
                if ($record->status != CompanyUser::STATUS_ACCEPTED) {
149
                    continue;
149
                    continue;
150
                }
150
                }
151
                
151
 
152
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
152
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
153
                foreach($otherUsers as $otherUser)
-
 
154
                {
153
                foreach ($otherUsers as $otherUser) {
155
                    if($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
154
                    if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
156
                        
155
 
157
                        if(!in_array($otherUser->user_id, $company_user_ids)) {
156
                        if (!in_array($otherUser->user_id, $company_user_ids)) {
158
                            array_push($company_user_ids, $otherUser->user_id);
157
                            array_push($company_user_ids, $otherUser->user_id);
159
                        }
158
                        }
160
                    }
159
                    }
161
                }
160
                }
162
            }
161
            }
163
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
162
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
164
            
163
 
165
            /* Usuario de los grupos donde soy dueño o participo */
164
            /* Usuario de los grupos donde soy dueño o participo */
166
            
165
 
167
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
166
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
168
            
167
 
169
            $group_member_ids = [];
168
            $group_member_ids = [];
170
            
169
 
171
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
170
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
172
            foreach($records as $record)
-
 
173
            {
171
            foreach ($records as $record) {
174
                if($record->status != GroupMember::STATUS_ACCEPTED) {
172
                if ($record->status != GroupMember::STATUS_ACCEPTED) {
175
                    continue;
173
                    continue;
176
                }
174
                }
177
                
175
 
178
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
176
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
179
                foreach($otherUsers as $otherUser)
-
 
180
                {
177
                foreach ($otherUsers as $otherUser) {
181
                    if($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
178
                    if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
182
                        
179
 
183
                        if(!in_array($otherUser->user_id, $group_member_ids)) {
180
                        if (!in_array($otherUser->user_id, $group_member_ids)) {
184
                            array_push($group_member_ids, $otherUser->user_id);
181
                            array_push($group_member_ids, $otherUser->user_id);
185
                        }
182
                        }
186
                    }
183
                    }
187
                }
-
 
188
                
-
 
189
                
184
                }
190
            }
185
            }
191
            
186
 
192
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
-
 
Línea -... Línea 187...
-
 
187
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
193
            
188
 
194
 
189
 
195
            
190
 
196
            /* Usuarios con que comparto capsulas */ 
191
            /* Usuarios con que comparto capsulas */
197
            $capsule_user_ids = [];
192
            $capsule_user_ids = [];
198
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
193
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
199
            
194
 
200
            $company_ids = [];
195
            $company_ids = [];
201
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
-
 
202
            foreach($records as $record)
196
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
203
            {
197
            foreach ($records as $record) {
204
                if(!in_array($record->company_id,$company_ids)) {
198
                if (!in_array($record->company_id, $company_ids)) {
205
                    array_push($company_ids, $record->company_id);
199
                    array_push($company_ids, $record->company_id);
206
                }
200
                }
207
            }
201
            }
208
            
202
 
209
      
203
 
210
            
-
 
211
            foreach($company_ids as $company_id)
204
 
212
            {
205
            foreach ($company_ids as $company_id) {
213
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
-
 
214
                foreach($otherUsers as $user_id)
206
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
215
                {
207
                foreach ($otherUsers as $user_id) {
216
                    if($currentUser->id != $user_id ) {
208
                    if ($currentUser->id != $user_id) {
217
                        
209
 
218
                        if(!in_array($user_id, $capsule_user_ids)) {
210
                        if (!in_array($user_id, $capsule_user_ids)) {
219
                            array_push($capsule_user_ids, $user_id);
211
                            array_push($capsule_user_ids, $user_id);
220
                        }
212
                        }
221
                    }
213
                    }
222
                }
214
                }
223
            }
215
            }
224
            
216
 
225
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
217
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
226
            
218
 
227
            
219
 
228
            $other_users = array_unique(array_merge(
220
            $other_users = array_unique(array_merge(
229
                $second_degree_connections_ids,
221
                $second_degree_connections_ids,
230
                $company_user_ids,
222
                $company_user_ids,
231
                $group_member_ids,
223
                $group_member_ids,
232
                $capsule_user_ids
224
                $capsule_user_ids
233
            ));
225
            ));
234
            
226
 
235
            
227
 
236
            
228
 
237
            
229
 
238
            
230
 
239
           
231
 
240
            
232
 
241
            
233
 
242
            $items = [];
234
            $items = [];
243
            $queryMapper = QueryMapper::getInstance($this->adapter);
235
            $queryMapper = QueryMapper::getInstance($this->adapter);
244
            $select = $queryMapper->getSql()->select();
236
            $select = $queryMapper->getSql()->select();
245
            $select->columns(['id', 'uuid',  'first_name','last_name', 'image']);
237
            $select->columns(['id', 'uuid',  'first_name', 'last_name', 'image']);
246
            $select->from(['u' => UserMapper::_TABLE]);
238
            $select->from(['u' => UserMapper::_TABLE]);
247
            $select->where->equalTo('network_id', $currentUser->network_id);
239
            $select->where->equalTo('network_id', $currentUser->network_id);
248
            $select->where->in('u.id', $other_users);
240
            $select->where->in('u.id', $other_users);
249
            $select->where->notIn('u.id', $first_degree_connections_ids);
241
            $select->where->notIn('u.id', $first_degree_connections_ids);
250
            $select->where->notEqualTo('u.id', $currentUser->id);
242
            $select->where->notEqualTo('u.id', $currentUser->id);
251
            $select->where->equalTo('u.status', User::STATUS_ACTIVE);
243
            $select->where->equalTo('u.status', User::STATUS_ACTIVE);
252
            $select->where->in('u.usertype_id', [UserType::ADMIN, UserType::USER]);
244
            $select->where->in('u.usertype_id', [UserType::ADMIN, UserType::USER]);
253
            $select->order(['first_name','last_name']);
245
            $select->order(['first_name', 'last_name']);
254
                
246
 
255
                //echo $select->getSqlString($this->adapter->platform); exit;
247
            //echo $select->getSqlString($this->adapter->platform); exit;
256
                
248
 
257
            $records = $queryMapper->fetchAll($select);
-
 
Línea 258... Línea 249...
258
            foreach($records as $record)
249
            $records = $queryMapper->fetchAll($select);
259
            {
250
            foreach ($records as $record) {
260
 
251
 
261
                $relation = [];
252
                $relation = [];
262
                if(in_array($record['id'], $second_degree_connections_ids)) {
253
                if (in_array($record['id'], $second_degree_connections_ids)) {
263
                    array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
254
                    array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
264
                }
255
                }
265
                if(in_array($record['id'], $company_user_ids)) {
256
                if (in_array($record['id'], $company_user_ids)) {
266
                    array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
257
                    array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
267
                }      
258
                }
268
                if(in_array($record['id'], $group_member_ids)) {
259
                if (in_array($record['id'], $group_member_ids)) {
269
                    array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
260
                    array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
270
                }      
261
                }
271
                if(in_array($record['id'], $capsule_user_ids)) {
262
                if (in_array($record['id'], $capsule_user_ids)) {
272
                    array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
263
                    array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
273
                }
264
                }
274
                    
265
 
275
              
266
 
276
                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
267
                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
277
                
268
 
278
                $item = [
269
                $item = [
279
                    'id'    => $record['uuid'],
270
                    'id'    => $record['uuid'],
280
                    'name'  => trim($record['first_name'] . ' ' . $record['last_name']),
271
                    'name'  => trim($record['first_name'] . ' ' . $record['last_name']),
281
                    'image' => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
272
                    'image' => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
282
                    'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
273
                    'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
283
                    'relation' => $relation,
274
                    'relation' => $relation,
284
                    'link_cancel'   => '', 
275
                    'link_cancel'   => '',
285
                    'link_request'  => '',
276
                    'link_request'  => '',
286
                ];
277
                ];
287
                
-
 
288
                if($connection) {
278
 
289
                    switch($connection->status)
279
                if ($connection) {
290
                    {
280
                    switch ($connection->status) {
291
                        case Connection::STATUS_SENT :
281
                        case Connection::STATUS_SENT:
292
                            $item['link_cancel'] = $this->url()->fromRoute('connection/delete',['id' => $record['uuid'] ]);
282
                            $item['link_cancel'] = $this->url()->fromRoute('connection/delete', ['id' => $record['uuid']]);
293
                            break;
283
                            break;
294
                            
284
 
295
                        case Connection::STATUS_ACCEPTED : 
285
                        case Connection::STATUS_ACCEPTED:
296
                            $item['link_cancel'] = $this->url()->fromRoute('connection/cancel',['id' => $record['uuid'] ]);
286
                            $item['link_cancel'] = $this->url()->fromRoute('connection/cancel', ['id' => $record['uuid']]);
297
                            break;
287
                            break;
298
                            
288
 
299
                        default :  
-
 
300
                            $item['link_request'] = $this->url()->fromRoute('connection/request',['id' => $record['uuid'] ]);
289
                        default:
301
                            break;
-
 
302
                            
-
 
303
                    }
290
                            $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
304
                    
291
                            break;
305
                    
292
                    }
306
                } else {
293
                } else {
307
                    $item['link_request'] = $this->url()->fromRoute('connection/request',['id' => $record['uuid'] ]);
294
                    $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
308
                }
295
                }
309
                
296
 
Línea 310... Línea 297...
310
                    
297
 
311
                array_push($items, $item);
298
                array_push($items, $item);
312
            }
299
            }
313
 
300
 
314
            return new JsonModel([
-
 
315
                'success' => true,
-
 
316
                'data' => $items
301
            return new JsonModel([
317
            ]);
302
                'success' => true,
318
            
303
                'data' => $items
319
            
304
            ]);
320
        } else {
305
        } else {
321
            return new JsonModel([
306
            return new JsonModel([
322
                'success' => false,
-
 
323
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
307
                'success' => false,
324
            ]);
308
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
325
        }
309
            ]);
326
 
310
        }
327
    }
311
    }
328
    
312
 
329
    /**
313
    /**
Línea 348... Línea 332...
348
     * @return \Laminas\View\Model\JsonModel
332
     * @return \Laminas\View\Model\JsonModel
349
     */
333
     */
350
    public function peopleViewedProfileAction()
334
    public function peopleViewedProfileAction()
351
    {
335
    {
352
        $request = $this->getRequest();
336
        $request = $this->getRequest();
353
        if($request->isGet()) {
337
        if ($request->isGet()) {
354
            $currentUserPlugin = $this->plugin('currentUserPlugin');
338
            $currentUserPlugin = $this->plugin('currentUserPlugin');
355
            $currentUser = $currentUserPlugin->getUser();
339
            $currentUser = $currentUserPlugin->getUser();
356
            
340
 
357
            $items = [];
341
            $items = [];
358
            $user_profile_id = $this->params()->fromRoute('user_profile_id');
342
            $user_profile_id = $this->params()->fromRoute('user_profile_id');
359
            
343
 
360
            $items = [];
344
            $items = [];
361
            
345
 
362
            $mapper = QueryMapper::getInstance($this->adapter);
346
            $mapper = QueryMapper::getInstance($this->adapter);
363
            $select = $mapper->getSql()->select(ProfileVisitMapper::_TABLE);
347
            $select = $mapper->getSql()->select(ProfileVisitMapper::_TABLE);
364
            $select->columns(['user_id' => new Expression('DISTINCT(visitor_id)')]);
348
            $select->columns(['user_id' => new Expression('DISTINCT(visitor_id)')]);
365
            $select->where->equalTo('user_profile_id', $user_profile_id);
349
            $select->where->equalTo('user_profile_id', $user_profile_id);
366
            $records = $mapper->fetchAll($select);
350
            $records = $mapper->fetchAll($select);
Línea 367... Línea 351...
367
 
351
 
368
            if($records) {
352
            if ($records) {
369
                
353
 
370
                $user_ids = [];
354
                $user_ids = [];
371
                foreach($records as $record)
-
 
372
                {
355
                foreach ($records as $record) {
373
                    array_push($user_ids, $record['user_id']);
356
                    array_push($user_ids, $record['user_id']);
374
                }
357
                }
375
                
358
 
376
                $mapper = QueryMapper::getInstance($this->adapter);
359
                $mapper = QueryMapper::getInstance($this->adapter);
377
                $select = $mapper->getSql()->select( UserMapper::_TABLE);
360
                $select = $mapper->getSql()->select(UserMapper::_TABLE);
378
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
361
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
379
                $select->where->in('id', $user_ids);
362
                $select->where->in('id', $user_ids);
380
                $select->where->equalTo('network_id', $currentUser->network_id);
363
                $select->where->equalTo('network_id', $currentUser->network_id);
381
                $select->where->equalTo('status',User::STATUS_ACTIVE);
364
                $select->where->equalTo('status', User::STATUS_ACTIVE);
382
                $select->order(['last_name ASC', 'first_name ASC']);
365
                $select->order(['last_name ASC', 'first_name ASC']);
383
                
366
 
384
                $records = $mapper->fetchAll($select);
367
                $records = $mapper->fetchAll($select);
385
                foreach($records as $record)
-
 
386
                {
368
                foreach ($records as $record) {
387
                    array_push($items, [
369
                    array_push($items, [
388
                        'id'        => $record['uuid'],
370
                        'id'        => $record['uuid'],
389
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
371
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
390
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
372
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
391
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
373
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
392
                    ]);
374
                    ]);
393
                }
375
                }
Línea 394... Línea 376...
394
            }
376
            }
395
 
377
 
396
            
378
 
397
            return new JsonModel([
379
            return new JsonModel([
398
                'success' => true,
380
                'success' => true,
399
                'data' => $items
-
 
400
            ]);
381
                'data' => $items
401
            
382
            ]);
402
        } else {
383
        } else {
403
            return new JsonModel([
384
            return new JsonModel([
404
                'success' => false,
385
                'success' => false,
405
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
386
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
406
            ]);
387
            ]);
407
        }
388
        }
408
    }
389
    }
409
    
390
 
410
    
391
 
411
    /**
392
    /**
412
     * Recuperamos los seguidores de la empresa
393
     * Recuperamos los seguidores de la empresa
413
     * tiene que enviarse un petición GET a la siguiente url: /helpers/company-follower/:company_id
394
     * tiene que enviarse un petición GET a la siguiente url: /helpers/company-follower/:company_id
Línea 430... Línea 411...
430
     * @return \Laminas\View\Model\JsonModel
411
     * @return \Laminas\View\Model\JsonModel
431
     */
412
     */
432
    public function companyFollowerAction()
413
    public function companyFollowerAction()
433
    {
414
    {
Línea 434... Línea 415...
434
 
415
 
435
        
416
 
436
        $request = $this->getRequest();
417
        $request = $this->getRequest();
437
        if($request->isGet()) {
418
        if ($request->isGet()) {
438
            $currentUserPlugin = $this->plugin('currentUserPlugin');
419
            $currentUserPlugin = $this->plugin('currentUserPlugin');
439
            $currentUser = $currentUserPlugin->getUser();
420
            $currentUser = $currentUserPlugin->getUser();
440
            
421
 
441
            $company_uuid  = $this->params()->fromRoute('company_id');
422
            $company_uuid  = $this->params()->fromRoute('company_id');
442
            
423
 
443
            $companyMapper = CompanyMapper::getInstance($this->adapter);
424
            $companyMapper = CompanyMapper::getInstance($this->adapter);
444
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
425
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
445
            
426
 
446
            $items = [];
427
            $items = [];
447
            if($company && $company->status == Company::STATUS_ACTIVE) {
428
            if ($company && $company->status == Company::STATUS_ACTIVE) {
448
            
429
 
449
            
430
 
Línea 450... Línea 431...
450
                //print_r($company);
431
                //print_r($company);
451
 
432
 
452
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
433
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
453
                $records = $companyFollowerMapper->fetchAllByCompanyId($company->id);
434
                $records = $companyFollowerMapper->fetchAllByCompanyId($company->id);
454
                
435
 
455
                $ids = [];
-
 
456
                foreach($records as $record)
436
                $ids = [];
457
                {
437
                foreach ($records as $record) {
458
                    if(!in_array($record->follower_id, $ids)) {
438
                    if (!in_array($record->follower_id, $ids)) {
459
                        array_push($ids, $record->follower_id);
439
                        array_push($ids, $record->follower_id);
460
                    }
440
                    }
461
                }
441
                }
462
                
442
 
463
                //print_r($records);
443
                //print_r($records);
464
                
444
 
465
               
445
 
466
                if($ids) {
446
                if ($ids) {
467
                    
447
 
468
                    $mapper = QueryMapper::getInstance($this->adapter);
448
                    $mapper = QueryMapper::getInstance($this->adapter);
469
                    $select = $mapper->getSql()->select(UserMapper::_TABLE);
449
                    $select = $mapper->getSql()->select(UserMapper::_TABLE);
470
                    $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
450
                    $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
471
                    $select->where->equalTo('network_id', $currentUser->network_id);
451
                    $select->where->equalTo('network_id', $currentUser->network_id);
472
                    $select->where->in('id',$ids);
452
                    $select->where->in('id', $ids);
473
                    $select->where->equalTo('status',User::STATUS_ACTIVE);
453
                    $select->where->equalTo('status', User::STATUS_ACTIVE);
474
                    $select->order(['last_name','first_name']);
454
                    $select->order(['last_name', 'first_name']);
475
                    
455
 
476
                    //echo $select->getSqlString($this->adapter->platform); exit;
456
                    //echo $select->getSqlString($this->adapter->platform); exit;
477
                    
457
 
478
                    
458
 
479
                    
459
 
480
                    $records = $mapper->fetchAll($select);
-
 
481
                    foreach($records as $record)
460
                    $records = $mapper->fetchAll($select);
482
                    {
461
                    foreach ($records as $record) {
483
                        
462
 
484
                        
463
 
485
                        array_push($items, [
464
                        array_push($items, [
486
                            'id'        => $record['uuid'],
465
                            'id'        => $record['uuid'],
487
                            'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
466
                            'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
488
                            'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
467
                            'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
489
                            'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
468
                            'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
490
                        ]);
469
                        ]);
491
                    }
470
                    }
492
                }
471
                }
493
            }
472
            }
494
            
473
 
495
            return new JsonModel([
474
            return new JsonModel([
496
                'success' => true,
475
                'success' => true,
497
                'data' => $items
-
 
498
            ]);
476
                'data' => $items
499
            
477
            ]);
500
        } else {
478
        } else {
501
            return new JsonModel([
479
            return new JsonModel([
502
                'success' => false,
480
                'success' => false,
503
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
481
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
504
            ]);
482
            ]);
505
        }
483
        }
506
    }
484
    }
507
    
485
 
508
    public function companySuggestionAction()
486
    public function companySuggestionAction()
509
    {
487
    {
510
        $request = $this->getRequest();
488
        $request = $this->getRequest();
511
        if($request->isGet()) {
489
        if ($request->isGet()) {
512
            $currentUserPlugin = $this->plugin('currentUserPlugin');
490
            $currentUserPlugin = $this->plugin('currentUserPlugin');
513
            $currentUser = $currentUserPlugin->getUser();
491
            $currentUser = $currentUserPlugin->getUser();
514
            
492
 
515
            $company_uuid = $this->params()->fromRoute('company_id');
493
            $company_uuid = $this->params()->fromRoute('company_id');
516
            
494
 
517
            $companyMapper = CompanyMapper::getInstance($this->adapter);
495
            $companyMapper = CompanyMapper::getInstance($this->adapter);
518
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
496
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
519
            
497
 
520
            $items = [];
498
            $items = [];
521
            if($company && $company->status == Company::STATUS_ACTIVE) {
499
            if ($company && $company->status == Company::STATUS_ACTIVE) {
522
                
500
 
523
                
501
 
524
                $mapper = QueryMapper::getInstance($this->adapter);
502
                $mapper = QueryMapper::getInstance($this->adapter);
525
                $select = $mapper->getSql()->select(CompanyMapper::_TABLE);
503
                $select = $mapper->getSql()->select(CompanyMapper::_TABLE);
526
                $select->columns(['id', 'uuid', 'name', 'image']);
504
                $select->columns(['id', 'uuid', 'name', 'image']);
527
                $select->where->equalTo('network_id', $currentUser->network_id);
505
                $select->where->equalTo('network_id', $currentUser->network_id);
528
                $select->where->notEqualTo('id', $company->id);
506
                $select->where->notEqualTo('id', $company->id);
529
                $select->where->equalTo('status',Company::STATUS_ACTIVE);
507
                $select->where->equalTo('status', Company::STATUS_ACTIVE);
530
                $select->where->equalTo('industry_id', $company->industry_id);
508
                $select->where->equalTo('industry_id', $company->industry_id);
531
              //  $select->where->equalTo('company_size_id', $company->company_size_id);
509
                //  $select->where->equalTo('company_size_id', $company->company_size_id);
532
                $select->order(['name']);
510
                $select->order(['name']);
533
                
511
 
534
                
512
 
535
                //echo $select->getSqlString($this->adapter->platform); exit;
513
                //echo $select->getSqlString($this->adapter->platform); exit;
536
                
514
 
537
                $records = $mapper->fetchAll($select);
-
 
538
                foreach($records as $record)
515
                $records = $mapper->fetchAll($select);
539
                {
516
                foreach ($records as $record) {
540
                    array_push($items, [
517
                    array_push($items, [
541
                        'id'        => $record['uuid'],
518
                        'id'        => $record['uuid'],
542
                        'name'      => trim($record['name']),
519
                        'name'      => trim($record['name']),
543
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'company', 'filename' => $record['image']]),
520
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'company', 'filename' => $record['image']]),
544
                        'profile'   => $this->url()->fromRoute('company/view', ['id' => $record['uuid'] ]),
521
                        'profile'   => $this->url()->fromRoute('company/view', ['id' => $record['uuid']]),
545
                    ]);
522
                    ]);
546
                }
523
                }
547
            }
524
            }
548
            
525
 
549
            return new JsonModel([
526
            return new JsonModel([
550
                'success' => true,
527
                'success' => true,
551
                'data' => $items
-
 
552
            ]);
528
                'data' => $items
553
            
529
            ]);
554
        } else {
530
        } else {
555
            return new JsonModel([
531
            return new JsonModel([
556
                'success' => false,
532
                'success' => false,
557
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
533
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
558
            ]);
534
            ]);
559
        }
535
        }
560
    }
536
    }
561
    
537
 
562
    /**
538
    /**
563
     * Recuperamos los miembros del grupo
539
     * Recuperamos los miembros del grupo
564
     * tiene que enviarse un petición GET a la siguiente url: /helpers/group-members/:group_id
540
     * tiene que enviarse un petición GET a la siguiente url: /helpers/group-members/:group_id
Línea 584... Línea 560...
584
    {
560
    {
585
        $currentUserPlugin = $this->plugin('currentUserPlugin');
561
        $currentUserPlugin = $this->plugin('currentUserPlugin');
586
        $currentUser = $currentUserPlugin->getUser();
562
        $currentUser = $currentUserPlugin->getUser();
Línea 587... Línea 563...
587
 
563
 
588
        $request = $this->getRequest();
564
        $request = $this->getRequest();
589
        if($request->isGet()) {
565
        if ($request->isGet()) {
590
            
566
 
591
            $group_uuid = $this->params()->fromRoute('group_id');
567
            $group_uuid = $this->params()->fromRoute('group_id');
592
            
568
 
593
            $groupMapper = GroupMapper::getInstance($this->adapter);
569
            $groupMapper = GroupMapper::getInstance($this->adapter);
594
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
570
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
595
            
571
 
596
            $items = [];
572
            $items = [];
597
            if($group && $group->status == Group::STATUS_ACTIVE) {
573
            if ($group && $group->status == Group::STATUS_ACTIVE) {
598
                
574
 
599
                $mapper = QueryMapper::getInstance($this->adapter);
575
                $mapper = QueryMapper::getInstance($this->adapter);
600
                $select = $mapper->getSql()->select();
576
                $select = $mapper->getSql()->select();
601
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
577
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
602
                $select->from(['u' => UserMapper::_TABLE]);
578
                $select->from(['u' => UserMapper::_TABLE]);
603
                $select->join(['gm' => GroupMemberMapper::_TABLE], 'gm.user_id = u.id ', ['user_id', 'status']);
579
                $select->join(['gm' => GroupMemberMapper::_TABLE], 'gm.user_id = u.id ', ['user_id', 'status']);
604
                $select->join(['g' => GroupMapper::_TABLE], 'gm.group_id = g.id', ['group_uuid' => 'uuid']  );
580
                $select->join(['g' => GroupMapper::_TABLE], 'gm.group_id = g.id', ['group_uuid' => 'uuid']);
605
                $select->where->equalTo('u.network_id',  $currentUser->network_id);
581
                $select->where->equalTo('u.network_id',  $currentUser->network_id);
606
                $select->where->equalTo('g.network_id', $currentUser->network_id);
582
                $select->where->equalTo('g.network_id', $currentUser->network_id);
607
                $select->where->equalTo('g.uuid', $group_uuid);
583
                $select->where->equalTo('g.uuid', $group_uuid);
608
                
584
 
609
                if($group->user_id == $currentUser->id) {
585
                if ($group->user_id == $currentUser->id) {
610
                    $select->where->in('gm.status', [
586
                    $select->where->in('gm.status', [
611
                        GroupMember::STATUS_ACCEPTED, 
587
                        GroupMember::STATUS_ACCEPTED,
612
                        GroupMember::STATUS_ADDED_BY_ADMIN,
588
                        GroupMember::STATUS_ADDED_BY_ADMIN,
613
                        GroupMember::STATUS_AUTO_JOIN,
589
                        GroupMember::STATUS_AUTO_JOIN,
614
                        GroupMember::STATUS_JOINING_REQUESTED,
590
                        GroupMember::STATUS_JOINING_REQUESTED,
615
                    ]);
591
                    ]);
616
                } else {
592
                } else {
617
                    $select->where->in('gm.status', [GroupMember::STATUS_ACCEPTED, GroupMember::STATUS_AUTO_JOIN]);
593
                    $select->where->in('gm.status', [GroupMember::STATUS_ACCEPTED, GroupMember::STATUS_AUTO_JOIN]);
618
                } 
594
                }
619
                
595
 
620
                
596
 
621
                $select->where->equalTo('u.status', User::STATUS_ACTIVE);
597
                $select->where->equalTo('u.status', User::STATUS_ACTIVE);
622
                $select->order(['last_name', 'first_name']);
598
                $select->order(['last_name', 'first_name']);
623
                
599
 
624
                //echo $select->getSqlString($this->adapter->platform);
-
 
625
       
-
 
Línea -... Línea 600...
-
 
600
                //echo $select->getSqlString($this->adapter->platform);
626
               
601
 
-
 
602
 
627
 
603
 
628
                
604
 
629
                $records = $mapper->fetchAll($select);
-
 
630
                foreach($records as $record)
605
                $records = $mapper->fetchAll($select);
631
                {
606
                foreach ($records as $record) {
632
                    
607
 
633
                    $actions = [];
608
                    $actions = [];
634
                    if($group->user_id == $currentUser->id) {
609
                    if ($group->user_id == $currentUser->id) {
635
                        if($record['id'] != $currentUser->id) {
610
                        if ($record['id'] != $currentUser->id) {
636
                          
611
 
637
                            
612
 
638
                            
-
 
639
                            switch($record['status'])
613
 
640
                            {
614
                            switch ($record['status']) {
641
                                case GroupMember::STATUS_JOINING_REQUESTED :
615
                                case GroupMember::STATUS_JOINING_REQUESTED:
642
                                    $actions['link_approve'] = $this->url()->fromRoute('helpers/group-members/approve', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
616
                                    $actions['link_approve'] = $this->url()->fromRoute('helpers/group-members/approve', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
643
                                    $actions['link_reject'] = $this->url()->fromRoute('helpers/group-members/reject', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
617
                                    $actions['link_reject'] = $this->url()->fromRoute('helpers/group-members/reject', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
644
                                    break;
618
                                    break;
645
                                    
619
 
646
                                case GroupMember::STATUS_ACCEPTED :
620
                                case GroupMember::STATUS_ACCEPTED:
647
                                case GroupMember::STATUS_AUTO_JOIN :
621
                                case GroupMember::STATUS_AUTO_JOIN:
648
                                case GroupMember::STATUS_ADDED_BY_ADMIN :
622
                                case GroupMember::STATUS_ADDED_BY_ADMIN:
649
                                    $actions['link_cancel'] = $this->url()->fromRoute('helpers/group-members/cancel', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
623
                                    $actions['link_cancel'] = $this->url()->fromRoute('helpers/group-members/cancel', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
650
                                    break;
624
                                    break;
651
                            }
-
 
652
                        }
-
 
653
                
-
 
654
                        
625
                            }
655
              
626
                        }
656
                    }
627
                    }
657
                        
628
 
658
                    array_push($items, [
629
                    array_push($items, [
659
                        'id'        => $record['uuid'],
630
                        'id'        => $record['uuid'],
660
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
631
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
661
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
632
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
662
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
633
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
663
                        'actions'   => $actions,
634
                        'actions'   => $actions,
664
                        
635
 
665
                    ]);
636
                    ]);
666
                }
637
                }
667
            }
638
            }
668
            
639
 
669
            return new JsonModel([
640
            return new JsonModel([
670
                'success' => true,
641
                'success' => true,
671
                'data' => [
642
                'data' => [
672
                    'items' => $items,
643
                    'items' => $items,
673
                    'link_invite' => $group->user_id == $currentUser->id ? $this->url()->fromRoute('helpers/group-members/invite',['group_id' => $group->uuid])  : '',
644
                    'link_invite' => $group->user_id == $currentUser->id ? $this->url()->fromRoute('helpers/group-members/invite', ['group_id' => $group->uuid])  : '',
674
                ]
-
 
675
            ]);
645
                ]
676
            
646
            ]);
677
        } else {
647
        } else {
678
            return new JsonModel([
648
            return new JsonModel([
679
                'success' => false,
649
                'success' => false,
680
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
650
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
681
            ]);
651
            ]);
682
        }
652
        }
683
    }
653
    }
684
    
654
 
685
    public function groupMemberInviteAction()
655
    public function groupMemberInviteAction()
686
    {
656
    {
Línea 687... Línea 657...
687
        $currentUserPlugin = $this->plugin('currentUserPlugin');
657
        $currentUserPlugin = $this->plugin('currentUserPlugin');
688
        $currentUser = $currentUserPlugin->getUser();
658
        $currentUser = $currentUserPlugin->getUser();
689
 
659
 
690
        $group_uuid = $this->params()->fromRoute('group_id');
660
        $group_uuid = $this->params()->fromRoute('group_id');
691
        
661
 
692
        $groupMapper = GroupMapper::getInstance($this->adapter);
662
        $groupMapper = GroupMapper::getInstance($this->adapter);
693
        $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
663
        $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
694
        
664
 
695
        if(!$group) {
665
        if (!$group) {
696
            return new JsonModel([
666
            return new JsonModel([
697
                'success' => false,
667
                'success' => false,
698
                'data' => 'ERROR_GROUP_NOT_FOUND'
668
                'data' => 'ERROR_GROUP_NOT_FOUND'
699
            ]);
669
            ]);
700
        }
670
        }
701
        
671
 
702
        if($group->status != Group::STATUS_ACTIVE) {
672
        if ($group->status != Group::STATUS_ACTIVE) {
703
            return new JsonModel([
673
            return new JsonModel([
704
                'success' => false,
674
                'success' => false,
705
                'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
675
                'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
706
            ]);
676
            ]);
707
        }
677
        }
708
        
678
 
709
        if($currentUser->id != $group->user_id) {
679
        if ($currentUser->id != $group->user_id) {
710
            return new JsonModel([
680
            return new JsonModel([
711
                'success' => false,
681
                'success' => false,
712
                'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
682
                'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
713
            ]);
683
            ]);
714
        }
684
        }
715
        
685
 
716
        
686
 
717
        $request = $this->getRequest();
687
        $request = $this->getRequest();
Línea 718... Línea 688...
718
        if($request->isGet()) {
688
        if ($request->isGet()) {
719
            $search = filter_var($this->params()->fromQuery('search', ''));
689
            $search = filter_var($this->params()->fromQuery('search', ''));
720
            if(strlen($search) >= 3) {
690
            if (strlen($search) >= 3) {
721
 
691
 
722
                $userMapper = UserMapper::getInstance($this->adapter);
692
                $userMapper = UserMapper::getInstance($this->adapter);
723
                $records  = $userMapper->fetchAllSuggestForInvitationByGroupIdAndNetworkIdAndSearch($group->id, $currentUser->network_id, $search);
-
 
724
                
693
                $records  = $userMapper->fetchAllSuggestForInvitationByGroupIdAndNetworkIdAndSearch($group->id, $currentUser->network_id, $search);
725
                $users = [];
694
 
726
                foreach($records as $record)
695
                $users = [];
727
                {
696
                foreach ($records as $record) {
728
                    array_push($users, [
697
                    array_push($users, [
729
                        'value' => $record->uuid,
698
                        'value' => $record->uuid,
730
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
699
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
731
                        
700
 
732
                    ]);
701
                    ]);
733
                }
702
                }
734
                
703
 
735
                return new JsonModel([
-
 
736
                    'success' => true,
-
 
737
                    'data' => $users
-
 
738
                ]);
-
 
739
                
704
                return new JsonModel([
740
                
705
                    'success' => true,
741
                
706
                    'data' => $users
742
                
707
                ]);
743
            } else {
-
 
744
                return new JsonModel([
-
 
745
                    'success' => true,
708
            } else {
746
                    'data' => [
709
                return new JsonModel([
747
                        
-
 
748
                    ]
-
 
749
                ]);
-
 
750
            } 
-
 
751
            
710
                    'success' => true,
752
            
711
                    'data' => []
753
 
712
                ]);
754
        } 
713
            }
755
        else if($request->isPost()) {
714
        } else if ($request->isPost()) {
756
            $uuid = $this->params()->fromPost('id');
715
            $uuid = $this->params()->fromPost('id');
757
            if(!$uuid) {
716
            if (!$uuid) {
758
                return new JsonModel([
717
                return new JsonModel([
759
                    'success'   => false,
718
                    'success'   => false,
760
                    'data'      => 'ERROR_INVALID_PARAMETER'
719
                    'data'      => 'ERROR_INVALID_PARAMETER'
761
                ]);
720
                ]);
762
            }
721
            }
763
            
722
 
764
            $userMapper = UserMapper::getInstance($this->adapter);
723
            $userMapper = UserMapper::getInstance($this->adapter);
765
            $user = $userMapper->fetchOneByUuidAndNetworkId($uuid, $currentUser->network_id);
724
            $user = $userMapper->fetchOneByUuidAndNetworkId($uuid, $currentUser->network_id);
766
            
725
 
767
            if(!$user) {
726
            if (!$user) {
768
                return new JsonModel([
727
                return new JsonModel([
769
                    'success'   => false,
728
                    'success'   => false,
770
                    'data'      => 'ERROR_USER_NOT_FOUND'
729
                    'data'      => 'ERROR_USER_NOT_FOUND'
771
                ]);
730
                ]);
772
            }
731
            }
773
            
732
 
774
            if($user->status != User::STATUS_ACTIVE) {
733
            if ($user->status != User::STATUS_ACTIVE) {
775
                return new JsonModel([
734
                return new JsonModel([
776
                    'success'   => false,
735
                    'success'   => false,
777
                    'data'      => 'ERROR_USER_IS_INACTIVE'
736
                    'data'      => 'ERROR_USER_IS_INACTIVE'
778
                ]);
737
                ]);
779
            }
738
            }
780
            
739
 
781
            if($group->user_id == $user->id) {
740
            if ($group->user_id == $user->id) {
782
                return new JsonModel([
741
                return new JsonModel([
783
                    'success'   => false,
742
                    'success'   => false,
784
                    'data'      => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
743
                    'data'      => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
785
                ]);
744
                ]);
786
            }
745
            }
787
            
746
 
788
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
747
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
789
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
748
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
790
            
749
 
791
            
750
 
792
            
751
 
793
            if($groupMember) {
-
 
794
                $result = false;
752
            if ($groupMember) {
795
                
753
                $result = false;
796
                switch($groupMember->status)
754
 
797
                {
755
                switch ($groupMember->status) {
798
                    case GroupMember::STATUS_ACCEPTED:
756
                    case GroupMember::STATUS_ACCEPTED:
799
                    case GroupMember::STATUS_AUTO_JOIN: 
757
                    case GroupMember::STATUS_AUTO_JOIN:
800
                        
758
 
801
                        return new JsonModel([
759
                        return new JsonModel([
802
                            'success'   => false,
760
                            'success'   => false,
803
                            'data'      => 'ERROR_GROUP_YOU_ARE_MEMBER',
761
                            'data'      => 'ERROR_GROUP_YOU_ARE_MEMBER',
804
                        ]);
762
                        ]);
805
                        break;
763
                        break;
806
                        
764
 
807
                        
765
 
808
                    case $groupMember->status == GroupMember::STATUS_REJECTED :
766
                    case $groupMember->status == GroupMember::STATUS_REJECTED:
809
                    case $groupMember->status == GroupMember::STATUS_CANCELLED :
767
                    case $groupMember->status == GroupMember::STATUS_CANCELLED:
810
                        
768
 
811
                        $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
769
                        $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
812
                        $groupMember->joining_request_on = date('H-m-d H:i:s');
770
                        $groupMember->joining_request_on = date('H-m-d H:i:s');
813
                        
771
 
814
                        $result = $groupMemberMapper->update($groupMember);
772
                        $result = $groupMemberMapper->update($groupMember);
815
                        break;
773
                        break;
816
                     
774
 
817
                    case GroupMember::STATUS_ADDED_BY_ADMIN : 
775
                    case GroupMember::STATUS_ADDED_BY_ADMIN:
818
                    case  GroupMember::STATUS_JOINING_REQUESTED :
776
                    case  GroupMember::STATUS_JOINING_REQUESTED:
819
                        return new JsonModel([
777
                        return new JsonModel([
820
                            'success'   => false,
778
                            'success'   => false,
821
                            'data'      => 'ERROR_GROUP_THERE_IS_A_PENDING_REQUEST'
779
                            'data'      => 'ERROR_GROUP_THERE_IS_A_PENDING_REQUEST'
822
                        ]);
780
                        ]);
823
                        break;
781
                        break;
824
                        
782
 
825
                    default :     
783
                    default:
826
                        return new JsonModel([
784
                        return new JsonModel([
827
                            'success'   => false,
-
 
828
                            'data'      => 'ERROR_UNKNOWN_OPERATION'
785
                            'success'   => false,
829
                        ]);
-
 
830
                        break;
-
 
831
                        
-
 
832
                }
-
 
833
 
-
 
834
               
-
 
835
                    
786
                            'data'      => 'ERROR_UNKNOWN_OPERATION'
836
                
787
                        ]);
837
                
788
                        break;
838
                
789
                }
839
            } else {
790
            } else {
840
                
791
 
841
                
792
 
842
                
793
 
843
                $groupMember = new GroupMember();
794
                $groupMember = new GroupMember();
844
                $groupMember->user_id = $user->id;
795
                $groupMember->user_id = $user->id;
845
                $groupMember->group_id = $group->id;
796
                $groupMember->group_id = $group->id;
846
                $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
-
 
847
                $groupMember->joining_request_on = date('H-m-d H:i:s');
-
 
848
              
797
                $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
849
                $result = $groupMemberMapper->insert($groupMember);
798
                $groupMember->joining_request_on = date('H-m-d H:i:s');
850
                
799
 
851
                
800
                $result = $groupMemberMapper->insert($groupMember);
852
            } 
801
            }
853
            
802
 
854
            if($result) {
803
            if ($result) {
855
                
804
 
856
                $notification = new Notification();
805
                $notification = new Notification();
857
                $notification->type     = Notification::TYPE_RECEIVE_INVITATION_GROUP;
806
                $notification->type     = Notification::TYPE_RECEIVE_INVITATION_GROUP;
858
                $notification->read     = Notification::NO;
807
                $notification->read     = Notification::NO;
859
                $notification->user_id  = $user->id;
808
                $notification->user_id  = $user->id;
860
                $notification->group_id = $group->id;
809
                $notification->group_id = $group->id;
861
                $notification->message  = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_GROUP';
810
                $notification->message  = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_GROUP';
862
                $notification->url      = $this->url()->fromRoute('group/view',['id' => $group->uuid]);
811
                $notification->url      = $this->url()->fromRoute('group/view', ['id' => $group->uuid]);
863
                
812
 
864
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
813
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
865
                $notificationMapper->insert($notification);
814
                $notificationMapper->insert($notification);
866
                
815
 
867
                $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
-
 
868
                $userNotification = $userNotificationMapper->fetchOne($user->id);
816
                $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
869
                
817
                $userNotification = $userNotificationMapper->fetchOne($user->id);
870
                if($userNotification && $userNotification->receive_invitation_group)
818
 
871
                {
819
                if ($userNotification && $userNotification->receive_invitation_group) {
872
                    $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
820
                    $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
873
                    $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_GROUP, $currentUser->network_id);
821
                    $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_GROUP, $currentUser->network_id);
874
                    
822
 
875
                    if($emailTemplate) {
823
                    if ($emailTemplate) {
876
                        $arrayCont = [
824
                        $arrayCont = [
Línea 882... Línea 830...
882
                            'group_name'            => $group->name,
830
                            'group_name'            => $group->name,
883
                            'content'               => '',
831
                            'content'               => '',
884
                            'code'                  => '',
832
                            'code'                  => '',
885
                            'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
833
                            'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
886
                        ];
834
                        ];
887
                        
835
 
888
                        $email = new QueueEmail($this->adapter);
836
                        $email = new QueueEmail($this->adapter);
889
                        $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
837
                        $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
890
                    }
838
                    }
891
                }
839
                }
892
                
840
 
893
                return new JsonModel([
841
                return new JsonModel([
894
                    'success'   => true,
842
                    'success'   => true,
895
                    'data'      => 'LABEL_GROUP_REQUEST_SUCCESS'
843
                    'data'      => 'LABEL_GROUP_REQUEST_SUCCESS'
896
                ]);
844
                ]);
897
                
-
 
898
            } else {
845
            } else {
899
                
846
 
900
                return new JsonModel([
847
                return new JsonModel([
901
                    'success'   => false,
848
                    'success'   => false,
902
                    'data'      => 'ERROR_GROUP_REQUEST_COULD_NOT_BE_SENT'
849
                    'data'      => 'ERROR_GROUP_REQUEST_COULD_NOT_BE_SENT'
903
                ]);
850
                ]);
904
                
-
 
905
            } 
851
            }
906
            
-
 
907
            
-
 
908
            
-
 
909
        } else {
852
        } else {
910
            return new JsonModel([
853
            return new JsonModel([
911
                'success' => false,
854
                'success' => false,
912
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
855
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
913
            ]);
856
            ]);
914
        }
857
        }
915
    }
858
    }
916
    
859
 
917
    public function  groupMemberCancelAction()
860
    public function  groupMemberCancelAction()
918
    {
861
    {
919
        $currentUserPlugin = $this->plugin('currentUserPlugin');
862
        $currentUserPlugin = $this->plugin('currentUserPlugin');
920
        $currentUser = $currentUserPlugin->getUser();
863
        $currentUser = $currentUserPlugin->getUser();
Línea 921... Línea 864...
921
 
864
 
922
        $request = $this->getRequest();
865
        $request = $this->getRequest();
923
        if($request->isPost()) {
866
        if ($request->isPost()) {
924
            $group_uuid = $this->params()->fromRoute('group_id');
867
            $group_uuid = $this->params()->fromRoute('group_id');
925
            $user_uuid  = $this->params()->fromRoute('user_id'); 
868
            $user_uuid  = $this->params()->fromRoute('user_id');
926
            
869
 
927
            $groupMapper = GroupMapper::getInstance($this->adapter);
870
            $groupMapper = GroupMapper::getInstance($this->adapter);
928
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
871
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
929
            
872
 
930
            if(!$group) {
873
            if (!$group) {
931
                return new JsonModel([
874
                return new JsonModel([
932
                    'success' => false,
875
                    'success' => false,
933
                    'data' => 'ERROR_GROUP_NOT_FOUND'
876
                    'data' => 'ERROR_GROUP_NOT_FOUND'
934
                ]);
877
                ]);
935
            }
878
            }
936
            
879
 
937
            if($group->status != Group::STATUS_ACTIVE) {
880
            if ($group->status != Group::STATUS_ACTIVE) {
938
                return new JsonModel([
881
                return new JsonModel([
939
                    'success' => false,
882
                    'success' => false,
940
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
883
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
941
                ]);
884
                ]);
942
            }
885
            }
943
            
886
 
944
            if($currentUser->id != $group->user_id) {
887
            if ($currentUser->id != $group->user_id) {
945
                return new JsonModel([
888
                return new JsonModel([
946
                    'success' => false,
889
                    'success' => false,
947
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
890
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
948
                ]);
891
                ]);
949
            }
892
            }
950
            
893
 
951
            $userMapper = UserMapper::getInstance($this->adapter);
894
            $userMapper = UserMapper::getInstance($this->adapter);
952
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
895
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
953
            
896
 
954
            if(!$user) {
897
            if (!$user) {
955
                return new JsonModel([
898
                return new JsonModel([
956
                    'success' => false,
899
                    'success' => false,
957
                    'data' => 'ERROR_USER_NOT_FOUND'
900
                    'data' => 'ERROR_USER_NOT_FOUND'
958
                ]);
901
                ]);
959
            }
902
            }
960
            
903
 
961
            if($user->id == $currentUser->id) {
904
            if ($user->id == $currentUser->id) {
962
                return new JsonModel([
905
                return new JsonModel([
963
                    'success' => false,
906
                    'success' => false,
964
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
907
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
965
                ]);
908
                ]);
966
            }
909
            }
967
            
910
 
968
            
911
 
969
            
912
 
970
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
913
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
971
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
914
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
972
            if($groupMember) {
915
            if ($groupMember) {
-
 
916
 
973
                
917
                if (
974
                if($groupMember->status == GroupMember::STATUS_ACCEPTED ||
918
                    $groupMember->status == GroupMember::STATUS_ACCEPTED ||
975
                    $groupMember->status == GroupMember::STATUS_ADDED_BY_ADMIN ||
919
                    $groupMember->status == GroupMember::STATUS_ADDED_BY_ADMIN ||
-
 
920
                    $groupMember->status == GroupMember::STATUS_AUTO_JOIN
976
                    $groupMember->status == GroupMember::STATUS_AUTO_JOIN) {
921
                ) {
977
                    
922
 
978
                    $groupMember->status = GroupMember::STATUS_CANCELLED;
923
                    $groupMember->status = GroupMember::STATUS_CANCELLED;
Línea 979... Línea 924...
979
                    if($groupMemberMapper->update($groupMember)) {
924
                    if ($groupMemberMapper->update($groupMember)) {
980
 
925
 
981
                        return new JsonModel([
926
                        return new JsonModel([
982
                            'success' => true,
927
                            'success' => true,
983
                            'data' =>  'LABEL_GROUP_MEMBER_CANCELLED_SUCCESS' 
-
 
984
                        ]);
928
                            'data' =>  'LABEL_GROUP_MEMBER_CANCELLED_SUCCESS'
985
                            
929
                        ]);
986
                    } else {
930
                    } else {
987
                        return new JsonModel([
931
                        return new JsonModel([
988
                            'success' => true,
932
                            'success' => true,
989
                            'data' =>    'LABEL_GROUP_MEMBER_CANCELLED_FAILED' 
933
                            'data' =>    'LABEL_GROUP_MEMBER_CANCELLED_FAILED'
990
                        ]);
934
                        ]);
991
                    }
-
 
992
                }
935
                    }
993
                
936
                }
994
            } 
937
            }
995
            
938
 
996
            
939
 
997
            return new JsonModel([
940
            return new JsonModel([
998
                'success' => false,
941
                'success' => false,
999
                'data' => 'ERROR_GROUP_REQUEST_OR_MEMBER_NOT_FOUND_TO_CANCEL'
-
 
1000
            ]);
-
 
1001
 
-
 
1002
            
-
 
1003
            
-
 
1004
            
942
                'data' => 'ERROR_GROUP_REQUEST_OR_MEMBER_NOT_FOUND_TO_CANCEL'
1005
            
943
            ]);
1006
        } else {
944
        } else {
1007
            
945
 
1008
            return new JsonModel([
946
            return new JsonModel([
1009
                'success' => false,
947
                'success' => false,
1010
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
948
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1011
            ]);
949
            ]);
1012
        }
950
        }
1013
    }
951
    }
1014
    
952
 
1015
    public function  groupMemberRejectAction()
953
    public function  groupMemberRejectAction()
1016
    {
954
    {
1017
        $currentUserPlugin = $this->plugin('currentUserPlugin');
955
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1018
        $currentUser = $currentUserPlugin->getUser();
956
        $currentUser = $currentUserPlugin->getUser();
1019
        
957
 
1020
        $request = $this->getRequest();
958
        $request = $this->getRequest();
1021
        if($request->isPost()) {
959
        if ($request->isPost()) {
1022
            $group_uuid = $this->params()->fromRoute('group_id');
960
            $group_uuid = $this->params()->fromRoute('group_id');
1023
            $user_uuid  = $this->params()->fromRoute('user_id');
961
            $user_uuid  = $this->params()->fromRoute('user_id');
1024
            
962
 
1025
            $groupMapper = GroupMapper::getInstance($this->adapter);
963
            $groupMapper = GroupMapper::getInstance($this->adapter);
1026
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
964
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1027
            
965
 
1028
            if(!$group) {
966
            if (!$group) {
1029
                return new JsonModel([
967
                return new JsonModel([
1030
                    'success' => false,
968
                    'success' => false,
1031
                    'data' => 'ERROR_GROUP_NOT_FOUND'
969
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1032
                ]);
970
                ]);
1033
            }
971
            }
1034
            
972
 
1035
            if($group->status != Group::STATUS_ACTIVE) {
973
            if ($group->status != Group::STATUS_ACTIVE) {
1036
                return new JsonModel([
974
                return new JsonModel([
1037
                    'success' => false,
975
                    'success' => false,
1038
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
976
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1039
                ]);
977
                ]);
1040
            }
978
            }
1041
            
979
 
1042
            if($currentUser->id != $group->user_id) {
980
            if ($currentUser->id != $group->user_id) {
1043
                return new JsonModel([
981
                return new JsonModel([
1044
                    'success' => false,
982
                    'success' => false,
1045
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
983
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1046
                ]);
984
                ]);
1047
            }
985
            }
1048
            
986
 
1049
            $userMapper = UserMapper::getInstance($this->adapter);
987
            $userMapper = UserMapper::getInstance($this->adapter);
1050
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
988
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1051
            
989
 
1052
            if(!$user) {
990
            if (!$user) {
1053
                return new JsonModel([
991
                return new JsonModel([
1054
                    'success' => false,
992
                    'success' => false,
1055
                    'data' => 'ERROR_USER_NOT_FOUND'
993
                    'data' => 'ERROR_USER_NOT_FOUND'
1056
                ]);
994
                ]);
1057
            }
995
            }
1058
            
996
 
1059
            if($user->id == $currentUser->id) {
997
            if ($user->id == $currentUser->id) {
1060
                return new JsonModel([
998
                return new JsonModel([
1061
                    'success' => false,
999
                    'success' => false,
1062
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1000
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1063
                ]);
1001
                ]);
1064
            }
1002
            }
1065
            
1003
 
1066
            
1004
 
1067
            
1005
 
1068
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1006
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1069
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1007
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1070
            if($groupMember) {
1008
            if ($groupMember) {
1071
                
1009
 
1072
                if($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1010
                if ($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1073
                        
1011
 
1074
                        $groupMember->status = GroupMember::STATUS_REJECTED;
1012
                    $groupMember->status = GroupMember::STATUS_REJECTED;
1075
                        if($groupMemberMapper->update($groupMember)) {
1013
                    if ($groupMemberMapper->update($groupMember)) {
1076
                            
1014
 
1077
                            return new JsonModel([
1015
                        return new JsonModel([
1078
                                'success' => true,
1016
                            'success' => true,
1079
                                'data' =>  'LABEL_GROUP_MEMBER_REJECTED_SUCCESS'
-
 
1080
                            ]);
1017
                            'data' =>  'LABEL_GROUP_MEMBER_REJECTED_SUCCESS'
1081
                            
1018
                        ]);
1082
                        } else {
1019
                    } else {
1083
                            return new JsonModel([
1020
                        return new JsonModel([
1084
                                'success' => true,
-
 
1085
                                'data' =>    'LABEL_GROUP_MEMBER_REJECTED_FAILED'
1021
                            'success' => true,
1086
                            ]);
1022
                            'data' =>    'LABEL_GROUP_MEMBER_REJECTED_FAILED'
1087
                        }
-
 
-
 
1023
                        ]);
1088
                    }
1024
                    }
1089
                    
1025
                }
1090
            }
1026
            }
1091
            
1027
 
1092
            
1028
 
1093
            return new JsonModel([
1029
            return new JsonModel([
1094
                'success' => false,
1030
                'success' => false,
1095
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_REJECT'
-
 
1096
            ]);
-
 
1097
            
-
 
1098
            
-
 
1099
            
-
 
1100
            
1031
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_REJECT'
1101
            
1032
            ]);
1102
        } else {
1033
        } else {
1103
            
1034
 
1104
            return new JsonModel([
1035
            return new JsonModel([
1105
                'success' => false,
1036
                'success' => false,
1106
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1037
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1107
            ]);
1038
            ]);
1108
        }
1039
        }
1109
    }
1040
    }
1110
    
1041
 
1111
    public function  groupMemberApproveAction()
1042
    public function  groupMemberApproveAction()
1112
    {
1043
    {
1113
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1044
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1114
        $currentUser = $currentUserPlugin->getUser();
1045
        $currentUser = $currentUserPlugin->getUser();
1115
        
1046
 
1116
        $request = $this->getRequest();
1047
        $request = $this->getRequest();
1117
        if($request->isPost()) {
1048
        if ($request->isPost()) {
1118
            $group_uuid = $this->params()->fromRoute('group_id');
1049
            $group_uuid = $this->params()->fromRoute('group_id');
1119
            $user_uuid  = $this->params()->fromRoute('user_id');
1050
            $user_uuid  = $this->params()->fromRoute('user_id');
1120
            
1051
 
1121
            $groupMapper = GroupMapper::getInstance($this->adapter);
1052
            $groupMapper = GroupMapper::getInstance($this->adapter);
1122
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1053
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1123
            
1054
 
1124
            if(!$group) {
1055
            if (!$group) {
1125
                return new JsonModel([
1056
                return new JsonModel([
1126
                    'success' => false,
1057
                    'success' => false,
1127
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1058
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1128
                ]);
1059
                ]);
1129
            }
1060
            }
1130
            
1061
 
1131
            if($group->status != Group::STATUS_ACTIVE) {
1062
            if ($group->status != Group::STATUS_ACTIVE) {
1132
                return new JsonModel([
1063
                return new JsonModel([
1133
                    'success' => false,
1064
                    'success' => false,
1134
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1065
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1135
                ]);
1066
                ]);
1136
            }
1067
            }
1137
            
1068
 
1138
            if($currentUser->id != $group->user_id) {
1069
            if ($currentUser->id != $group->user_id) {
1139
                return new JsonModel([
1070
                return new JsonModel([
1140
                    'success' => false,
1071
                    'success' => false,
1141
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1072
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1142
                ]);
1073
                ]);
1143
            }
1074
            }
1144
            
1075
 
1145
            $userMapper = UserMapper::getInstance($this->adapter);
1076
            $userMapper = UserMapper::getInstance($this->adapter);
1146
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1077
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1147
            
1078
 
1148
            if(!$user) {
1079
            if (!$user) {
1149
                return new JsonModel([
1080
                return new JsonModel([
1150
                    'success' => false,
1081
                    'success' => false,
1151
                    'data' => 'ERROR_USER_NOT_FOUND'
1082
                    'data' => 'ERROR_USER_NOT_FOUND'
1152
                ]);
1083
                ]);
1153
            }
1084
            }
1154
            
1085
 
1155
            if($user->id == $currentUser->id) {
1086
            if ($user->id == $currentUser->id) {
1156
                return new JsonModel([
1087
                return new JsonModel([
1157
                    'success' => false,
1088
                    'success' => false,
1158
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1089
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1159
                ]);
1090
                ]);
1160
            }
1091
            }
1161
            
1092
 
1162
            
1093
 
1163
            
1094
 
1164
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1095
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1165
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1096
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1166
            if($groupMember) {
1097
            if ($groupMember) {
1167
                
1098
 
1168
                if($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1099
                if ($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1169
                    
1100
 
1170
                    $groupMember->status = GroupMember::STATUS_ACCEPTED;
1101
                    $groupMember->status = GroupMember::STATUS_ACCEPTED;
1171
                    if($groupMemberMapper->update($groupMember)) {
1102
                    if ($groupMemberMapper->update($groupMember)) {
1172
                        
1103
 
1173
                        
1104
 
1174
                        $notification = new Notification();
1105
                        $notification = new Notification();
1175
                        $notification->type     = Notification::TYPE_ACCEPT_MY_REQUEST_JOIN_GROUP;
1106
                        $notification->type     = Notification::TYPE_ACCEPT_MY_REQUEST_JOIN_GROUP;
1176
                        $notification->read     = Notification::NO;
1107
                        $notification->read     = Notification::NO;
1177
                        $notification->user_id  = $user->id;
1108
                        $notification->user_id  = $user->id;
1178
                        $notification->group_id = $group->id;
1109
                        $notification->group_id = $group->id;
1179
                        $notification->message  = 'LABEL_NOTIFICATION_ACCEPT_MY_REQUEST_JOIN_GROUP';
1110
                        $notification->message  = 'LABEL_NOTIFICATION_ACCEPT_MY_REQUEST_JOIN_GROUP';
1180
                        $notification->url      = $this->url()->fromRoute('group/view', ['id' => $group->uuid]);
1111
                        $notification->url      = $this->url()->fromRoute('group/view', ['id' => $group->uuid]);
1181
                        
1112
 
1182
                        $notificationMapper = NotificationMapper::getInstance($this->adapter);
1113
                        $notificationMapper = NotificationMapper::getInstance($this->adapter);
1183
                        $notificationMapper->insert($notification);
1114
                        $notificationMapper->insert($notification);
1184
                        
1115
 
1185
                        $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
1116
                        $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
1186
                        $userNotification = $userNotificationMapper->fetchOne($user->id);
1117
                        $userNotification = $userNotificationMapper->fetchOne($user->id);
1187
                        
-
 
1188
                        if($userNotification && $userNotification->receive_invitation_group)
1118
 
1189
                        {
1119
                        if ($userNotification && $userNotification->receive_invitation_group) {
1190
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1120
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1191
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_ACCEPT_MY_REQUEST_JOIN_GROUP, $currentUser->network_id);
1121
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_ACCEPT_MY_REQUEST_JOIN_GROUP, $currentUser->network_id);
1192
                            
1122
 
1193
                            if($emailTemplate) {
1123
                            if ($emailTemplate) {
1194
                                $arrayCont = [
1124
                                $arrayCont = [
1195
                                    'firstname'             => $currentUser->first_name,
1125
                                    'firstname'             => $currentUser->first_name,
1196
                                    'lastname'              => $currentUser->last_name,
1126
                                    'lastname'              => $currentUser->last_name,
Línea 1200... Línea 1130...
1200
                                    'group_name'            => $group->name,
1130
                                    'group_name'            => $group->name,
1201
                                    'content'               => '',
1131
                                    'content'               => '',
1202
                                    'code'                  => '',
1132
                                    'code'                  => '',
1203
                                    'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
1133
                                    'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
1204
                                ];
1134
                                ];
1205
                                
1135
 
1206
                                $email = new QueueEmail($this->adapter);
1136
                                $email = new QueueEmail($this->adapter);
1207
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1137
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1208
                            }
1138
                            }
1209
                        }
1139
                        }
1210
                        
1140
 
1211
                        return new JsonModel([
1141
                        return new JsonModel([
1212
                            'success' => true,
1142
                            'success' => true,
1213
                            'data' =>  'LABEL_GROUP_MEMBER_APPROVED_SUCCESS'
1143
                            'data' =>  'LABEL_GROUP_MEMBER_APPROVED_SUCCESS'
1214
                        ]);
1144
                        ]);
1215
                        
-
 
1216
                    } else {
1145
                    } else {
1217
                        return new JsonModel([
1146
                        return new JsonModel([
1218
                            'success' => true,
1147
                            'success' => true,
1219
                            'data' =>    'LABEL_GROUP_MEMBER_APPROVED_FAILED'
1148
                            'data' =>    'LABEL_GROUP_MEMBER_APPROVED_FAILED'
1220
                        ]);
1149
                        ]);
1221
                    }
1150
                    }
1222
                }
1151
                }
1223
                
-
 
1224
            }
1152
            }
1225
            
1153
 
1226
            
1154
 
1227
            return new JsonModel([
1155
            return new JsonModel([
1228
                'success' => false,
1156
                'success' => false,
1229
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_APPROVED'
1157
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_APPROVED'
1230
            ]);
1158
            ]);
1231
            
-
 
1232
            
-
 
1233
            
-
 
1234
            
-
 
1235
            
-
 
1236
        } else {
1159
        } else {
1237
            
1160
 
1238
            return new JsonModel([
1161
            return new JsonModel([
1239
                'success' => false,
1162
                'success' => false,
1240
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1163
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1241
            ]);
1164
            ]);
1242
        }
1165
        }
1243
    }
1166
    }
1244
    
1167
 
1245
    
1168
 
1246
    /**
1169
    /**
1247
     * Recuperamos los grupos sugeridos
1170
     * Recuperamos los grupos sugeridos
1248
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1171
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1249
     * retorna un json en caso de ser  positivo
1172
     * retorna un json en caso de ser  positivo
1250
     * [
1173
     * [
Línea 1266... Línea 1189...
1266
     */
1189
     */
1267
    public function groupsSuggestionAction()
1190
    public function groupsSuggestionAction()
1268
    {
1191
    {
Línea 1269... Línea 1192...
1269
 
1192
 
1270
        $request = $this->getRequest();
1193
        $request = $this->getRequest();
1271
        if($request->isGet()) {
1194
        if ($request->isGet()) {
1272
            
1195
 
1273
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1196
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1274
            $currentUser = $currentUserPlugin->getUser();
1197
            $currentUser = $currentUserPlugin->getUser();
1275
            
1198
 
1276
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1199
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1277
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
1200
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
1278
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
1201
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
1279
            
1202
 
1280
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
1203
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
1281
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
1204
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
1282
            
1205
 
1283
            /*Usuarios de la empresas donde trabajo o soy dueño */
1206
            /*Usuarios de la empresas donde trabajo o soy dueño */
1284
            $company_user_ids = [];
1207
            $company_user_ids = [];
1285
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1208
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1286
            
1209
 
1287
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1210
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1288
            foreach($records as $record)
-
 
1289
            {
1211
            foreach ($records as $record) {
1290
                
1212
 
1291
                if($record->status != CompanyUser::STATUS_ACCEPTED) {
1213
                if ($record->status != CompanyUser::STATUS_ACCEPTED) {
1292
                    continue;
1214
                    continue;
1293
                }
1215
                }
1294
                
1216
 
1295
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
1217
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
1296
                foreach($otherUsers as $otherUser)
-
 
1297
                {
1218
                foreach ($otherUsers as $otherUser) {
1298
                    if($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
1219
                    if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
1299
                        
1220
 
1300
                        if(!in_array($otherUser->user_id, $company_user_ids)) {
1221
                        if (!in_array($otherUser->user_id, $company_user_ids)) {
1301
                            array_push($company_user_ids, $otherUser->user_id);
1222
                            array_push($company_user_ids, $otherUser->user_id);
1302
                        }
1223
                        }
1303
                    }
1224
                    }
1304
                }
1225
                }
1305
            }
1226
            }
1306
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
1227
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
1307
            
1228
 
1308
            /* Usuario de los grupos donde soy dueño o participo */
1229
            /* Usuario de los grupos donde soy dueño o participo */
1309
            
1230
 
1310
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1231
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1311
            
1232
 
1312
            $group_member_ids = [];
1233
            $group_member_ids = [];
1313
            
1234
 
1314
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
1235
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
1315
            foreach($records as $record)
-
 
1316
            {
1236
            foreach ($records as $record) {
1317
                if($record->status != GroupMember::STATUS_ACCEPTED) {
1237
                if ($record->status != GroupMember::STATUS_ACCEPTED) {
1318
                    continue;
1238
                    continue;
1319
                }
1239
                }
1320
                
1240
 
1321
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
1241
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
1322
                foreach($otherUsers as $otherUser)
-
 
1323
                {
1242
                foreach ($otherUsers as $otherUser) {
1324
                    if($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
1243
                    if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
1325
                        
1244
 
1326
                        if(!in_array($otherUser->user_id, $group_member_ids)) {
1245
                        if (!in_array($otherUser->user_id, $group_member_ids)) {
1327
                            array_push($group_member_ids, $otherUser->user_id);
1246
                            array_push($group_member_ids, $otherUser->user_id);
1328
                        }
1247
                        }
1329
                    }
1248
                    }
1330
                }
-
 
1331
                
-
 
1332
                
1249
                }
1333
            }
1250
            }
1334
            
1251
 
1335
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
1252
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
1336
            
1253
 
1337
            /* Usuarios con que comparto capsulas */
1254
            /* Usuarios con que comparto capsulas */
1338
            $capsule_user_ids = [];
1255
            $capsule_user_ids = [];
1339
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
1256
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
1340
            
1257
 
1341
            $company_ids = [];
1258
            $company_ids = [];
1342
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
1259
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
1343
            foreach($records as $record)
-
 
1344
            {
1260
            foreach ($records as $record) {
1345
                if(!in_array($record->company_id,$company_ids)) {
1261
                if (!in_array($record->company_id, $company_ids)) {
1346
                    array_push($company_ids, $record->company_id);
1262
                    array_push($company_ids, $record->company_id);
1347
                }
1263
                }
1348
            }
1264
            }
1349
            
1265
 
1350
            foreach($company_ids as $company_id)
-
 
1351
            {
1266
            foreach ($company_ids as $company_id) {
1352
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
1267
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
1353
                foreach($otherUsers as $user_id)
-
 
1354
                {
1268
                foreach ($otherUsers as $user_id) {
1355
                    if($currentUser->id != $user_id ) {
1269
                    if ($currentUser->id != $user_id) {
1356
                        
1270
 
1357
                        if(!in_array($user_id, $capsule_user_ids)) {
1271
                        if (!in_array($user_id, $capsule_user_ids)) {
1358
                            array_push($capsule_user_ids, $user_id);
1272
                            array_push($capsule_user_ids, $user_id);
1359
                        }
1273
                        }
1360
                    }
1274
                    }
1361
                }
1275
                }
1362
            }
1276
            }
1363
            
1277
 
1364
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
1278
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
1365
            
1279
 
1366
 
1280
 
1367
            $other_users = array_unique(array_merge(
1281
            $other_users = array_unique(array_merge(
1368
               
1282
 
1369
                $second_degree_connections_ids,
1283
                $second_degree_connections_ids,
1370
                $company_user_ids,
1284
                $company_user_ids,
1371
                $group_member_ids,
1285
                $group_member_ids,
1372
                $capsule_user_ids
1286
                $capsule_user_ids
1373
            ));
1287
            ));
1374
            
1288
 
1375
            $queryMapper = QueryMapper::getInstance($this->adapter);
1289
            $queryMapper = QueryMapper::getInstance($this->adapter);
1376
           
1290
 
1377
  
1291
 
1378
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1292
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1379
            $group_ids = $groupMemberMapper->fetchAllGroupIdsByUserIds( $other_users);
1293
            $group_ids = $groupMemberMapper->fetchAllGroupIdsByUserIds($other_users);
Línea 1380... Línea 1294...
1380
            $group_ids = $group_ids ? $group_ids : [0];
1294
            $group_ids = $group_ids ? $group_ids : [0];
1381
 
1295
 
1382
            
1296
 
1383
                
1297
 
1384
   
1298
 
1385
            $select = $queryMapper->getSql()->select();
1299
            $select = $queryMapper->getSql()->select();
1386
            $select->columns(['id', 'uuid', 'name','image','status','privacy', 'priority' => new Expression('0') ]);
1300
            $select->columns(['id', 'uuid', 'name', 'image', 'status', 'privacy', 'priority' => new Expression('0')]);
1387
            $select->from(['g' => GroupMapper::_TABLE]); 
1301
            $select->from(['g' => GroupMapper::_TABLE]);
1388
            $select->where->equalTo('network_id', $currentUser->network_id);
1302
            $select->where->equalTo('network_id', $currentUser->network_id);
1389
            $select->where->equalTo('privacy', Group::PRIVACY_IS_PUBLIC);
1303
            $select->where->equalTo('privacy', Group::PRIVACY_IS_PUBLIC);
1390
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1304
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1391
            $select->where->in('g.id', $group_ids);
1305
            $select->where->in('g.id', $group_ids);
1392
            $select->where->notEqualTo('g.user_id', $currentUser->id);
1306
            $select->where->notEqualTo('g.user_id', $currentUser->id);
1393
            $select->order('name ASC');
1307
            $select->order('name ASC');
1394
            
1308
 
1395
            
1309
 
1396
            
1310
 
1397
            //echo $select->getSqlString($this->adapter->platform); exit;
1311
            //echo $select->getSqlString($this->adapter->platform); exit;
1398
            
1312
 
1399
            $records = $queryMapper->fetchAll($select);
1313
            $records = $queryMapper->fetchAll($select);
1400
            usort($records, function ($a, $b) {
1314
            usort($records, function ($a, $b) {
1401
                if( $a['priority'] == $b['priority'] ) {
1315
                if ($a['priority'] == $b['priority']) {
1402
                    return 0; 
1316
                    return 0;
1403
                } else {
1317
                } else {
1404
                    return $a['priority'] < $b['priority'] ? 1 : -1;
1318
                    return $a['priority'] < $b['priority'] ? 1 : -1;
Línea 1405... Línea 1319...
1405
                }
1319
                }
1406
            });
1320
            });
1407
 
1321
 
1408
 
-
 
1409
            $items = [];
1322
 
1410
            
1323
            $items = [];
1411
            foreach($records as $record)
1324
 
1412
            {
1325
            foreach ($records as $record) {
1413
                    
1326
 
1414
                array_push($items, [
1327
                array_push($items, [
1415
                    'id'        => $record['uuid'],
1328
                    'id'        => $record['uuid'],
1416
                    'name'      => trim($record['name']),
-
 
1417
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
-
 
Línea -... Línea 1329...
-
 
1329
                    'name'      => trim($record['name']),
1418
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid'] ]),
1330
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
1419
                    'priority'  => $record['priority'],
1331
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid']]),
1420
                    
1332
                    'priority'  => $record['priority'],
1421
                ]);
1333
 
1422
 
1334
                ]);
1423
            }
1335
            }
1424
            
-
 
1425
            return new JsonModel([
-
 
1426
                'success' => true,
1336
 
1427
                'data' => $items
1337
            return new JsonModel([
1428
            ]);
1338
                'success' => true,
1429
            
1339
                'data' => $items
1430
            
1340
            ]);
1431
        } else {
1341
        } else {
1432
            return new JsonModel([
1342
            return new JsonModel([
1433
                'success' => false,
1343
                'success' => false,
1434
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1344
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1435
            ]);
1345
            ]);
1436
        }
1346
        }
1437
    }
1347
    }
1438
    
1348
 
1439
    public function postsAction()
1349
    public function postsAction()
1440
    {
1350
    {
1441
        $request = $this->getRequest();
1351
        $request = $this->getRequest();
1442
        if($request->isGet()) {
1352
        if ($request->isGet()) {
1443
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1353
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1444
            $currentUser = $currentUserPlugin->getUser();
1354
            $currentUser = $currentUserPlugin->getUser();
1445
            
1355
 
1446
            $items = [];
1356
            $items = [];
1447
            $postMapper = PostMapper::getInstance($this->adapter);
1357
            $postMapper = PostMapper::getInstance($this->adapter);
1448
            $posts = $postMapper->fetchAllActiveByNetworkId($currentUser->network_id);
-
 
1449
            
1358
            $posts = $postMapper->fetchAllActiveByNetworkId($currentUser->network_id);
1450
            //print_r($posts);
1359
 
1451
            
1360
            //print_r($posts);
1452
            foreach($posts as $post)
1361
 
1453
            {
1362
            foreach ($posts as $post) {
1454
                $dt = \DateTime::createFromFormat('Y-m-d', $post->date);
1363
                $dt = \DateTime::createFromFormat('Y-m-d', $post->date);
1455
                array_push($items, [
1364
                array_push($items, [
1456
                    'image' => $this->url()->fromRoute('storage', ['code' => $post->uuid, 'type' => 'post', 'filename' => $post->image  ]),
-
 
1457
                    'date' => $dt->format('d/m/Y'),
1365
                    'image' => $this->url()->fromRoute('storage', ['code' => $post->uuid, 'type' => 'post', 'filename' => $post->image]),
1458
                   'title' => $post->title,
1366
                    'date' => $dt->format('d/m/Y'),
1459
                   'link' => $this->url()->fromRoute('post', ['id' => $post->uuid]), 
1367
                    'title' => $post->title,
1460
                ]);
1368
                    'link' => $this->url()->fromRoute('post', ['id' => $post->uuid]),
1461
                
1369
                ]);
1462
            }
1370
            }
1463
            
1371
 
1464
            return new JsonModel([
1372
            return new JsonModel([
1465
                'success' => true,
1373
                'success' => true,
1466
                'data' => $items
1374
                'data' => $items
1467
            ]);
1375
            ]);
1468
        }
1376
        }
1469
        
1377
 
1470
        return new JsonModel([
-
 
Línea -... Línea 1378...
-
 
1378
        return new JsonModel([
1471
            'success' => false,
1379
            'success' => false,
1472
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1380
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1473
        ]);
1381
        ]);
1474
    }
1382
    }
1475
    
1383
 
Línea 1476... Línea 1384...
1476
 
1384
 
1477
    
1385
 
Línea 1478... Línea 1386...
1478
    public function searchPeopleAction()
1386
    public function searchPeopleAction()
1479
    {
1387
    {
1480
        $request = $this->getRequest();
1388
        $request = $this->getRequest();
1481
        if($request->isGet()) {
1389
        //if($request->isGet()) {
1482
 
1390
 
1483
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1391
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1484
            $currentUser = $currentUserPlugin->getUser();
1392
        $currentUser = $currentUserPlugin->getUser();
1485
 
1393
 
1486
            $search = trim(filter_var( $this->params()->fromQuery('search'), FILTER_SANITIZE_STRING)) ;
1394
        $search = trim(filter_var($this->params()->fromQuery('search'), FILTER_SANITIZE_STRING));
1487
            if(strlen($search) >= 3) {
-
 
1488
                
1395
        //if(strlen($search) >= 3) {
1489
                
1396
 
1490
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
1491
                $records  = $userMapper->fetchAllSuggestByNetworkIdAndSearch($currentUser->network_id, $search);
-
 
1492
                
-
 
1493
                $users = [];
-
 
1494
                foreach($records as $record)
-
 
1495
                {
-
 
1496
                    if($currentUser->id == $record->id) {
-
 
1497
                        continue;
-
 
1498
                    }
-
 
1499
                    
-
 
1500
                    
-
 
1501
                    array_push($users, [
-
 
1502
                        'value' => $record->uuid,
-
 
1503
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
-
 
1504
                        
-
 
1505
                    ]);
-
 
1506
                }
-
 
1507
                
-
 
1508
                return new JsonModel([
-
 
1509
                    'success' => true,
-
 
1510
                    'data' => $users
-
 
1511
                ]);
-
 
1512
                
-
 
1513
                
-
 
1514
                
-
 
1515
                
1397
 
1516
            } else {
-
 
1517
                return new JsonModel([
1398
        $userMapper = UserMapper::getInstance($this->adapter);
1518
                    'success' => true,
-
 
1519
                    'data' => [
1399
        $records  = $userMapper->fetchAllSuggestByNetworkIdAndSearch($currentUser->network_id, $search);
1520
                        
-
 
1521
                    ]
1400
 
1522
                ]);
1401
        $users = [];
1523
            }
1402
        foreach ($records as $record) {
-
 
1403
            if ($currentUser->id == $record->id) {
1524
            
1404
                continue;
1525
            
1405
            }
-
 
1406
 
-
 
1407
 
-
 
1408
            array_push($users, [
-
 
1409
                'value' => $record->uuid,
-
 
1410
                'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
-
 
1411
 
-
 
1412
            ]);
-
 
1413
        }
-
 
1414
 
-
 
1415
        return new JsonModel([
-
 
1416
            'success' => true,
-
 
1417
            'data' => $users
-
 
1418
        ]);
-
 
1419
 
-
 
1420
 
-
 
1421
 
-
 
1422
 
-
 
1423
        // } else {
-
 
1424
        //     return new JsonModel([
-
 
1425
        //         'success' => true,
-
 
1426
        //         'data' => [
-
 
1427
 
-
 
1428
        //         ]
-
 
1429
        //     ]);
-
 
1430
        // }
-
 
1431
 
-
 
1432
 
1526
            
1433
 
1527
            
1434
 
1528
        } else {
1435
        // } else {
1529
            return new JsonModel([
1436
        //     return new JsonModel([
1530
                'success' => false,
1437
        //         'success' => false,
1531
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1438
        //         'data' => 'ERROR_METHOD_NOT_ALLOWED'
1532
            ]);
1439
        //     ]);
1533
        }
1440
        // }
1534
    }
1441
    }
1535
    
1442
 
1536
    public function footerAction()
1443
    public function footerAction()
1537
    {
1444
    {
1538
        $request = $this->getRequest();
1445
        $request = $this->getRequest();
1539
        if($request->isGet()) {
-
 
1540
            
1446
        if ($request->isGet()) {
1541
            
1447
 
1542
            $links = isset($this->navigation['footer']) ?  $this->navigation['footer'] : [];
1448
 
1543
            
1449
            $links = isset($this->navigation['footer']) ?  $this->navigation['footer'] : [];
1544
       
1450
 
1545
            $data = [];
1451
 
1546
            foreach($links as $link)
1452
            $data = [];
1547
            {
1453
            foreach ($links as $link) {
1548
                $data[ $link['route'] ] = $link['label'];
-
 
1549
            }
1454
                $data[$link['route']] = $link['label'];
1550
            
1455
            }
1551
            
1456
 
1552
            return new JsonModel([
1457
 
1553
               'success' => true, 
1458
            return new JsonModel([
1554
               'data' => $data,
1459
                'success' => true,
1555
            ]);
1460
                'data' => $data,
1556
            
1461
            ]);
1557
        } else {
1462
        } else {
1558
            return new JsonModel([
1463
            return new JsonModel([
1559
                'success' => false,
1464
                'success' => false,
1560
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1465
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1561
            ]);
1466
            ]);
1562
        }
1467
        }
Línea 1584... Línea 1489...
1584
     * ]
1489
     * ]
1585
     * @return \Laminas\View\Model\JsonModel
1490
     * @return \Laminas\View\Model\JsonModel
1586
     */
1491
     */
1587
    public function myGroupsAction()
1492
    public function myGroupsAction()
1588
    {
1493
    {
1589
        
1494
 
1590
        $request = $this->getRequest();
1495
        $request = $this->getRequest();
1591
        if($request->isGet()) {
1496
        if ($request->isGet()) {
1592
            
1497
 
1593
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1498
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1594
            $currentUser = $currentUserPlugin->getUser();
1499
            $currentUser = $currentUserPlugin->getUser();
1595
            
1500
 
1596
            
1501
 
1597
            $queryMapper = QueryMapper::getInstance($this->adapter);
1502
            $queryMapper = QueryMapper::getInstance($this->adapter);
1598
            $select = $queryMapper->getSql()->select();
1503
            $select = $queryMapper->getSql()->select();
1599
            $select->columns(['id', 'uuid', 'name','image','status','privacy', 'priority' => new Expression('0') ]);
1504
            $select->columns(['id', 'uuid', 'name', 'image', 'status', 'privacy', 'priority' => new Expression('0')]);
1600
            $select->from(['g' => GroupMapper::_TABLE]);
1505
            $select->from(['g' => GroupMapper::_TABLE]);
1601
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1506
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1602
            $select->where->equalTo('g.user_id', $currentUser->id);
1507
            $select->where->equalTo('g.user_id', $currentUser->id);
1603
            $select->order('name ASC');
1508
            $select->order('name ASC');
1604
            
1509
 
1605
            
1510
 
1606
            $items = [];
1511
            $items = [];
1607
            
1512
 
1608
            $records = $queryMapper->fetchAll($select);
1513
            $records = $queryMapper->fetchAll($select);
1609
            foreach($records as $record)
1514
            foreach ($records as $record) {
1610
            {
-
 
1611
                    
1515
 
1612
                array_push($items, [
1516
                array_push($items, [
1613
                    'id'        => $record['uuid'],
1517
                    'id'        => $record['uuid'],
1614
                    'name'      => trim($record['name']),
1518
                    'name'      => trim($record['name']),
1615
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
1519
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
1616
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid'] ]),
1520
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid']]),
1617
                    'priority'  => $record['priority'],
1521
                    'priority'  => $record['priority'],
1618
                        
1522
 
1619
                ]);
1523
                ]);
1620
                    
-
 
1621
            }
1524
            }
1622
                
1525
 
1623
            return new JsonModel([
1526
            return new JsonModel([
1624
                'success' => true,
1527
                'success' => true,
1625
                'data' => $items
1528
                'data' => $items
1626
            ]);
1529
            ]);
1627
                
-
 
1628
                
-
 
1629
        } else {
1530
        } else {
1630
            return new JsonModel([
1531
            return new JsonModel([
1631
                'success' => false,
1532
                'success' => false,
1632
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1533
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1633
            ]);
1534
            ]);
1634
        }
1535
        }
1635
    }
1536
    }
1636
    
1537
 
1637
    public function nextEventsAction()
1538
    public function nextEventsAction()
1638
    {
1539
    {
1639
        $request = $this->getRequest();
1540
        $request = $this->getRequest();
1640
        if($request->isGet()) {
1541
        if ($request->isGet()) {
1641
            
1542
 
1642
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1543
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1643
            $currentUser = $currentUserPlugin->getUser();
1544
            $currentUser = $currentUserPlugin->getUser();
1644
            
1545
 
1645
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1546
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1646
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1547
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1647
            
-
 
Línea -... Línea 1548...
-
 
1548
 
1648
 
1549
 
1649
            
1550
 
1650
            $dt = new \DateTime();
1551
            $dt = new \DateTime();
1651
            $dt->setTime(0, 0, 0);
1552
            $dt->setTime(0, 0, 0);
1652
            $start = $dt->format('Y-m-d H:i:s');
1553
            $start = $dt->format('Y-m-d H:i:s');
1653
            
1554
 
1654
            $dt->add(new \DateInterval('P30D'));
1555
            $dt->add(new \DateInterval('P30D'));
1655
            $dt->setTime(23, 59, 59);
1556
            $dt->setTime(23, 59, 59);
1656
            $end = $dt->format('Y-m-d H:i:s');
1557
            $end = $dt->format('Y-m-d H:i:s');
1657
            
1558
 
1658
          
1559
 
1659
            
1560
 
1660
            
1561
 
1661
            $events = [];
1562
            $events = [];
1662
            
1563
 
1663
            
1564
 
1664
            
1565
 
1665
            //3 días
1566
            //3 días
1666
            $expirePeriod = 86400 * 3;
1567
            $expirePeriod = 86400 * 3;
1667
            $t1 = time();
1568
            $t1 = time();
1668
            
1569
 
1669
            $companies = [];
1570
            $companies = [];
1670
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1571
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1671
            
1572
 
1672
            $companyUsers = [];
1573
            $companyUsers = [];
1673
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1574
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1674
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1575
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1675
            
1576
 
1676
            foreach($records as $record) {
1577
            foreach ($records as $record) {
1677
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
1578
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
1678
            }
1579
            }
1679
            
1580
 
1680
            
1581
 
1681
            
1582
 
1682
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
1583
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
1683
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
1584
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
1684
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1585
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1685
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
1586
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
1686
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
1587
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
1687
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
1588
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
1688
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1589
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1689
            $userMapper = UserMapper::getInstance($this->adapter);
1590
            $userMapper = UserMapper::getInstance($this->adapter);
1690
            
1591
 
1691
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
1592
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
1692
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
1593
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
1693
            foreach($records as $record)
-
 
1694
            {
1594
            foreach ($records as $record) {
1695
                switch($record->type)
-
 
1696
                {
1595
                switch ($record->type) {
1697
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW  :
1596
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW:
1698
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color ;
1597
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color;
1699
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
1598
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
1700
                        
1599
 
1701
                        
1600
 
1702
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
1601
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
1703
                        if($recruitmentSelectionInterview) {
1602
                        if ($recruitmentSelectionInterview) {
1704
                            
1603
 
1705
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
1604
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
1706
                            
1605
 
1707
                            
1606
 
1708
                            
1607
 
1709
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
1608
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
1710
                            if($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
1609
                            if ($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
1711
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
1610
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
1712
                                if($jobDescription) {
1611
                                if ($jobDescription) {
1713
                                    $hasLink = false;
1612
                                    $hasLink = false;
1714
                                    if(isset($companyUsers[$currentUser->id])) {
1613
                                    if (isset($companyUsers[$currentUser->id])) {
1715
                                        if($companyUsers[$currentUser->id]) {
1614
                                        if ($companyUsers[$currentUser->id]) {
1716
                                            $hasLink = true;
1615
                                            $hasLink = true;
1717
                                        }
1616
                                        }
1718
                                    }
1617
                                    }
1719
                                    
1618
 
1720
                                    if($hasLink) {
1619
                                    if ($hasLink) {
1721
                                        
1620
 
1722
                                        if(!isset($companies[$recruitmentSelectionInterview->company_id])) {
1621
                                        if (!isset($companies[$recruitmentSelectionInterview->company_id])) {
1723
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
1622
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
1724
                                            
1623
 
1725
                                            $companies[ $company->id ]  = $company;
1624
                                            $companies[$company->id]  = $company;
1726
                                        } else {
1625
                                        } else {
1727
                                            $company = $companies[ $recruitmentSelectionInterview->company_id ];
1626
                                            $company = $companies[$recruitmentSelectionInterview->company_id];
1728
                                        }
1627
                                        }
1729
                                        
1628
 
1730
                                        
1629
 
1731
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1630
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1732
                                            'id' => $company->uuid,
1631
                                            'id' => $company->uuid,
1733
                                            'relational' => $recruitmentSelectionInterview->uuid,
1632
                                            'relational' => $recruitmentSelectionInterview->uuid,
1734
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
1633
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
1735
                                        ]);
1634
                                        ]);
1736
                                        
1635
 
1737
                                        
1636
 
1738
                                        $agenda = '<a href="'.$href.'" class="goto-backend"><br>';
1637
                                        $agenda = '<a href="' . $href . '" class="goto-backend"><br>';
1739
                                    }
1638
                                    }
1740
                                    
1639
 
1741
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
1640
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
1742
                                    switch($recruitmentSelectionInterview->type)
-
 
1743
                                    {
1641
                                    switch ($recruitmentSelectionInterview->type) {
1744
                                        case RecruitmentSelectionInterview::TYPE_BOSS :
1642
                                        case RecruitmentSelectionInterview::TYPE_BOSS:
1745
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";
1643
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";
1746
                                            break;
1644
                                            break;
1747
                                            
1645
 
1748
                                        case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
1646
                                        case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE:
1749
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";
1647
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";
1750
                                            break;
1648
                                            break;
1751
                                    }
1649
                                    }
1752
                                    
1650
 
1753
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";
1651
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";
1754
                                    
1652
 
1755
                                    
1653
 
1756
                                    
1654
 
1757
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
1655
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
1758
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
1656
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>";
1759
                                    
1657
 
1760
                                    if($hasLink) {
1658
                                    if ($hasLink) {
1761
                                        $agenda .= "</a><br>";
1659
                                        $agenda .= "</a><br>";
1762
                                    }
1660
                                    }
1763
                                    
1661
 
1764
                                    
1662
 
1765
                                    
1663
 
1766
                                    
1664
 
1767
                                    array_push($events, [
1665
                                    array_push($events, [
1768
                                        'id'                => $recruitmentSelectionInterview->uuid,
1666
                                        'id'                => $recruitmentSelectionInterview->uuid,
1769
                                        'title'             => $recruitmentSelectionVacancy->name,
1667
                                        'title'             => $recruitmentSelectionVacancy->name,
1770
                                        'agenda'            => $agenda,
1668
                                        'agenda'            => $agenda,
Línea 1776... Línea 1674...
1776
                                        'type'              => 'task',
1674
                                        'type'              => 'task',
1777
                                    ]);
1675
                                    ]);
1778
                                }
1676
                                }
1779
                            }
1677
                            }
1780
                        }
1678
                        }
1781
                        
1679
 
1782
                        
1680
 
1783
                        break;
1681
                        break;
1784
                    
1682
 
1785
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
1683
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION:
1786
                        
1684
 
1787
                        
1685
 
1788
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;
1686
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color;
1789
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
1687
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
1790
                        
1688
 
1791
                        
1689
 
1792
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
1690
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
1793
                        if($performanceEvaluationTest) {
1691
                        if ($performanceEvaluationTest) {
1794
                            
1692
 
1795
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
1693
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
1796
                            if($performanceEvaluationForm) {
1694
                            if ($performanceEvaluationForm) {
1797
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
1695
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
1798
                                if($jobDescription) {
1696
                                if ($jobDescription) {
1799
                                    
1697
 
1800
                                    
1698
 
1801
                                    if($performanceEvaluationTest->supervisor_id) {
1699
                                    if ($performanceEvaluationTest->supervisor_id) {
1802
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
1700
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
1803
                                    } else {
1701
                                    } else {
1804
                                        $supervisor = '';
1702
                                        $supervisor = '';
1805
                                    }
1703
                                    }
1806
                                    
1704
 
1807
                                    if($performanceEvaluationTest->employee_id) {
1705
                                    if ($performanceEvaluationTest->employee_id) {
1808
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
1706
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
1809
                                    } else {
1707
                                    } else {
1810
                                        $employee = '';
1708
                                        $employee = '';
1811
                                    }
1709
                                    }
1812
                                    
1710
 
1813
                                    
1711
 
1814
                                    
1712
 
1815
                                    
1713
 
1816
                                    $hasLink = false;
1714
                                    $hasLink = false;
1817
                                    if(isset($companyUsers[$currentUser->id])) {
1715
                                    if (isset($companyUsers[$currentUser->id])) {
1818
                                        if($companyUsers[$currentUser->id]) {
1716
                                        if ($companyUsers[$currentUser->id]) {
1819
                                            $hasLink = true;
1717
                                            $hasLink = true;
1820
                                        }
1718
                                        }
1821
                                    }
1719
                                    }
1822
                                    
1720
 
1823
                                    if($hasLink) {
1721
                                    if ($hasLink) {
1824
                                        
1722
 
1825
                                        if(!isset($companies[$performanceEvaluationTest->company_id])) {
1723
                                        if (!isset($companies[$performanceEvaluationTest->company_id])) {
1826
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
1724
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
1827
                                            
1725
 
1828
                                            $companies[ $company->id ]  = $company;
1726
                                            $companies[$company->id]  = $company;
1829
                                        } else {
1727
                                        } else {
1830
                                            $company = $companies[ $performanceEvaluationTest->company_id ];
1728
                                            $company = $companies[$performanceEvaluationTest->company_id];
1831
                                        }
1729
                                        }
1832
                                        
1730
 
1833
                                        
1731
 
1834
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1732
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1835
                                            'id' => $company->uuid,
1733
                                            'id' => $company->uuid,
1836
                                            'relational' => $performanceEvaluationTest->uuid,
1734
                                            'relational' => $performanceEvaluationTest->uuid,
1837
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
1735
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
1838
                                        ]);
1736
                                        ]);
1839
                                        
1737
 
1840
                                        
1738
 
1841
                                        $agenda = '<a href="'.$href.'" class="goto-backend"><br>';
1739
                                        $agenda = '<a href="' . $href . '" class="goto-backend"><br>';
1842
                                    }
1740
                                    }
1843
                                    
1741
 
1844
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
1742
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
1845
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
1743
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
1846
                                    
1744
 
1847
                                    switch($performanceEvaluationTest->type)
1745
                                    switch ($performanceEvaluationTest->type) {
1848
                                    {
-
 
1849
                                        case PerformanceEvaluationTest::TYPE_BOTH :
1746
                                        case PerformanceEvaluationTest::TYPE_BOTH:
1850
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
1747
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
1851
                                            break;
1748
                                            break;
1852
                                            
1749
 
1853
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR :
1750
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR:
1854
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
1751
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
1855
                                            break;
1752
                                            break;
1856
                                            
1753
 
1857
                                        case PerformanceEvaluationTest::TYPE_EMPLOYEE :
1754
                                        case PerformanceEvaluationTest::TYPE_EMPLOYEE:
1858
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
1755
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
1859
                                            break;
1756
                                            break;
1860
                                            
-
 
1861
                                            
-
 
1862
                                    }
1757
                                    }
1863
                                    
1758
 
1864
                                    if($supervisor) {
1759
                                    if ($supervisor) {
1865
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
1760
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
1866
                                        
-
 
1867
                                    }
1761
                                    }
1868
                                    if($employee) {
1762
                                    if ($employee) {
1869
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
1763
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
1870
                                        
-
 
1871
                                    }
1764
                                    }
1872
                                    
1765
 
1873
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
1766
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
1874
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
1767
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>";
1875
                                    
1768
 
1876
                                    if($hasLink) {
1769
                                    if ($hasLink) {
1877
                                        $agenda .= "</a><br>";
1770
                                        $agenda .= "</a><br>";
1878
                                    }
1771
                                    }
1879
                                    
1772
 
1880
                                    
1773
 
1881
                                    
1774
 
1882
                                    
1775
 
1883
                                    array_push($events, [
1776
                                    array_push($events, [
1884
                                        'id'                => $performanceEvaluationTest->uuid,
1777
                                        'id'                => $performanceEvaluationTest->uuid,
1885
                                        'title'             =>  $performanceEvaluationForm->name,
1778
                                        'title'             =>  $performanceEvaluationForm->name,
1886
                                        'agenda'            => $agenda,
1779
                                        'agenda'            => $agenda,
1887
                                        'start'             => $dtStart->format('Y-m-d'),
1780
                                        'start'             => $dtStart->format('Y-m-d'),
Línea 1891... Línea 1784...
1891
                                        'allDay'            => true,
1784
                                        'allDay'            => true,
1892
                                        'type'              => 'task',
1785
                                        'type'              => 'task',
1893
                                    ]);
1786
                                    ]);
1894
                                }
1787
                                }
1895
                            }
1788
                            }
1896
                            
-
 
1897
                        }
1789
                        }
1898
                        
1790
 
1899
                        
1791
 
1900
                        
1792
 
1901
                        
1793
 
1902
                        
1794
 
1903
                        break;
1795
                        break;
1904
                    
1796
 
1905
                    
1797
 
1906
                    case CalendarEvent::TYPE_ZOOM :
1798
                    case CalendarEvent::TYPE_ZOOM:
1907
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
1799
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
1908
                        if($zoomMeeting) {
1800
                        if ($zoomMeeting) {
1909
                            
1801
 
1910
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color ;
1802
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color;
1911
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
1803
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
1912
                            
1804
 
1913
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
1805
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
1914
                            $t2 = $dtStart->getTimestamp();
1806
                            $t2 = $dtStart->getTimestamp();
1915
                            
1807
 
1916
                            if($t2 > $t1) {
1808
                            if ($t2 > $t1) {
1917
                                
1809
 
1918
                                $t3 = $t1 + $expirePeriod;
1810
                                $t3 = $t1 + $expirePeriod;
1919
                                if($t3 > $t2) {
1811
                                if ($t3 > $t2) {
1920
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
1812
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
1921
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
1813
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
1922
                                }
1814
                                }
1923
                                
-
 
1924
                            }
1815
                            }
1925
                            
1816
 
1926
                            
1817
 
1927
                            
1818
 
1928
                            if($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
1819
                            if ($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
1929
                                
1820
 
1930
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
1821
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
1931
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
1822
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
1932
                                
-
 
1933
                                
-
 
1934
                                
-
 
1935
                                
-
 
1936
                                
-
 
1937
                            } else {
1823
                            } else {
1938
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
1824
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
1939
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
1825
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
1940
                            }
1826
                            }
1941
                            
1827
 
1942
                            
1828
 
1943
                            
1829
 
1944
                            
1830
 
1945
                            
1831
 
1946
                            
1832
 
1947
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
1833
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
1948
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
1834
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
1949
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
1835
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
1950
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
1836
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
1951
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
1837
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
1952
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
1838
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
1953
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
1839
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
1954
                                "</a>";
1840
                                "</a>";
1955
                            
1841
 
1956
                            array_push($events, [
1842
                            array_push($events, [
1957
                                'id'                => $zoomMeeting->id,
1843
                                'id'                => $zoomMeeting->id,
1958
                                'title'             => $zoomMeeting->topic,
1844
                                'title'             => $zoomMeeting->topic,
1959
                                'agenda'            => $agenda,
1845
                                'agenda'            => $agenda,
1960
                                'start'             => $start,
1846
                                'start'             => $start,
Línea 1964... Línea 1850...
1964
                                'textColor'         => $textColor,
1850
                                'textColor'         => $textColor,
1965
                                'type'              => 'event'
1851
                                'type'              => 'event'
1966
                            ]);
1852
                            ]);
1967
                        }
1853
                        }
1968
                        break;
1854
                        break;
1969
                        
-
 
1970
                        
-
 
1971
                }
1855
                }
1972
                
-
 
1973
                
-
 
1974
                
-
 
1975
            }
1856
            }
1976
            
1857
 
1977
            
1858
 
1978
            
1859
 
1979
            return new JsonModel([
1860
            return new JsonModel([
1980
                'success' => true,
1861
                'success' => true,
1981
                'data' => $events
1862
                'data' => $events
1982
            ]);
1863
            ]);
1983
            
-
 
1984
            
-
 
1985
        } else {
1864
        } else {
1986
            return new JsonModel([
1865
            return new JsonModel([
1987
                'success' => false,
1866
                'success' => false,
1988
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1867
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1989
            ]);
1868
            ]);
1990
        }
1869
        }
1991
    }
1870
    }
1992
    
-
 
1993
    
-
 
1994
    
-
 
1995
}
1871
}