Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 585 Rev 586
Línea 1401... Línea 1401...
1401
            ]);
1401
            ]);
1402
        }
1402
        }
Línea 1403... Línea 1403...
1403
 
1403
 
1404
        return $data;
1404
        return $data;
-
 
1405
    }
-
 
1406
 
-
 
1407
    /**
-
 
1408
     * @param MicrolearningCapsule $capsule The capsule object.
-
 
1409
     * @param Storage $storage The storage object.
-
 
1410
     * @return array The slides data.
-
 
1411
     */
-
 
1412
    private function _getSlidesByCapsule($capsule, $storage)
-
 
1413
    {
-
 
1414
        $data = [];
-
 
1415
        $accessGrantedIds = $this->getAccessGranted();
-
 
1416
 
-
 
1417
        if (!$capsule) {
-
 
1418
            return $data;
-
 
1419
        }
-
 
1420
 
-
 
1421
        if (!in_array($capsule->id, $accessGrantedIds->capsules)) {
-
 
1422
            return $data;
-
 
1423
        }
-
 
1424
 
-
 
1425
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1426
        $currentUser = $currentUserPlugin->getUser();
-
 
1427
 
-
 
1428
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
1429
        $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
1430
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
-
 
1431
 
-
 
1432
        $path = $storage->getPathMicrolearningSlide();
-
 
1433
        $slides = $slideMapper->fetchAllByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $capsule->topic_id, $capsule->id);
-
 
1434
 
-
 
1435
        foreach ($slides as $slide) {
-
 
1436
            $userProgress = $userProgressMapper->fetchOneByUserIdAndSlideId($currentUser->id, $slide->id);
-
 
1437
            $completed = $userProgress ? $userProgress->completed : 0;
-
 
1438
 
-
 
1439
            $quiz_uuid = '';
-
 
1440
            $quiz_data = [];
-
 
1441
            $link_take_a_test = '';
-
 
1442
 
-
 
1443
            if ($slide->quiz_id) {
-
 
1444
                $quiz = $quizMapper->fetchOne($slide->quiz_id);
-
 
1445
                if ($quiz) {
-
 
1446
                    $quiz_uuid = $quiz->uuid;
-
 
1447
                    $quiz_data = $this->getQuiz($slide->quiz_id);
-
 
1448
                    $link_take_a_test = $this->url()->fromRoute('microlearning/take-a-test', ['slide_id' => $slide->uuid], ['force_canonical' => true]);
-
 
1449
                }
-
 
1450
            }
-
 
1451
 
-
 
1452
            array_push($data, [
-
 
1453
                'quiz'                  => $quiz_uuid,
-
 
1454
                'quiz_data'             => $quiz_data,
-
 
1455
                'uuid'                  => $slide->uuid,
-
 
1456
                'name'                  => $slide->name ? $slide->name : '',
-
 
1457
                'description'           => $slide->description ? $slide->description : '',
-
 
1458
                'type'                  => $slide->type,
-
 
1459
                'background'            => $slide->background ? $storage->getGenericImage($path, $slide->uuid, $slide->background) : '',
-
 
1460
                'file'                  => $slide->file ? $storage->getGenericFile($path, $slide->uuid, $slide->file) : '',
-
 
1461
                'order'                 => $slide->order,
-
 
1462
                'completed'             => $completed,
-
 
1463
                'link_get'              => $this->url()->fromRoute('microlearning/get-slide', ['id' => $slide->uuid], ['force_canonical' => true]),
-
 
1464
                'link_sync'             => $this->url()->fromRoute('microlearning/sync', ['operation' => 'slide-view', 'topic_uuid' => $capsule->topic_id, 'capsule_uuid' => $capsule->uuid, 'slide_uuid' => $slide->uuid], ['force_canonical' => true]),
-
 
1465
                'link_take_a_test'      => $link_take_a_test,
-
 
1466
                'added_on'              => $slide->added_on,
-
 
1467
                'updated_on'            => $slide->updated_on,
-
 
1468
            ]);
-
 
1469
        }
-
 
1470
 
-
 
1471
        // Sort slides by order, then by added_on, then by name
-
 
