Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 588 Rev 590
Línea 133... Línea 133...
133
        return new JsonModel([
133
        return new JsonModel([
134
            'success' => false,
134
            'success' => false,
135
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
135
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
136
        ]);
136
        ]);
137
    }
137
    }
138
    
138
        
139
    public function companiesAction()
139
    public function companiesAction()
140
    {
140
    {
Línea 141... Línea 141...
141
 
141
 
Línea 173... Línea 173...
173
        return new JsonModel([
173
        return new JsonModel([
174
            'success' => false,
174
            'success' => false,
175
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
175
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
176
        ]);
176
        ]);
177
    }
177
    }
178
    
-
 
179
    
178
 
180
    
-
 
181
    public function capsuleCommentsAction()
179
    public function capsuleCommentsAction()
182
    {
180
    {
Línea 183... Línea 181...
183
        
181
        
Línea 1840... Línea 1838...
1840
                    'type'                  => $slide->type,
1838
                    'type'                  => $slide->type,
1841
                    'background'            => $slide->background ? $storage->getGenericImage($path, $slide->uuid, $slide->background) : '',
1839
                    'background'            => $slide->background ? $storage->getGenericImage($path, $slide->uuid, $slide->background) : '',
1842
                    'file'                  => $slide->file ? $storage->getGenericFile($path, $slide->uuid, $slide->file) : '',
1840
                    'file'                  => $slide->file ? $storage->getGenericFile($path, $slide->uuid, $slide->file) : '',
1843
                    'order'                 => $slide->order,
1841
                    'order'                 => $slide->order,
1844
                    'completed'             => $completed,
1842
                    'completed'             => $completed,
1845
                    'link_get'              => $this->url()->fromRoute('microlearning/get-slide', ['id' => $slide->uuid], ['force_canonical' => true]),
-
 
1846
                    '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]),
1843
                    '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]),
1847
                    'link_take_a_test'      => $link_take_a_test,
1844
                    'link_take_a_test'      => $link_take_a_test,
1848
                    'added_on'              => $slide->added_on,
1845
                    'added_on'              => $slide->added_on,
1849
                    'updated_on'            => $slide->updated_on,
1846
                    'updated_on'            => $slide->updated_on,
1850
                ]);
1847
                ]);
Línea 2217... Línea 2214...
2217
                'success' => false,
2214
                'success' => false,
2218
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2215
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2219
            ]);
2216
            ]);
2220
        }
2217
        }
2221
    }
2218
    }
2222
    
2219
 
-
 
2220
    /**
-
 
2221
     * 
-
 
2222
     * @return \Laminas\View\Model\JsonModel
-
 
2223
     */
2223
    public function syncAction()
2224
    public function syncAction()
