Proyectos de Subversion LeadersLinked - Services

Rev

Rev 191 | Rev 225 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
119 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Mvc\Controller\AbstractActionController;
7
use Laminas\View\Model\JsonModel;
8
use LeadersLinked\Library\Functions;
9
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
10
use LeadersLinked\Mapper\QueryMapper;
11
use LeadersLinked\Mapper\UserMapper;
12
use Laminas\Db\Sql\Select;
13
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleUserMapper;
14
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleCommentMapper;
15
use LeadersLinked\Form\Service\CapsuleCommentForm;
16
use LeadersLinked\Model\CompanyMicrolearningCapsuleComment;
17
use LeadersLinked\Model\CompanyMicrolearningCapsuleUser;
18
use LeadersLinked\Model\CompanyMicrolearningAnswer;
19
use LeadersLinked\Mapper\CompanyMicrolearningUserProgressMapper;
20
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
21
use LeadersLinked\Mapper\CompanyMicrolearningUserLogMapper;
22
use LeadersLinked\Model\CompanyMicrolearningUserLog;
23
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
24
use LeadersLinked\Mapper\CompanyMapper;
25
use LeadersLinked\Model\CompanyMicrolearningUserProgress;
26
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserMapper;
27
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserCompanyMapper;
28
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserFunctionMapper;
29
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserGroupMapper;
30
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserInstitutionMapper;
31
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserPartnerMapper;
32
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserProgramMapper;
33
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserStudentTypeMapper;
34
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserSectorMapper;
35
 
36
 
37
class MicrolearningUserAccessGrantedIds
38
{
39
    public $companies;
40
    public $topics;
41
    public $capsules;
42
 
43
 
44
    public function __construct()
45
    {
46
        $this->companies    = [];
47
        $this->topics       = [];
48
        $this->capsules     = [];
49
    }
50
}
51
 
52
class MicrolearningController extends AbstractActionController
53
{
54
 
55
    /**
56
     *
57
     * @var \Laminas\Db\Adapter\AdapterInterface
58
     */
59
    private $adapter;
60
 
61
    /**
62
     *
63
     * @var \LeadersLinked\Cache\CacheInterface
64
     */
65
    private $cache;
66
 
67
 
68
    /**
69
     *
70
     * @var \Laminas\Log\LoggerInterface
71
     */
72
    private $logger;
73
 
74
    /**
75
     *
76
     * @var array
77
     */
78
    private $config;
79
 
80
 
81
    /**
82
     *
83
     * @var \Laminas\Mvc\I18n\Translator
84
     */
85
    private $translator;
86
 
87
 
88
    /**
89
     *
90
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
91
     * @param \LeadersLinked\Cache\CacheInterface $cache
92
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
93
     * @param array $config
94
     * @param \Laminas\Mvc\I18n\Translator $translator
95
     */
96
    public function __construct($adapter, $cache, $logger, $config, $translator)
97
    {
98
        $this->adapter      = $adapter;
99
        $this->cache        = $cache;
100
        $this->logger       = $logger;
101
        $this->config       = $config;
102
        $this->translator   = $translator;
103
    }
104
 
105
    public function indexAction()
106
    {
107
        $request = $this->getRequest();
108
 
109
        if($request->isGet()) {
110
            return new JsonModel([
111
                'success' => true,
112
                'data' =>  [
113
                    'link_companies' => $this->url()->fromRoute('microlearning/companies',[], ['force_canonical' => true]),
114
                    'link_timeline' => $this->url()->fromRoute('microlearning/timeline',[], ['force_canonical' => true]),
115
                    'link_last_capsule_in_progress' => $this->url()->fromRoute('microlearning/last-capsule-in-progress',[], ['force_canonical' => true]),
116
                    'link_profile' => $this->url()->fromRoute('microlearning/profile',[], ['force_canonical' => true]),
117
                    'link_topics' => $this->url()->fromRoute('microlearning/topics',[], ['force_canonical' => true]),
118
                    'link_capsules_pending' => $this->url()->fromRoute('microlearning/capsules-pending',[], ['force_canonical' => true]),
119
                    'link_capsules_completed' => $this->url()->fromRoute('microlearning/capsules-completed',[], ['force_canonical' => true]),
120
                    'link_capsules_in_progress' => $this->url()->fromRoute('microlearning/capsules-in-progress',[], ['force_canonical' => true]),
121
 
122
 
123
                ]
124
            ]);
125
        }
126
 
127
        return new JsonModel([
128
            'success' => false,
129
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
130
        ]);
131
    }
132
 
133
    public function companiesAction()
134
    {
135
 
136
        $request = $this->getRequest();
137
 
138
        if($request->isGet()) {
139
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
140
            $currentNetwork = $currentNetworkPlugin->getNetwork();
141
 
142
 
143
            $accessGrantedIds = $this->getAccessGranted();
144
            $companyMapper = CompanyMapper::getInstance($this->adapter);
145
            $records = $companyMapper->fetchAllByIdsAndNetworkId($accessGrantedIds->companies, $currentNetwork->id);
146
 
147
 
148
            $companies = [];
149
            foreach($records as $record)
150
            {
151
                array_push($companies, [
164 efrain 152
                    'uuid' => $record->uuid,
119 efrain 153
                    'name' => $record->name,
164 efrain 154
                    'image' => $this->url()->fromRoute('storage',['type' => 'company', 'code' => $record->uuid, 'filename' => $record->image], ['force_canonical' => true]),
119 efrain 155
                    'link_progress' => $this->url()->fromRoute('microlearning/progress',['id' => $record->uuid], ['force_canonical' => true]),
156
                ]);
157
            }
158
 
159
            return new JsonModel([
160
                'success' => true,
161
                'data' =>  $companies
162
            ]);
163
 
164
 
165
        }
166
        return new JsonModel([
167
            'success' => false,
168
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
169
        ]);
170
    }
171
 
172
 
173
 
174
    public function capsuleCommentsAction()
175
    {
176
 
177
        $request = $this->getRequest();
178
 
179
        if($request->isGet()) {
180
            $serviceDatetimeFormat = $this->config['leaderslinked.services.datetime'];
181
 
182
            $currentUserPlugin = $this->plugin('currentUserPlugin');
183
            $currentUser = $currentUserPlugin->getUser();
184
 
185
            $capsule_id = $this->params()->fromRoute('capsule_id');
186
 
187
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
188
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_id);
189
 
190
            if(!$capsule) {
191
                return new JsonModel([
192
                    'success' => false,
193
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
194
 
195
                ]);
196
 
197
            }
198
 
199
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
200
            $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
201
            if(! $capsuleUser) {
202
                return new JsonModel([
203
                    'success' => false,
204
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE',
205
                ]);
206
            }
207
 
208
            $userMapper = UserMapper::getInstance($this->adapter);
209
            $users = [];
210
 
211
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
212
            $records = $capsuleCommentMapper->fetchAllByCapsuleId($capsule->id);
213
 
214
            $comments = [];
215
            foreach($records as $record)
216
            {
217
 
218
                if(isset($users[$record->user_id])) {
219
 
220
                    $user = $users[$record->user_id];
221
 
222
                } else {
223
 
224
                    $user = $userMapper->fetchOne($record->user_id);
225
                    if(!$user) {
226
                        continue;
227
                    }
228
 
229
                    $users[$record->user_id] = $user;
230
 
231
 
232
                }
233
 
234
 
235
                $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
236
 
237
                array_push($comments, [
238
                    'date' => $dt->format($serviceDatetimeFormat),
239
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image], ['force_canonical' => true]),
240
                    'fullname' => trim(trim($user->first_name) . ' ' . trim($user->last_name)),
241
                    'rating' => strval($record->rating),
242
                    'comment' => $record->comment,
243
                    'link_delete' => $record->user_id == $currentUser->id ? $this->url()->fromRoute('microlearning/capsules-comments/delete', ['capsule_id' => $capsule->uuid, 'comment_id' => $record->uuid], ['force_canonical' => true]) : '',
244
                ]);
245
            }
246
 
247
            $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
248
 
249
            return new JsonModel([
250
                'success' => true,
251
                'data' => [
252
                    'comments' => $comments,
253
                    'capsule' => [
254
                        'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
255
                        'total_rating' => strval($dataCountAndRatingAverage['total_rating'])
256
                    ]
257
                ]
258
 
259
            ]);
260
 
261
        }
262
 
263
        return new JsonModel([
264
            'success' => false,
265
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
266
        ]);
267
    }
268
 
269
 
270
 
271
    public function capsuleDeleteMyCommentAction()
272
    {
273
 
274
        $request = $this->getRequest();
275
 
276
        if($request->isPost()) {
277
 
278
            $currentUserPlugin = $this->plugin('currentUserPlugin');
279
            $currentUser = $currentUserPlugin->getUser();
280
 
281
            $capsule_id = $this->params()->fromRoute('capsule_id');
282
            $comment_id = $this->params()->fromRoute('comment_id');
283
 
284
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
285
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_id);
286
 
287
            if(!$capsule) {
288
                return new JsonModel([
289
                    'success' => false,
290
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
291
 
292
                ]);
293
 
294
            }
295
 
296
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
297
            $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
298
            if(! $capsuleUser) {
299
                return new JsonModel([
300
                    'success' => false,
301
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE',
302
                ]);
303
            }
304
 
305
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
306
            $capsuleComment = $capsuleCommentMapper->fetchOneByUuid($comment_id);
307
 
308
            if(!$capsuleComment) {
309
                return new JsonModel([
310
                    'success' => false,
311
                    'data' => 'ERROR_CAPSULE_COMMENT_NOT_FOUND',
312
                ]);
313
            }
314
 
315
            if($capsuleComment->capsule_id != $capsule->id || $capsuleComment->user_id != $currentUser->id) {
316
                return new JsonModel([
317
                    'success' => false,
318
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE_COMMENT',
319
                ]);
320
            }
321
 
322
 
323
            $result = $capsuleCommentMapper->delete($capsuleComment->id);
324
            if($result) {
325
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
326
 
327
 
328
 
329
 
330
                return new JsonModel([
331
                    'success' => true,
332
                    'data' => [
333
                        'message' => 'LABEL_CAPSULE_COMMENT_HAVE_BEEN_SUCCESSFULLY_DELETE',
334
                        'capsule' => [
335
                            'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
336
                            'total_rating' => strval($dataCountAndRatingAverage['total_rating'])
337
                        ]
338
                    ],
339
 
340
                ]);
341
            } else {
342
                return new JsonModel([
343
                    'success' => false,
344
                    'data' => $capsuleCommentMapper->getError()
345
 
346
                ]);
347
            }
348
 
349
 
350
 
351
        }