1472
        usort($data, function($a, $b) {
-
 
1473
            $result = $a['order'] <=> $b['order'];
-
 
1474
            if (0 == $result) {
-
 
1475
                $result = strcasecmp($a['added_on'], $b['added_on']);
-
 
1476
                if (0 == $result) {
-
 
1477
                    $result = strcasecmp($a['name'], $b['name']);
-
 
1478
                }
-
 
1479
            }
-
 
1480
 
-
 
1481
            if ($result < 0) {
-
 
1482
                return 1;
-
 
1483
            } else if ($result > 0) {
-
 
1484
                return -1;
-
 
1485
            } else {
-
 
1486
                return 0;
-
 
1487
            }
-
 
1488
        });
-
 
1489
 
-
 
1490
        return $data;
1405
    }
1491
    }
1406
    
1492
 
1407
    public function capsulesAction()
1493
    public function capsulesAction()
1408
    {
1494
    {
1409
        $request = $this->getRequest();
1495
        $request = $this->getRequest();
1410
        if($request->isGet()) {
1496
        if($request->isGet()) {
Línea 1562... Línea 1648...
1562
    }
1648
    }
Línea 1563... Línea 1649...
1563
    
1649
    
1564
    public function getCapsuleAction()
1650
    public function getCapsuleAction()
1565
    {
1651
    {
-
 
1652
        $request = $this->getRequest();
1566
        $request = $this->getRequest();
1653
        
1567
        if($request->isGet()) {
1654
        if($request->isGet()) {
1568
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1655
            $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 1569... Línea -...
1569
            $currentUser = $currentUserPlugin->getUser();
-
 
1570
            
-
 
1571
            
1656
            $currentUser = $currentUserPlugin->getUser();
1572
            
1657
            
1573
            $capsule_uuid = $this->params()->fromRoute('id');
1658
            $capsule_uuid = $this->params()->fromRoute('id');
Línea 1574... Línea 1659...
1574
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
1659
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
Línea 1581... Línea 1666...
1581
                ]);
1666
                ]);
1582
            }
1667
            }
Línea 1583... Línea 1668...
1583
            
1668
            
Línea 1584... Línea -...
1584
            $accessGrantedIds = $this->getAccessGranted();
-
 
1585
            
1669
            $accessGrantedIds = $this->getAccessGranted();
1586
            // Verificar si el usuario tiene acceso a esta cápsula específica
1670
            
1587
            if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
1671
            if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
1588
                return new JsonModel([
1672
                return new JsonModel([
1589
                    'success' => false,
1673
                    'success' => false,
1590
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
1674
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
Línea 1591... Línea 1675...
1591
                ]);
1675
                ]);
1592
            }
1676
            }
1593
            
1677
            
1594
            // --- Obtener el Tópico asociado (si existe y es necesario) ---
1678
            // Obtener el Tópico asociado
1595
            $topic = null;
-
 
1596
            $topic_uuid_for_links = null; // UUID del tópico para construir enlaces
-
 
1597
            $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
1598
            // Asumiendo que una cápsula puede estar asociada a múltiples tópicos (muchos-a-muchos),
1679
            $topic = null;
Línea 1599... Línea 1680...
1599
            // necesitamos decidir cuál tópico usar como contexto aquí. Usaremos el primero que encontremos.
1680
            $topic_uuid_for_links = null;
1600
            // Si una cápsula SIEMPRE pertenece a UN SOLO tópico, la tabla de unión podría tener una restricción UNIQUE(capsule_id).
1681
            $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
1601
            $relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id); // Necesitamos un método como este
1682
            $relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
1602
            
1683
            
1603
            if ($relation && in_array($relation->topic_id, $accessGrantedIds->topics)) {
1684
            if ($relation && in_array($relation->topic_id, $accessGrantedIds->topics)) {
1604
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
1685
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
1605
                $topic = $topicMapper->fetchOne($relation->topic_id);
1686
                $topic = $topicMapper->fetchOne($relation->topic_id);
1606
                if ($topic) {
-
 
1607
                    $topic_uuid_for_links = $topic->uuid;
-
 
1608
                }
-
 
1609
            }
-
 
1610
            // Si no se encontró un tópico asociado o el usuario no tiene acceso a él,
-
 
Línea 1611... Línea 1687...
1611
            // algunos enlaces podrían no generarse o la lógica necesitaría ajustarse.
1687
                if ($topic) {
1612
            // Por ahora, si no hay $topic_uuid_for_links, el link_slides será inválido.
1688
                    $topic_uuid_for_links = $topic->uuid;
Línea 1613... Línea -...
1613
            // --------------------------------------------------------------
-
 
1614
    
-
 
1615
            
1689
                }
1616
            $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
1617
            $capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
1690
            }
