Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17178 Rev 17248
Línea 12... Línea 12...
12
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Db\ResultSet\HydratingResultSet;
13
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Adapter\DbSelect;
14
use Laminas\Paginator\Paginator;
14
use Laminas\Paginator\Paginator;
15
use Laminas\Mvc\I18n\Translator;
15
use Laminas\Mvc\I18n\Translator;
16
use LeadersLinked\Mapper\MicrolearningTopicMapper;
16
use LeadersLinked\Mapper\MicrolearningTopicMapper;
17
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
-
 
18
use LeadersLinked\Mapper\MicrolearningTopicCapsuleMapper;
-
 
19
use LeadersLinked\Mapper\MicrolearningCapsuleUserMapper;
-
 
20
use LeadersLinked\Mapper\MicrolearningUserMapper;
17
use LeadersLinked\Mapper\MicrolearningUserMapper;
21
use LeadersLinked\Mapper\UserMapper;
18
use LeadersLinked\Mapper\UserMapper;
22
use LeadersLinked\Mapper\QueryMapper;
19
use LeadersLinked\Mapper\QueryMapper;
23
use LeadersLinked\Mapper\ApplicationMapper;
20
use LeadersLinked\Mapper\ApplicationMapper;
24
use LeadersLinked\Mapper\PushMapper;
21
use LeadersLinked\Mapper\PushMapper;
Línea 39... Línea 36...
39
use LeadersLinked\Mapper\MicrolearningExtendUserProgramMapper;
36
use LeadersLinked\Mapper\MicrolearningExtendUserProgramMapper;
40
use LeadersLinked\Mapper\MicrolearningExtendUserPartnerMapper;
37
use LeadersLinked\Mapper\MicrolearningExtendUserPartnerMapper;
41
use LeadersLinked\Mapper\MicrolearningExtendUserSectorMapper;
38
use LeadersLinked\Mapper\MicrolearningExtendUserSectorMapper;
42
use LeadersLinked\Mapper\MicrolearningExtendUserStudentTypeMapper;
39
use LeadersLinked\Mapper\MicrolearningExtendUserStudentTypeMapper;
43
use LeadersLinked\Mapper\MicrolearningExtendUserCountryMapper;
40
use LeadersLinked\Mapper\MicrolearningExtendUserCountryMapper;
44
use LeadersLinked\Model\MicrolearningCapsuleUser;
-
 
45
use LeadersLinked\Model\MicrolearningUser;
41
use LeadersLinked\Model\MicrolearningUser;
46
use LeadersLinked\Model\Push;
42
use LeadersLinked\Model\Push;
47
use LeadersLinked\Model\Application;
43
use LeadersLinked\Model\Application;
48
use LeadersLinked\Model\Notification;
44
use LeadersLinked\Model\Notification;
49
use LeadersLinked\Model\Network;
45
use LeadersLinked\Model\Network;
Línea 60... Línea 56...
60
use LeadersLinked\Model\MicrolearningExtendUserProgram;
56
use LeadersLinked\Model\MicrolearningExtendUserProgram;
61
use LeadersLinked\Model\MicrolearningExtendUserPartner;
57
use LeadersLinked\Model\MicrolearningExtendUserPartner;
62
use LeadersLinked\Model\MicrolearningExtendUserSector;
58
use LeadersLinked\Model\MicrolearningExtendUserSector;
63
use LeadersLinked\Model\MicrolearningExtendUserStudentType;
59
use LeadersLinked\Model\MicrolearningExtendUserStudentType;
64
use LeadersLinked\Model\MicrolearningExtendUserCountry;
60
use LeadersLinked\Model\MicrolearningExtendUserCountry;
65
use LeadersLinked\Form\Microlearning\TopicCapsuleForm;
61
use LeadersLinked\Form\Microlearning\TopicUserForm;
66
use LeadersLinked\Form\Microlearning\PushMicrolearningNotificationForm;
62
use LeadersLinked\Form\Microlearning\PushMicrolearningNotificationForm;
67
use LeadersLinked\Form\Microlearning\CapsuleCustomerUploadForm;
63
use LeadersLinked\Form\Microlearning\TopicCustomerUploadForm;
68
use LeadersLinked\Library\Functions;
64
use LeadersLinked\Library\Functions;
69
use LeadersLinked\Cache\CacheInterface;
65
use LeadersLinked\Cache\CacheInterface;
70
use LeadersLinked\Cache\CacheImpl;
66
use LeadersLinked\Cache\CacheImpl;
71
use PhpOffice\PhpSpreadsheet\IOFactory;
67
use PhpOffice\PhpSpreadsheet\IOFactory;
-
 
68
use LeadersLinked\Mapper\MicrolearningTopicUserMapper;
-
 
69
use LeadersLinked\Model\MicrolearningTopicUser;
Línea 72... Línea 70...
72
 
70
 