352
 
353
        return new JsonModel([
354
            'success' => false,
355
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
356
        ]);
357
    }
358
 
359
    public function capsuleAddMyCommentAction()
360
    {
361
 
362
        $request = $this->getRequest();
363
 
364
        if($request->isPost()) {
365
 
366
            $currentUserPlugin = $this->plugin('currentUserPlugin');
367
            $currentUser = $currentUserPlugin->getUser();
368
 
369
            $capsule_id = $this->params()->fromRoute('capsule_id');
370
 
371
 
372
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
373
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_id);
374
 
375
            if(!$capsule) {
376
                return new JsonModel([
377
                    'success' => false,
378
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
379
 
380
                ]);
381
 
382
            }
383
 
384
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
385
            $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
386
            if(! $capsuleUser) {
387
                return new JsonModel([
388
                    'success' => false,
389
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE',
390
                ]);
391
            }
392
 
393
            //$rawdata = file_get_contents("php://input");
394
            //  error_log('$rawdata = ' . $rawdata );
395
 
396
 
397
            $form = new  CapsuleCommentForm();
398
            $dataPost = $request->getPost()->toArray();
399
            $dataPost['added_on'] = $capsuleMapper->getDatebaseNow();
400
 
401
 
402
            $form->setData($dataPost);
403
 
404
            if($form->isValid()) {
405
                $dataPost = (array) $form->getData();
406
 
407
 
408
                $capsuleComment = new CompanyMicrolearningCapsuleComment();
409
                $capsuleComment->company_id = $capsule->company_id;
410
                $capsuleComment->topic_id = $capsule->topic_id;
411
                $capsuleComment->capsule_id = $capsule->id;
412
                $capsuleComment->user_id = $currentUser->id;
413
                $capsuleComment->comment = $dataPost['comment'];
414
                $capsuleComment->rating = strval($dataPost['rating']);
415
                $capsuleComment->added_on =  $dataPost['added_on'];
416
 
417
 
418
                $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
419
                $result = $capsuleCommentMapper->insert($capsuleComment);
420
                if($result) {
421
 
422
                    $capsuleComment = $capsuleCommentMapper->fetchOne($capsuleComment->id);
423
 
424
                    $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
425
 
426
 
427
 
428
                    return new JsonModel([
429
                        'success' => true,
430
                        'data' => [
431
                            'message' =>'LABEL_CAPSULE_COMMENT_HAVE_BEEN_SUCCESSFULLY_ADDED',
432
 
433
                            'comment' => [
434
                                'comment' => $capsuleComment->comment,
435
                                'rating' => $capsuleComment->rating,
436
                                'link_delete' => $this->url()->fromRoute('microlearning/capsules-comments/delete', ['capsule_id' => $capsule->uuid, 'comment_id' => $capsuleComment->uuid], ['force_canonical' => true])
437
                            ],
438
                            'capsule' => [
439
                                'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
440
                                'total_rating' => strval($dataCountAndRatingAverage['total_rating'])
441
                            ]
442
                        ]
443
 
444
                    ]);
445
                } else {
446
                    return new JsonModel([
447
                        'success' => false,
448
                        'data' => $capsuleCommentMapper->getError()
449
 
450
                    ]);
451
                }
452
 
453
 
454
            } else {
455
                $messages = [];
456
                $form_messages = (array) $form->getMessages();
457
                foreach($form_messages  as $fieldname => $field_messages)
458
                {
459
 
460
                    $messages[$fieldname] = array_values($field_messages);
461
                }
462
 
463
                return new JsonModel([
464
                    'success'   => false,
465
                    'data'   => $messages
466
                ]);
467
            }
468
 
469
 
470
 
471
 
472
        }
473
 
474
        return new JsonModel([
475
            'success' => false,
476
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
477
        ]);
478
    }
479
 
480
    public function lastCapsuleInProgressAction()
481
    {
482
        $request = $this->getRequest();
483
 
484
        if($request->isGet())
485
        {
486
            $currentUserPlugin = $this->plugin('currentUserPlugin');
487
            $currentUser = $currentUserPlugin->getUser();
488
 
489
            $accessGrantedIds = $this->getAccessGranted();
490
 
491
 
492
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
493
            $userProgress = $userProgressMapper->fetchOneLastCapsuleInProgressByUserIdAndCapsuleIds($currentUser->id, $accessGrantedIds->capsules);
494
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
495
 
496
            if($userProgress) {
497
                $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
498
                $capsule = $capsuleMapper->fetchOne($userProgress->capsule_id);
499
 
500
                $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
501
 
502
 
503
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
504
 
505
                $topic = $topicMapper->fetchOne($capsule->topic_id);
506
 
507
                $response = [
508
                    'success' => true,
509
                    'data' => [
164 efrain 510
                        'uuid'              => $capsule->uuid,
119 efrain 511
                        'name'              => $capsule->name ? $capsule->name : '',
512
                        'description'       => $capsule->description ? $capsule->description : '',
164 efrain 513
                        'image'             => $capsule->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image ], ['force_canonical' => true])  : '',
119 efrain 514
                        'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
515
                        'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
516
                        'link_slides'       => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
517
                        'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
518
                        'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
519
                        'completed'         => $userProgress->completed,
145 efrain 520
                        'progress'          => $userProgress->progress,
162 efrain 521
                        'link_get'          => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
119 efrain 522
                        'added_on'          => $userProgress->added_on,
523
                        'updated_on'        => $userProgress->updated_on
524
                    ]
525
                ];
526
 
527
 
528
            } else {
529
                $response = [
530
                    'success' => true,
531
                    'data' => [
532
 
533
                    ]
534
                ];
535
            }
536
 
537
 
538
        } else {
539
 
540
            $response = [
541
                'success' => false,
542
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
543
            ];
544
 
545
 
546
        }
547
 
548
        return new JsonModel($response);
549
    }
550
 
551
    public function capsulesPendingAction()
552
    {
553
        $request = $this->getRequest();
554
        if($request->isGet()) {
555
            $currentUserPlugin = $this->plugin('currentUserPlugin');
556
            $currentUser = $currentUserPlugin->getUser();
557
 
558
            $name = Functions::sanitizeFilterString($this->params()->fromQuery('name'));
559
 
560
 
561
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
562
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
563
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
564
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
565
 
566
            $accessGranted = $this->getAccessGranted();
567
 
568
 
569
            $topics = [];
570
            $capsules = [];
571
 
572
            foreach($accessGranted->capsules as $capsule_id)
573
            {
574
                $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
575
                if($userProgress) {
576
                    continue;
577
                }
578
 
579
                $capsule = $capsuleMapper->fetchOne($capsule_id);
580
 
581
                if($name) {
582
                    if(empty($name) || stripos($capsule->name, $name) === false) {
583
                        continue;
584
                    }
585
                }
586
 
587
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
588
 
589
                if(isset($topics[$capsule->topic_id])) {
590
                    $topic = $topics[$capsule->topic_id];
591
                } else {
592
                    $topic = $topicMapper->fetchOne($capsule->topic_id);
593
                    $topics[ $capsule->topic_id ] = $topic;
594
                }
595
 
596
 
597
                array_push($capsules, [
598
                    'uuid'              => $capsule->uuid,
599
                    'name'              => $capsule->name ? $capsule->name : '',
600
                    'description'       => $capsule->description ? $capsule->description : '',
164 efrain 601
                    'image'             => $capsule->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image ], ['force_canonical' => true])  : '',
119 efrain 602
                    'position'          => $capsule->order,
603
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
604
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
605
                    'link_slides'       => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
606
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
607
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
191 efrain 608
                    'progress'          => 0,
162 efrain 609
                    'link_get'          => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
119 efrain 610
                    'added_on'          => $capsule->added_on,
611
                    'updated_on'        => $capsule->updated_on,
612
                ]);
613
            }
614
 
615
            usort($capsules, function($a, $b) {
616
                $result = strcasecmp($a['name'], $b['name']);
617
                if($result < 0) {
618
                    return 1;
619
                } else if($result > 0) {
620
                    return -1;
621
                } else  {
622
                    return  0;
623
                }
624
 
625
            });
626
 
627
 
628
            return new JsonModel([
629
                'success' => true,
630
                'data' => $capsules
631
            ]);
632
 
633
 
634
 
635
        }
636
 
637
        return new JsonModel([
638
            'success' => false,
639
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
640
        ]);
641
 
642
    }
643
 
644
    public function capsulesCompletedAction()