1618
            
1691
            
1619
 
-
 
1620
                
-
 
1621
            $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
-
 
1622
            if($userProgress) {
-
 
1623
                $progress = $userProgress->progress;
-
 
1624
                $completed = $userProgress->completed;
-
 
1625
            } else {
-
 
Línea 1626... Línea -...
1626
                $progress = 0;
-
 
1627
                $completed = 0;
-
 
1628
            }
-
 
1629
                
-
 
1630
            $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id,  $capsule->id);
1692
            $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
1631
                
-
 
Línea 1632... Línea -...
1632
            
-
 
1633
            $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
1634
            // Para contar slides, necesitamos el contexto del tópico.
-
 
1635
            $totalSlides = 0;
-
 
1636
            if ($topic) { // Solo contar si tenemos un tópico asociado válido
-
 
1637
                $totalSlides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
-
 
1638
            }
-
 
1639
            
-
 
1640
         
-
 
1641
            $link_first_slide = '';
-
 
1642
            $type_first_slide = '';
-
 
1643
            if ($topic) { // Solo buscar primer slide si tenemos tópico
1693
            $capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
1644
                $slide = $slideMapper->fetchFirstByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
1694
            
Línea -... Línea 1695...
-
 
1695
            $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
-
 
1696
            $progress = $userProgress ? $userProgress->progress : 0;
1645
                if($slide) {
1697
            $completed = $userProgress ? $userProgress->completed : 0;
1646
                    $link_first_slide = $this->url()->fromRoute('microlearning/get-slide', ['id' => $slide->uuid], ['force_canonical' => true]);
1698
            
1647
                    $type_first_slide = $slide->type;
1699
            $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
1648
                }
1700
            
1649
            }
1701
            $storage = Storage::getInstance($this->config, $this->adapter);
1650
                
1702
            $path = $storage->getPathMicrolearningCapsule();
1651
            $storage = Storage::getInstance($this->config, $this->adapter);
1703
            
1652
            $path = $storage->getPathMicrolearningCapsule();
1704
            // Obtener slides usando el método _getSlidesByCapsule
1653
            
1705
            $slides = $this->_getSlidesByCapsule($capsule, $storage);
1654
                
1706
            
1655
            // Construir enlaces usando $topic_uuid_for_links si está disponible
1707
            // Construir enlaces usando $topic_uuid_for_links si está disponible
1656
            $link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
1708
            $link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
1657
                
1709
            
1658
            $data = [
1710
            $data = [
1659
                    'uuid'              => $capsule->uuid,
1711
                'uuid'              => $capsule->uuid,
1660
                    'name'              => $capsule->name ? $capsule->name : '',
1712
                'name'              => $capsule->name ? $capsule->name : '',
1661
                    'description'       => $capsule->description ? $capsule->description : '',
1713
                'description'       => $capsule->description ? $capsule->description : '',
1662
                    'image'             => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image)  : '',
-
 
1663
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
1714
                'image'             => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
1664
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
1715
                'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
1665
                    'link_slides'       => $link_slides, // Usar el enlace construido
1716
                'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
1666
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
1717
                'link_slides'       => $link_slides,
1667
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
1718
                'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
1668
                    'progress'          => $progress,
-
 
1669
                    'completed'         => $completed,
1719
                'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
1670
                    'total_slides'      => $totalSlides,
-
 
1671
                    'link_first_slide'  => $link_first_slide,
1720
                'progress'          => $progress,
1672
                    'type_first_slide'  => $type_first_slide,
1721
                'completed'         => $completed,
1673
                    'order'             => $capsule->order,
1722
                'total_slides'      => count($slides),
1674
                    'added_on'          => $capsule->added_on,
1723
                'slides'            => $slides,
1675
                    'updated_on'        => $capsule->updated_on,
-
 
1676
            ];
-
 
1677
  
-
 
1678
                
-
 
1679
                
-
 
1680
            return new JsonModel([
-
 
1681
                'success' => true,
1724
                'order'             => $capsule->order,
-
 
1725
                'added_on'          => $capsule->added_on,
-
 
1726
                'updated_on'        => $capsule->updated_on,
-
 
1727
            ];
-
 
1728
            
-
 
1729
            return new JsonModel([
1682
                'data' => $data
1730
                'success' => true,
Línea 1683... Línea 1731...
1683
            ]);
1731
                'data' => $data
1684
                
1732
            ]);
1685
        } else {
1733
        }