2224
    {
2225
    {
2225
        $request = $this->getRequest();
2226
        $request = $this->getRequest();
2226
        if($request->isPost()) {
2227
        if (!$request->isPost()) {
2227
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
2228
            $currentUser = $currentUserPlugin->getUser();
-
 
2229
            
-
 
2230
           
-
 
2231
            $operation = $this->params()->fromRoute('operation');
-
 
2232
            if($operation == 'slide-view' || $operation == 'capsule-close' || $operation == 'topic-close') {
-
 
2233
                $accessGrantedIds = $this->getAccessGranted();
-
 
2234
                
-
 
2235
                $topic_uuid     = $this->params()->fromRoute('topic_uuid');
-
 
2236
                $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
-
 
2237
                $slide_uuid     = $this->params()->fromRoute('slide_uuid');
-
 
2238
                
-
 
2239
                $accessGrantedIds = $this->getAccessGranted();
-
 
2240
                if($operation == 'slide-view') {
-
 
2241
                    
-
 
2242
                    if(empty($slide_uuid) || empty($capsule_uuid ) || empty($topic_uuid)) {
-
 
2243
                        return new JsonModel([
-
 
2244
                            'success' => false,
-
 
2245
                            'data' => 'ERROR_INVALID_PARAMETERS'
2228
            return new JsonModel(['success' => false, 'data' => 'ERROR_INVALID_REQUEST']);
2246
                        ]);
-
 
2247
                    }
-
 
2248
                    
-
 
2249
                    
-
 
2250
                    $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
2251
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
2252
                    
-
 
2253
                    if(!$topic) {
-
 
2254
                        return new JsonModel([
-
 
2255
                            'success' => false,
-
 
2256
                            'data' => 'ERROR_TOPIC_NOT_FOUND'
-
 
2257
                        ]);
-
 
2258
                    }
-
 
2259
                    
-
 
2260
                    
-
 
2261
                    
-
 
2262
                    if(!in_array($topic->id, $accessGrantedIds->topics)) {
-
 
2263
                        return new JsonModel([
-
 
2264
                            'success' => false,
-
 
2265
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
-
 
2266
                        ]);
-
 
2267
                    }
-
 
2268
                    
-
 
2269
                    $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
2270
                    $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
-
 
2271
                    
-
 
2272
                    if(!$capsule) {
-
 
2273
                        return new JsonModel([
-
 
2274
                            'success' => false,
-
 
2275
                            'data' => 'ERROR_CAPSULE_NOT_FOUND'
-
 
2276
                        ]);
-
 
2277
                    }
-
 
2278
    
-
 
2279
                    if(!in_array($capsule->id, $accessGrantedIds->capsules) || $capsule->topic_id != $topic->id) {
-
 
2280
                        return new JsonModel([
-
 
2281
                            'success' => false,
-
 
2282
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
-
 
2283
                        ]);
-
 
2284
                    }
-
 
2285
                    
-
 
2286
                    $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
2287
                    $slide = $slideMapper->fetchOneByUuid($slide_uuid);
-
 
2288
                    if(!$slide) {
-
 
2289
                        return new JsonModel([
-
 
2290
                            'success' => false,
-
 
2291
                            'data' => 'ERROR_SLIDE_NOT_FOUND'
-
 
2292
                        ]);
-
 
2293
                    }
-
 
2294
                    
-
 
2295
                    if($slide->capsule_id != $capsule->id && $slide->topic_id != $topic->id) {
-
 
2296
                        return new JsonModel([
-
 
2297
                            'success' => false,
-
 
2298
                            'data' => 'ERROR_SLIDE_NOT_FOUND'
-
 
2299
                        ]);
-
 
2300
                        
-
 
2301
                    }
2229
        }
2302
                    
-
 
2303
                    
-
 
2304
                    $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
-
 
2305
                    
-
 
2306
                    $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
2307
                    $added_on = $userProgressMapper->getDatebaseNow();
-
 
2308
                    
-
 
2309
                    
-
 
2310
                    $userProgressTopic = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
-
 
2311
                    if(!$userProgressTopic) {
-
 
2312
                        
-
 
2313
                        $userProgressTopic = new MicrolearningUserProgress();
-
 
2314
                        $userProgressTopic->company_id                  = $topic->company_id; // Usar company_id del tópico
-
 
2315
                        $userProgressTopic->topic_id                    = $topic->id;        // Usar id del tópico
-
 
2316
                        $userProgressTopic->user_id                     = $currentUser->id;
-
 
2317
                        $userProgressTopic->progress                    = 0;
-
 
2318
                        $userProgressTopic->returning                   = 0;
-
 
2319
                        $userProgressTopic->returning_after_completed   = 0;
-
 
2320
                        $userProgressTopic->completed                   = 0;
-
 
2321
                        $userProgressTopic->total_slides                = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($topic->company_id, $topic->id);
-
 
2322
                        $userProgressTopic->view_slides                 = 0;
-
 
2323
                        $userProgressTopic->type                        = MicrolearningUserProgress::TYPE_TOPIC;
-
 
2324
                        $userProgressTopic->added_on                    = $added_on;
-
 
2325
                        $userProgressTopic->updated_on                  = $added_on;
-
 
Línea 2326... Línea -...
2326
 
-
 
2327
                        if($userProgressMapper->insert($userProgressTopic)) {
-
 
2328
                            
-
 
2329
                            $userLog = new MicrolearningUserLog();
-
 
2330
                            $userLog->activity      = MicrolearningUserLog::ACTIVITY_START_TOPIC;
-
 
2331
                            $userLog->user_id       = $currentUser->id;
-
 
2332
                            $userLog->company_id    = $topic->company_id;
-
 
2333
                            $userLog->topic_id      = $topic->id;
-
 
2334
                            $userLog->added_on      = $added_on;
-
 
2335
                            
-
 
2336
                            if(!$userLogMapper->insert($userLog)) {
-
 
2337
                                return new JsonModel([
-
 
2338
                                    'success' => false,
-
 
2339
                                    'data' => $userProgressMapper->getError()
-
 
2340
                                ]);
-
 
2341
                            }
-
 
2342
                        } else {
-
 
2343
                            return new JsonModel([
-
 
2344
                                'success' => false,
-
 
2345
                                'data' => $userProgressMapper->getError()
-
 
2346
                            ]);
-
 
2347
                        }
-
 
2348
                    }
-
 
2349
                    
-
 
2350
                    
-
 
2351
                    $userProgressCapsule = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
-
 
2352
                    if(!$userProgressCapsule) {
-
 
2353
                        
-
 
2354
                        $userProgressCapsule = new MicrolearningUserProgress();
-
 
2355
                        $userProgressCapsule->company_id                  = $capsule->company_id; // Usar company_id de la cápsula
-
 
2356
                        $userProgressCapsule->topic_id                    = $topic->id;         // Usar el id del tópico obtenido previamente
-
 
2357
                        $userProgressCapsule->capsule_id                  = $capsule->id;       // Usar id de la cápsula
-
 
2358
                        $userProgressCapsule->user_id                     = $currentUser->id;
-
 
2359
                        $userProgressCapsule->progress                    = 0;
-
 
2360
                        $userProgressCapsule->returning                   = 0;
-
 
2361
                        $userProgressCapsule->returning_after_completed   = 0;
-
 
2362
                        $userProgressCapsule->completed                   = 0;
-
 
2363
                        $userProgressCapsule->total_slides                = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
-
 
2364
                        $userProgressCapsule->view_slides                 = 0;
-
 
2365
                        $userProgressTopic->updated_on                    = $added_on;
-
 
2366
                        
-
 
2367
                        if($userProgressMapper->insert($userProgressCapsule)) {
-
 
2368
                            
-
 
2369
                            $userLog = new MicrolearningUserLog();
-
 
2370
                            $userLog->activity      = MicrolearningUserLog::ACTIVITY_START_CAPSULE;
-
 
2371
                            $userLog->user_id       = $currentUser->id;
-
 
2372
                            $userLog->company_id    = $capsule->company_id;
-
 
2373
                            $userLog->topic_id      = $topic->id;
-
 
2374
                            $userLog->capsule_id    = $capsule->id;
-
 
2375
                            $userLog->added_on      = $added_on;
-
 
2376
                            
-
 
2377
                            if(!$userLogMapper->insert($userLog)) {
-
 
2378
                                return new JsonModel([
-
 
2379
                                    'success' => false,
-
 
2380
                                    'data' => $userLogMapper->getError()
-
 
2381
                                ]);
-
 
2382
                            }
-
 
2383
                        } else {
-
 
2384
                            return new JsonModel([
-
 
2385
                                'success' => false,
-
 
2386
                                'data' => $userProgressMapper->getError()
-
 
2387
                            ]);
-
 
2388
                        }
-
 
2389
                    }
-
 
2390
                    
-
 
2391
                    
-
 
2392
                    $userProgressSlide = $userProgressMapper->fetchOneByUserIdAndSlideId($currentUser->id, $slide->id);
-
 
2393
                    if(!$userProgressSlide) {
-
 
2394
                        $userProgressSlide = new MicrolearningUserProgress();
-
 
2395
                        $userProgressSlide->company_id                  = $slide->company_id;
-
 
2396
                        $userProgressSlide->topic_id                    = $slide->topic_id;
-
 
2397
                        $userProgressSlide->capsule_id                  = $slide->capsule_id;
-
 
2398
                        $userProgressSlide->slide_id                    = $slide->id;
-
 
2399
                        $userProgressSlide->user_id                     = $currentUser->id;
-
 
2400
                        $userProgressSlide->progress                    = 0;
-
 
2401
                        $userProgressSlide->returning                   = 0;
-
 
2402
                        $userProgressSlide->returning_after_completed   = 0;
-
 
2403
                        $userProgressSlide->completed                   = 1;
-
 
2404
                        $userProgressSlide->total_slides                = 0;
-
 
2405
                        $userProgressSlide->view_slides                 = 0;
-
 
2406
                        $userProgressSlide->type                        = MicrolearningUserProgress::TYPE_SLIDE;
-
 
2407
                        $userProgressSlide->added_on                    = $added_on;
-
 
2408
                        $userProgressSlide->updated_on                  = $added_on;
-
 
2409
                        
-
 
2410
                        if(!$userProgressMapper->insert($userProgressSlide)) {
-
 
2411
                            return new JsonModel([
-
 
2412
                                'success' => false,
-
 
2413
                                'data' => $userProgressMapper->getError()
-
 
2414
                            ]);
-
 
2415
                        }
-
 
2416
                    } 
-
 
2417
                    
-
 
2418
                    $userLog = new MicrolearningUserLog();
-
 
2419
                    $userLog->activity      = MicrolearningUserLog::ACTIVITY_VIEW_SLIDE;
-
 
2420
                    $userLog->user_id       = $currentUser->id;
-
 
2421
                    $userLog->company_id    = $slide->company_id;
-
 
2422
                    $userLog->topic_id      = $slide->topic_id;
-
 
2423
                    $userLog->capsule_id    = $slide->capsule_id;
2230
 
2424
                    $userLog->slide_id      = $slide->id;
-
 
2425
                    $userLog->added_on      = $added_on;
-
 
2426
                    
-
 
2427
                    if(!$userLogMapper->insert($userLog)) {
-
 
2428
                        return new JsonModel([
-
 
2429
                            'success' => false,
-
 
2430
                            'data' => $userLogMapper->getError()
-
 
2431
                        ]);
-
 
2432
                    }
-
 
2433
                    
-
 
2434
                    $closeCapsule = false;
-
 
2435
                    
-
 
2436
                    if($userProgressCapsule->completed) {
-
 
2437
                        
-
 
2438
                        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $added_on);
-
 
2439
                        $returning_on = $dt->format('Y-m-d');
-
 
2440
                        
-
 
2441
                        // Asegurarse que returning_on existe en el objeto antes de comparar
-
 
2442
                        $current_returning_on = isset($userProgressCapsule->returning_on) ? $userProgressCapsule->returning_on : null;
-
 
2443
                        
-
 
2444
                        if(!$current_returning_on || $current_returning_on != $returning_on) {
-
 
2445
                            
-
 
2446
                            $userProgressCapsule->returning_on = $returning_on;
-
 
2447
                            // Asegurarse que returning_after_completed existe y es numérico antes de incrementar
-
 
2448
                            $userProgressCapsule->returning_after_completed = (isset($userProgressCapsule->returning_after_completed) ? intval($userProgressCapsule->returning_after_completed) : 0) + 1;
-
 
2449
                            
-
 
2450
                            if(!$userProgressMapper->update($userProgressCapsule)) {
-
 
2451
                                return new JsonModel([
-
 
2452
                                    'success' => false,
-
 
2453
                                    'data' => $userProgressMapper->getError()
-
 
2454
                                ]);
-
 
2455
                            }
-
 
2456
                        }
-
 
2457
                        
-
 
2458
                    }  else {
-
 
2459
                        
-
 
2460
                        // Usar $topic->id para obtener el total de slides de la cápsula en el contexto de este tópico
-
 
2461
                        $userProgressCapsule->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
-
 
2462
                        $userProgressCapsule->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndCapsuleId($currentUser->id, $capsule->id);
-
 
2463
                        
2231
        $slide_uuid = $this->params()->fromRoute('slide_uuid');
2464
                        if($userProgressCapsule->total_slides) {
-
 
2465
                          
-
 
2466
                            $userProgressCapsule->progress = ($userProgressCapsule->view_slides * 100) / $userProgressCapsule->total_slides;
-
 
2467
                            $userProgressCapsule->progress = $userProgressCapsule->progress > 100 ? 100 : $userProgressCapsule->progress;
-
 
2468
                        } 
-
 
2469
                        
-
 
2470
                        if(!$userProgressMapper->update($userProgressCapsule)) {
-
 
2471
                            return new JsonModel([
-
 
2472
                                'success' => false,
-
 
2473
                                'data' => $userProgressMapper->getError()
-
 
2474
                            ]);
-
 
2475
                        }
-
 
2476
                        
-
 
2477
                        if($userProgressCapsule->progress >= 100) {
-
 
2478
                            $closeCapsule = true;
-
 
2479
                        }
-
 
Línea 2480... Línea -...
2480
                        
-
 
2481
 
-
 
2482
                    }
-
 
2483
                    
-
 
2484
                    $closeTopic = false;
-
 
2485
                    if(!$userProgressTopic->completed) {
-
 
2486
                        
-
 
2487
                        // Usar $topic->id para obtener el total de slides del tópico
-
 
2488
                        $userProgressTopic->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($topic->company_id, $topic->id);
-
 
2489
                        $userProgressTopic->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndTopicId($currentUser->id, $topic->id);
-
 
2490
                        
-
 
2491
                        if($userProgressTopic->total_slides) {
-
 
2492
                            
-
 
2493
                            $userProgressTopic->progress = ($userProgressTopic->view_slides * 100) / $userProgressTopic->total_slides;
-
 
2494
                            $userProgressTopic->progress = $userProgressTopic->progress > 100 ? 100 : $userProgressTopic->progress;
-
 
2495
                        }
-
 
2496
                        if(!$userProgressMapper->update($userProgressTopic)) {
-
 
2497
                            return new JsonModel([
-
 
2498
                                'success' => false,
-
 
2499
                                'data' => $userProgressMapper->getError()
-
 
2500
                            ]);
-
 
2501
                        }
-
 
2502
                        
-
 
2503
                        if($userProgressTopic->progress >= 100) {
-
 
2504
                            $closeTopic = true;
-
 
2505
                        }
-
 
2506
                    }
-
 
2507
                    
-
 
2508
                    
-
 
2509
                    $data = [
-
 
2510
                        'message' => 'LABEL_THE_USER_PROGRESS_FOR_THIS_SLIDE_HAS_BEEN_COMPLETED',
-
 
2511
                        
-
 
2512
                    ]; 
-
 
2513
                    
-
 
2514
                    if($closeCapsule) {
-
 
2515
                        $data['link_close_capsule'] = $this->url()->fromRoute('microlearning/sync', ['operation' => 'capsule-close', 'topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid], ['force_canonical' => true]);
-
 
2516
                    }
-
 
2517
                    
-
 
2518
          
-
 
2519
                    if($closeTopic) {
-
 
2520
                        $data['link_close_topic'] = $this->url()->fromRoute('microlearning/sync', ['operation' => 'topic-close', 'topic_uuid' => $topic->uuid], ['force_canonical' => true]);
-
 
2521
                    }
-
 
2522
                    
-
 
2523
                    
-
 
2524
                    return new JsonModel([
-
 
2525
                        'success' => true,
-
 
2526
                        'data' => $data
-
 
2527
                    ]);
-
 
2528
                    
-
 
2529
                    
-
 
2530
                    
-
 
2531
                    
-
 
2532
                } else if($operation == 'capsule-close') {
2232
        $topic_uuid = $this->params()->fromRoute('topic_uuid');
2533
                    
-
 
2534
                    if(empty($capsule_uuid ) || empty($topic_uuid)) {
-
 
2535
                        return new JsonModel([
2233
 
2536
                            'success' => false,
-
 
2537
                            'data' => 'ERROR_INVALID_PARAMETERS'
-
 
2538
                        ]);
-
 
2539
                    }
-
 
2540
                    
-
 
2541
                    
-
 
2542
                    $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
2543
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
2544
                    
-
 
2545
                    if(!$topic) {
-
 
2546
                        return new JsonModel([
-
 
2547
                            'success' => false,
-
 
2548
                            'data' => 'ERROR_TOPIC_NOT_FOUND'
-
 
2549
                        ]);
-
 
2550
                    }
-
 
2551
                    
-
 
2552
                    
-
 
2553
                    
-
 
2554
                    if(!in_array($topic->id, $accessGrantedIds->topics)) {
-
 
2555
                        return new JsonModel([
-
 
2556
                            'success' => false,
-
 
2557
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
-
 
2558
                        ]);
-
 
2559
                    }
-
 
2560
                    
-
 
2561
                    $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
2562
                    $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
-
 
2563
                    
-
 
2564
                    if(!$capsule) {
-
 
2565
                        return new JsonModel([
-
 
2566
                            'success' => false,
-
 
2567
                            'data' => 'ERROR_CAPSULE_NOT_FOUND'
-
 
2568
                        ]);
-
 
2569
                    }
-
 
2570
                    
-
 
2571
                    if(!in_array($capsule->id, $accessGrantedIds->capsules) || $capsule->topic_id != $topic->id) {
-
 
2572
                        return new JsonModel([
-
 
2573
                            'success' => false,
-
 
2574
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
-
 
2575
                        ]);
-
 
2576
                    }
-
 
2577
                    
-
 
2578
                    
-
 
2579
                    $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
-
 
2580
                    
-
 
2581
                    $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
2582
                    $updated_on = $userProgressMapper->getDatebaseNow();
-
 
2583
                    
-
 
2584
                    $userProgressCapsule = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
-
 
2585
                    if(!$userProgressCapsule) {
-
 
2586
                        return new JsonModel([
-
 
2587
                            'success' => false,
-
 
2588
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_CAPSULE_NOT_FOUND'
-
 
2589
                        ]);
-
 
2590
                    }
-
 
2591
                    
-
 
2592
                    if($userProgressCapsule->completed) {
-
 
2593
                        return new JsonModel([
-
 
2594
                            'success' => false,
-
 
2595
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_CAPSULE_ALREADY_CLOSED'
-
 
2596
                        ]);
-
 
2597
                    }
-
 
2598
                    
-
 
2599
                    
-
 
2600
                    $userProgressCapsule->completed = 1;
-
 
2601
                    $userProgressCapsule->updated_on = $updated_on;
-
 
2602
                    
-
 
2603
                    if($userProgressMapper->update($userProgressCapsule)) {
-
 
2604
                        
-
 
2605
                        
-
 
2606
                        $userLog = new MicrolearningUserLog();
-
 
2607
                        $userLog->activity      = MicrolearningUserLog::ACTIVITY_COMPLETED_CAPSULE;
-
 
2608
                        $userLog->user_id       = $currentUser->id;
-
 
2609
                        $userLog->company_id    = $capsule->company_id;
-
 
2610
                        $userLog->topic_id      = $capsule->topic_id;
-
 
2611
                        $userLog->capsule_id    = $capsule->id;
-
 
2612
                        $userLog->added_on      = $updated_on;
-
 
2613
                        
-
 
2614
                        if(!$userLogMapper->insert($userLog)) {
-
 
2615
                            return new JsonModel([
-
 
2616
                                'success' => false,
-
 
2617
                                'data' => $userProgressMapper->getError()
-
 
2618
                            ]);
-
 
2619
                        }
-
 
2620
                        
-
 
2621
                        
-
 
2622
                        return new JsonModel([
-
 
2623
                            'success' => true,
-
 
2624
                            'data' => 'LABEL_THE_USER_PROGRESS_FOR_THIS_CAPSULE_HAS_BEEN_COMPLETED'
-
 
2625
                        ]);
-
 
2626
                    } else {
-
 
2627
                        return new JsonModel([
-
 
2628
                            'success' => false,
-
 
2629
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_CAPSULE_COULD_NOT_BE_COMPLETED'
-
 
2630
                        ]);
-
 
2631
                    }
-
 
2632
                    
-
 
2633
                    
-
 
2634
                    
-
 
2635
                    
-
 
2636
                    
-
 
2637
                    
-
 
2638
                    
-
 
2639
                } else if($operation == 'topic-close') {
-
 
2640
                    if(empty($topic_uuid)) {
-
 
2641
                        return new JsonModel([
-
 
2642
                            'success' => false,
-
 
2643
                            'data' => 'ERROR_INVALID_PARAMETERS'
-
 
2644
                        ]);
-
 
2645
                    }
-
 
2646
                    
-
 
2647
                    
-
 
2648
                    $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
2649
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
2650
                    
-
 
2651
                    if(!$topic) {
-
 
2652
                        return new JsonModel([
-
 
2653
                            'success' => false,
-
 
2654
                            'data' => 'ERROR_TOPIC_NOT_FOUND'
-
 
2655
                        ]);
-
 
2656
                    }
-
 
2657
                    
-
 
2658
                    
-
 
2659
                    
-
 
2660
                    if(!in_array($topic->id, $accessGrantedIds->topics)) {
-
 
2661
                        return new JsonModel([
-
 
2662
                            'success' => false,
-
 
2663
                            'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_TOPIC'
-
 
2664
                        ]);
-
 
2665
                    }
-
 
2666
                    
-
 
2667
                 
-
 
2668
                    
-
 
2669
                    
-
 
2670
                    $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
-
 
2671
                    
-
 
2672
                    $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
2673
                    $updated_on = $userProgressMapper->getDatebaseNow();
-
 
2674
                    
-
 
2675
                    $userProgressTopic = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
-
 
2676
                    if(!$userProgressTopic) {
-
 
2677
                        return new JsonModel([
-
 
2678
                            'success' => false,
-
 
2679
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_TOPIC_NOT_FOUND'
-
 
2680
                        ]);
-
 
2681
                    }
-
 
2682
                    
-
 
2683
                    if($userProgressTopic->completed) {
-
 
2684
                        return new JsonModel([
-
 
2685
                            'success' => false,
-
 
2686
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_TOPIC_ALREADY_CLOSED'
-
 
2687
                        ]);
-
 
2688
                    }
-
 
2689
                    
-
 
2690
                    
-
 
2691
                    $userProgressTopic->completed = 1;
-
 
2692
                    $userProgressTopic->updated_on = $updated_on;
-
 
2693
                    
-
 
2694
                    if($userProgressMapper->update($userProgressTopic)) {
-
 
2695
                        
-
 
2696
                        $userLog = new MicrolearningUserLog();
-
 
2697
                        $userLog->activity      = MicrolearningUserLog::ACTIVITY_COMPLETED_TOPIC;
-
 
2698
                        $userLog->user_id       = $currentUser->id;
-
 
2699
                        $userLog->company_id    = $topic->company_id;
-
 
2700
                        $userLog->topic_id      = $topic->id;
-
 
2701
                        $userLog->added_on      = $updated_on;
-
 
2702
                        
-
 
2703
                        if(!$userLogMapper->insert($userLog)) {
-
 
2704
                            return new JsonModel([
-
 
2705
                                'success' => false,
-
 
2706
                                'data' => $userProgressMapper->getError()
-
 
2707
                            ]);
-
 
2708
                        }
-
 
2709
                        
-
 
2710
                        return new JsonModel([
-
 
2711
                            'success' => true,
-
 
2712
                            'data' => 'LABEL_THE_USER_PROGRESS_FOR_THIS_TOPIC_HAS_BEEN_COMPLETED'
-
 
2713
                        ]);
-
 
2714
                    } else {
-
 
2715
                        return new JsonModel([
-
 
2716
                            'success' => false,
-
 
2717
                            'data' => 'ERROR_THE_USER_PROGRESS_FOR_THIS_TOPIC_COULD_NOT_BE_COMPLETED'
-
 
2718
                        ]);
-
 
2719
                    }
-
 
2720
                }
-
 
2721
                
-
 
2722
                
-
 
2723
                
-
 
2724
                
-
 
2725
            } else {
-
 
2726
                
-
 
2727
                return new JsonModel([
-
 
2728
                    'success' => false,
-
 
2729
                    'data' => 'ERROR_OPERATION_UNKNOWN'
-
 
2730
                ]);
-
 
2731
                    
-
 
2732
            
-
 
2733
            }
-
 
2734
            
-
 
2735
        } else {
-
 
2736
            return new JsonModel([
-
 
2737
                'success' => false,
-
 
2738
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2234
        if (empty($slide_uuid) || empty($topic_uuid)) {
-
 
2235
            return new JsonModel(['success' => false, 'data' => 'ERROR_MISSING_PARAMETERS']);
-
 
2236
        }
-
 
2237
 
-
 
2238
        $currentUser = $this->plugin('currentUserPlugin')->getUser();
-
 
2239
        $user_id = $currentUser->id ?? null;
2739
            ]);
2240
        if (!$user_id) {
-
 
2241
            return new JsonModel(['success' => false, 'data' => 'ERROR_USER_NOT_FOUND']);
-
 
2242
        }
-
 
2243
 
-
 
2244
        $accessGrantedIds = $this->getAccessGranted();
-
 
2245
 
-
 
2246
        // Obtener Slide
-
 
2247
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
2248
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
-
 
2249
        if (!$slide) {
-
 
2250
            return new JsonModel(['success' => false, 'data' => 'ERROR_SLIDE_NOT_FOUND']);
-
 
2251
        }
-
 
2252
 
-
 
2253
        // Obtener Cápsula
-
 
2254
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
2255
        $capsule = $capsuleMapper->fetchById($slide->capsule_id);
-
 
2256
        if (!$capsule || !in_array($capsule->id, $accessGrantedIds->capsules)) {
-
 
2257
            return new JsonModel(['success' => false, 'data' => 'ERROR_CAPSULE_ACCESS_DENIED']);
-
 
2258
        }
-
 
2259
 
-
 
2260
        // Obtener Tópico
-
 
2261
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
2262
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
2263
        if (!$topic || !in_array($topic->id, $accessGrantedIds->topics)) {
-
 
2264
            return new JsonModel(['success' => false, 'data' => 'ERROR_TOPIC_ACCESS_DENIED']);
-
 
2265
        }
-
 
2266
 
-
 
2267
        // Validar que la cápsula pertenece al tópico
-
 
2268
        $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
2269
        $relation = $topicCapsuleMapper->fetchOneByTopicIdAndCapsuleId($topic->id, $capsule->id);
-
 
2270
        if (!$relation) {
2740
        }
2271
            return new JsonModel(['success' => false, 'data' => 'ERROR_CAPSULE_DOES_NOT_BELONG_TO_TOPIC']);
-
 
2272
        }
-
 
2273
 
-
 
2274
        // Marcar slide como visto
2741
    }
2275
        $progressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
2276
        $progressMapper->markSlideViewed($user_id, $topic->id, $capsule->id, $slide->id);
2742
    
2277
 
-
 
2278
        $data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_SLIDE_HAS_BEEN_COMPLETED';
-
 
2279
 
-
 
2280
        // Si vio todos los slides → marcar cápsula como completada
-
 
2281
        if ($progressMapper->hasViewedAllSlidesInCapsule($user_id, $capsule->id)) {
-
 
2282
            $progressMapper->markCapsuleCompleted($user_id, $topic->id, $capsule->id);
-
 
2283
            $data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_CAPSULE_HAS_BEEN_COMPLETED';
-
 
2284
        }
-
 
2285
 
-
 
2286
        // Si completó todas las cápsulas del tópico → marcar tópico como completado
-
 
2287
        if ($progressMapper->hasCompletedAllCapsulesInTopic($user_id, $topic->id)) {
-
 
2288
            $progressMapper->markTopicCompleted($user_id, $topic->id);
2743
    
2289
            $data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_TOPIC_HAS_BEEN_COMPLETED';
-
 
2290
        }
-
 
2291
 
Línea 2744... Línea 2292...
2744
   
2292
        return new JsonModel(['success' => true, 'data' => $data]);
2745
    
2293
    }    
2746
    
2294
    
2747
    /**
2295
    /**
Línea 2787... Línea 2335...
2787
        }
2335
        }
Línea 2788... Línea 2336...
2788
        
2336
        
2789
        return $accessGrantedIds;
2337
        return $accessGrantedIds;
Línea -... Línea 2338...
-
 
2338
    }
-
 
2339
    
-
 
2340
    /**
-
 
2341
     * Marks a slide as completed and cascades completion status to capsule and topic if needed
-
 
2342
     * 
-
 
2343
     * @return \Laminas\View\Model\JsonModel
-
 
2344
     */
-
 
2345
    public function completeSlideAction()
-
 
2346
    {
-
 
2347
        $request = $this->getRequest();
-
 
2348
        if($request->isPost()) {
-
 
2349
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
2350
            $currentUser = $currentUserPlugin->getUser();
-
 
2351
            
-
 
2352
            $slide_uuid = $this->params()->fromRoute('slide_uuid');
-
 
2353
            $topic_uuid = $this->params()->fromRoute('topic_uuid');
-
 
2354
            $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
-
 
2355
 
-
 
2356
            if(empty($slide_uuid) || empty($topic_uuid) || empty($capsule_uuid)) {
-
 
2357
                return new JsonModel([
-
 
2358
                    'success' => false,
-
 
2359
                    'data' => 'ERROR_INVALID_PARAMETERS'
-
 
2360
                ]);
-
 
2361
            }
-
 
2362
 
-
 
2363
            // Get slide
-
 
2364
            $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
2365
            $slide = $slideMapper->fetchOneByUuid($slide_uuid);
-
 
2366
 
-
 
2367
            if(!$slide) {
-
 
2368
                return new JsonModel([
-
 
2369
                    'success' => false,
-
 
2370
                    'data' => 'ERROR_SLIDE_NOT_FOUND'
-
 
2371
                ]);
-
 
2372
            }
-
 
2373
 
-
 
2374
            // Get capsule
-
 
2375
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
2376
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
-
 
2377
 
-
 
2378
            if(!$capsule) {
-
 
2379
                return new JsonModel([
-
 
2380
                    'success' => false,
-
 
2381
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
-
 
2382
                ]);
-
 
2383
            }
-
 
2384
 
-
 
2385
            // Get topic
-
 
2386
            $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
2387
            $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
2388
 
-
 
2389
            if(!$topic) {
-
 
2390
                return new JsonModel([
-
 
2391
                    'success' => false,
-
 
2392
                    'data' => 'ERROR_TOPIC_NOT_FOUND'
-
 
2393
                ]);
-
 
2394
            }
-
 
2395
 
-
 
2396
            // Update slide progress
-
 
2397
            $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
2398
            $slideProgress = $userProgressMapper->fetchOneByUserIdAndSlideId($currentUser->id, $slide->id);
-
 
2399
            $updated_on = $userProgressMapper->getDatebaseNow();
-
 
2400
            
-
 
2401
            if(!$slideProgress) {
-
 
2402
                $slideProgress = new MicrolearningUserProgress();
-
 
2403
                $slideProgress->user_id = $currentUser->id;
-
 
2404
                $slideProgress->slide_id = $slide->id;
-
 
2405
                $slideProgress->topic_id = $topic->id;
-
 
2406
                $slideProgress->capsule_id = $capsule->id;
-
 
2407
            }
-
 
2408
 
-
 
2409
            $slideProgress->completed = 1;
-
 
2410
            $slideProgress->updated_on = $updated_on;
-
 
2411
 
-
 
2412
            if($userProgressMapper->update($slideProgress)) {
-
 
2413
                $closeCapsule = false;
-
 
2414
                $closeTopic = false;
-
 
2415
            }
-
 
2416
 
-
 
2417
            // Check if capsule is completed
-
 
2418
            $capsuleProgress = $userProgressMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
-
 
2419
 
-
 
2420
            $capsuleProgress->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndCapsuleId($capsule->company_id, $capsule->id);
-
 
2421
            $capsuleProgress->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndCapsuleId($currentUser->id, $capsule->id);
-
 
2422
            
-
 
2423
            if($capsuleProgress->total_slides) {
-
 
2424
                $capsuleProgress->progress = ($capsuleProgress->view_slides * 100) / $capsuleProgress->total_slides;
-
 
2425
                $capsuleProgress->progress = $capsuleProgress->progress > 100 ? 100 : $capsuleProgress->progress;
-
 
2426
            } 
-
 
2427
            
-
 
2428
            if(!$userProgressMapper->update($capsuleProgress)) {
-
 
2429
                return new JsonModel([
-
 
2430
                    'success' => false,
-
 
2431
                    'data' => $userProgressMapper->getError()
-
 
2432
                ]);
-
 
2433
            }
-
 
2434
             
-
 
2435
            if($capsuleProgress->progress >= 100) {
-
 
2436
                $closeCapsule = true;
-
 
2437
            }
-
 
2438
 
-
 
2439
            // Check if topic is completed
-
 
2440
            $topicProgress = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
-
 
2441
            if($topicProgress->completed) {
-
 
2442
                $closeTopic = true;
-
 
2443
            }
-
 
2444
            
-
 
2445
 
-
 
2446
            // Prepare response
-
 
2447
            $data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_SLIDE_HAS_BEEN_COMPLETED';
-
 
2448
 
-
 
2449
            if($closeCapsule) {
-
 
2450
                $data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_CAPSULE_HAS_BEEN_COMPLETED';
-
 
2451
            }
-
 
2452
 
-
 
2453
            if($closeTopic) {
-
 
2454
                $data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_TOPIC_HAS_BEEN_COMPLETED';
-
 
2455
            }
-
 
2456
 
-
 
2457
            return new JsonModel([
-
 
2458
                'success' => true,
-
 
2459
                'data' => $data
2790
    }
2460
            ]);
-
 
2461
        }
-
 
2462
 
-
 
2463
        return new JsonModel([
-
 
2464
            'success' => false,
-
 
2465
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2791
    
2466
        ]);
2792
  
2467
    }