645
    {
646
        $request = $this->getRequest();
647
        if($request->isGet()) {
648
            $currentUserPlugin = $this->plugin('currentUserPlugin');
649
            $currentUser = $currentUserPlugin->getUser();
650
 
651
            $name = Functions::sanitizeFilterString($this->params()->fromQuery('name'));
652
 
653
 
654
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
655
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
656
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
657
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
658
 
659
            $accessGranted = $this->getAccessGranted();
660
 
661
            $topics = [];
662
            $capsules = [];
663
 
664
            foreach($accessGranted->capsules as $capsule_id)
665
            {
666
                $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
667
                if(!$userProgress) {
668
                    continue;
669
                }
670
 
671
                if(!$userProgress->completed) {
672
                    continue;
673
                }
674
 
675
 
676
 
677
                $capsule = $capsuleMapper->fetchOne($capsule_id);
678
 
679
                if($name) {
680
                    if(empty($name) || stripos($capsule->name, $name) === false) {
681
                        continue;
682
                    }
683
                }
684
 
685
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
686
 
687
                if(isset($topics[$capsule->topic_id])) {
688
                    $topic = $topics[$capsule->topic_id];
689
                } else {
690
                    $topic = $topicMapper->fetchOne($capsule->topic_id);
691
                    $topics[ $capsule->topic_id ] = $topic;
692
                }
693
 
694
 
695
 
696
                array_push($capsules, [
697
                    'uuid'              => $capsule->uuid,
698
                    'name'              => $capsule->name ? $capsule->name : '',
699
                    'description'       => $capsule->description ? $capsule->description : '',
164 efrain 700
                    'image'             => $capsule->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image ], ['force_canonical' => true])  : '',
119 efrain 701
                    'position'          => $capsule->order,
702
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
703
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
704
                    'link_slides'       => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
705
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
706
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
145 efrain 707
                    'progress'          => $userProgress->progress,
162 efrain 708
                    'link_get'          => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
119 efrain 709
                    'added_on'          => $capsule->added_on,
710
                    'updated_on'        => $capsule->updated_on,
711
                ]);
712
            }
713
 
714
            usort($capsules, function($a, $b) {
715
                $result = strcasecmp($a['name'], $b['name']);
716
                if($result < 0) {
717
                    return 1;
718
                } else if($result > 0) {
719
                    return -1;
720
                } else  {
721
                    return  0;
722
                }
723
 
724
            });
725
 
726
 
727
            return new JsonModel([
728
                'success' => true,
729
                'data' => $capsules
730
            ]);
731
 
732
        }
733
 
734
        return new JsonModel([
735
            'success' => false,
736
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
737
        ]);
738
    }
739
 
740
    public function capsulesInProgressAction()
741
    {
742
        $request = $this->getRequest();
743
        if($request->isGet()) {
744
            $currentUserPlugin = $this->plugin('currentUserPlugin');
745
            $currentUser = $currentUserPlugin->getUser();
746
 
747
            $name = Functions::sanitizeFilterString($this->params()->fromQuery('name'));
748
 
749
 
750
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
751
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
752
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
753
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
754
 
755
            $accessGranted = $this->getAccessGranted();
756
 
757
            $topics = [];
758
            $capsules = [];
759
 
760
            foreach($accessGranted->capsules as $capsule_id)
761
            {
762
                $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
763
                if(!$userProgress) {
764
                    continue;
765
                }
766
 
767
                if($userProgress->completed) {
768
                    continue;
769
                }
770
 
771
 
772
 
773
                $capsule = $capsuleMapper->fetchOne($capsule_id);
774
 
775
                if($name) {
776
                    if(empty($name) || stripos($capsule->name, $name) === false) {
777
                        continue;
778
                    }
779
                }
780
 
781
 
782
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
783
 
784
                if(isset($topics[$capsule->topic_id])) {
785
                    $topic = $topics[$capsule->topic_id];
786
                } else {
787
                    $topic = $topicMapper->fetchOne($capsule->topic_id);
788
                    $topics[ $capsule->topic_id ] = $topic;
789
                }
790
 
791
 
792
 
793
 
794
                array_push($capsules, [
795
                    'uuid'              => $capsule->uuid,
796
                    'name'              => $capsule->name ? $capsule->name : '',
797
                    'description'       => $capsule->description ? $capsule->description : '',
164 efrain 798
                    'image'             => $capsule->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image ], ['force_canonical' => true])  : '',
119 efrain 799
                    'position'          => $capsule->order,
800
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
801
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
802
                    'link_slides'       => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
803
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
804
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
145 efrain 805
                    'progress'          => $userProgress->progress,
162 efrain 806
                    'link_get'          => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
119 efrain 807
                    'added_on'          => $capsule->added_on,
808
                    'updated_on'        => $capsule->updated_on,
809
                ]);
810
            }
811
 
812
            usort($capsules, function($a, $b) {
813
                $result = strcasecmp($a['name'], $b['name']);
814
                if($result < 0) {
815
                    return 1;
816
                } else if($result > 0) {
817
                    return -1;
818
                } else  {
819
                    return  0;
820
                }
821
 
822
            });
823
 
824
 
825
            return new JsonModel([
826
                'success' => true,
827
                'data' => $capsules
828
            ]);
829
 
830
 
831
 
832
        }
833
 
834
        return new JsonModel([
835
            'success' => false,
836
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
837
        ]);
838
    }
839
 
840
 
841
    public function timelineAction()
842
    {
843
 
844
        $request = $this->getRequest();
845
        if($request->isGet()) {
846
            $currentUserPlugin = $this->plugin('currentUserPlugin');
847
            $currentUser = $currentUserPlugin->getUser();
848
 
849
 
850
            $page = intval($this->params()->fromQuery('page'), 10);
851
 
852
            $activities = [
853
                CompanyMicrolearningUserLog::ACTIVITY_SIGNIN            => 'LABEL_MICROLEARNING_ACTIVITY_SIGNIN',
854
                CompanyMicrolearningUserLog::ACTIVITY_SIGNOUT           => 'LABEL_MICROLEARNING_ACTIVITY_SIGNOUT',
855
                CompanyMicrolearningUserLog::ACTIVITY_START_TOPIC       => 'LABEL_MICROLEARNING_ACTIVITY_START_TOPIC',
856
                CompanyMicrolearningUserLog::ACTIVITY_START_CAPSULE     => 'LABEL_MICROLEARNING_ACTIVITY_START_CAPSULE',
857
                CompanyMicrolearningUserLog::ACTIVITY_VIEW_SLIDE        => 'LABEL_MICROLEARNING_ACTIVITY_VIEW_SLIDE',
858
                CompanyMicrolearningUserLog::ACTIVITY_TAKE_A_TEST       => 'LABEL_MICROLEARNING_ACTIVITY_TAKE_A_TEST',
859
                CompanyMicrolearningUserLog::ACTIVITY_RETAKE_A_TEST     => 'LABEL_MICROLEARNING_ACTIVITY_RETAKE_A_TEST',
860
                CompanyMicrolearningUserLog::ACTIVITY_APPROVED_TEST     => 'LABEL_MICROLEARNING_ACTIVITY_APPROVED_TEST',
861
                CompanyMicrolearningUserLog::ACTIVITY_COMPLETED_CAPSULE => 'LABEL_MICROLEARNING_ACTIVITY_COMPLETED_CAPSULE',
862
                CompanyMicrolearningUserLog::ACTIVITY_COMPLETED_TOPIC   => 'LABEL_MICROLEARNING_ACTIVITY_COMPLETED_TOPIC',
863
            ];
864
 
865
 
866
 
867
            $companyMicrolearningUserLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
868
            $paginator = $companyMicrolearningUserLogMapper->getAllMessagesPaginatorByUserId($currentUser->id, $page);
869
 
870
            $items = [];
871
            foreach($paginator as $record)
872
            {
873
                $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
874
 
875
                array_push($items, [
876
                    'activity' => $activities[$record->activity],
877
                    'added_on' => $dt->format('d/m/Y H:i a')
878
                ]);
879
            }
880
 
881
 
882
            return new JsonModel([
883
                'success' => true,
884
                'data' => [
885
                    'total' => [
886
                        'count' => $paginator->getTotalItemCount(),
887
                        'pages' => $paginator->getPages()->pageCount,
888
                    ],
889
                    'current' => [
890
                        'items'    => $items,
891
                        'page'     => $paginator->getCurrentPageNumber(),
892
                        'count'    => $paginator->getCurrentItemCount(),
893
                    ]
894
                ]
895
            ]);
896
 
897
 
898
        } else {
899
            return new JsonModel([
900
                'success' => false,
901
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
902
            ]);
903
        }
904
    }
905
 
906
    /**
907
     * Valores para la generación de los gráficos de progreso
908
     * Para las repuesta afirmativa
909
     * [
910
     *  'success' => true,
911
     *      'data' => [
912
     *          'topicTotal' => cantidad total de tópicos,
913
     *          'topicStarted' => cantidad de tópicos iniciados,
914
     *          'topicIncompleted' => cantidad de tópicos incompletos,
915
     *          'topicCompleted' => cantidad de tópicos completos,
916
     *          'percentCompleted' => % de diapositivas completados ,
917
     *          'percentIncompleted' => % de diapositivas incompletos ,
918
     *          'percentWithoutReturning' => % de cápsulas sin retorno después de completada,
919
     *          'percentWithReturning' => % de cápsulas con retorno después de completada,
920
     *       ],
921
     * ]
922
     *
923
     *
924
     *  En caso contrario
925
     *  [
926
     *      'success' => false,
927
     *      'data' => mensaje de error
928
     *  ]
929
     *
930
     *
931
     * @return \Laminas\View\Model\JsonModel
932
     */
933
    public function progressAction()