73
class MicrolearningAccessForStudentsController extends AbstractActionController
71
class MicrolearningAccessForStudentsController extends AbstractActionController
74
{
72
{
75
    /**
73
    /**
Línea 138... Línea 136...
138
                }
136
                }
Línea 139... Línea 137...
139
                
137
                
140
                if($isJson) {
138
                if($isJson) {
141
                    try {
139
                    try {
142
                        $topic_uuid     = Functions::sanitizeFilterString($request->getQuery('topic_uuid'));
-
 
Línea 143... Línea 140...
143
                        $capsule_uuid   = Functions::sanitizeFilterString($request->getQuery('capsule_uuid'));
140
                        $topic_uuid     = Functions::sanitizeFilterString($request->getQuery('topic_uuid'));
144
                        
141
                        
145
                        $data = [
142
                        $data = [
146
                            'link_upload' => '',
143
                            'link_upload' => '',
147
                            'items' => [] ,
-
 
148
                            'total' => 0,
144
                            'items' => [] ,
Línea 149... Línea 145...
149
                            'capsules' => []
145
                            'total' => 0,
150
                        ];      
146
                        ];      
151
                        
147
                        
Línea 170... Línea 166...
170
                            return new JsonModel([
166
                            return new JsonModel([
171
                                'success' => true,
167
                                'success' => true,
172
                                'data' => 'ERROR_UNAUTHORIZED'
168
                                'data' => 'ERROR_UNAUTHORIZED'
173
                            ]);
169
                            ]);
174
                        }
170
                        }
175
                        
-
 
176
                        if(!$capsule_uuid) {
-
 
177
                            $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
178
                            $records = $topicCapsuleMapper->fetchAllByTopicId($topic->id);
-
 
179
                            
-
 
180
                            $capsules = [];
-
 
181
 
-
 
182
                            foreach($records as $record)
-
 
183
                            {
-
 
184
                                $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
185
                                $capsule = $capsuleMapper->fetchOneById($record->capsule_id);
-
 
186
                                $capsules[$capsule->uuid] = $capsule->name;
-
 
187
                            }
-
 
188
                            
-
 
189
                            $data['capsules']  = $capsules;
-
 
190
                        }
-
 
191
                        
-
 
192
                        if(!$capsule_uuid) {
-
 
193
                            return new JsonModel([
-
 
194
                                'success' => true,
-
 
195
                                'data' => $data
-
 
196
                            ]);
-
 
197
                            
-
 
198
                        }
-
 
199
                        
-
 
200
                        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
201
                        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
-
 
202
                        
-
 
203
                        if(!$capsule) {
-
 
204
                            return new JsonModel([
-
 
205
                                'success' => true,
-
 
206
                                'data' => 'ERROR_CAPSULE_NOT_FOUND'
-
 
207
                            ]);
-
 
208
                        }
-
 
Línea 209... Línea 171...
209
 
171
 
210
                        $data['link_upload'] = $this->url()->fromRoute('microlearning/access-for-students/upload',['topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid]);
172
                        $data['link_upload'] = $this->url()->fromRoute('microlearning/access-for-students/upload',['topic_uuid' => $topic->uuid]);
Línea 211... Línea 173...
211
                        $data['link_notification'] = $this->url()->fromRoute('microlearning/access-for-students/notification',['topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid]);
173
                        $data['link_notification'] = $this->url()->fromRoute('microlearning/access-for-students/notification',['topic_uuid' => $topic->uuid]);
212
                        
174
                        
Línea 213... Línea 175...
213
                        $search = $this->params()->fromQuery('search', []);
175
                        $search = $this->params()->fromQuery('search', []);
Línea 234... Línea 196...
234
                        
196
                        
235
                        $queryMapper = QueryMapper::getInstance($this->adapter);
197
                        $queryMapper = QueryMapper::getInstance($this->adapter);
236
                        $sql = $queryMapper->getSql();
198
                        $sql = $queryMapper->getSql();
237
                        $select = $sql->select();
199
                        $select = $sql->select();
238
                        $select->columns(['access', 'paid_from', 'paid_to', 'added_on', 'updated_on']);
200
                        $select->columns(['access', 'paid_from', 'paid_to', 'added_on', 'updated_on']);
239
                        $select->from(['tb1' => MicrolearningCapsuleUserMapper::_TABLE] );
201
                        $select->from(['tb1' => MicrolearningTopicUserMapper::_TABLE] );
240
                        $select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
202
                        $select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
241
                        $select->where->equalTo('tb1.company_id', $capsule->company_id);
203
                        $select->where->equalTo('tb1.company_id', $topic->company_id);
242
                        $select->where->equalTo('tb1.topic_id', $topic->id);
-
 
Línea 243... Línea 204...
243
                        $select->where->equalTo('tb1.capsule_id', $capsule->id);
204
                        $select->where->equalTo('tb1.topic_id', $topic->id);
244
                        
205
                        
245
                        if($search) {
206
                        if($search) {
246
                            $select->where->nest()
207
                            $select->where->nest()
Línea 267... Línea 228...
267
                        $records = $paginator->getCurrentItems();
228
                        $records = $paginator->getCurrentItems();
268
                        foreach($records as $record)
229
                        foreach($records as $record)
269
                        {
230
                        {
270
                            $params = [
231
                            $params = [
271
                                'topic_uuid' => $topic->uuid,
232
                                'topic_uuid' => $topic->uuid,
272
                                'capsule_uuid' => $capsule->uuid,
-
 
273
                                'user_uuid' => $record['uuid']
233
                                'user_uuid' => $record['uuid']
274
                            ];
234
                            ];
Línea 275... Línea 235...
275
                            
235
                            
Línea 276... Línea 236...
276
                            $actions = [];
236
                            $actions = [];
277
                            
237
                            
278
                            
238
                            
279
                            
239
                            
280
                            switch($record['access'])
240
                            switch($record['access'])
281
                            {
241
                            {
Línea 282... Línea 242...
282
                                case MicrolearningCapsuleUser::ACCESS_UNLIMITED :
242
                                case MicrolearningTopicUser::ACCESS_UNLIMITED :
283
                                    $actions['link_revoke'] = $allowRevoke ? $this->url()->fromRoute('microlearning/access-for-students/revoke', $params) : '';
243
                                    $actions['link_revoke'] = $allowRevoke ? $this->url()->fromRoute('microlearning/access-for-students/revoke', $params) : '';
284
                                    $details['access'] = 'LABEL_UNLIMIT';
244
                                    $details['access'] = 'LABEL_UNLIMIT';
285
                                    break;
245
                                    break;
Línea 286... Línea 246...
286
                                    
246
                                    
287
                                case MicrolearningCapsuleUser::ACCESS_REVOKE :
247
                                case MicrolearningTopicUser::ACCESS_REVOKE :
Línea 288... Línea 248...
288
                                    $actions['link_unlimit'] = $allowUnlimit ? $this->url()->fromRoute('microlearning/access-for-students/unlimit', $params) : '';
248
                                    $actions['link_unlimit'] = $allowUnlimit ? $this->url()->fromRoute('microlearning/access-for-students/unlimit', $params) : '';
289
                                    $details['access'] = 'LABEL_REVOKED';
249
                                    $details['access'] = 'LABEL_REVOKED';
Línea 290... Línea 250...
290
                                    break;
250
                                    break;
291
                                    
251
                                    
292
                                case MicrolearningCapsuleUser::ACCESS_PAY_PERIOD :
252
                                case MicrolearningTopicUser::ACCESS_PAY_PERIOD :
293
                                    $actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('microlearning/access-for-students/cancel', $params) : '';
253
                                    $actions['link_cancel'] = $allowCancel ? $this->url()->fromRoute('microlearning/access-for-students/cancel', $params) : '';
Línea 294... Línea 254...
294
                                    
254
                                    
295
                                    $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
255
                                    $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
296
                                    $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
256
                                    $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
Línea 297... Línea 257...
297
                                    
257
                                    
298
                                    $details['access'] = 'LABEL_PAY_PERIOD';
258
                                    $details['access'] = 'LABEL_PAY_PERIOD';
299
                                    $details['paid_from'] = $dt_paid_from->format('d/m/Y');
259
                                    $details['paid_from'] = $dt_paid_from->format('d/m/Y');
300
                                    $details['paid_to'] = $dt_paid_to->format('d/m/Y');
260
                                    $details['paid_to'] = $dt_paid_to->format('d/m/Y');
Línea 301... Línea 261...
301
                                    break;
261
                                    break;
Línea 302... Línea 262...
302
                                    
262
                                    
303
                                case MicrolearningCapsuleUser::ACCESS_SUPENDED :
263
                                case MicrolearningTopicUser::ACCESS_SUPENDED :
304
                                    $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
264
                                    $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
305
                                    $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
265
                                    $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
Línea 370... Línea 330...
370
                        $topic_id = $topics[0]->id;
330
                        $topic_id = $topics[0]->id;
371
                    }  else {
331
                    }  else {
372
                        $topic_id = 0;
332
                        $topic_id = 0;
373
                    }
333
                    }
Línea 374... Línea -...
374
                    
-
 
375
                    
334
                    
376
                    $form = new TopicCapsuleForm($this->adapter, $currentCompany->id, $topic_id);
335
                    $form = new TopicUserForm($this->adapter, $currentCompany->id, $topic_id);
377
                    $formPushNotification = new PushMicrolearningNotificationForm($this->adapter, $currentCompany->id);
336
                    $formPushNotification = new PushMicrolearningNotificationForm($this->adapter, $currentCompany->id);
378
                    $formCapsuleCustomer = new CapsuleCustomerUploadForm();
-
 
379
                    
-
 
Línea 380... Línea 337...
380
                    
337
                    $formTopicCustomer = new TopicCustomerUploadForm();
381
                    
338
                    
382
                    $this->layout()->setTemplate('layout/layout-backend');
339
                    $this->layout()->setTemplate('layout/layout-backend');
383
                    $viewModel = new ViewModel();
340
                    $viewModel = new ViewModel();
384
                    $viewModel->setTemplate('leaders-linked/microlearning-access-for-students/index.phtml');
341
                    $viewModel->setTemplate('leaders-linked/microlearning-access-for-students/index.phtml');
385
                    $viewModel->setVariables([
342
                    $viewModel->setVariables([
386
                        'form' => $form,
343
                        'form' => $form,
387
                        'formPushNotification' => $formPushNotification,
344
                        'formPushNotification' => $formPushNotification,
Línea 388... Línea 345...
388
                        'formCapsuleCustomer' => $formCapsuleCustomer
345
                        'formTopicCustomer' => $formTopicCustomer
389
                    ]);
346
                    ]);
Línea 403... Línea 360...
403
                'success' => false,
360
                'success' => false,
404
                'data' => $e->getMessage()
361
                'data' => $e->getMessage()
405
            ]);
362
            ]);
406
        }
363
        }
407
    }
364
    }
408
    
365
 
-
 
366
    /**
-
 
367
     * Revokes unlimited access for a user to a specific microlearning topic
409
    
368
     * 
-
 
369
     * This action handles the revocation of unlimited access privileges for a user.
-
 
370
     * It checks various conditions before proceeding with the revocation:
-
 
371
     * - Validates current user and company
-
 
372
     * - Verifies topic and user existence
-
 
373
     * - Ensures proper authorization
-
 
374
     * - Confirms the user has unlimited access before revoking
410
    
375
     * 
-
 
376
     * @return JsonModel Returns a JSON response indicating success or failure
411
    
377
     */
412
    public function revokeAction()
378
    public function revokeAction()
413
    {
379
    {
-
 
380
        // Get the current request object
414
        $request = $this->getRequest();
381
        $request = $this->getRequest();
Línea -... Línea 382...
-
 
382
        
415
        
383
        // Get current user and company from plugin
416
        $currentUserPlugin = $this->plugin('currentUserPlugin');
384
        $currentUserPlugin = $this->plugin('currentUserPlugin');
417
        $currentUser    = $currentUserPlugin->getUser();
385
        $currentUser    = $currentUserPlugin->getUser();
Línea -... Línea 386...
-
 
386
        $currentCompany = $currentUserPlugin->getCompany();
418
        $currentCompany = $currentUserPlugin->getCompany();
387
        
419
        
388
        // Get topic and user UUIDs from route parameters
420
        $request    = $this->getRequest();
-
 
421
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
389
        $request    = $this->getRequest();
422
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
-
 
423
        $user_uuid   = $this->params()->fromRoute('user_uuid');
390
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
424
        
-
 
425
        
391
        $user_uuid   = $this->params()->fromRoute('user_uuid');
426
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
392
 
427
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
393
        // Validate current user exists
428
        if(!$topic) {
394
        if(!$currentUser) {
429
            return new JsonModel([
395
            return new JsonModel([
430
                'success'   => false,
396
                'success'   => false,
431
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
397
                'data'   => 'ERROR_UNAUTHORIZED'
432
            ]);
-
 
433
        }
398
            ]);
434
        
-
 
-
 
399
        }
435
        
400
 
436
        
401
        // Validate current company exists
437
        if($topic->company_id != $currentCompany->id) {
402
        if(!$currentCompany) {
438
            return new JsonModel([
403
            return new JsonModel([
439
                'success'   => false,
404
                'success'   => false,
440
                'data'   => 'ERROR_UNAUTHORIZED'
405
                'data'   => 'ERROR_UNAUTHORIZED'
441
            ]);
406
            ]);
442
        }
-
 
443
        
407
        }
444
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
408
 
445
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
409
        // Validate topic UUID was provided
446
        if(!$capsule) {
410
        if(!$topic_uuid) {
447
            return new JsonModel([
411
            return new JsonModel([
-
 
412
                'success'   => false,
-
 
413
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
414
            ]);
-
 
415
        }
-
 
416
 
-
 
417
        // Validate user UUID was provided
-
 
418
        if(!$user_uuid) {
-
 
419
            return new JsonModel([
448
                'success'   => false,
420
                'success'   => false,
449
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
421
                'data'   => 'ERROR_USER_NOT_FOUND'
Línea -... Línea 422...
-
 
422
            ]);
-
 
423
        }
-
 
424
        
-
 
425
        // Fetch topic by UUID and validate it exists
-
 
426
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
427
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
428
        if(!$topic) {
-
 
429
            return new JsonModel([
-
 
430
                'success'   => false,
Línea -... Línea 431...
-
 
431
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
450
            ]);
432
            ]);
451
        }
433
        }
452
        
434
        
453
        
435
        // Validate topic belongs to current company
454
        if($capsule->topic_id != $topic->id) {
436
        if($topic->company_id != $currentCompany->id) {
455
            return new JsonModel([
437
            return new JsonModel([
Línea -... Línea 438...
-
 
438
                'success'   => false,
456
                'success'   => false,
439
                'data'   => 'ERROR_UNAUTHORIZED'
457
                'data'   => 'ERROR_UNAUTHORIZED'
440
            ]);
Línea 458... Línea 441...
458
            ]);
441
        }
459
        }
442
        
460
        
443
        // Fetch user by UUID and validate it exists
461
        $userMapper = UserMapper::getInstance($this->adapter);
444
        $userMapper = UserMapper::getInstance($this->adapter);
462
        $user = $userMapper->fetchOneByUuid($user_uuid);
445
        $user = $userMapper->fetchOneByUuid($user_uuid);
463
        
446
        
Línea -... Línea 447...
-
 
447
        if(!$user) {
464
        if(!$user) {
448
            return new JsonModel([
465
            return new JsonModel([
449
                'success'   => false,
466
                'success'   => false,
450
                'data'   => 'ERROR_USER_NOT_FOUND'
467
                'data'   => 'ERROR_USER_NOT_FOUND'
451
            ]);
468
            ]);
452
        }
469
        }
453
        
470
        
454
        // Fetch topic-user relationship and validate it exists
471
        $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
455
        $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
Línea -... Línea 456...
-
 
456
        $topicUser = $topicUserMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);        
472
        $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($user->id, $capsule->id);        
457
        if(!$topicUser) {
473
        if(!$capsuleUser) {
-
 
474
            return new JsonModel([
-
 
-
 
458
            return new JsonModel([
475
                'success'   => false,
459
                'success'   => false,
476
                'data'   => 'ERROR_UNAUTHORIZED'
460
                'data'   => 'ERROR_UNAUTHORIZED'
477
            ]);
461
            ]);
478
        }
462
        }
479
        
463
        
480
        if($request->isPost()) {
464
        // Process revocation only for POST requests
-
 
465
        if($request->isPost()) {
-
 
466
            // Validate user has unlimited access before revoking
481
           
467
            if($topicUser->access != MicrolearningTopicUser::ACCESS_UNLIMITED) {
482
 
468
                return new JsonModel([
483
            if($capsuleUser->access != MicrolearningCapsuleUser::ACCESS_UNLIMITED) {
469
                    'success'   => false,
-
 
470
                    'data'   => 'ERROR_USER_ACCESS_CANNT_BE_REVOKE'
484
                return new JsonModel([
471
                ]);
485
                    'success'   => false,
472
            }
-
 
473
            
486
                    'data'   => 'ERROR_USER_ACCESS_CANNT_BE_REVOKE'
474
            // Update access to revoked status
487
                ]);
475
            $topicUser->access = MicrolearningTopicUser::ACCESS_REVOKE;
488
            }
476
            if($topicUserMapper->update($topicUser)) { 
-
 
477
                
489
            $capsuleUser->access = MicrolearningCapsuleUser::ACCESS_REVOKE;
478
                // Refresh topic user data after update
490
            if($capsuleUserMapper->update($capsuleUser)) { 
-
 
491
                
479
                $topicUser = $topicUserMapper->fetchOne($topicUser->id);
Línea 492... Línea 480...
492
                $capsuleUser = $capsuleUserMapper->fetchOne($capsuleUser->id);
480
                if($topicUser) {
-
 
481
                    // Update or create microlearning user record
493
                if($capsuleUser) {
482
                    $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
494
                    $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
483
                    $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($topicUser->user_id, $topicUser->company_id);
495
                    $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($capsuleUser->user_id, $capsuleUser->company_id);
484
                    if($microlearningUser) {
496
                    if($microlearningUser) {
485
                        // Update existing microlearning user
497
                        $microlearningUser->updated_on = $capsuleUser->updated_on;
486
                        $microlearningUser->updated_on = $topicUser->updated_on;
Línea 498... Línea 487...
498
                        
487
                        $microlearningUserMapper->update($microlearningUser);
499
                        $microlearningUserMapper->update($microlearningUser);
488
                        
500
                        
489
                    } else {
Línea 516... Línea 505...
516
                
505
                
Línea 517... Línea 506...
517
            } else {
506
            } else {
518
                
507
                
519
                return new JsonModel([
508
                return new JsonModel([
520
                    'success'   => false,
509
                    'success'   => false,
521
                    'data'      => $capsuleUserMapper->getError()
510
                    'data'      => $topicUserMapper->getError()
522
                ]);
511
                ]);
Línea -... Línea 512...
-
 
512
            }
523
            }
513
        }
524
        }
514
        
525
        
515
        // Return error for non-POST requests
526
        return new JsonModel([
516
        return new JsonModel([
527
            'success' => false,
517
            'success' => false,
Línea 528... Línea 518...
528
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
518
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
529
        ]);
519
        ]);
-
 
520
    }
530
    }
521
    
531
    
522
    public function unlimitAction()
532
    public function unlimitAction()
523
    {
533
    {
524
        try {
534
        $request = $this->getRequest();
525
            $request    = $this->getRequest();
535
        
526
 
536
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
537
        $currentUser    = $currentUserPlugin->getUser();
527
            $currentUserPlugin = $this->plugin('currentUserPlugin');
538
        $currentCompany = $currentUserPlugin->getCompany();
-
 
539
        
528
            $currentUser    = $currentUserPlugin->getUser();
540
        $request    = $this->getRequest();
-
 
541
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
529
            $currentCompany = $currentUserPlugin->getCompany();
542
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
-
 
543
        $user_uuid   = $this->params()->fromRoute('user_uuid');
-
 
544
        
530
 
545
        
531
            $topic_uuid     = $this->params()->fromRoute('topic_uuid');
546
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
532
            $user_uuid   = $this->params()->fromRoute('user_uuid');
547
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
533
 
548
        if(!$topic) {
534
            if(!$currentUser) {
549
            return new JsonModel([
535
                return new JsonModel([
550
                'success'   => false,
-
 
551
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
552
            ]);
536
                    'success'   => false,
553
        }
537
                    'data'   => 'ERROR_UNAUTHORIZED'
554
        
538
                ]);
555
        
539
            }
556
        
540
 
557
        if($topic->company_id != $currentCompany->id) {
541
            if(!$currentCompany) {
558
            return new JsonModel([
542
                return new JsonModel([
559
                'success'   => false,
543
                    'success'   => false,
560
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
561
            ]);
-
 
562
        }
544
                    'data'   => 'ERROR_UNAUTHORIZED'
563
        
545
                ]);
564
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
546
            }
565
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
547
 
566
        if(!$capsule) {
548
            if(!$topic_uuid) {
567
            return new JsonModel([
549
                return new JsonModel([
568
                'success'   => false,
-
 
569
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
550
                    'success'   => false,
570
            ]);
551
                    'data'   => 'ERROR_TOPIC_NOT_FOUND'
571
        }
552
                ]);
572
        
553
            }
573
        
554
 
574
        if($capsule->topic_id != $topic->id) {
555
            if(!$user_uuid) {
575
            return new JsonModel([
556
                return new JsonModel([
576
                'success'   => false,
-
 
577
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
578
            ]);
-
 
579
        }
557
                    'success'   => false,
580
        
558
                    'data'   => 'ERROR_USER_NOT_FOUND'
581
        $userMapper = UserMapper::getInstance($this->adapter);
559
                ]);
582
        $user = $userMapper->fetchOneByUuid($user_uuid);
560
            }
583
        
561
 
584
        if(!$user) {
562
            if(!$request->isPost()) {
585
            return new JsonModel([
563
                return new JsonModel([
586
                'success'   => false,
564
                    'success'   => false,
587
                'data'   => 'ERROR_USER_NOT_FOUND'
565
                    'data'   => 'ERROR_METHOD_NOT_ALLOWED'
588
            ]);
566
                ]);
589
        }
567
            }
590
        
568
 
591
        $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
569
            $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
592
        $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($user->id, $capsule->id);
570
            $topic = $topicMapper->fetchOneByUuid($topic_uuid);
593
        if(!$capsuleUser) {
571
            if(!$topic) {
594
            return new JsonModel([
572
                return new JsonModel([
Línea -... Línea 573...
-
 
573
                    'success'   => false,
595
                'success'   => false,
574
                    'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
575
                ]);
-
 
576
            }   
-
 
577
        
-
 
578
            if($topic->company_id != $currentCompany->id) {
Línea -... Línea 579...
-
 
579
                return new JsonModel([
-
 
580
                    'success'   => false,
Línea 596... Línea 581...
596
                'data'   => 'ERROR_UNAUTHORIZED'
581
                    'data'   => 'ERROR_UNAUTHORIZED'
597
            ]);
582
                ]);
598
        }
583
            }
599
        
584
            
600
        if($request->isPost()) {
585
            $userMapper = UserMapper::getInstance($this->adapter);
601
            
586
            $user = $userMapper->fetchOneByUuid($user_uuid);
602
            
-
 
603
            if($capsuleUser->access != MicrolearningCapsuleUser::ACCESS_REVOKE) {
-
 
604
                return new JsonModel([
587
            
605
                    'success'   => false,
-
 
606
                    'data'   => 'ERROR_USER_ACCESS_CANNT_BE_UNLIMIT'
-
 
607
                ]);
588
            if(!$user) {
608
            }
589
                return new JsonModel([
609
            $capsuleUser->access = MicrolearningCapsuleUser::ACCESS_UNLIMITED;
-
 
610
            if($capsuleUserMapper->update($capsuleUser)) {
-
 
611
                
-
 
612
                $capsuleUser = $capsuleUserMapper->fetchOne($capsuleUser->id);
-
 
613
                if($capsuleUser) {
-
 
614
                    $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
590
                    'success'   => false,
615
                    $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($capsuleUser->user_id, $capsuleUser->company_id);
-
 
616
                    if($microlearningUser) {
-
 
617
                        $microlearningUser->updated_on = $capsuleUser->updated_on;
-
 
618
                        
-
 
619
                        $microlearningUserMapper->update($microlearningUser);
-
 
620
                        
-
 
621
                    } else {
-
 
622
                        $microlearningUser = new MicrolearningUser();
-
 
623
                        $microlearningUser->company_id = $capsuleUser->company_id;
-
 
624
                        $microlearningUser->user_id = $capsuleUser->user_id;
-
 
625
                        $microlearningUser->added_on = $capsuleUser->added_on;
591
                    'data'   => 'ERROR_USER_NOT_FOUND'
626
                        $microlearningUser->updated_on = $capsuleUser->updated_on;
592
                ]);
627
                        
593
            }
628
                        $microlearningUserMapper->insert($microlearningUser);
594
            
-
 
595
            $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
629
                    }
596
            $topicUser = $topicUserMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);
-
 
597
            if(!$topicUser) {
-
 
598
                return new JsonModel([
-
 
599
                    'success'   => false,
-
 
600
                    'data'   => 'ERROR_UNAUTHORIZED'
-
 
601
                ]);
-
 
602
            }
-
 
603
        
-
 
604
            if($topicUser->access != MicrolearningTopicUser::ACCESS_REVOKE) {
-
 
605
                return new JsonModel([
-
 
606
                    'success'   => false,
630
                }
607
                    'data'   => 'ERROR_USER_ACCESS_CANNT_BE_UNLIMIT'
-
 
608
                ]);
-
 
609
            }
-
 
610
 
-
 
611
            $topicUser->access = MicrolearningTopicUser::ACCESS_UNLIMITED;
631
                
612
            $topicUser->updated_on = date('Y-m-d H:i:s');
-
 
613
            
-
 
614
            try {
-
 
615
                $topicUserMapper->update($topicUser);
-
 
616
 
-
 
617
                $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
-
 
618
                $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($topicUser->user_id, $topicUser->company_id);
-
 
619
 
-
 
620
                if(!$microlearningUser) {
-
 
621
                    $microlearningUser = new MicrolearningUser();
-
 
622
                    $microlearningUser->company_id = $topicUser->company_id;
-
 
623
                    $microlearningUser->user_id = $topicUser->user_id;
-
 
624
                    $microlearningUser->added_on = $topicUser->added_on;
-
 
625
                    $microlearningUser->updated_on = $topicUser->updated_on;
632
                return new JsonModel([
626
                    $microlearningUserMapper->insert($microlearningUser);
633
                    'success' => true,
627
                } else {
634
                    'data' => 'LABEL_USER_ACCESS_HAS_BEEN_UNLIMITED'
628
                    $microlearningUser->updated_on = $topicUser->updated_on;
635
                ]);
629
                    $microlearningUserMapper->update($microlearningUser);
636
                
630
                }
-
 
631
            } catch (\Exception $e) {
-
 
632
                $this->logger->err('Error updating topic user: ' . $e->getMessage());
-
 
633
                return new JsonModel([
-
 
634
                    'success'   => false,
-
 
635
                    'data'      => 'ERROR_UPDATING_TOPIC_USER'
-
 
636
                ]);
-
 
637
            }
-
 
638
            
-
 
639
            return new JsonModel([
-
 
640
                'success' => true,
-
 
641
                'data' => 'LABEL_USER_ACCESS_HAS_BEEN_UNLIMITED'
637
            } else {
642
            ]);
638
                
-
 
639
                return new JsonModel([
-
 
640
                    'success'   => false,
-
 
641
                    'data'      => $capsuleUserMapper->getError()
-
 
642
                ]);
-
 
643
            }
643
        } catch (\Exception $e) {
Línea 644... Línea 644...
644
        }
644
            $this->logger->err('Fatal error in unlimitAction: ' . $e->getMessage());
645
        
645
            return new JsonModel([
646
        return new JsonModel([
646
                'success' => false,
Línea 660... Línea 660...
660
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
660
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
661
        $currentNetwork = $currentNetworkPlugin->getNetwork();
661
        $currentNetwork = $currentNetworkPlugin->getNetwork();
Línea 662... Línea 662...
662
        
662
        
663
        $request    = $this->getRequest();
663
        $request    = $this->getRequest();
664
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
-
 
Línea 665... Línea 664...
665
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
664
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
666
        
665
        
667
        
666
        
Línea 672... Línea 671...
672
                'success'   => false,
671
                'success'   => false,
673
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
672
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
674
            ]);
673
            ]);
675
        }
674
        }
Línea 676... Línea -...
676
        
-
 
677
        
-
 
678
        
675
        
679
        if($topic->company_id != $currentCompany->id) {
676
        if($topic->company_id != $currentCompany->id) {
680
            return new JsonModel([
677
            return new JsonModel([
681
                'success'   => false,
678
                'success'   => false,
682
                'data'   => 'ERROR_UNAUTHORIZED'
679
                'data'   => 'ERROR_UNAUTHORIZED'
683
            ]);
680
            ]);
Línea 684... Línea -...
684
        }
-
 
685
        
-
 
686
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
687
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
-
 
688
        if(!$capsule) {
-
 
689
            return new JsonModel([
-
 
690
                'success'   => false,
-
 
691
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
-
 
692
            ]);
-
 
693
        }
-
 
694
        
-
 
695
        
-
 
696
        if($capsule->topic_id != $topic->id) {
-
 
697
            return new JsonModel([
-
 
698
                'success'   => false,
-
 
699
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
700
            ]);
-
 
701
        }
-
 
702
        
-
 
703
        
681
        }
Línea 704... Línea 682...
704
        
682
        
705
        if($request->isPost()) {
683
        if($request->isPost()) {
706
            
-
 
707
            $step = Functions::sanitizeFilterString($this->params()->fromPost('step')); 
-
 
708
            if($step == 'validation') {
684
            
709
               
685
            $step = Functions::sanitizeFilterString($this->params()->fromPost('step')); 
Línea 710... Línea 686...
710
                
686
            if($step == 'validation') { 
711
                $userMapper = UserMapper::getInstance($this->adapter);
687
                $userMapper = UserMapper::getInstance($this->adapter);
Línea 712... Línea 688...
712
                $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
688
                $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
Línea 713... Línea 689...
713
 
689
 
Línea 795... Línea 771...
795
                        
771
                        
Línea 796... Línea 772...
796
                        if(!in_array($email, $emails)) {
772
                        if(!in_array($email, $emails)) {
797
                            
773
                            
798
                            $user = $userMapper->fetchOneByEmail($email);
774
                            $user = $userMapper->fetchOneByEmail($email);
799
                            if($user) {
775
                            if($user) {
800
                                $assigned_capsules =  $capsuleUserMapper->fetchCountByCompanyIdAndTopicIdAndUserId($topic->company_id, $topic->id, $user->id);
776
                                $assigned_topics =  $topicUserMapper->fetchCountByCompanyIdAndTopicIdAndUserId($topic->company_id, $topic->id, $user->id);
801
                            } else {
777
                            } else {
Línea 802... Línea 778...
802
                                $assigned_capsules = 0;
778
                                $assigned_topics = 0;
Línea 803... Línea 779...
803
                            }
779
                            }
Línea 809... Línea 785...
809
                                'id' => $count_users,
785
                                'id' => $count_users,
810
                                'first_name' => $first_name,
786
                                'first_name' => $first_name,
811
                                'last_name' => $last_name,
787
                                'last_name' => $last_name,
812
                                'password'  => $password,
788
                                'password'  => $password,
813
                                'email' => $email,
789
                                'email' => $email,
814
                                'assigned_capsules' => $assigned_capsules, 
790
                                'assigned_topics' => $assigned_topics, 
815
                                'company' => $company, 
791
                                'company' => $company, 
816
                                'function' => $function, 
792
                                'function' => $function, 
817
                                'group' => $group, 
793
                                'group' => $group, 
818
                                'institution' => $institution, 
794
                                'institution' => $institution, 
819
                                'program' => $program,
795
                                'program' => $program,
Línea 832... Línea 808...
832
                                'password'  => $password,
808
                                'password'  => $password,
833
                                'email' => $email,
809
                                'email' => $email,
834
                                'status' => 'DUPLICATE IN EXCEL'
810
                                'status' => 'DUPLICATE IN EXCEL'
835
                            ]);
811
                            ]);
836
                        }
812
                        }
837
                        
-
 
838
                        
-
 
839
                        
-
 
840
                        
-
 
841
                        
-
 
842
                    }
813
                    }
Línea 843... Línea -...
843
 
-
 
-
 
814
 
844
                    
815
                    // cache the users
845
                    $key = md5($currentUser->id . '-' . $topic->uuid . '-' . $capsule->uuid);
816
                    $key = md5($currentUser->id . '-' . $topic->uuid . '-' . $topic->uuid);
846
                    $this->cache->setItem($key, serialize($users));
817
                    $this->cache->setItem($key, serialize($users));
-
 
818
 
847
                    
819
                    // return the key
848
                    return new JsonModel([
820
                    return new JsonModel([
849
                        'success' => true,
821
                        'success' => true,
850
                        'data' => [
822
                        'data' => [
851
                            'key' => $key,
823
                            'key' => $key,
852
                            'topic' => $topic->name,
-
 
853
                            'capsule' => $capsule->name,
824
                            'topic' => $topic->name,
854
                            'items' => [
825
                            'items' => [
855
                                'ok' => $users,
826
                                'ok' => $users,
856
                                'error' => $errors,
827
                                'error' => $errors,
857
                            ],     
828
                            ],     
858
                        ]
829
                        ]
859
                    ]);
-
 
860
                    
-
 
861
                    
-
 
862
                    
830
                    ]);
863
                } else {
831
                } else {
864
                    $messages = [];
832
                    $messages = [];
865
                    $form_messages = (array) $form->getMessages();
833
                    $form_messages = (array) $form->getMessages();
866
                    foreach($form_messages  as $fieldname => $field_messages)
834
                    foreach($form_messages  as $fieldname => $field_messages)
Línea 873... Línea 841...
873
                        'success'   => false,
841
                        'success'   => false,
874
                        'data'   => $messages
842
                        'data'   => $messages
875
                    ]);
843
                    ]);