934
    {
935
 
936
        $request = $this->getRequest();
937
        if($request->isGet()) {
938
            $currentUserPlugin = $this->plugin('currentUserPlugin');
939
            $currentUser = $currentUserPlugin->getUser();
940
 
941
 
942
            $accessGrantedIds = $this->getAccessGranted();
943
            $id = $this->params()->fromRoute('id');
944
 
945
            $companyMapper = CompanyMapper::getInstance($this->adapter);
946
            $company = $companyMapper->fetchOneByUuid($id);
947
 
948
            if(!$company) {
949
                $response = [
950
                    'success' => false,
951
                    'data' => 'ERROR_COMPANY_NOT_FOUND',
952
                ];
953
 
954
 
955
                return new JsonModel($response);
956
            }
957
 
958
            if(!in_array($company->id, $accessGrantedIds->companies)) {
959
                $response = [
960
                    'success' => false,
961
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_COMPANY',
962
                ];
963
 
964
 
965
                return new JsonModel($response);
966
            }
967
 
968
            $capsuleTotal              = 0;
969
            $capsuleCompleted          = 0;
970
            $capsuleWithReturning      = 0;
971
            $capsuleWithoutReturning   = 0;
972
            $capsuleStarted            = 0;
973
            $capsuleToStart            = 0;
974
            $percentCompleted          = 0;
975
            $percentIncompleted        = 100;
976
 
977
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
978
            $topics = $topicMapper->fetchAllActiveByCompanyIdAndIds($company->id, $accessGrantedIds->topics);
979
 
980
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
981
            $progressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
982
 
983
 
984
            foreach($topics as $topic)
985
            {
986
                $resultCount = $capsuleMapper->fetchCountByCompanyIdAndTopicId($company->id, $topic->id);
987
                $capsuleTotal =  $capsuleTotal + $resultCount;
988
 
989
                $resultCount = $progressMapper->fetchCountCapsulesCompletedByIdAndTopicId($currentUser->id, $topic->id);
990
                $capsuleCompleted = $capsuleCompleted + $resultCount;
991
 
992
                $resultCount = $progressMapper->fetchCountCapsulesCompletedWithReturningByIdAndTopicId($currentUser->id, $topic->id);
993
                $capsuleWithReturning = $capsuleWithReturning + $resultCount;
994
 
995
                $resultCount = $progressMapper->fetchCountCapsulesCompletedWithoutReturningByIdAndTopicId($currentUser->id, $topic->id);
996
                $capsuleWithoutReturning = $capsuleWithoutReturning + $resultCount;
997
 
998
                $resultCount = $progressMapper->fetchCountCapsulesCompletedByIdAndTopicId($currentUser->id, $topic->id);
999
                $capsuleStarted = $capsuleStarted + $resultCount;
1000
            }
1001
 
1002
            $capsuleToStart = $capsuleTotal -  $capsuleStarted;
1003
 
1004
 
1005
            if($capsuleTotal > 0) {
1006
                $percentCompleted = ($capsuleCompleted * 100) /  $capsuleTotal;
1007
                $percentIncompleted = 100 - $percentCompleted;
1008
            }
1009
 
1010
 
1011
 
1012
            return new JsonModel([
1013
                'success' => true,
1014
                'data' => [
1015
                    'capsuleTotal' => $capsuleTotal,
1016
                    'capsuleCompleted' => $capsuleCompleted,
1017
                    'capsuleStarted' => $capsuleStarted,
1018
                    'capsuleToStart' => $capsuleToStart,
1019
                    'percentCompleted' => number_format($percentCompleted, 2, '.', ','),
1020
                    'percentIncompleted' => number_format($percentIncompleted, 2, '.', ','),
1021
                    'capsuleWithReturning' => $capsuleWithReturning,
1022
                    'capsuleWithoutReturning' => $capsuleWithoutReturning,
1023
                ],
1024
            ]);
1025
 
1026
 
1027
        } else {
1028
            return new JsonModel([
1029
                'success' => false,
1030
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1031
            ]);
1032
        }
1033
    }
1034
 
1035
 
1036
    public function topicsAction()
1037
    {
1038
        $request = $this->getRequest();
1039
        if($request->isGet()) {
1040
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1041
            $currentUser = $currentUserPlugin->getUser();
1042
 
1043
 
1044
            $data = [];
1045
            $accessGrantedIds = $this->getAccessGranted();
1046
 
1047
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1048
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1049
 
1050
 
1051
            foreach($accessGrantedIds->topics as $id)
1052
            {
1053
                $topic = $topicMapper->fetchOne($id);
1054
                if(!$topic) {
1055
                    continue;
1056
                }
1057
 
1058
                $userProgress = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $id);
1059
                if($userProgress) {
1060
                    $progress = $userProgress->progress;
1061
                    $completed = $userProgress->completed;
1062
                } else {
1063
                    $progress = 0;
1064
                    $completed = 0;
1065
                }
1066
 
1067
 
1068
 
1069
                array_push($data, [
164 efrain 1070
                    'uuid'          => $topic->uuid,
119 efrain 1071
                    'name'          => $topic->name ? $topic->name : '',
1072
                    'description'   => $topic->description ? $topic->description : '',
164 efrain 1073
                    'image'         => $topic->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-topic', 'code' => $topic->uuid, 'filename' => $topic->image ], ['force_canonical' => true]) : '',
119 efrain 1074
                    'progress'      => $progress,
1075
                    'completed'     => $completed,
1076
                    'order'         => $topic->order,
1077
                    'added_on'      => $topic->added_on,
1078
                    'updated_on'    => $topic->updated_on,
1079
                    'link_capsules' => $this->url()->fromRoute('microlearning/capsules', ['topic_id' => $topic->uuid], ['force_canonical' => true]),
161 efrain 1080
                    'link_get'      => $this->url()->fromRoute('microlearning/get-topic', ['id' => $topic->uuid], ['force_canonical' => true]),
119 efrain 1081
 
1082
                ]);
1083
            }
1084
 
1085
            usort($data, function($a, $b) {
1086
 
1087
                $result =  $a['order'] <=> $b['order'];
1088
                if(0 == $result) {
1089
                    $result = strcasecmp($a['added_on'], $b['added_on']);
1090
                    if(0 == $result) {
1091
                        $result = strcasecmp($a['name'], $b['name']);
1092
                    }
1093
                }
1094
 
1095
                if($result < 0) {
1096
                    return 1;
1097
                } else if($result > 0) {
1098
                    return -1;
1099
                } else  {
1100
                    return  0;
1101
                }
1102
            });
1103
 
1104
 
1105
 
1106
                return new JsonModel([
1107
                    'success' => true,
1108
                    'data' => $data
1109
                ]);
1110
 
1111
        } else {
1112
            return new JsonModel([
1113
                'success' => false,
1114
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1115
            ]);
1116
        }
1117
    }
1118
 
161 efrain 1119
    public function getTopicAction()
1120
    {
1121
        $request = $this->getRequest();
1122
        if($request->isGet()) {
1123
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1124
            $currentUser = $currentUserPlugin->getUser();
1125
 
1126
 
1127
            $id = $this->params()->fromRoute('id');
1128
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1129
            $topic = $topicMapper->fetchOneByUuid($id);
1130
 
1131
            if(!$topic) {
1132
                return new JsonModel([
1133
                    'success' => false,
1134
                    'data' => 'ERROR_TOPIC_NOT_FOUND'
1135
                ]);
1136
            }
1137
 
1138
            $accessGrantedIds = $this->getAccessGranted();
1139
 
1140
            if(!in_array($topic->id, $accessGrantedIds->topics)) {
1141
                return new JsonModel([
1142
                    'success' => false,
1143
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
1144
                ]);
1145
            }
1146
 
1147
 
1148
            $data = [];
1149
            $accessGrantedIds = $this->getAccessGranted();
1150
 
1151
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1152
 
1153
            $userProgress = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $id);
1154
            if($userProgress) {
1155
                $progress = $userProgress->progress;
1156
                $completed = $userProgress->completed;
1157
            } else {
1158
                $progress = 0;
1159
                $completed = 0;
1160
            }
1161
 
1162
 
1163
 
1164
            $data = [
165 efrain 1165
                'uuid'          => $topic->uuid,
161 efrain 1166
                'name'          => $topic->name ? $topic->name : '',
1167
                'description'   => $topic->description ? $topic->description : '',
164 efrain 1168
                'image'         => $topic->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-topic', 'code' => $topic->uuid, 'filename' => $topic->image ], ['force_canonical' => true]) : '',
161 efrain 1169
                'progress'      => $progress,
1170
                'completed'     => $completed,
1171
                'order'         => $topic->order,
1172
                'added_on'      => $topic->added_on,
1173
                'updated_on'    => $topic->updated_on,
1174
                'link_capsules' => $this->url()->fromRoute('microlearning/capsules', ['topic_id' => $topic->uuid], ['force_canonical' => true]),
1175
 
1176
            ];
1177
 
1178
 
1179
 
1180
            return new JsonModel([
1181
                'success' => true,
1182
                'data' => $data
1183
            ]);
1184
 
1185
        } else {
1186
            return new JsonModel([
1187
                'success' => false,
1188
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1189
            ]);
1190
        }
1191
    }
119 efrain 1192
 
161 efrain 1193
 
119 efrain 1194
    public function capsulesAction()
1195
    {
1196
        $request = $this->getRequest();
1197
        if($request->isGet()) {
1198
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1199
            $currentUser = $currentUserPlugin->getUser();
1200
 
1201
 
1202
 
1203
            $topic_id = $this->params()->fromRoute('topic_id');
1204
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1205
            $topic = $topicMapper->fetchOneByUuid($topic_id);
1206
 
1207
            if(!$topic) {
1208
                return new JsonModel([
1209
                    'success' => false,
1210
                    'data' => 'ERROR_TOPIC_NOT_FOUND'
1211
                ]);
1212
            }
1213
 
1214
            $accessGrantedIds = $this->getAccessGranted();
1215
 
1216
            if(!in_array($topic->id, $accessGrantedIds->topics)) {
1217
                return new JsonModel([
1218
                    'success' => false,
1219
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
1220
                ]);
1221
            }
1222
 
1223
 
1224
 
1225
            $data = [];
1226
 
1227
 
1228
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1229
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1230
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
1231
 
1232
 
1233
            $capsules = $capsuleMapper->fetchAllActiveByCompanyIdAndTopicId($topic->company_id, $topic->id);
1234
            foreach($capsules as $capsule)
1235
            {
1236
 
1237
                if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
1238
                    continue;
1239
                }
1240
 
1241
                $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
1242
                if($userProgress) {
1243
                    $progress = $userProgress->progress;
1244
                    $completed = $userProgress->completed;
1245
                } else {
1246
                    $progress = 0;
1247
                    $completed = 0;
1248
                }
1249
 
1250
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
1251
 
1252
 
1253
 
1254
                array_push($data, [
166 efrain 1255
                    'uuid'              => $capsule->uuid,
119 efrain 1256
                    'name'              => $capsule->name ? $capsule->name : '',
1257
                    'description'       => $capsule->description ? $capsule->description : '',
164 efrain 1258
                    'image'             => $capsule->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image ], ['force_canonical' => true])  : '',
119 efrain 1259
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
1260
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
1261
                    'link_slides'       => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
161 efrain 1262
                    'link_get'          => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
119 efrain 1263
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
1264
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
1265
                    'progress'          => $progress,
1266
                    'completed'         => $completed,
1267
                    'order'             => $capsule->order,
1268
                    'added_on'          => $capsule->added_on,
1269
                    'updated_on'        => $capsule->updated_on,
1270
                ]);
1271
 
1272
 
1273
 
1274
            }
1275
 
1276
            usort($data, function($a, $b) {
1277
 
1278
                $result =  $a['order'] <=> $b['order'];
1279
                if(0 == $result) {
1280
                    $result = strcasecmp($a['added_on'], $b['added_on']);
1281
                    if(0 == $result) {
1282
                        $result = strcasecmp($a['name'], $b['name']);
1283
                    }
1284
                }
1285
 
1286
                if($result < 0) {
1287
                    return 1;
1288
                } else if($result > 0) {
1289
                    return -1;
1290
                } else  {
1291
                    return  0;
1292
                }
1293
            });
1294
 
1295
 
1296
 
1297
                return new JsonModel([
1298
                    'success' => true,
1299
                    'data' => $data
1300
                ]);
1301
 
1302
        } else {
1303
            return new JsonModel([
1304
                'success' => false,
1305
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1306
            ]);
1307
        }
1308
    }
1309
 
161 efrain 1310
    public function getCapsuleAction()
1311
    {
1312
        $request = $this->getRequest();
1313
        if($request->isGet()) {
1314
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1315
            $currentUser = $currentUserPlugin->getUser();
1316
 
1317
 
1318
 
1319
            $capsule_id = $this->params()->fromRoute('id');
1320
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1321
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_id);
1322
 
1323
            if(!$capsule) {
1324
                return new JsonModel([
1325
                    'success' => false,
1326
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
1327
                ]);
1328
            }
1329
 
1330
            $accessGrantedIds = $this->getAccessGranted();
1331
 
1332
            if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
1333
                return new JsonModel([
1334
                    'success' => false,
1335
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
1336
                ]);
1337
            }
1338
 
1339
 
1340
 
1341
 
1342
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1343
            $topic = $topicMapper->fetchOne($capsule->topic_id);
1344
 
1345
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1346
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
1347
 
1348
 
1349
 
1350
            $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
1351
            if($userProgress) {
1352
                $progress = $userProgress->progress;
1353
                $completed = $userProgress->completed;
1354
            } else {
1355
                $progress = 0;
1356
                $completed = 0;
1357
            }
1358
 
1359
            $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->topic_id, $capsule->id);
1360
 
1361
 
1362
 
1363
            $data = [
164 efrain 1364
                    'uuid'              => $capsule->uuid,
161 efrain 1365
                    'name'              => $capsule->name ? $capsule->name : '',
1366
                    'description'       => $capsule->description ? $capsule->description : '',
164 efrain 1367
                    'image'             => $capsule->image ? $this->url()->fromRoute('storage',['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image ], ['force_canonical' => true])  : '',
161 efrain 1368
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
1369
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
1370
                    'link_slides'       => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
1371
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
1372
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
1373
                    'progress'          => $progress,
1374
                    'completed'         => $completed,
1375
                    'order'             => $capsule->order,
1376
                    'added_on'          => $capsule->added_on,
1377
                    'updated_on'        => $capsule->updated_on,
1378
            ];
1379
 
1380
 
1381
 
1382
            return new JsonModel([
1383
                'success' => true,
1384
                'data' => $data
1385
            ]);
1386
 
1387
        } else {
1388
            return new JsonModel([
1389
                'success' => false,
1390
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1391
            ]);
1392
        }
1393
    }
1394
 
119 efrain 1395
    public function slidesAction()
1396
    {
1397
        $request = $this->getRequest();
1398
        if($request->isGet()) {
1399
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1400
            $currentUser = $currentUserPlugin->getUser();
1401
 
1402
 
1403
 
1404
            $topic_id = $this->params()->fromRoute('topic_id');
1405
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1406
            $topic = $topicMapper->fetchOneByUuid($topic_id);
1407
 
1408
            if(!$topic) {
1409
                return new JsonModel([
1410
                    'success' => false,
1411
                    'data' => 'ERROR_TOPIC_NOT_FOUND'
1412
                ]);
1413
            }
1414
 
1415
            $accessGrantedIds = $this->getAccessGranted();
1416
 
1417
            if(!in_array($topic->id, $accessGrantedIds->topics)) {
1418
                return new JsonModel([
1419
                    'success' => false,
1420
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
1421
                ]);
1422
            }
1423
 
1424
            $capsule_id = $this->params()->fromRoute('capsule_id');
1425
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1426
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_id);
1427
 
1428
            if(!$capsule) {
1429
                return new JsonModel([
1430
                    'success' => false,
1431
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
1432
                ]);
1433
            }
1434
 
1435
 
1436
 
1437
            if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
1438
                return new JsonModel([
1439
                    'success' => false,
1440
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
1441
                ]);
1442
            }
1443
 
1444
 
1445
 
1446
            $data = [];
1447
 
1448
 
1449
            $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
1450
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1451
 
1452
 
1453
            $slides = $slideMapper->fetchAllByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $capsule->topic_id, $capsule->id);
1454
            foreach($slides as $slide)