876
                }
844
                }
877
            } else if($step == 'process') {
845
            } else if($step == 'process') {
878
            
-
 
-
 
846
                // get the key from the post
879
                $key = Functions::sanitizeFilterString($this->params()->fromPost('key')); 
847
                $key = Functions::sanitizeFilterString($this->params()->fromPost('key')); 
880
                if(!$key) {
848
                if(!$key) {
881
                    return new JsonModel([
849
                    return new JsonModel([
882
                        'success' => false,
850
                        'success' => false,
883
                        'data' => 'ERROR_CACHE_KEY_EMPTY'
851
                        'data' => 'ERROR_CACHE_KEY_EMPTY'
884
                    ]); 
852
                    ]); 
885
                }
853
                }
886
                
-
 
-
 
854
                // get the value from the cache
887
                $value = $this->cache->getItem($key);
855
                $value = $this->cache->getItem($key);
-
 
856
 
-
 
857
                // if the value is not found, return an error
888
                if(!$value) {
858
                if(!$value) {
889
                    
-
 
890
                    return new JsonModel([
859
                    return new JsonModel([
891
                        'success' => false,
860
                        'success' => false,
892
                        'data' => 'ERROR_CACHE_NOT_FOUND'
861
                        'data' => 'ERROR_CACHE_NOT_FOUND'
893
                    ]); 
862
                    ]); 
894
                }
863
                }
Línea -... Línea 864...
-
 
864
                
895
                
865
                // unserialize the value
-
 
866
                $records = unserialize($value);
-
 
867
 
896
                $records = unserialize($value);
868
                // if the value is not found, return an error
897
                if(!$records) {
869
                if(!$records) {
898
                    return new JsonModel([
870
                    return new JsonModel([
899
                        'success' => false,
871
                        'success' => false,
900
                        'data' => 'ERROR_CACHE_INVALID'
872
                        'data' => 'ERROR_CACHE_INVALID'
901
                    ]);
873
                    ]);
902
                }
-
 
903
                
874
                }
904
            
-
 
905
                
-
 
-
 
875
 
906
                
876
                // get the network, company, company follower
907
                $networkMapper = NetworkMapper::getInstance($this->adapter);
877
                $networkMapper = NetworkMapper::getInstance($this->adapter);
908
                $companyMapper = CompanyMapper::getInstance($this->adapter);
878
                $companyMapper = CompanyMapper::getInstance($this->adapter);
909
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
879
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
-
 
880
             
910
                
881
                // get the connection, user, user password, topic user
911
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
882
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
912
                $userMapper = UserMapper::getInstance($this->adapter);
883
                $userMapper = UserMapper::getInstance($this->adapter);
913
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
884
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
Línea -... Línea 885...
-
 
885
                $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
914
                $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
886
                
915
                
887
                // get the microlearning extend user, microlearning extend user company, microlearning extend user function, microlearning extend user group, microlearning extend user institution, microlearning extend user program, microlearning extend user partner, microlearning extend user sector, microlearning extend user student type, microlearning extend user country
916
                $microlearningExtendUserMapper = MicrolearningExtendUserMapper::getInstance($this->adapter);
888
                $microlearningExtendUserMapper = MicrolearningExtendUserMapper::getInstance($this->adapter);
917
                $microlearningExtendUserCompanyMapper = MicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
889
                $microlearningExtendUserCompanyMapper = MicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
918
                $microlearningExtendUserFunctionMapper = MicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
890
                $microlearningExtendUserFunctionMapper = MicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
Línea 922... Línea 894...
922
                $microlearningExtendUserPartnerMapper = MicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
894
                $microlearningExtendUserPartnerMapper = MicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
923
                $microlearningExtendUserSectorMapper = MicrolearningExtendUserSectorMapper::getInstance($this->adapter);
895
                $microlearningExtendUserSectorMapper = MicrolearningExtendUserSectorMapper::getInstance($this->adapter);
924
                $microlearningExtendUserStudentTypeMapper = MicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
896
                $microlearningExtendUserStudentTypeMapper = MicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
925
                $microlearningExtendUserCountryMapper = MicrolearningExtendUserCountryMapper::getInstance($this->adapter);
897
                $microlearningExtendUserCountryMapper = MicrolearningExtendUserCountryMapper::getInstance($this->adapter);
Línea 926... Línea -...
926
 
-
 
-
 
898
 
927
                
899
                // get the network default, user default for connection, company for follower
928
                $networkDefault = $networkMapper->fetchOneByDefault();
900
                $networkDefault = $networkMapper->fetchOneByDefault();
Línea 929... Línea 901...
929
                $userDefaultForConnection = $userMapper->fetchOneDefaultForConnection();
901
                $userDefaultForConnection = $userMapper->fetchOneDefaultForConnection();
Línea -... Línea 902...
-
 
902
                
930
                
903
                $companyForFollower = $companyMapper->fetchOneDefaultForFollowers();
Línea 931... Línea -...
931
                $companyForFollower = $companyMapper->fetchOneDefaultForFollowers();
-
 
-
 
904
                
932
                
905
                // create the csv
933
                $csv = "FIRST NAME|LAST NAME|EMAIL|STATUS\r\n";
906
                $csv = "FIRST NAME|LAST NAME|EMAIL|STATUS\r\n";
934
                
907
                
935
           
908
                // get the users processed, users assigned, user ids
936
                $users_processed = 0;
909
                $users_processed = 0;
937
                $users_assigned = 0;
910
                $users_assigned = 0;
938
                $user_ids = [];
911
                $user_ids = [];
939
                foreach($records as $record)
912
                foreach($records as $record)
940
                {
913
                {
941
                    $first_name = $record['first_name'];
-
 
942
                    $last_name = $record['last_name'];
-
 
943
                    $password = $record['password'];
914
                    $first_name = $record['first_name'];
944
                    $email = $record['email'];
915
                    $last_name = $record['last_name'];
945
                    
916
                    $password = $record['password'];
946
                    
917
                    $email = $record['email'];
947
                    $company = $record['company'];
918
                    $company = $record['company'];
Línea 953... Línea 924...
953
                    $sector = $record['sector'];
924
                    $sector = $record['sector'];
954
                    $studentType = $record['studentType'];
925
                    $studentType = $record['studentType'];
955
                    $country = $record['country'];
926
                    $country = $record['country'];
956
                    $isAdult = strtolower(trim( $record['isAdult'])) == User::IS_ADULT_YES;
927
                    $isAdult = strtolower(trim( $record['isAdult'])) == User::IS_ADULT_YES;
Línea 957... Línea -...
957
    
-
 
958
    
928
    
959
                    $user = $userMapper->fetchOneByEmail($email);
-
 
960
                    if(!$user) {
929
                    $user = $userMapper->fetchOneByEmail($email);
961
                        
-
 
-
 
930
 
-
 
931
                    // if the user is not found, create the user
-
 
932
                    if(!$user) {    
962
                        
933
                        // if the password is not empty, create the user
963
                        if($password) {
934
                        if($password) {
Línea 964... Línea 935...
964
                            $password_hash = password_hash($password, PASSWORD_DEFAULT);
935
                            $password_hash = password_hash($password, PASSWORD_DEFAULT);
Línea 1298... Línea 1269...
1298
                    $last_name = $user->last_name;
1269
                    $last_name = $user->last_name;
1299
                    $email = $user->email;
1270
                    $email = $user->email;
Línea 1300... Línea 1271...
1300
                    
1271
                    
1301
                    
1272
                    
1302
                    $users_processed++;
1273
                    $users_processed++;
1303
                    $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($user_id, $capsule->id);
1274
                    $topicUser = $topicUserMapper->fetchOneByUserIdAndTopicId($user_id, $topic->id);
1304
                    if($capsuleUser) {
1275
                    if($topicUser) {
1305
                        $users_previous++;
1276
                        $users_previous++;
1306
                        $csv .= "$first_name|$last_name|$email|PREVIOUS FOUND \r\n";
1277
                        $csv .= "$first_name|$last_name|$email|PREVIOUS FOUND \r\n";
1307
                    } else {
1278
                    } else {
1308
                        $capsuleUser = new MicrolearningCapsuleUser();
1279
                        $topicUser = new MicrolearningTopicUser();
1309
                        $capsuleUser->company_id = $capsule->company_id;
1280
                        $topicUser->company_id = $topic->company_id;
1310
                        $capsuleUser->topic_id = $capsule->topic_id;
1281
                        $topicUser->topic_id = $topic->id;
1311
                        $capsuleUser->capsule_id = $capsule->id;
1282
                        $topicUser->topic_id = $topic->id;
Línea 1312... Línea 1283...
1312
                        $capsuleUser->user_id = $user_id;
1283
                        $topicUser->user_id = $user_id;
Línea 1313... Línea 1284...
1313
                        $capsuleUser->access = MicrolearningCapsuleUser::ACCESS_UNLIMITED;
1284
                        $topicUser->access = MicrolearningTopicUser::ACCESS_UNLIMITED;
1314
                        
1285
                        
1315
                        if($capsuleUserMapper->insert($capsuleUser)) {
1286
                        if($topicUserMapper->insert($topicUser)) {
1316
                            
1287
                            
1317
                            $notification = new Notification();
1288
                            $notification = new Notification();
1318
                            $notification->company_id = $capsule->company_id;
1289
                            $notification->company_id = $topic->company_id;
1319
                            $notification->user_id = $user_id;
1290
                            $notification->user_id = $user_id;
1320
                            $notification->topic_id = $capsule->topic_id;
1291
                            $notification->topic_id = $topic->id;
Línea 1321... Línea 1292...
1321
                            $notification->capsule_id = $capsule->id;
1292
                            $notification->topic_id = $topic->id;
Línea 1322... Línea 1293...
1322
                            $notification->type = Notification::TYPE_NEW_MICROLEARNING_CAPSULE;
1293
                            $notification->type = Notification::TYPE_NEW_MICROLEARNING_CAPSULE;
1323
                            $notification->message  = 'LABEL_NOTIFICATION_NEW_MICROLEARNING_CAPSULE' . ' : ' . $capsule->name;
1294
                            $notification->message  = 'LABEL_NOTIFICATION_NEW_MICROLEARNING_CAPSULE' . ' : ' . $topic->name;
Línea 1324... Línea 1295...
1324
                            $notification->url      = '/microlearning/capsules/' . $capsule->uuid .  '/detail';
1295
                            $notification->url      = '/microlearning/topics/' . $topic->uuid .  '/detail';
1325
                            
1296
                            
1326
                            $notificationMapper->insert($notification);
1297
                            $notificationMapper->insert($notification);
1327
                            
1298
                            
1328
                            
1299
                            
1329
                            $csv .= "$first_name|$last_name|$email|CAPSULE USER ASSIGNED\r\n";
1300
                            $csv .= "$first_name|$last_name|$email|CAPSULE USER ASSIGNED\r\n";
Línea 1330... Línea 1301...
1330
                            $users_assigned++;  
1301
                            $users_assigned++;  
Línea 1331... Línea 1302...
1331
                            
1302
                            
1332
                            
1303
                            
1333
                            $capsuleUser = $capsuleUserMapper->fetchOne($capsuleUser->id);
1304
                            $topicUser = $topicUserMapper->fetchOne($topicUser->id);
1334
                            if($capsuleUser) {
1305
                            if($topicUser) {
1335
                                $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
1306
                                $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
1336
                                $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($capsuleUser->user_id, $capsuleUser->company_id);
1307
                                $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($topicUser->user_id, $topicUser->company_id);
Línea 1337... Línea 1308...
1337
                                if($microlearningUser) {
1308
                                if($microlearningUser) {
1338
                                    $microlearningUser->updated_on = $capsuleUser->updated_on;
1309
                                    $microlearningUser->updated_on = $topicUser->updated_on;
1339
                                    
1310
                                    
1340
                                    $microlearningUserMapper->update($microlearningUser);
1311
                                    $microlearningUserMapper->update($microlearningUser);
Línea 1357... Línea 1328...
1357
                    
1328
                    
Línea 1358... Línea 1329...
1358
                 
1329
                 
Línea 1359... Línea 1330...
1359
                    
1330
                    
1360
                }
1331
                }
1361
                
1332
                
1362
                $users_in_the_capsule = $capsuleUserMapper->fetchCountByCompanyIdAndCapsuleId($capsule->company_id, $capsule->id);
1333
                $users_in_the_topic = $topicUserMapper->fetchCountByCompanyIdAndTopicId($topic->company_id, $topic->id);
1363
                
1334
                
1364
                return new JsonModel([
1335
                return new JsonModel([
1365
                    'success' => true, 
1336
                    'success' => true, 
1366
                    'data' => [
1337
                    'data' => [
1367
                        'users_assigned' => $users_assigned, 
1338
                        'users_assigned' => $users_assigned, 
1368
                        'users_processed' => $users_processed,
1339
                        'users_processed' => $users_processed,
1369
                        'users_in_the_capsule' => $users_in_the_capsule,
1340
                        'users_in_the_topic' => $users_in_the_topic,
Línea 1392... Línea 1363...
1392
            'success' => false,
1363
            'success' => false,
1393
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1364
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1394
        ]);
1365
        ]);
1395
    }
1366
    }
Línea -... Línea 1367...
-
 
1367
    
-
 
1368
    /**
-
 
1369
     * Handles sending push notifications to selected users about a microlearning topic
-
 
1370
     * 
-
 
1371
     * This action processes push notifications for microlearning topics:
-
 
1372
     * 1. Validates user permissions and input data
-
 
1373
     * 2. Processes the notification form
-
 
1374
     * 3. Sends push notifications to selected users' devices
-
 
1375
     * 
-
 
1376
     * Required parameters:
-
 
1377
     * - topic_uuid: UUID of the microlearning topic
-
 
1378
     * - customer_uuids: Array of user UUIDs to receive the notification
-
 
1379
     * - push_template_id: UUID of the push notification template to use
-
 
1380
     * 
-
 
1381
     * @return JsonModel Returns JSON response with:
-
 
1382
     *                   - success: true/false
-
 
1383
     *                   - data: Contains push_to_send count or error message
-
 
1384
     * @throws \Throwable When an error occurs during processing
1396
    
1385
     */
1397
    public function notificationAction()
1386
    public function notificationAction()
1398
    {
-
 
1399
        $request = $this->getRequest();
-
 
1400
        
-
 
1401
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1402
        $currentUser    = $currentUserPlugin->getUser();
-
 
1403
        $currentCompany = $currentUserPlugin->getCompany();
-
 
1404
        
-
 
1405
        $request    = $this->getRequest();
-
 
1406
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
-
 
1407
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
-
 
1408
        
-
 
1409
        
-
 
1410
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
1411
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
1412
        if(!$topic) {
-
 
1413
            return new JsonModel([
-
 
1414
                'success'   => false,
-
 
1415
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
1387
    {
1416
            ]);
-
 
1417
        }
-
 
1418
        
-
 
1419
        
-
 
1420
        
-
 
1421
        if($topic->company_id != $currentCompany->id) {
-
 
1422
            return new JsonModel([
-
 
1423
                'success'   => false,
-
 
1424
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
1425
            ]);
-
 
1426
        }
-
 
1427
        
-
 
1428
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
1429
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
-
 
1430
        if(!$capsule) {
1388
        try {
1431
            return new JsonModel([
-
 
1432
                'success'   => false,
-
 
1433
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
-
 
1434
            ]);
-
 
1435
        }
-
 
1436
        
-
 
1437
        
-
 
1438
        if($capsule->topic_id != $topic->id) {
1389
            // Get current request and user context
1439
            return new JsonModel([
-
 
1440
                'success'   => false,
-
 
1441
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
1442
            ]);
-
 
Línea -... Línea 1390...
-
 
1390
            $request = $this->getRequest();
-
 
1391
        
-
 
1392
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1393
            $currentUser    = $currentUserPlugin->getUser();
-
 
1394
            $currentCompany = $currentUserPlugin->getCompany();
-
 
1395
            
-
 
1396
            $topic_uuid     = $this->params()->fromRoute('topic_uuid');
-
 
1397
    
-
 
1398
            // Validate topic UUID exists
-
 
1399
            if(!$topic_uuid) {
-
 
1400
                return new JsonModel([
-
 
1401
                    'success'   => false,
-
 
1402
                    'data'   => 'ERROR_TOPIC_UUID_NOT_FOUND'
-
 
1403
                ]);
-
 
1404
            }
-
 
1405
            
-
 
1406
            // Validate company exists
-
 
1407
            if(!$currentCompany) {
-
 
1408
                return new JsonModel([
-
 
1409
                    'success'   => false,
-
 
1410
                    'data'   => 'ERROR_COMPANY_NOT_FOUND'
-
 
1411
                ]);
-
 
1412
            }
-
 
1413
    
-
 
1414
            // Fetch and validate topic
-
 
1415
            $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
1416
            $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
1417
            if(!$topic) {
-
 
1418
                return new JsonModel([
-
 
1419
                    'success'   => false,
-
 
1420
                    'data'   => 'ERROR_TOPIC_NOT_FOUND'
Línea -... Línea 1421...
-
 
1421
                ]);
-
 
1422
            }
-
 
1423
        
-
 
1424
            // Validate topic belongs to current company
-
 
1425
            if($topic->company_id != $currentCompany->id) {
-
 
1426
                return new JsonModel([
-
 
1427
                    'success'   => false,
-
 
1428
                    'data'   => 'ERROR_UNAUTHORIZED'
-
 
1429
                ]);
1443
        }
1430
            }
-
 
1431
            
-
 
1432
            // Validate request method
-
 
1433
            if(!$request->isPost()) {
-
 
1434
                return new JsonModel([
-
 
1435
                    'success' => false,
-
 
1436
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
1437
                ]);
1444
        
1438
            }
1445
        
1439
 
Línea 1446... Línea 1440...
1446
        if($request->isPost()) {
1440
            // Process notification form
Línea 1447... Línea 1441...
1447
            $dataPost = $request->getPost()->toArray();
1441
            $dataPost = $request->getPost()->toArray();
1448
            $form = new PushMicrolearningNotificationForm($this->adapter, $currentCompany->id);
-
 
1449
            
1442
            $form = new PushMicrolearningNotificationForm($this->adapter, $currentCompany->id);
1450
            $form->setData($dataPost);
1443
            
1451
            
1444
            $form->setData($dataPost);
1452
            if($form->isValid()) {
1445
            
1453
                $customer_uuids = $this->params()->fromPost('customer_uuids');
1446
            // Validate form data
1454
                if(!$customer_uuids) {
-
 
-
 
1447
            if(!$form->isValid()) {      
1455
                    return new JsonModel([
1448
                $messages = [];
Línea -... Línea 1449...
-
 
1449
                $form_messages = (array) $form->getMessages();
-
 
1450
                foreach($form_messages  as $fieldname => $field_messages)
-
 
1451
                {
-
 
1452
                    $messages[$fieldname] = array_values($field_messages);
-
 
1453
                }
-
 
1454
                
-
 
1455
                return new JsonModel([
1456
                        'success' => false,
1456
                    'success'   => false,
-
 
1457
                    'data'      => $messages
1457
                        'data' => 'ERROR_NOT_SELECTED_CUSTOMERS'
1458
                ]);
1458
                    ]);
1459
            }
1459
                    
1460
 
-
 
1461
            // Validate selected users
Línea -... Línea 1462...
-
 
1462
            $customer_uuids = $this->params()->fromPost('customer_uuids');
-
 
1463
            if(!$customer_uuids) {
-
 
1464
                return new JsonModel([
-
 
1465
                    'success' => false,
-
 
1466
                    'data' => 'ERROR_NOT_SELECTED_CUSTOMERS'
-
 
1467
                ]);
-
 
1468
                
-
 
1469
            }
1460
                }
1470
            
1461
                
1471
            // Get push template
1462
                $push_template_uuid = Functions::sanitizeFilterString($form->get('push_template_id')->getValue());
1472
            $push_template_uuid = Functions::sanitizeFilterString($form->get('push_template_id')->getValue());
1463
                $pushMapper = PushMapper::getInstance($this->adapter);
1473
            $pushMapper = PushMapper::getInstance($this->adapter);
1464
                $pushTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
1474
            $pushTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
-
 
1475
            $pushTemplate = $pushTemplateMapper->fetchOneByUuid($push_template_uuid);
-
 
1476
            
-
 
1477
            if(!$pushTemplate) {
-
 
1478
                return new JsonModel([
-
 
1479
                    'success' => false,
-
 
1480
                    'data' => 'ERROR_PUSH_TEMPLATE_NOT_FOUND'
-
 
1481
                ]);
-
 
1482
            }
-
 
1483
 
-
 
1484
            // Initialize push notification process
-
 
1485
            $applicationMapper = ApplicationMapper::getInstance($this->adapter);
-
 
1486
            $application = $applicationMapper->fetchOne(Application::TWOGETSKILLS);
-
 
1487
            
-
 
1488
            $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
-
 
1489
            
-
 
1490
            $push_to_send = 0;
-
 
1491
 
-
 
1492
            // Process each selected user
1465
                $pushTemplate = $pushTemplateMapper->fetchOneByUuid($push_template_uuid);
1493
            $userMapper = UserMapper::getInstance($this->adapter);
Línea -... Línea 1494...
-
 
1494
            $deviceHistoryMapper = DeviceHistoryMapper::getInstance($this->adapter);
-
 
1495
            foreach($customer_uuids as $customer_uuid)
-
 
1496
            {    
-
 
1497
                $user = $userMapper->fetchOneByUuid($customer_uuid);
Línea -... Línea 1498...
-
 
1498
                if(!$user) {
-
 
1499
                    continue;
Línea 1466... Línea -...
1466
                
-
 
1467
                if(!$pushTemplate) {
-
 
1468
                    return new JsonModel([
-
 
1469
                        'success' => false,
-
 
1470
                        'data' => 'ERROR_PUSH_TEMPLATE_NOT_FOUND'
-
 
1471
                    ]);
-
 
1472
                }
-
 
1473
                
-
 
1474
                
-
 
1475
                
-
 
1476
                $applicationMapper = ApplicationMapper::getInstance($this->adapter);
-
 
1477
                $application = $applicationMapper->fetchOne(Application::TWOGETSKILLS);
-
 
1478
                
-
 
1479
                $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
-
 
1480
                
-
 
1481
                $push_to_send = 0;
-
 
1482
                
-
 
1483
                
-
 
1484
                
-
 
1485
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
1486
                $deviceHistoryMapper = DeviceHistoryMapper::getInstance($this->adapter);
-
 
1487
                foreach($customer_uuids as $customer_uuid)
1500
                }
1488
                {
-
 
1489
                    
-
 
1490
                    
-
 
1491
                    $user = $userMapper->fetchOneByUuid($customer_uuid);
-
 
1492
                    if(!$user) {
-
 
1493
                        continue;
-
 
Línea 1494... Línea -...
1494
                    }
-
 
1495
                    
-
 
-
 
1501
                
1496
                    $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($user->id, $capsule->id);
1502
                $topicUser = $topicUserMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);
Línea 1497... Línea 1503...
1497
                    if(!$capsuleUser) {
1503
                if(!$topicUser) {
-
 
1504
                    continue;
1498
                        continue;
1505
                }
1499
                    }
-
 
1500
                    
1506
                
-
 
1507
                // Get user's latest device
1501
                    
1508
                $device = $deviceHistoryMapper->fetchLastDeviceByApplicationIdAndUserId(Application::TWOGETSKILLS, $user->id);
1502
                    //$token = $deviceHistoryMapper->fetchLastDeviceTokenByApplicationIdAndUserId(Application::TWOGETSKILLS, $user->id);
1509
                
1503
                    $device = $deviceHistoryMapper->fetchLastDeviceByApplicationIdAndUserId(Application::TWOGETSKILLS, $user->id);
1510
                if($device && $device->token) {
1504
                    
-
 
1505
                    
-
 
1506
                    
-
 
1507
                    if($device && $device->token) {
-
 
1508
                        
-
 
1509
                        $key = $application->key;
1511
                    
1510
                        if($device->variant_id) {
-
 
1511
                            
1512
                    $key = $application->key;
Línea -... Línea 1513...
-
 
1513
                    if($device->variant_id) {
-
 
1514
                        
-
 
1515
                        $applicationVariantMapper = ApplicationVariantMapper::getInstance($this->adapter);
1512
                            $applicationVariantMapper = ApplicationVariantMapper::getInstance($this->adapter);
1516
                        $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndVariantId($device->application_id, $device->variant_id);
1513
                            $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndVariantId($device->application_id, $device->variant_id);
1517
                        if($applicationVariant) {
1514
                            if($applicationVariant) {
1518
                            $key = $applicationVariant->key;
1515
                                $key = $applicationVariant->key;
1519
                        } else {
1516
                            } else {
1520
                            $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndDefault($device->application_id);
-
 
1521
                            if($applicationVariant) {
-
 
1522
                                $key = $applicationVariant->key;
-
 
1523
                            }
-
 
1524
                        }
1517
                                $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndDefault($device->application_id);
1525
                        
1518
                                if($applicationVariant) {
-
 
1519
                                    $key = $applicationVariant->key;
-
 
1520
                                }
-
 
1521
                            }
-
 
1522
                            
1526
                    }
1523
                        }
1527
                    
1524
                        
1528
                    // Create push notification
1525
                        $push = new Push();
1529
                    $push = new Push();
1526
                        $push->status = Push::STATUS_PENDING;
1530
                    $push->status = Push::STATUS_PENDING;
1527
                        $push->data = json_encode([
1531
                    $push->data = json_encode([
1528
                            'server' => [
1532
                        'server' => [
1529
                                'key' => $key,
1533
                            'key' => $key,
1530
                            ],
1534
                        ],
1531
                            'push' => [
-
 
1532
                                'registration_ids'   => [
1535
                        'push' => [
1533
                                    $device->token,
-
 
1534
                                ],
-
 
1535
                                'notification' => [
-
 
1536
                                    'body' =>  $pushTemplate->body,
-
 
1537
                                    'title' => $pushTemplate->title,
1536
                            'registration_ids'   => [
1538
                                    'vibrate' => 1,
-
 
1539
                                    'sound' =>  1
-
 
1540
                                ],
-
 
1541
                                'data' => [
-
 
1542
                                    'command' => 'content-refresh',
-
 
1543
                                    'new_capsules' => '0',
-
 
1544
                                ]
-
 
1545
                            ]
-
 
1546
                        ]);
1537
                                $device->token,
-
 
1538
                            ],
-
 
1539
                            'notification' => [
-
 
1540
                                'body' =>  $pushTemplate->body,
-
 
1541
                                'title' => $pushTemplate->title,
-
 
1542
                                'vibrate' => 1,
1547
                        
1543
                                'sound' =>  1
1548
                        if($pushMapper->insert($push)) {
-
 
1549
                            $push_to_send = $push_to_send + 1;
-
 
1550
                        }
-
 
1551
                        
-
 
1552
                    }
-
 
1553
                }
-
 
1554
                
-
 
1555
                if(0 == $push_to_send) {
-
 
1556
                    return new JsonModel([
-
 
1557
                        'success' => false,
-
 
1558
                        'data' => 'ERROR_NO_USER_DEVICES_WERE_FOUND_TO_SEND_PUSH'
-
 
1559
                    ]);
-
 
1560
                }
-
 
1561
                
-
 
1562
                
-
 
1563
                
-
 
1564
                
1544
                            ],
1565
                
1545
                            'data' => [
1566
                return new JsonModel([
-
 
1567
                    'success' => true,
1546
                                'command' => 'content-refresh',
1568
                    'data' => [
-
 
1569
                        'push_to_send' => $push_to_send,
1547
                                'new_topics' => '0',
1570
                    ]
-
 
1571
                ]);
-
 
1572
                
-
 
1573
                
1548
                            ]
1574
                
1549
                        ]
1575
                
1550
                    ]);
1576
                
1551
                    
1577
            } else {
1552
                    if($pushMapper->insert($push)) {
-
 
1553
                        $push_to_send = $push_to_send + 1;
-
 
1554
                    }
-
 
1555
                    
-
 
1556
                }
-
 
1557
            }
-
 
1558
            
-
 
1559
            // Validate notifications were created
-
 
1560
            if(0 == $push_to_send) {
-
 
1561
                return new JsonModel([
-
 
1562
                    'success' => false,
-
 
1563
                    'data' => 'ERROR_NO_USER_DEVICES_WERE_FOUND_TO_SEND_PUSH'
-
 
1564
                ]);
-
 
1565
            }
1578
                
1566
            
1579
                $messages = [];
-
 
1580
                $form_messages = (array) $form->getMessages();
-
 
1581
                foreach($form_messages  as $fieldname => $field_messages)
-
 
1582
                {
-
 
1583
                    $messages[$fieldname] = array_values($field_messages);
-
 
1584
                }
1567
            return new JsonModel([
1585
                
-
 
1586
                return new JsonModel([
-
 
1587
                    'success'   => false,
1568
                'success' => true,