1455
            {
1456
 
1457
 
1458
                $userProgress = $userProgressMapper->fetchOneByUserIdAndSlideId($currentUser->id, $slide->id);
1459
                if($userProgress) {
224 efrain 1460
                    $completed =  $userProgress->completed ;
119 efrain 1461
                } else {
1462
                    $completed = 0;
1463
                }
1464
 
1465
 
1466
 
1467
                array_push($data, [
1468
                    'quiz'          => '',
165 efrain 1469
                    'uuid'          => $slide->uuid,
119 efrain 1470
                    'name'          => $slide->name ? $slide->name : '',
1471
                    'description'   => $slide->description ? $slide->description : '',
1472
                    'type'          => $slide->type,
164 efrain 1473
                    'background'    => $slide->background ? $this->url()->fromRoute('storage',['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->background], ['force_canonical' => true]) : '',
1474
                    'file'          => $slide->file ? $this->url()->fromRoute('storage',['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->file], ['force_canonical' => true]) : '',
119 efrain 1475
                    'order'         => $slide->order,
1476
                    'completed'     => $completed,
161 efrain 1477
                    'link_get'      => $this->url()->fromRoute('microlearning/get-slide', ['id' => $slide->uuid], ['force_canonical' => true]),
169 efrain 1478
                    'link_sync'     => $this->url()->fromRoute('microlearning/sync', ['operation' => 'slide-view', 'topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid, 'slide_uuid' => $slide->uuid], ['force_canonical' => true]),
119 efrain 1479
                    'added_on'      => $slide->added_on,
1480
                    'updated_on'    => $slide->updated_on,
1481
                ]);
1482
 
1483
 
1484
 
1485
            }
1486
 
1487
            usort($data, function($a, $b) {
1488
 
1489
                $result =  $a['order'] <=> $b['order'];
1490
                if(0 == $result) {
1491
                    $result = strcasecmp($a['added_on'], $b['added_on']);
1492
                    if(0 == $result) {
1493
                        $result = strcasecmp($a['name'], $b['name']);
1494
                    }
1495
                }
1496
 
1497
                if($result < 0) {
1498
                    return 1;
1499
                } else if($result > 0) {
1500
                    return -1;
1501
                } else  {
1502
                    return  0;
1503
                }
1504
            });
1505
 
1506
 
1507
 
1508
                return new JsonModel([
1509
                    'success' => true,
1510
                    'data' => $data
1511
                ]);
1512
 
1513
        } else {
1514
            return new JsonModel([
1515
                'success' => false,
1516
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1517
            ]);
1518
        }
1519
    }
1520
 
161 efrain 1521
 
1522
    public function getSlideAction()
1523
    {
1524
        $request = $this->getRequest();
1525
        if($request->isGet()) {
1526
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1527
            $currentUser = $currentUserPlugin->getUser();
1528
 
1529
 
1530
 
1531
            $id = $this->params()->fromRoute('id');
1532
            $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
1533
            $slide = $slideMapper->fetchOneByUuid($id);
1534
 
1535
            if(!$slide) {
1536
                return new JsonModel([
1537
                    'success' => false,
1538
                    'data' => 'ERROR_SLIDE_NOT_FOUND'
1539
                ]);
1540
            }
1541
 
1542
            $accessGrantedIds = $this->getAccessGranted();
1543
 
1544
 
1545
 
1546
            if(!in_array($slide->capsule_id, $accessGrantedIds->capsules)) {
1547
                return new JsonModel([
1548
                    'success' => false,
1549
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
1550
                ]);
1551
            }
1552
 
1553
 
1554
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1555
            $topic = $topicMapper->fetchOne($slide->topic_id);
1556
 
1557
            $capsuleMapper =  CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1558
            $capsule = $capsuleMapper->fetchOne($slide->capsule_id);
1559
 
1560
 
1561
 
1562
 
1563
 
1564
            $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
1565
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1566
 
1567
 
1568
            $userProgress = $userProgressMapper->fetchOneByUserIdAndSlideId($currentUser->id, $slide->id);
1569
            if($userProgress) {
1570
                $completed = $userProgress->completed;
1571
            } else {
1572
                $completed = 0;
1573
            }
1574
 
1575
 
1576
 
1577
            $data =[
1578
                'quiz'          => '',
164 efrain 1579
                'uuid'          => $slide->uuid,
161 efrain 1580
                'name'          => $slide->name ? $slide->name : '',
1581
                'description'   => $slide->description ? $slide->description : '',
1582
                'type'          => $slide->type,
164 efrain 1583
                'background'    => $slide->background ? $this->url()->fromRoute('storage',['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->background], ['force_canonical' => true]) : '',
1584
                'file'          => $slide->file ? $this->url()->fromRoute('storage',['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->file], ['force_canonical' => true]) : '',
161 efrain 1585
                'order'         => $slide->order,
1586
                'completed'     => $completed,
169 efrain 1587
                'link_sync'     => $this->url()->fromRoute('microlearning/sync', ['operation' => 'slide-view', 'topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid, 'slide_uuid' => $slide->uuid], ['force_canonical' => true]),
161 efrain 1588
                'added_on'      => $slide->added_on,
1589
                'updated_on'    => $slide->updated_on,
1590
            ];
1591
 
1592
 
1593
 
1594
 
1595
            return new JsonModel([
1596
                'success' => true,
1597
                'data' => $data
1598
            ]);
1599
 
1600
        } else {
1601
            return new JsonModel([
1602
                'success' => false,
1603
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1604
            ]);
1605
        }
1606
    }
1607
 
119 efrain 1608
    public function profileAction()
1609
    {
1610
        $request = $this->getRequest();
1611
        if($request->isGet()) {
1612
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1613
            $currentUser = $currentUserPlugin->getUser();
1614
 
1615
 
1616
            $accessGrantedIds = $this->getAccessGranted();
1617
 
1618
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1619
            $companyExtendUserMapper = CompanyMicrolearningExtendUserMapper::getInstance($this->adapter);
1620
            $companyExtendUserCompanyMapper = CompanyMicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
1621
            $companyExtendUserFunctionMapper = CompanyMicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
1622
            $companyExtendUserGroupMapper = CompanyMicrolearningExtendUserGroupMapper::getInstance($this->adapter);
1623
            $companyExtendUserInstitutionMapper = CompanyMicrolearningExtendUserInstitutionMapper::getInstance($this->adapter);
1624
            $companyExtendUserPartnerMapper = CompanyMicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
1625
            $companyExtendUserProgramMapper = CompanyMicrolearningExtendUserProgramMapper::getInstance($this->adapter);
1626
            $companyExtendUserStudentTypeMapper = CompanyMicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
1627
            $companyExtendUserSectorMapper = CompanyMicrolearningExtendUserSectorMapper::getInstance($this->adapter);
1628
 
1629
 
1630
            $data = [];
1631
            foreach($accessGrantedIds->companies as $company_id)
1632
            {
1633
                $company = $companyMapper->fetchOne($company_id);
1634
                if(!$company) {
1635
                    continue;
1636
                }
1637
 
1638
                $record = [
1639
                    'name' => $company->name,
164 efrain 1640
                    'image' => $this->url()->fromRoute('storage',['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image], ['force_canonical' => true]),
119 efrain 1641
                    'details' => [],
1642
                ];
1643
 
1644
                $companyExtendUser = $companyExtendUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
1645
                if(!$companyExtendUser) {
1646
                    continue;
1647
                }
1648
 
1649
                if($companyExtendUser->extend_company_id) {
1650
 
1651
                    $extendedCompany = $companyExtendUserCompanyMapper->fetchOne($companyExtendUser->company_id);
1652
                    if($extendedCompany) {
1653
                        array_push($record['details'],[
1654
                            'uuid' => $extendedCompany->uuid,
1655
                            'label' => 'LABEL_COMPANY',
1656
                            'value' => $extendedCompany->name
1657
                        ]);
1658
                    }
1659
                }
1660
 
1661
                if($companyExtendUser->extend_function_id) {
1662
                    $extendedFunction = $companyExtendUserFunctionMapper->fetchOne($companyExtendUser->extend_function_id);
1663
                    if($extendedFunction) {
1664
                        array_push($record['details'],[
1665
                            'uuid' => $extendedFunction->uuid,
1666
                            'label' => 'LABEL_FUNCTION',
1667
                            'value' => $extendedFunction->name
1668
                        ]);
1669
                    }
1670
                }
1671
 
1672
                if($companyExtendUser->extend_group_id) {
1673
                    $extendedGroup = $companyExtendUserGroupMapper->fetchOne($companyExtendUser->extend_group_id);
1674
                    if($extendedGroup) {
1675
                        array_push($record['details'],[
1676
                            'uuid' => $extendedGroup->uuid,
1677
                            'label' => 'LABEL_GROUP',
1678
                            'value' => $extendedGroup->name
1679
                        ]);
1680
                    }
1681
                }
1682
 
1683
                if($companyExtendUser->extend_institution_id) {
1684
                    $extendedInstitution= $companyExtendUserInstitutionMapper->fetchOne($companyExtendUser->extend_institution_id);
1685
                    if($extendedInstitution) {
1686
                        array_push($record['details'],[
1687
                            'uuid' => $extendedInstitution->uuid,
1688
                            'label' => 'LABEL_INSTITUTION',
1689
                            'value' => $extendedInstitution->name
1690
                        ]);
1691
                    }
1692
                }
1693
 
1694
                if($companyExtendUser->extend_program_id) {
1695
                    $extendedProgram = $companyExtendUserProgramMapper->fetchOne($companyExtendUser->extend_program_id);
1696
                    if($extendedProgram) {
1697
                        array_push($record['details'],[
1698
                            'uuid' => $extendedProgram->uuid,
1699
                            'label' => 'LABEL_PROGRAM',
1700
                            'value' => $extendedProgram->name
1701
                        ]);
1702
 
1703
                    }
1704
                }
1705
 
1706
                if($companyExtendUser->extend_sector_id) {
1707
                    $extendedSector = $companyExtendUserSectorMapper->fetchOne($companyExtendUser->extend_sector_id);
1708
                    if($extendedSector) {
1709
                        array_push($record['details'],[
1710
                            'uuid' => $extendedSector->uuid,
1711
                            'label' => 'LABEL_SECTOR',
1712
                            'value' => $extendedSector->name
1713
                        ]);
1714
                    }
1715
                }
1716
 
1717
                if($companyExtendUser->extend_partner_id) {
1718
                    $extendedPartner = $companyExtendUserPartnerMapper->fetchOne($companyExtendUser->extend_partner_id);
1719
                    if($extendedPartner) {
1720
                        array_push($record['details'],[
1721
                            'uuid' => $extendedPartner->uuid,
1722
                            'label' => 'LABEL_PARTNER',
1723
                            'value' => $extendedPartner->name
1724
                        ]);
1725
                    }
1726
                }
1727
 
1728
                if($companyExtendUser->extend_student_type_id) {
1729
                    $extendedStudentType = $companyExtendUserStudentTypeMapper->fetchOne($companyExtendUser->extend_student_type_id);
1730
                    if($extendedStudentType) {
1731
                        array_push($record['details'],[
1732
                            'uuid' => $extendedStudentType->uuid,
1733
                            'label' => 'LABEL_TYPE',
1734
                            'value' => $extendedStudentType->name
1735
                        ]);
1736
                    }
1737
                }
1738
 
1739
                array_push($data, $record);
1740
            }
1741
 
1742
            return new JsonModel([
1743
                'success' => true,
1744
                'data' => $data
1745
            ]);
1746
 
1747
        } else {
1748
            return new JsonModel([
1749
                'success' => false,
1750
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1751
            ]);
1752
        }
1753
    }
1754
 
167 efrain 1755
    public function syncAction()
1756
    {
1757
        $request = $this->getRequest();
168 efrain 1758
        if($request->isPost()) {
167 efrain 1759
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1760
            $currentUser = $currentUserPlugin->getUser();
1761
 
1762
 
1763
            $operation = $this->params()->fromRoute('operation');
1764
            if($operation == 'slide-view' || $operation == 'capsule-close' || $operation == 'topic-close') {
1765
                $accessGrantedIds = $this->getAccessGranted();
1766
 
1767
                $topic_uuid     = $this->params()->fromRoute('topic_uuid');
1768
                $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
1769
                $slide_uuid     = $this->params()->fromRoute('slide_uuid');
1770
 
1771
                $accessGrantedIds = $this->getAccessGranted();
1772
                if($operation == 'slide-view') {
1773
 
1774
                    if(empty($slide_uuid) || empty($capsule_uuid ) || empty($topic_uuid)) {
1775
                        return new JsonModel([
1776
                            'success' => false,
1777
                            'data' => 'ERROR_INVALID_PARAMETERS'
1778
                        ]);
1779
                    }
1780
 
1781
 
1782
                    $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1783
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
1784
 
1785
                    if(!$topic) {
1786
                        return new JsonModel([
1787
                            'success' => false,
1788
                            'data' => 'ERROR_TOPIC_NOT_FOUND'
1789
                        ]);
1790
                    }
1791
 
1792
 
1793
 
1794
                    if(!in_array($topic->id, $accessGrantedIds->topics)) {
1795
                        return new JsonModel([
1796
                            'success' => false,
1797
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
1798
                        ]);
1799
                    }
1800
 
1801
                    $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1802
                    $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
1803
 
1804
                    if(!$capsule) {
1805
                        return new JsonModel([
1806
                            'success' => false,
1807
                            'data' => 'ERROR_CAPSULE_NOT_FOUND'
1808
                        ]);
1809
                    }
119 efrain 1810
 
167 efrain 1811
                    if(!in_array($capsule->id, $accessGrantedIds->capsules) || $capsule->topic_id != $topic->id) {
1812
                        return new JsonModel([
1813
                            'success' => false,
1814
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
1815
                        ]);
1816
                    }
1817
 
1818
                    $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
1819
                    $slide = $slideMapper->fetchOneByUuid($slide_uuid);
1820
                    if(!$slide) {
1821
                        return new JsonModel([
1822
                            'success' => false,
1823
                            'data' => 'ERROR_SLIDE_NOT_FOUND'
1824
                        ]);
1825
                    }
1826
 
1827
                    if($slide->capsule_id != $capsule->id && $slide->topic_id != $topic->id) {
1828
                        return new JsonModel([
1829
                            'success' => false,
1830
                            'data' => 'ERROR_SLIDE_NOT_FOUND'
1831
                        ]);
1832
 
1833
                    }
1834
 
1835
 
1836
                    $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
1837
 
1838
                    $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
1839
                    $added_on = $userProgressMapper->getDatebaseNow();
1840
 
1841
 
1842
                    $userProgressTopic = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
1843
                    if(!$userProgressTopic) {
1844
 
1845
                        $userProgressTopic = new CompanyMicrolearningUserProgress();
1846
                        $userProgressTopic->company_id                  = $slide->company_id;
1847
                        $userProgressTopic->topic_id                    = $slide->topic_id;
176 efrain 1848
                        $userProgressTopic->user_id                     = $currentUser->id;
167 efrain 1849
                        $userProgressTopic->progress                    = 0;
1850
                        $userProgressTopic->returning                   = 0;
1851
                        $userProgressTopic->returning_after_completed   = 0;
1852
                        $userProgressTopic->completed                   = 0;
1853
                        $userProgressTopic->total_slides                = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($slide->company_id, $slide->topic_id);
1854
                        $userProgressTopic->view_slides                 = 0;
1855
                        $userProgressTopic->type                        = CompanyMicrolearningUserProgress::TYPE_TOPIC;
1856
                        $userProgressTopic->added_on                    = $added_on;
1857
                        $userProgressTopic->updated_on                  = $added_on;
1858
 
1859
                        if($userProgressMapper->insert($userProgressTopic)) {
1860
 
1861
                            $userLog = new CompanyMicrolearningUserLog();
1862
                            $userLog->activity      = CompanyMicrolearningUserLog::ACTIVITY_START_TOPIC;
1863
                            $userLog->user_id       = $currentUser->id;
1864
                            $userLog->company_id    = $slide->company_id;
1865
                            $userLog->topic_id      = $slide->topic_id;
1866
                            $userLog->added_on      = $added_on;
1867
 
1868
                            if(!$userLogMapper->insert($userLog)) {
1869
                                return new JsonModel([
1870
                                    'success' => false,
1871
                                    'data' => $userProgressMapper->getError()
1872
                                ]);
1873
                            }
1874
                        } else {
1875
                            return new JsonModel([
1876
                                'success' => false,
1877
                                'data' => $userProgressMapper->getError()
1878
                            ]);
1879
                        }
1880
                    }
1881
 
1882
 
1883
                    $userProgressCapsule = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
1884
                    if(!$userProgressCapsule) {
1885
 
1886
                        $userProgressCapsule = new CompanyMicrolearningUserProgress();
1887
                        $userProgressCapsule->company_id                  = $slide->company_id;
1888
                        $userProgressCapsule->topic_id                    = $slide->topic_id;
1889
                        $userProgressCapsule->capsule_id                  = $slide->capsule_id;
176 efrain 1890
                        $userProgressCapsule->user_id                     = $currentUser->id;
167 efrain 1891
                        $userProgressCapsule->progress                    = 0;
1892
                        $userProgressCapsule->returning                   = 0;
1893
                        $userProgressCapsule->returning_after_completed   = 0;
1894
                        $userProgressCapsule->completed                   = 0;
1895
                        $userProgressCapsule->total_slides                = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($slide->company_id, $slide->topic_id, $slide->capsule_id);
1896
                        $userProgressCapsule->view_slides                 = 0;
1897
                        $userProgressCapsule->type                        = CompanyMicrolearningUserProgress::TYPE_CAPSULE;
1898
                        $userProgressCapsule->added_on                    = $added_on;
1899
                        $userProgressTopic->updated_on                    = $added_on;
1900
 
1901
                        if($userProgressMapper->insert($userProgressCapsule)) {
1902
 
1903
                            $userLog = new CompanyMicrolearningUserLog();
1904
                            $userLog->activity      = CompanyMicrolearningUserLog::ACTIVITY_START_CAPSULE;
1905
                            $userLog->user_id       = $currentUser->id;
1906
                            $userLog->company_id    = $slide->company_id;
1907
                            $userLog->topic_id      = $slide->topic_id;
1908
                            $userLog->capsule_id    = $slide->capsule_id;
1909
                            $userLog->added_on      = $added_on;
1910
 
1911
                            if(!$userLogMapper->insert($userLog)) {
1912
                                return new JsonModel([
1913
                                    'success' => false,
1914
                                    'data' => $userLogMapper->getError()
1915
                                ]);
1916
                            }
1917
                        } else {
1918
                            return new JsonModel([
1919
                                'success' => false,
1920
                                'data' => $userProgressMapper->getError()
1921
                            ]);
1922
                        }
1923
                    }
1924
 
1925
 
1926
                    $userProgressSlide = $userProgressMapper->fetchOneByUserIdAndSlideId($currentUser->id, $slide->id);
1927
                    if(!$userProgressSlide) {
1928
                        $userProgressSlide = new CompanyMicrolearningUserProgress();
1929
                        $userProgressSlide->company_id                  = $slide->company_id;
1930
                        $userProgressSlide->topic_id                    = $slide->topic_id;
1931
                        $userProgressSlide->capsule_id                  = $slide->capsule_id;
1932
                        $userProgressSlide->slide_id                    = $slide->id;
176 efrain 1933
                        $userProgressSlide->user_id                     = $currentUser->id;
167 efrain 1934
                        $userProgressSlide->progress                    = 0;
1935
                        $userProgressSlide->returning                   = 0;
1936
                        $userProgressSlide->returning_after_completed   = 0;
1937
                        $userProgressSlide->completed                   = 1;
1938
                        $userProgressSlide->total_slides                = 0;
1939
                        $userProgressSlide->view_slides                 = 0;
1940
                        $userProgressSlide->type                        = CompanyMicrolearningUserProgress::TYPE_SLIDE;
1941
                        $userProgressSlide->added_on                    = $added_on;
1942
                        $userProgressSlide->updated_on                  = $added_on;
1943
 
1944
                        if(!$userProgressMapper->insert($userProgressSlide)) {
1945
                            return new JsonModel([
1946
                                'success' => false,
1947
                                'data' => $userProgressMapper->getError()
1948
                            ]);
1949
                        }
1950
                    }
1951
 
1952
                    $userLog = new CompanyMicrolearningUserLog();
1953
                    $userLog->activity      = CompanyMicrolearningUserLog::ACTIVITY_VIEW_SLIDE;
1954
                    $userLog->user_id       = $currentUser->id;
1955
                    $userLog->company_id    = $slide->company_id;
1956
                    $userLog->topic_id      = $slide->topic_id;
1957
                    $userLog->capsule_id    = $slide->capsule_id;
1958
                    $userLog->slide_id      = $slide->id;
1959
                    $userLog->added_on      = $added_on;
1960
 
1961
                    if(!$userLogMapper->insert($userLog)) {
1962
                        return new JsonModel([
1963
                            'success' => false,
1964
                            'data' => $userLogMapper->getError()
1965
                        ]);
1966
                    }
1967
 
1968
                    $closeCapsule = false;
1969
 
1970
                    if($userProgressCapsule->completed) {
1971
 
1972
                        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $added_on);
1973
                        $returning_on = $dt->format('Y-m-d');
1974
 
1975
                        if(!$userProgressCapsule->returning_on || $userProgressCapsule->returning_on != $returning_on) {
1976
 
1977
                            $userProgressCapsule->returning_on = $returning_on;
1978
                            $userProgressCapsule->returning_after_completed = $userProgressCapsule->returning_after_completed + 1;
1979
 
1980
                            if(!$userProgressMapper->update($userProgressCapsule)) {
1981
                                return new JsonModel([
1982
                                    'success' => false,
1983
                                    'data' => $userProgressMapper->getError()
1984
                                ]);
1985
                            }
1986
                        }
1987
 
1988
                    }  else {
1989
 
1990
                        $userProgressCapsule->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($slide->company_id, $slide->topic_id, $slide->capsule_id);
1991
                        $userProgressCapsule->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndCapsuleId($currentUser->id, $slide->capsule_id);
1992
 
1993
                        if($userProgressCapsule->total_slides) {
1994
 
1995
                            $userProgressCapsule->progress = ($userProgressCapsule->view_slides * 100) / $userProgressCapsule->total_slides;
1996
                            $userProgressCapsule->progress = $userProgressCapsule->progress > 100 ? 100 : $userProgressCapsule->progress;
1997
                        }
1998
 
1999
                        if(!$userProgressMapper->update($userProgressCapsule)) {
2000
                            return new JsonModel([
2001
                                'success' => false,
2002
                                'data' => $userProgressMapper->getError()
2003
                            ]);
2004
                        }
2005
 
2006
                        if($userProgressCapsule->progress >= 100) {
2007
                            $closeCapsule = true;
2008
                        }
171 efrain 2009
 
172 efrain 2010
                       // print_r($userProgressCapsule);
167 efrain 2011
                    }
2012
 
2013
                    $closeTopic = false;
2014
                    if(!$userProgressTopic->completed) {
2015
 
2016
 
2017
                        $userProgressTopic->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($slide->company_id, $slide->topic_id);
2018
                        $userProgressTopic->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndTopicId($currentUser->id, $slide->topic_id);
2019
 
2020
                        if($userProgressTopic->total_slides) {
2021
 
2022
                            $userProgressTopic->progress = ($userProgressTopic->view_slides * 100) / $userProgressTopic->total_slides;
2023
                            $userProgressTopic->progress = $userProgressTopic->progress > 100 ? 100 : $userProgressTopic->progress;
2024
                        }
2025
                        if(!$userProgressMapper->update($userProgressTopic)) {
2026
                            return new JsonModel([
2027
                                'success' => false,
2028
                                'data' => $userProgressMapper->getError()
2029
                            ]);
2030
                        }
2031
 
2032
                        if($userProgressTopic->progress >= 100) {
2033
                            $closeTopic = true;
2034
                        }
2035
 
172 efrain 2036
                        //print_r($userProgressTopic);
167 efrain 2037
 
171 efrain 2038
 
167 efrain 2039
                    }
2040
 
2041
 
2042
                    $data = [
2043
                        'message' => 'LABEL_THE_USER_PROGRESS_FOR_THIS_SLIDE_HAS_BEEN_COMPLETED',
2044
 
2045
                    ];
2046
 
2047
                    if($closeCapsule) {
173 efrain 2048
                        $data['link_close_capsule'] = $this->url()->fromRoute('microlearning/sync', ['operation' => 'capsule-close', 'topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid], ['force_canonical' => true]);
167 efrain 2049
                    }
2050
 
2051
 
2052
                    if($closeTopic) {
173 efrain 2053
                        $data['link_close_topic'] = $this->url()->fromRoute('microlearning/sync', ['operation' => 'topic-close', 'topic_uuid' => $topic->uuid], ['force_canonical' => true]);
167 efrain 2054
                    }
2055
 
2056
 
2057
                    return new JsonModel([
2058
                        'success' => true,
2059
                        'data' => $data
2060
                    ]);
2061
 
2062
 
2063
 
2064
 
2065
                } else if($operation == 'capsule-close') {
2066
 
2067
                    if(empty($capsule_uuid ) || empty($topic_uuid)) {
2068
                        return new JsonModel([
2069
                            'success' => false,
2070
                            'data' => 'ERROR_INVALID_PARAMETERS'
2071
                        ]);
2072
                    }
2073
 
2074
 
2075
                    $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
2076
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
2077
 
2078
                    if(!$topic) {
2079
                        return new JsonModel([
2080
                            'success' => false,
2081
                            'data' => 'ERROR_TOPIC_NOT_FOUND'
2082
                        ]);
2083
                    }
2084
 
2085
 
2086
 
2087
                    if(!in_array($topic->id, $accessGrantedIds->topics)) {
2088
                        return new JsonModel([
2089
                            'success' => false,
2090
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
2091
                        ]);
2092
                    }
2093
 
2094
                    $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
2095
                    $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
2096
 
2097
                    if(!$capsule) {
2098
                        return new JsonModel([
2099
                            'success' => false,
2100
                            'data' => 'ERROR_CAPSULE_NOT_FOUND'
2101
                        ]);
2102
                    }
2103
 
2104
                    if(!in_array($capsule->id, $accessGrantedIds->capsules) || $capsule->topic_id != $topic->id) {
2105
                        return new JsonModel([
2106
                            'success' => false,
2107
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
2108
                        ]);
2109
                    }
2110
 
2111
 
2112
                    $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
2113
 
2114
                    $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
2115
                    $updated_on = $userProgressMapper->getDatebaseNow();
2116
 
2117
                    $userProgressCapsule = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
2118
                    if(!$userProgressCapsule) {
2119
                        return new JsonModel([
2120
                            'success' => false,
2121
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_CAPSULE_NOT_FOUND'
2122
                        ]);
2123
                    }
2124
 
2125
                    if($userProgressCapsule->completed) {
2126
                        return new JsonModel([
2127
                            'success' => false,
2128
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_CAPSULE_ALREADY_CLOSED'
2129
                        ]);
2130
                    }
2131
 
2132
 
2133
                    $userProgressCapsule->completed = 1;
2134
                    $userProgressCapsule->updated_on = $updated_on;
2135
 
2136
                    if($userProgressMapper->update($userProgressCapsule)) {
2137
                        return new JsonModel([
2138
                            'success' => true,
2139
                            'data' => 'LABEL_THE_USER_PROGRESS_FOR_THIS_CAPSULE_HAS_BEEN_COMPLETED'
2140
                        ]);
2141
                    } else {
2142
                        return new JsonModel([
2143
                            'success' => false,
2144
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_CAPSULE_COULD_NOT_BE_COMPLETED'
2145
                        ]);
2146
                    }
2147
 
2148
 
2149
 
2150
 
2151
 
2152
 
2153
 
2154
                } else if($operation == 'topic-close') {
174 efrain 2155
                    if(empty($topic_uuid)) {
167 efrain 2156
                        return new JsonModel([
2157
                            'success' => false,
2158
                            'data' => 'ERROR_INVALID_PARAMETERS'
2159
                        ]);
2160
                    }
2161
 
2162
 
2163
                    $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
2164
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
2165
 
2166
                    if(!$topic) {
2167
                        return new JsonModel([
2168
                            'success' => false,
2169
                            'data' => 'ERROR_TOPIC_NOT_FOUND'
2170
                        ]);
2171
                    }
2172
 
2173
 
2174
 
2175
                    if(!in_array($topic->id, $accessGrantedIds->topics)) {
2176
                        return new JsonModel([
2177
                            'success' => false,
2178
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
2179
                        ]);
2180
                    }
2181
 
2182
 
2183
 
2184
 
2185
                    $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
2186
 
2187
                    $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
2188
                    $updated_on = $userProgressMapper->getDatebaseNow();
2189
 
2190
                    $userProgressTopic = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
2191
                    if(!$userProgressTopic) {
2192
                        return new JsonModel([
2193
                            'success' => false,
2194
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_TOPIC_NOT_FOUND'
2195
                        ]);
2196
                    }
2197
 
2198
                    if($userProgressTopic->completed) {
2199
                        return new JsonModel([
2200
                            'success' => false,
2201
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_TOPIC_ALREADY_CLOSED'
2202
                        ]);
2203
                    }
2204
 
2205
 
2206
                    $userProgressTopic->completed = 1;
2207
                    $userProgressTopic->updated_on = $updated_on;
2208
 
2209
                    if($userProgressMapper->update($userProgressTopic)) {
2210
                        return new JsonModel([
2211
                            'success' => true,
2212
                            'data' => 'LABEL_THE_USER_PROGRESS_FOR_THIS_TOPIC_HAS_BEEN_COMPLETED'
2213
                        ]);
2214
                    } else {
2215
                        return new JsonModel([
2216
                            'success' => false,
2217
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_TOPIC_COULD_NOT_BE_COMPLETED'
2218
                        ]);
2219
                    }
2220
                }
2221
 
2222
 
2223
 
2224
 
2225
            } else {
2226
 
2227
                return new JsonModel([
2228
                    'success' => false,
2229
                    'data' => 'ERROR_OPERATION_UNKNOWN'
2230
                ]);
2231
 
2232
 
2233
            }
2234
 
2235
        } else {
2236
            return new JsonModel([
2237
                'success' => false,
2238
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2239
            ]);
2240
        }
2241
    }
2242
 
2243
 
119 efrain 2244
    /**
2245
     *
2246
     * @return \LeadersLinked\Controller\MicrolearningUserAccessGrantedIds
2247
     */
2248
    private function getAccessGranted()
2249
    {
2250
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2251
        $currentUser = $currentUserPlugin->getUser();
2252
 
2253
        $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
2254
        $now = $capsuleUserMapper->getDatebaseNow();
2255
 
2256
        $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
2257
 
2258
        $accessGrantedIds = new MicrolearningUserAccessGrantedIds();
2259
 
2260
 
2261
        foreach($records as $record)
2262
        {
2263
            if($record->access != CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED && $record->access != CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
2264
                continue;
2265
            }
2266
            if($record->access == CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
2267
                if($now < $record->paid_from || $now > $record->paid_to) {
2268
                    continue;
2269
                }
2270
            }
2271
 
2272
 
2273
            if(!in_array($record->company_id, $accessGrantedIds->companies )) {
2274
                array_push($accessGrantedIds->companies, $record->company_id);
2275
            }
2276
 
2277
            if(!in_array($record->topic_id, $accessGrantedIds->topics )) {
2278
                array_push( $accessGrantedIds->topics, $record->topic_id);
2279
            }
2280
 
2281
            if(!in_array($record->capsule_id, $accessGrantedIds->capsules)) {
2282
                array_push( $accessGrantedIds->capsules, $record->capsule_id);
2283
            }
2284
        }
2285
 
2286
        return $accessGrantedIds;
2287
    }
2288
 
2289
 
2290
}