| Línea 575... |
Línea 575... |
| 575 |
if(!in_array($order_field,['name', 'added_on'] )) {
|
575 |
if(!in_array($order_field,['name', 'added_on'] )) {
|
| 576 |
$order_field = 'name';
|
576 |
$order_field = 'name';
|
| 577 |
}
|
577 |
}
|
| Línea 578... |
Línea 578... |
| 578 |
|
578 |
|
| 579 |
if(!in_array( $order_direction,['asc', 'desc'])) {
|
579 |
if(!in_array( $order_direction,['asc', 'desc'])) {
|
| 580 |
$order_field = 'asc';
|
580 |
$order_direction = 'asc'; // Corregido: asignar a $order_direction
|
| Línea 581... |
Línea -... |
| 581 |
}
|
- |
|
| 582 |
|
581 |
}
|
| 583 |
|
582 |
|
| 584 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
583 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
| 585 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
584 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
| - |
|
585 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter); // Añadido
|
| Línea 586... |
Línea 586... |
| 586 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
586 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
| 587 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
- |
|
| 588 |
|
587 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter); // Reordenado
|
| 589 |
$accessGranted = $this->getAccessGranted();
|
588 |
|
| 590 |
|
589 |
$accessGranted = $this->getAccessGranted();
|
| Línea 591... |
Línea 590... |
| 591 |
|
590 |
|
| 592 |
$topics = [];
|
591 |
// $topics = []; // Ya no es necesario cachear tópicos aquí
|
| Línea 593... |
Línea 592... |
| 593 |
$capsules = [];
|
592 |
$capsulesData = []; // Renombrado
|
| 594 |
|
593 |
|
| - |
|
594 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 595 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
595 |
$path = $storage->getPathMicrolearningCapsule();
|
| 596 |
$path = $storage->getPathMicrolearningCapsule();
|
596 |
|
| 597 |
|
597 |
foreach($accessGranted->capsules as $capsule_id)
|
| 598 |
foreach($accessGranted->capsules as $capsule_id)
|
598 |
{
|
| 599 |
{
|
599 |
// 1. Verificar progreso (debe ser nulo para pendiente)
|
| - |
|
600 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
| 600 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
601 |
if($userProgress) {
|
| - |
|
602 |
continue;
|
| - |
|
603 |
}
|
| - |
|
604 |
|
| Línea -... |
Línea 605... |
| - |
|
605 |
// 2. Obtener detalles de la cápsula
|
| 601 |
if($userProgress) {
|
606 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
| 602 |
continue;
|
607 |
if(!$capsule) { // Añadir verificación por si la cápsula no existe
|
| 603 |
}
|
608 |
continue;
|
| 604 |
|
609 |
}
|
| 605 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
610 |
|
| Línea -... |
Línea 611... |
| - |
|
611 |
// 3. Filtrar por nombre
|
| - |
|
612 |
if($name) {
|
| - |
|
613 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
| 606 |
|
614 |
continue;
|
| 607 |
if($name) {
|
- |
|
| 608 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
615 |
}
|
| 609 |
continue;
|
616 |
}
|
| 610 |
}
|
617 |
|
| 611 |
}
|
618 |
// 4. Obtener Tópico asociado válido
|
| 612 |
|
619 |
$topic = null;
|
| 613 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
620 |
$topic_uuid_for_links = null;
|
| - |
|
621 |
$relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
|
| - |
|
622 |
if ($relation && in_array($relation->topic_id, $accessGranted->topics)) {
|
| - |
|
623 |
$topic = $topicMapper->fetchOne($relation->topic_id);
|
| Línea -... |
Línea 624... |
| - |
|
624 |
if ($topic) {
|
| - |
|
625 |
$topic_uuid_for_links = $topic->uuid;
|
| Línea -... |
Línea 626... |
| - |
|
626 |
}
|
| 614 |
|
627 |
}
|
| 615 |
if(isset($topics[$capsule->topic_id])) {
|
628 |
|
| 616 |
$topic = $topics[$capsule->topic_id];
|
629 |
// 5. Obtener datos de comentarios
|
| 617 |
} else {
|
630 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
| 618 |
$topic = $topicMapper->fetchOne($capsule->topic_id);
|
631 |
|
| 619 |
$topics[ $capsule->topic_id ] = $topic;
|
632 |
// 6. Construir enlace slides
|
| 620 |
}
|
633 |
$link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
|
| 621 |
|
634 |
|
| 622 |
|
635 |
// 7. Añadir al array de resultados
|
| 623 |
array_push($capsules, [
|
636 |
array_push($capsulesData, [
|
| 624 |
'uuid' => $capsule->uuid,
|
637 |
'uuid' => $capsule->uuid,
|
| 625 |
'name' => $capsule->name ? $capsule->name : '',
|
638 |
'name' => $capsule->name ? $capsule->name : '',
|
| 626 |
'description' => $capsule->description ? $capsule->description : '',
|
639 |
'description' => $capsule->description ? $capsule->description : '',
|
| 627 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
640 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
| 628 |
'position' => $capsule->order,
|
641 |
'position' => $capsule->order,
|
| 629 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
642 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
| 630 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
643 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
| Línea -... |
Línea 644... |
| - |
|
644 |
'link_slides' => $link_slides, // Usar enlace construido
|
| Línea 631... |
Línea 645... |
| 631 |
'link_slides' => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
645 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
| 632 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
646 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
| 633 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
647 |
'progress' => 0,
|
| 634 |
'progress' => 0,
|
648 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
| 635 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
649 |
'added_on' => $capsule->added_on,
|
| 636 |
'added_on' => $capsule->added_on,
|
650 |
'updated_on' => $capsule->updated_on,
|
| 637 |
'updated_on' => $capsule->updated_on,
|
651 |
]);
|
| 638 |
]);
|
652 |
}
|
| 639 |
}
|
- |
|
| 640 |
|
- |
|
| 641 |
|
653 |
|
| 642 |
if($order_field == 'name') {
|
- |
|
| 643 |
if($order_direction == 'asc') {
|
- |
|
| 644 |
usort($capsules, function($a, $b) {
|
- |
|
| 645 |
return strcasecmp($a['name'], $b['name']);
|
- |
|
| 646 |
});
|
654 |
// 8. Ordenar
|
| 647 |
} else {
|
655 |
|
| Línea 648... |
Línea 656... |
| 648 |
usort($capsules, function($a, $b) {
|
656 |
if($order_field == 'name') {
|
| Línea 649... |
Línea 657... |
| 649 |
$result = strcasecmp($a['name'], $b['name']);
|
657 |
if($order_direction == 'asc') {
|
| 650 |
if($result < 0) {
|
658 |
usort($capsulesData, function($a, $b) {
|
| 651 |
return 1;
|
659 |
return strcasecmp($a['name'], $b['name']);
|
| 652 |
} else if($result > 0) {
|
660 |
});
|
| 653 |
return -1;
|
661 |
} else {
|
| 654 |
} else {
|
662 |
usort($capsulesData, function($a, $b) {
|
| 655 |
return 0;
|
663 |
$result = strcasecmp($a['name'], $b['name']);
|
| 656 |
}
|
664 |
if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; } // Simplificado
|
| 657 |
});
|
- |
|
| 658 |
}
|
- |
|
| 659 |
|
665 |
});
|
| 660 |
}
|
- |
|
| 661 |
|
- |
|
| 662 |
if($order_field == 'added_on') {
|
- |
|
| 663 |
if($order_direction == 'asc') {
|
- |
|
| 664 |
usort($capsules, function($a, $b) {
|
666 |
}
|
| 665 |
return strcasecmp($a['added_on'], $b['added_on']);
|
667 |
|
| Línea 666... |
Línea 668... |
| 666 |
});
|
668 |
}
|
| 667 |
} else {
|
- |
|
| 668 |
usort($capsules, function($a, $b) {
|
- |
|
| 669 |
$result = strcasecmp($a['added_on'], $b['added_on']);
|
- |
|
| 670 |
if($result < 0) {
|
- |
|
| 671 |
return 1;
|
- |
|
| 672 |
} else if($result > 0) {
|
- |
|
| Línea -... |
Línea 669... |
| - |
|
669 |
|
| 673 |
return -1;
|
670 |
if($order_field == 'added_on') {
|
| 674 |
} else {
|
671 |
if($order_direction == 'asc') {
|
| 675 |
return 0;
|
672 |
usort($capsulesData, function($a, $b) {
|
| 676 |
}
|
673 |
return strcasecmp($a['added_on'], $b['added_on']);
|
| Línea 677... |
Línea 674... |
| 677 |
});
|
674 |
});
|
| Línea 720... |
Línea 717... |
| 720 |
$order_field = 'asc';
|
717 |
$order_field = 'asc';
|
| 721 |
}
|
718 |
}
|
| Línea 722... |
Línea 719... |
| 722 |
|
719 |
|
| 723 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
720 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
| 724 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
721 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
| 725 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
722 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
| - |
|
723 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
| Línea 726... |
Línea 724... |
| 726 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
724 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
| Línea 727... |
Línea -... |
| 727 |
|
- |
|
| 728 |
$accessGranted = $this->getAccessGranted();
|
725 |
|
| Línea 729... |
Línea 726... |
| 729 |
|
726 |
$accessGranted = $this->getAccessGranted();
|
| 730 |
$topics = [];
|
727 |
|
| Línea 731... |
Línea 728... |
| 731 |
$capsules = [];
|
728 |
$capsulesData = [];
|
| 732 |
|
729 |
|
| - |
|
730 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 733 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
731 |
$path = $storage->getPathMicrolearningCapsule();
|
| 734 |
$path = $storage->getPathMicrolearningCapsule();
|
732 |
|
| 735 |
|
733 |
foreach($accessGranted->capsules as $capsule_id)
|
| 736 |
foreach($accessGranted->capsules as $capsule_id)
|
734 |
{
|
| Línea 737... |
Línea 735... |
| 737 |
{
|
735 |
// 1. Verificar progreso
|
| 738 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
736 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
| 739 |
if(!$userProgress) {
|
737 |
if(!$userProgress) {
|
| Línea 740... |
Línea -... |
| 740 |
continue;
|
- |
|
| 741 |
}
|
- |
|
| - |
|
738 |
continue;
|
| 742 |
|
739 |
}
|
| - |
|
740 |
|
| - |
|
741 |
if(!$userProgress->completed) {
|
| - |
|
742 |
continue;
|
| Línea -... |
Línea 743... |
| - |
|
743 |
}
|
| 743 |
if(!$userProgress->completed) {
|
744 |
|
| 744 |
continue;
|
745 |
// 2. Obtener detalles de la cápsula
|
| 745 |
}
|
746 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
| 746 |
|
747 |
if(!$capsule) {
|
| 747 |
|
748 |
continue;
|
| Línea -... |
Línea 749... |
| - |
|
749 |
}
|
| - |
|
750 |
|
| - |
|
751 |
// 3. Filtrar por nombre
|
| 748 |
|
752 |
if($name) {
|
| 749 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
- |
|
| 750 |
|
753 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
| 751 |
if($name) {
|
754 |
continue;
|
| 752 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
755 |
}
|
| 753 |
continue;
|
756 |
}
|
| 754 |
}
|
757 |
|
| 755 |
}
|
758 |
// 4. Obtener Tópico asociado válido
|
| - |
|
759 |
$topic = null;
|
| - |
|
760 |
$topic_uuid_for_links = null;
|
| - |
|
761 |
$relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
|
| Línea -... |
Línea 762... |
| - |
|
762 |
if ($relation && in_array($relation->topic_id, $accessGranted->topics)) {
|
| - |
|
763 |
$topic = $topicMapper->fetchOne($relation->topic_id);
|
| Línea 756... |
Línea -... |
| 756 |
|
- |
|
| - |
|
764 |
if ($topic) {
|
| 757 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
765 |
$topic_uuid_for_links = $topic->uuid;
|
| 758 |
|
766 |
}
|
| 759 |
if(isset($topics[$capsule->topic_id])) {
|
767 |
}
|
| 760 |
$topic = $topics[$capsule->topic_id];
|
768 |
|
| 761 |
} else {
|
769 |
// 5. Obtener datos de comentarios
|
| 762 |
$topic = $topicMapper->fetchOne($capsule->topic_id);
|
770 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
| 763 |
$topics[ $capsule->topic_id ] = $topic;
|
771 |
|
| 764 |
}
|
772 |
// 6. Construir enlace slides
|
| 765 |
|
773 |
$link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
|
| 766 |
|
774 |
|
| 767 |
|
775 |
// 7. Añadir al array de resultados
|
| 768 |
array_push($capsules, [
|
776 |
array_push($capsulesData, [
|
| 769 |
'uuid' => $capsule->uuid,
|
777 |
'uuid' => $capsule->uuid,
|
| 770 |
'name' => $capsule->name ? $capsule->name : '',
|
778 |
'name' => $capsule->name ? $capsule->name : '',
|
| 771 |
'description' => $capsule->description ? $capsule->description : '',
|
779 |
'description' => $capsule->description ? $capsule->description : '',
|
| 772 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
780 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
| 773 |
'position' => $capsule->order,
|
781 |
'position' => $capsule->order,
|
| 774 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
782 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
| Línea -... |
Línea 783... |
| - |
|
783 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
| 775 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
784 |
'link_slides' => $link_slides,
|
| 776 |
'link_slides' => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
785 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
| 777 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
786 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
| 778 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
787 |
'progress' => $userProgress->progress,
|
| 779 |
'progress' => $userProgress->progress,
|
788 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
| 780 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
789 |
'added_on' => $capsule->added_on,
|
| 781 |
'added_on' => $capsule->added_on,
|
790 |
'last_access_on' => $userProgress->updated_on,
|
| 782 |
'last_access_on' => $userProgress->updated_on,
|
791 |
'updated_on' => $capsule->updated_on,
|
| 783 |
'updated_on' => $capsule->updated_on,
|
- |
|
| 784 |
]);
|
- |
|
| 785 |
}
|
792 |
]);
|
| 786 |
|
- |
|
| 787 |
if($order_field == 'name') {
|
- |
|
| 788 |
if($order_direction == 'asc') {
|
- |
|
| 789 |
usort($capsules, function($a, $b) {
|
- |
|
| 790 |
return strcasecmp($a['name'], $b['name']);
|
793 |
}
|
| 791 |
});
|
794 |
|
| 792 |
} else {
|
- |
|
| 793 |
usort($capsules, function($a, $b) {
|
795 |
// 8. Ordenar (lógica de ordenación permanece igual, usando $capsulesData)
|
| Línea 794... |
Línea 796... |
| 794 |
$result = strcasecmp($a['name'], $b['name']);
|
796 |
if($order_field == 'name') {
|
| 795 |
if($result < 0) {
|
797 |
if($order_direction == 'asc') {
|
| 796 |
return 1;
|
798 |
usort($capsulesData, function($a, $b) {
|
| 797 |
} else if($result > 0) {
|
799 |
return strcasecmp($a['name'], $b['name']);
|
| 798 |
return -1;
|
800 |
});
|
| 799 |
} else {
|
801 |
} else {
|
| 800 |
return 0;
|
802 |
usort($capsulesData, function($a, $b) {
|
| 801 |
}
|
803 |
$result = strcasecmp($a['name'], $b['name']);
|
| 802 |
});
|
- |
|
| 803 |
}
|
- |
|
| 804 |
|
804 |
if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; }
|
| 805 |
}
|
- |
|
| 806 |
|
- |
|
| 807 |
if($order_field == 'added_on') {
|
- |
|
| 808 |
if($order_direction == 'asc') {
|
- |
|
| 809 |
usort($capsules, function($a, $b) {
|
805 |
});
|
| 810 |
return strcasecmp($a['added_on'], $b['added_on']);
|
806 |
}
|
| 811 |
});
|
- |
|
| 812 |
} else {
|
807 |
}
|
| Línea 813... |
Línea 808... |
| 813 |
usort($capsules, function($a, $b) {
|
808 |
|
| 814 |
$result = strcasecmp($a['added_on'], $b['added_on']);
|
809 |
if($order_field == 'added_on') {
|
| 815 |
if($result < 0) {
|
810 |
if($order_direction == 'asc') {
|
| 816 |
return 1;
|
811 |
usort($capsulesData, function($a, $b) {
|
| 817 |
} else if($result > 0) {
|
812 |
return strcasecmp($a['added_on'], $b['added_on']);
|
| 818 |
return -1;
|
813 |
});
|
| 819 |
} else {
|
814 |
} else {
|
| 820 |
return 0;
|
815 |
usort($capsulesData, function($a, $b) {
|
| 821 |
}
|
- |
|
| 822 |
});
|
- |
|
| 823 |
}
|
816 |
$result = strcasecmp($a['added_on'], $b['added_on']);
|
| 824 |
|
- |
|
| 825 |
}
|
- |
|
| 826 |
|
- |
|
| 827 |
if($order_field == 'last_access_on') {
|
- |
|
| 828 |
if($order_direction == 'asc') {
|
817 |
if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; }
|
| 829 |
usort($capsules, function($a, $b) {
|
818 |
});
|
| 830 |
return strcasecmp($a['last_access_on'], $b['last_access_on']);
|
- |
|
| 831 |
});
|
819 |
}
|
| Línea 832... |
Línea 820... |
| 832 |
} else {
|
820 |
}
|
| 833 |
usort($capsules, function($a, $b) {
|
821 |
|
| 834 |
$result = strcasecmp($a['last_access_on'], $b['last_access_on']);
|
822 |
if($order_field == 'last_access_on') {
|
| 835 |
if($result < 0) {
|
823 |
if($order_direction == 'asc') {
|
| Línea 836... |
Línea 824... |
| 836 |
return 1;
|
824 |
usort($capsulesData, function($a, $b) {
|
| Línea 837... |
Línea 825... |
| 837 |
} else if($result > 0) {
|
825 |
return strcasecmp($a['last_access_on'], $b['last_access_on']);
|
| Línea 875... |
Línea 863... |
| 875 |
if(!in_array($order_field,['name', 'added_on', 'last_access_on'] )) {
|
863 |
if(!in_array($order_field,['name', 'added_on', 'last_access_on'] )) {
|
| 876 |
$order_field = 'name';
|
864 |
$order_field = 'name';
|
| 877 |
}
|
865 |
}
|
| Línea 878... |
Línea 866... |
| 878 |
|
866 |
|
| 879 |
if(!in_array( $order_direction,['asc', 'desc'])) {
|
867 |
if(!in_array( $order_direction,['asc', 'desc'])) {
|
| 880 |
$order_field = 'asc';
|
868 |
$order_direction = 'asc';
|
| Línea 881... |
Línea 869... |
| 881 |
}
|
869 |
}
|
| 882 |
|
870 |
|
| 883 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
871 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
| 884 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
872 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
| - |
|
873 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
| Línea 885... |
Línea 874... |
| 885 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
874 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
| Línea 886... |
Línea -... |
| 886 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
- |
|
| 887 |
|
875 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
| Línea 888... |
Línea 876... |
| 888 |
$accessGranted = $this->getAccessGranted();
|
876 |
|
| 889 |
|
877 |
$accessGranted = $this->getAccessGranted();
|
| Línea 890... |
Línea 878... |
| 890 |
$topics = [];
|
878 |
|
| 891 |
$capsules = [];
|
879 |
$capsulesData = [];
|
| - |
|
880 |
|
| 892 |
|
881 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 893 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
- |
|
| 894 |
$path = $storage->getPathMicrolearningCapsule();
|
- |
|
| 895 |
|
- |
|
| 896 |
foreach($accessGranted->capsules as $capsule_id)
|
- |
|
| 897 |
{
|
882 |
$path = $storage->getPathMicrolearningCapsule();
|
| 898 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
883 |
|
| 899 |
if(!$userProgress) {
|
884 |
foreach($accessGranted->capsules as $capsule_id)
|
| Línea -... |
Línea 885... |
| - |
|
885 |
{
|
| 900 |
continue;
|
886 |
// 1. Verificar progreso
|
| - |
|
887 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
| - |
|
888 |
if(!$userProgress || $userProgress->completed) { // Si no hay progreso o ya está completada
|
| - |
|
889 |
continue;
|
| Línea -... |
Línea 890... |
| - |
|
890 |
}
|
| 901 |
}
|
891 |
|
| 902 |
|
892 |
// 2. Obtener detalles de la cápsula
|
| 903 |
if($userProgress->completed) {
|
893 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
| 904 |
continue;
|
894 |
if(!$capsule) {
|
| 905 |
}
|
895 |
continue;
|
| Línea -... |
Línea 896... |
| - |
|
896 |
}
|
| - |
|
897 |
|
| - |
|
898 |
// 3. Filtrar por nombre
|
| - |
|
899 |
if($name) {
|
| - |
|
900 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
| - |
|
901 |
continue;
|
| - |
|
902 |
}
|
| - |
|
903 |
}
|
| - |
|
904 |
|
| - |
|
905 |
// 4. Obtener Tópico asociado válido
|
| Línea -... |
Línea 906... |
| - |
|
906 |
$topic = null;
|
| 906 |
|
907 |
$topic_uuid_for_links = null;
|
| Línea 907... |
Línea -... |
| 907 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
- |
|
| 908 |
|
908 |
$relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
|
| 909 |
if($name) {
|
- |
|
| 910 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
909 |
if ($relation && in_array($relation->topic_id, $accessGranted->topics)) {
|
| 911 |
continue;
|
- |
|
| 912 |
}
|
- |
|
| 913 |
}
|
- |
|
| Línea 914... |
Línea -... |
| 914 |
|
- |
|
| 915 |
|
- |
|
| - |
|
910 |
$topic = $topicMapper->fetchOne($relation->topic_id);
|
| 916 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
911 |
if ($topic) {
|
| 917 |
|
912 |
$topic_uuid_for_links = $topic->uuid;
|
| 918 |
if(isset($topics[$capsule->topic_id])) {
|
913 |
}
|
| 919 |
$topic = $topics[$capsule->topic_id];
|
914 |
}
|
| 920 |
} else {
|
915 |
|
| 921 |
$topic = $topicMapper->fetchOne($capsule->topic_id);
|
916 |
// 5. Obtener datos de comentarios
|
| 922 |
$topics[ $capsule->topic_id ] = $topic;
|
917 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
| 923 |
}
|
918 |
|
| 924 |
|
919 |
// 6. Construir enlace slides
|
| 925 |
|
920 |
$link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
|
| 926 |
|
921 |
|
| 927 |
|
922 |
// 7. Añadir al array de resultados
|
| 928 |
array_push($capsules, [
|
923 |
array_push($capsulesData, [
|
| 929 |
'uuid' => $capsule->uuid,
|
924 |
'uuid' => $capsule->uuid,
|
| 930 |
'name' => $capsule->name ? $capsule->name : '',
|
925 |
'name' => $capsule->name ? $capsule->name : '',
|
| 931 |
'description' => $capsule->description ? $capsule->description : '',
|
926 |
'description' => $capsule->description ? $capsule->description : '',
|
| 932 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
927 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
| 933 |
'position' => $capsule->order,
|
928 |
'position' => $capsule->order,
|
| Línea -... |
Línea 929... |
| - |
|
929 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
| 934 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
930 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
| 935 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
931 |
'link_slides' => $link_slides,
|
| 936 |
'link_slides' => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
932 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
| 937 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
933 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
| 938 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
934 |
'progress' => $userProgress->progress, // Progreso real
|
| 939 |
'progress' => $userProgress->progress,
|
935 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
| 940 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
936 |
'last_access_on' => $userProgress->updated_on, // Fecha del progreso
|
| 941 |
'last_access_on' => $userProgress->updated_on,
|
937 |
'added_on' => $capsule->added_on, // Fecha de la cápsula
|
| 942 |
'added_on' => $capsule->added_on,
|
- |
|
| 943 |
'updated_on' => $capsule->updated_on,
|
- |
|
| 944 |
]);
|
938 |
'updated_on' => $capsule->updated_on, // Fecha de la cápsula
|
| 945 |
}
|
- |
|
| 946 |
|
- |
|
| 947 |
if($order_field == 'name') {
|
- |
|
| 948 |
if($order_direction == 'asc') {
|
- |
|
| 949 |
usort($capsules, function($a, $b) {
|
939 |
]);
|
| 950 |
return strcasecmp($a['name'], $b['name']);
|
940 |
}
|
| 951 |
});
|
- |
|
| 952 |
} else {
|
941 |
|
| Línea 953... |
Línea 942... |
| 953 |
usort($capsules, function($a, $b) {
|
942 |
// 8. Ordenar (lógica de ordenación permanece igual, usando $capsulesData)
|
| 954 |
$result = strcasecmp($a['name'], $b['name']);
|
943 |
if($order_field == 'name') {
|
| 955 |
if($result < 0) {
|
944 |
if($order_direction == 'asc') {
|
| 956 |
return 1;
|
945 |
usort($capsulesData, function($a, $b) {
|
| 957 |
} else if($result > 0) {
|
946 |
return strcasecmp($a['name'], $b['name']);
|
| 958 |
return -1;
|
947 |
});
|
| 959 |
} else {
|
948 |
} else {
|
| 960 |
return 0;
|
949 |
usort($capsulesData, function($a, $b) {
|
| 961 |
}
|
- |
|
| 962 |
});
|
- |
|
| 963 |
}
|
950 |
$result = strcasecmp($a['name'], $b['name']);
|
| 964 |
|
- |
|
| 965 |
}
|
- |
|
| 966 |
|
- |
|
| 967 |
if($order_field == 'added_on') {
|
- |
|
| 968 |
if($order_direction == 'asc') {
|
951 |
if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; }
|
| 969 |
usort($capsules, function($a, $b) {
|
952 |
});
|
| 970 |
return strcasecmp($a['added_on'], $b['added_on']);
|
- |
|
| 971 |
});
|
953 |
}
|
| Línea 972... |
Línea 954... |
| 972 |
} else {
|
954 |
}
|
| 973 |
usort($capsules, function($a, $b) {
|
955 |
|
| 974 |
$result = strcasecmp($a['added_on'], $b['added_on']);
|
956 |
if($order_field == 'added_on') {
|
| 975 |
if($result < 0) {
|
957 |
if($order_direction == 'asc') {
|
| 976 |
return 1;
|
958 |
usort($capsulesData, function($a, $b) {
|
| 977 |
} else if($result > 0) {
|
959 |
return strcasecmp($a['added_on'], $b['added_on']);
|
| 978 |
return -1;
|
960 |
});
|
| 979 |
} else {
|
961 |
} else {
|
| 980 |
return 0;
|
- |
|
| 981 |
}
|
- |
|
| 982 |
});
|
962 |
usort($capsulesData, function($a, $b) {
|
| 983 |
}
|
- |
|
| 984 |
|
- |
|
| 985 |
}
|
- |
|
| 986 |
|
- |
|
| 987 |
if($order_field == 'last_access_on') {
|
963 |
$result = strcasecmp($a['added_on'], $b['added_on']);
|
| 988 |
if($order_direction == 'asc') {
|
964 |
if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; }
|
| 989 |
usort($capsules, function($a, $b) {
|
- |
|
| 990 |
return strcasecmp($a['last_access_on'], $b['last_access_on']);
|
965 |
});
|
| Línea 991... |
Línea 966... |
| 991 |
});
|
966 |
}
|
| 992 |
} else {
|
967 |
}
|
| 993 |
usort($capsules, function($a, $b) {
|
968 |
|
| 994 |
$result = strcasecmp($a['last_access_on'], $b['last_access_on']);
|
969 |
if($order_field == 'last_access_on') {
|
| 995 |
if($result < 0) {
|
- |
|
| 996 |
return 1;
|
- |
|
| 997 |
} else if($result > 0) {
|
- |
|
| 998 |
return -1;
|
970 |
if($order_direction == 'asc') {
|
| Línea 999... |
Línea 971... |
| 999 |
} else {
|
971 |
usort($capsulesData, function($a, $b) {
|
| 1000 |
return 0;
|
972 |
return strcasecmp($a['last_access_on'], $b['last_access_on']);
|
| 1001 |
}
|
973 |
});
|
| Línea 1098... |
Línea 1070... |
| 1098 |
* 'topicCompleted' => cantidad de tópicos completos,
|
1070 |
* 'topicCompleted' => cantidad de tópicos completos,
|
| 1099 |
* 'percentCompleted' => % de diapositivas completados ,
|
1071 |
* 'percentCompleted' => % de diapositivas completados ,
|
| 1100 |
* 'percentIncompleted' => % de diapositivas incompletos ,
|
1072 |
* 'percentIncompleted' => % de diapositivas incompletos ,
|
| 1101 |
* 'percentWithoutReturning' => % de cápsulas sin retorno después de completada,
|
1073 |
* 'percentWithoutReturning' => % de cápsulas sin retorno después de completada,
|
| 1102 |
* 'percentWithReturning' => % de cápsulas con retorno después de completada,
|
1074 |
* 'percentWithReturning' => % de cápsulas con retorno después de completada,
|
| 1103 |
* ],
|
1075 |
* ],
|
| 1104 |
* ]
|
1076 |
* ]
|
| 1105 |
*
|
1077 |
*
|
| 1106 |
*
|
1078 |
*
|
| 1107 |
* En caso contrario
|
1079 |
* En caso contrario
|
| 1108 |
* [
|
1080 |
* [
|
| Línea 1388... |
Línea 1360... |
| 1388 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
1360 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 1389 |
$currentUser = $currentUserPlugin->getUser();
|
1361 |
$currentUser = $currentUserPlugin->getUser();
|
| Línea 1390... |
Línea 1362... |
| 1390 |
|
1362 |
|
| 1391 |
|
1363 |
|
| 1392 |
|
1364 |
|
| Línea 1393... |
Línea 1365... |
| 1393 |
$topic_id = $this->params()->fromRoute('topic_id');
|
1365 |
$topic_id_param = $this->params()->fromRoute('topic_id'); // Renombrado para claridad
|
| 1394 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
1366 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
| 1395 |
$topic = $topicMapper->fetchOneByUuid($topic_id);
|
1367 |
$topic = $topicMapper->fetchOneByUuid($topic_id_param);
|
| 1396 |
|
1368 |
|
| Línea 1412... |
Línea 1384... |
| 1412 |
|
1384 |
|
| Línea -... |
Línea 1385... |
| - |
|
1385 |
|
| - |
|
1386 |
|
| - |
|
1387 |
$data = [];
|
| - |
|
1388 |
|
| - |
|
1389 |
// Obtener la relación Tópico-Cápsula
|
| - |
|
1390 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
| - |
|
1391 |
$topicCapsuleRelations = $topicCapsuleMapper->fetchAllActiveByTopicId($topic->id);
|
| - |
|
1392 |
|
| - |
|
1393 |
$capsuleIdsToFetch = [];
|
| - |
|
1394 |
$capsuleRelationData = []; // Para guardar datos específicos de la relación si es necesario
|
| - |
|
1395 |
foreach ($topicCapsuleRelations as $relation) {
|
| - |
|
1396 |
if (in_array($relation->capsule_id, $accessGrantedIds->capsules)) {
|
| - |
|
1397 |
$capsuleIdsToFetch[] = $relation->capsule_id;
|
| - |
|
1398 |
$capsuleRelationData[$relation->capsule_id] = [
|
| - |
|
1399 |
// Aquí puedes guardar datos de $relation si los necesitas más tarde
|
| - |
|
1400 |
// por ejemplo: 'publish_on' => $relation->publish_on
|
| - |
|
1401 |
];
|
| - |
|
1402 |
}
|
| - |
|
1403 |
}
|
| - |
|
1404 |
|
| - |
|
1405 |
if (empty($capsuleIdsToFetch)) {
|
| - |
|
1406 |
return new JsonModel([
|
| Línea -... |
Línea 1407... |
| - |
|
1407 |
'success' => true,
|
| 1413 |
|
1408 |
'data' => [] // No hay cápsulas accesibles para este tópico
|
| 1414 |
|
1409 |
]);
|
| - |
|
1410 |
}
|
| 1415 |
$data = [];
|
1411 |
|
| 1416 |
|
1412 |
// Obtener los detalles de las cápsulas
|
| Línea 1417... |
Línea 1413... |
| 1417 |
|
1413 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
| 1418 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
1414 |
$capsules = $capsuleMapper->fetchAllByIds($capsuleIdsToFetch);
|
| Línea 1419... |
Línea 1415... |
| 1419 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
1415 |
|
| 1420 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
1416 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
| 1421 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
1417 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
|
| - |
|
1418 |
|
| - |
|
1419 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| Línea -... |
Línea 1420... |
| - |
|
1420 |
$path = $storage->getPathMicrolearningCapsule();
|
| 1422 |
|
1421 |
|
| 1423 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
1422 |
// Construir la respuesta combinando datos de Cápsula y Progreso
|
| 1424 |
$path = $storage->getPathMicrolearningCapsule();
|
1423 |
foreach($capsules as $capsule) // Iterar sobre los objetos Capsule obtenidos
|
| Línea 1425... |
Línea 1424... |
| 1425 |
|
1424 |
{
|
| 1426 |
$capsules = $topicCapsuleMapper->fetchAllActiveByTopicId($topic->id);
|
1425 |
// $capsule ya no tiene topic_id directamente.
|
| 1427 |
foreach($capsules as $capsule)
|
1426 |
// El contexto del tópico viene de $topic (obtenido al inicio).
|
| Línea 1438... |
Línea 1437... |
| 1438 |
} else {
|
1437 |
} else {
|
| 1439 |
$progress = 0;
|
1438 |
$progress = 0;
|
| 1440 |
$completed = 0;
|
1439 |
$completed = 0;
|
| 1441 |
}
|
1440 |
}
|
| Línea -... |
Línea 1441... |
| - |
|
1441 |
|
| 1442 |
|
1442 |
// Pasar company_id y capsule_id de la cápsula
|
| Línea 1443... |
Línea 1443... |
| 1443 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
1443 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
| 1444 |
|
1444 |
|
| 1445 |
|
1445 |
|
| 1446 |
|
1446 |
|
| 1447 |
array_push($data, [
|
1447 |
array_push($data, [
|
| - |
|
1448 |
'uuid' => $capsule->uuid,
|
| 1448 |
'uuid' => $capsule->uuid,
|
1449 |
'name' => $capsule->name ? $capsule->name : '',
|
| 1449 |
'name' => $capsule->name ? $capsule->name : '',
|
1450 |
'description' => $capsule->description ? $capsule->description : '',
|
| 1450 |
'description' => $capsule->description ? $capsule->description : '',
|
1451 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
| 1451 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
1452 |
// Usar $topic->uuid y $capsule->uuid para los enlaces
|
| 1452 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
1453 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
| 1453 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
1454 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
| 1454 |
'link_slides' => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
1455 |
'link_slides' => $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
| 1455 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
1456 |
'link_get' => $this->url()->fromRoute('microlearning/get-capsule', ['id' => $capsule->uuid], ['force_canonical' => true]),
|
| 1456 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
1457 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
| 1457 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
1458 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
| 1458 |
'progress' => $progress,
|
1459 |
'progress' => $progress,
|
| - |
|
1460 |
'completed' => $completed,
|
| 1459 |
'completed' => $completed,
|
1461 |
'order' => $capsule->order, // Asumiendo que el orden viene de la cápsula
|
| Línea 1460... |
Línea 1462... |
| 1460 |
'order' => $capsule->order,
|
1462 |
'added_on' => $capsule->added_on, // Fecha de la cápsula
|
| Línea 1598... |
Línea 1600... |
| 1598 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
1600 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 1599 |
$currentUser = $currentUserPlugin->getUser();
|
1601 |
$currentUser = $currentUserPlugin->getUser();
|
| Línea 1600... |
Línea 1602... |
| 1600 |
|
1602 |
|
| 1601 |
|
1603 |
|
| 1602 |
|
1604 |
|
| Línea 1603... |
Línea 1605... |
| 1603 |
$capsule_id = $this->params()->fromRoute('id');
|
1605 |
$capsule_uuid = $this->params()->fromRoute('id');
|
| 1604 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
1606 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
| 1605 |
$capsule = $capsuleMapper->fetchOneByUuid($capsule_id);
|
1607 |
$capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
|
| 1606 |
|
1608 |
|
| 1607 |
if(!$capsule) {
|
1609 |
if(!$capsule) {
|
| 1608 |
return new JsonModel([
|
1610 |
return new JsonModel([
|
| Línea 1609... |
Línea 1611... |
| 1609 |
'success' => false,
|
1611 |
'success' => false,
|
| Línea -... |
Línea 1612... |
| - |
|
1612 |
'data' => 'ERROR_CAPSULE_NOT_FOUND'
|
| 1610 |
'data' => 'ERROR_CAPSULE_NOT_FOUND'
|
1613 |
]);
|
| 1611 |
]);
|
1614 |
}
|
| 1612 |
}
|
1615 |
|
| 1613 |
|
1616 |
$accessGrantedIds = $this->getAccessGranted();
|
| 1614 |
$accessGrantedIds = $this->getAccessGranted();
|
1617 |
|
| 1615 |
|
1618 |
// Verificar si el usuario tiene acceso a esta cápsula específica
|
| Línea -... |
Línea 1619... |
| - |
|
1619 |
if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
|
| - |
|
1620 |
return new JsonModel([
|
| - |
|
1621 |
'success' => false,
|
| - |
|
1622 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
|
| - |
|
1623 |
]);
|
| - |
|
1624 |
}
|
| - |
|
1625 |
|
| - |
|
1626 |
// --- Obtener el Tópico asociado (si existe y es necesario) ---
|
| - |
|
1627 |
$topic = null;
|
| - |
|
1628 |
$topic_uuid_for_links = null; // UUID del tópico para construir enlaces
|
| - |
|
1629 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
| - |
|
1630 |
// Asumiendo que una cápsula puede estar asociada a múltiples tópicos (muchos-a-muchos),
|
| - |
|
1631 |
// necesitamos decidir cuál tópico usar como contexto aquí. Usaremos el primero que encontremos.
|
| - |
|
1632 |
// 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).
|
| - |
|
1633 |
$relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id); // Necesitamos un método como este
|
| - |
|
1634 |
|
| - |
|
1635 |
if ($relation && in_array($relation->topic_id, $accessGrantedIds->topics)) {
|
| - |
|
1636 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
| - |
|
1637 |
$topic = $topicMapper->fetchOne($relation->topic_id);
|
| - |
|
1638 |
if ($topic) {
|
| Línea 1616... |
Línea -... |
| 1616 |
if(!in_array($capsule->id, $accessGrantedIds->capsules)) {
|
- |
|
| 1617 |
return new JsonModel([
|
- |
|
| 1618 |
'success' => false,
|
- |
|
| 1619 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE'
|
- |
|
| 1620 |
]);
|
1639 |
$topic_uuid_for_links = $topic->uuid;
|
| 1621 |
}
|
1640 |
}
|
| Línea 1642... |
Línea 1661... |
| 1642 |
|
1661 |
|
| Línea 1643... |
Línea 1662... |
| 1643 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
1662 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
| - |
|
1663 |
|
| - |
|
1664 |
|
| - |
|
1665 |
$slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
|
| 1644 |
|
1666 |
// Para contar slides, necesitamos el contexto del tópico.
|
| - |
|
1667 |
$totalSlides = 0;
|
| Línea -... |
Línea 1668... |
| - |
|
1668 |
if ($topic) { // Solo contar si tenemos un tópico asociado válido
|
| - |
|
1669 |
$totalSlides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
|
| - |
|
1670 |
}
|
| 1645 |
|
1671 |
|
| 1646 |
$slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
|
1672 |
|
| 1647 |
$totalSlides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $capsule->topic_id, $capsule->id);
|
- |
|
| 1648 |
|
1673 |
$link_first_slide = '';
|
| 1649 |
|
1674 |
$type_first_slide = '';
|
| 1650 |
$slide = $slideMapper->fetchFirstByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $capsule->topic_id, $capsule->id);
|
- |
|
| 1651 |
if($slide) {
|
- |
|
| 1652 |
|
1675 |
if ($topic) { // Solo buscar primer slide si tenemos tópico
|
| 1653 |
$link_first_slide = $this->url()->fromRoute('microlearning/get-slide', ['id' => $slide->uuid], ['force_canonical' => true]);
|
- |
|
| 1654 |
$type_first_slide = $slide->type;
|
- |
|
| 1655 |
|
1676 |
$slide = $slideMapper->fetchFirstByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
|
| Línea 1656... |
Línea 1677... |
| 1656 |
|
1677 |
if($slide) {
|
| 1657 |
} else {
|
1678 |
$link_first_slide = $this->url()->fromRoute('microlearning/get-slide', ['id' => $slide->uuid], ['force_canonical' => true]);
|
| Línea -... |
Línea 1679... |
| - |
|
1679 |
$type_first_slide = $slide->type;
|
| - |
|
1680 |
}
|
| Línea 1658... |
Línea 1681... |
| 1658 |
$link_first_slide = '';
|
1681 |
}
|
| 1659 |
$type_first_slide = '';
|
1682 |
|
| 1660 |
}
|
1683 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 1661 |
|
1684 |
$path = $storage->getPathMicrolearningCapsule();
|
| 1662 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
1685 |
|
| 1663 |
$path = $storage->getPathMicrolearningCapsule();
|
1686 |
|
| 1664 |
|
1687 |
// Construir enlaces usando $topic_uuid_for_links si está disponible
|
| 1665 |
|
1688 |
$link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
|
| 1666 |
|
1689 |
|
| 1667 |
$data = [
|
1690 |
$data = [
|
| 1668 |
'uuid' => $capsule->uuid,
|
1691 |
'uuid' => $capsule->uuid,
|
| 1669 |
'name' => $capsule->name ? $capsule->name : '',
|
1692 |
'name' => $capsule->name ? $capsule->name : '',
|
| 1670 |
'description' => $capsule->description ? $capsule->description : '',
|
1693 |
'description' => $capsule->description ? $capsule->description : '',
|
| Línea 2266... |
Línea 2289... |
| 2266 |
|
2289 |
|
| 2267 |
$userProgressTopic = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
|
2290 |
$userProgressTopic = $userProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic->id);
|
| Línea 2268... |
Línea 2291... |
| 2268 |
if(!$userProgressTopic) {
|
2291 |
if(!$userProgressTopic) {
|
| 2269 |
|
2292 |
|
| 2270 |
$userProgressTopic = new MicrolearningUserProgress();
|
2293 |
$userProgressTopic = new MicrolearningUserProgress();
|
| 2271 |
$userProgressTopic->company_id = $slide->company_id;
|
2294 |
$userProgressTopic->company_id = $topic->company_id; // Usar company_id del tópico
|
| 2272 |
$userProgressTopic->topic_id = $slide->topic_id;
|
2295 |
$userProgressTopic->topic_id = $topic->id; // Usar id del tópico
|
| 2273 |
$userProgressTopic->user_id = $currentUser->id;
|
2296 |
$userProgressTopic->user_id = $currentUser->id;
|
| 2274 |
$userProgressTopic->progress = 0;
|
2297 |
$userProgressTopic->progress = 0;
|
| 2275 |
$userProgressTopic->returning = 0;
|
2298 |
$userProgressTopic->returning = 0;
|
| 2276 |
$userProgressTopic->returning_after_completed = 0;
|
2299 |
$userProgressTopic->returning_after_completed = 0;
|
| 2277 |
$userProgressTopic->completed = 0;
|
2300 |
$userProgressTopic->completed = 0;
|
| 2278 |
$userProgressTopic->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($slide->company_id, $slide->topic_id);
|
2301 |
$userProgressTopic->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($topic->company_id, $topic->id);
|
| 2279 |
$userProgressTopic->view_slides = 0;
|
2302 |
$userProgressTopic->view_slides = 0;
|
| 2280 |
$userProgressTopic->type = MicrolearningUserProgress::TYPE_TOPIC;
|
2303 |
$userProgressTopic->type = MicrolearningUserProgress::TYPE_TOPIC;
|
| Línea 2281... |
Línea 2304... |
| 2281 |
$userProgressTopic->added_on = $added_on;
|
2304 |
$userProgressTopic->added_on = $added_on;
|
| Línea 2282... |
Línea 2305... |
| 2282 |
$userProgressTopic->updated_on = $added_on;
|
2305 |
$userProgressTopic->updated_on = $added_on;
|
| 2283 |
|
2306 |
|
| 2284 |
if($userProgressMapper->insert($userProgressTopic)) {
|
2307 |
if($userProgressMapper->insert($userProgressTopic)) {
|
| 2285 |
|
2308 |
|
| 2286 |
$userLog = new MicrolearningUserLog();
|
2309 |
$userLog = new MicrolearningUserLog();
|
| 2287 |
$userLog->activity = MicrolearningUserLog::ACTIVITY_START_TOPIC;
|
2310 |
$userLog->activity = MicrolearningUserLog::ACTIVITY_START_TOPIC;
|
| Línea 2288... |
Línea 2311... |
| 2288 |
$userLog->user_id = $currentUser->id;
|
2311 |
$userLog->user_id = $currentUser->id;
|
| 2289 |
$userLog->company_id = $slide->company_id;
|
2312 |
$userLog->company_id = $topic->company_id;
|
| 2290 |
$userLog->topic_id = $slide->topic_id;
|
2313 |
$userLog->topic_id = $topic->id;
|
| Línea 2307... |
Línea 2330... |
| 2307 |
|
2330 |
|
| 2308 |
$userProgressCapsule = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
|
2331 |
$userProgressCapsule = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
|
| Línea 2309... |
Línea 2332... |
| 2309 |
if(!$userProgressCapsule) {
|
2332 |
if(!$userProgressCapsule) {
|
| 2310 |
|
2333 |
|
| 2311 |
$userProgressCapsule = new MicrolearningUserProgress();
|
2334 |
$userProgressCapsule = new MicrolearningUserProgress();
|
| 2312 |
$userProgressCapsule->company_id = $slide->company_id;
|
2335 |
$userProgressCapsule->company_id = $capsule->company_id; // Usar company_id de la cápsula
|
| 2313 |
$userProgressCapsule->topic_id = $slide->topic_id;
|
2336 |
$userProgressCapsule->topic_id = $topic->id; // Usar el id del tópico obtenido previamente
|
| 2314 |
$userProgressCapsule->capsule_id = $slide->capsule_id;
|
2337 |
$userProgressCapsule->capsule_id = $capsule->id; // Usar id de la cápsula
|
| 2315 |
$userProgressCapsule->user_id = $currentUser->id;
|
2338 |
$userProgressCapsule->user_id = $currentUser->id;
|
| 2316 |
$userProgressCapsule->progress = 0;
|
2339 |
$userProgressCapsule->progress = 0;
|
| 2317 |
$userProgressCapsule->returning = 0;
|
2340 |
$userProgressCapsule->returning = 0;
|
| 2318 |
$userProgressCapsule->returning_after_completed = 0;
|
2341 |
$userProgressCapsule->returning_after_completed = 0;
|
| 2319 |
$userProgressCapsule->completed = 0;
|
2342 |
$userProgressCapsule->completed = 0;
|
| 2320 |
$userProgressCapsule->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($slide->company_id, $slide->topic_id, $slide->capsule_id);
|
- |
|
| 2321 |
$userProgressCapsule->view_slides = 0;
|
- |
|
| 2322 |
$userProgressCapsule->type = MicrolearningUserProgress::TYPE_CAPSULE;
|
2343 |
$userProgressCapsule->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
|
| Línea 2323... |
Línea 2344... |
| 2323 |
$userProgressCapsule->added_on = $added_on;
|
2344 |
$userProgressCapsule->view_slides = 0;
|
| Línea 2324... |
Línea 2345... |
| 2324 |
$userProgressTopic->updated_on = $added_on;
|
2345 |
$userProgressTopic->updated_on = $added_on;
|
| 2325 |
|
2346 |
|
| 2326 |
if($userProgressMapper->insert($userProgressCapsule)) {
|
2347 |
if($userProgressMapper->insert($userProgressCapsule)) {
|
| 2327 |
|
2348 |
|
| 2328 |
$userLog = new MicrolearningUserLog();
|
2349 |
$userLog = new MicrolearningUserLog();
|
| 2329 |
$userLog->activity = MicrolearningUserLog::ACTIVITY_START_CAPSULE;
|
2350 |
$userLog->activity = MicrolearningUserLog::ACTIVITY_START_CAPSULE;
|
| 2330 |
$userLog->user_id = $currentUser->id;
|
2351 |
$userLog->user_id = $currentUser->id;
|
| Línea 2331... |
Línea 2352... |
| 2331 |
$userLog->company_id = $slide->company_id;
|
2352 |
$userLog->company_id = $capsule->company_id;
|
| 2332 |
$userLog->topic_id = $slide->topic_id;
|
2353 |
$userLog->topic_id = $topic->id;
|
| 2333 |
$userLog->capsule_id = $slide->capsule_id;
|
2354 |
$userLog->capsule_id = $capsule->id;
|
| Línea 2395... |
Línea 2416... |
| 2395 |
if($userProgressCapsule->completed) {
|
2416 |
if($userProgressCapsule->completed) {
|
| Línea 2396... |
Línea 2417... |
| 2396 |
|
2417 |
|
| 2397 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $added_on);
|
2418 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $added_on);
|
| Línea -... |
Línea 2419... |
| - |
|
2419 |
$returning_on = $dt->format('Y-m-d');
|
| - |
|
2420 |
|
| - |
|
2421 |
// Asegurarse que returning_on existe en el objeto antes de comparar
|
| 2398 |
$returning_on = $dt->format('Y-m-d');
|
2422 |
$current_returning_on = isset($userProgressCapsule->returning_on) ? $userProgressCapsule->returning_on : null;
|
| Línea 2399... |
Línea 2423... |
| 2399 |
|
2423 |
|
| - |
|
2424 |
if(!$current_returning_on || $current_returning_on != $returning_on) {
|
| 2400 |
if(!$userProgressCapsule->returning_on || $userProgressCapsule->returning_on != $returning_on) {
|
2425 |
|
| Línea 2401... |
Línea 2426... |
| 2401 |
|
2426 |
$userProgressCapsule->returning_on = $returning_on;
|
| 2402 |
$userProgressCapsule->returning_on = $returning_on;
|
2427 |
// Asegurarse que returning_after_completed existe y es numérico antes de incrementar
|
| 2403 |
$userProgressCapsule->returning_after_completed = $userProgressCapsule->returning_after_completed + 1;
|
2428 |
$userProgressCapsule->returning_after_completed = (isset($userProgressCapsule->returning_after_completed) ? intval($userProgressCapsule->returning_after_completed) : 0) + 1;
|
| 2404 |
|
2429 |
|
| Línea 2410... |
Línea 2435... |
| 2410 |
}
|
2435 |
}
|
| 2411 |
}
|
2436 |
}
|
| Línea 2412... |
Línea 2437... |
| 2412 |
|
2437 |
|
| Línea -... |
Línea 2438... |
| - |
|
2438 |
} else {
|
| 2413 |
} else {
|
2439 |
|
| 2414 |
|
2440 |
// Usar $topic->id para obtener el total de slides de la cápsula en el contexto de este tópico
|
| Línea 2415... |
Línea 2441... |
| 2415 |
$userProgressCapsule->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($slide->company_id, $slide->topic_id, $slide->capsule_id);
|
2441 |
$userProgressCapsule->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $topic->id, $capsule->id);
|
| Línea 2416... |
Línea 2442... |
| 2416 |
$userProgressCapsule->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndCapsuleId($currentUser->id, $slide->capsule_id);
|
2442 |
$userProgressCapsule->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndCapsuleId($currentUser->id, $capsule->id);
|
| 2417 |
|
2443 |
|
| Línea 2436... |
Línea 2462... |
| 2436 |
}
|
2462 |
}
|
| Línea 2437... |
Línea 2463... |
| 2437 |
|
2463 |
|
| 2438 |
$closeTopic = false;
|
2464 |
$closeTopic = false;
|
| Línea 2439... |
Línea -... |
| 2439 |
if(!$userProgressTopic->completed) {
|
- |
|
| - |
|
2465 |
if(!$userProgressTopic->completed) {
|
| 2440 |
|
2466 |
|
| 2441 |
|
2467 |
// Usar $topic->id para obtener el total de slides del tópico
|
| Línea 2442... |
Línea 2468... |
| 2442 |
$userProgressTopic->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($slide->company_id, $slide->topic_id);
|
2468 |
$userProgressTopic->total_slides = $slideMapper->fetchTotalCountByCompanyIdAndTopicId($topic->company_id, $topic->id);
|
| Línea 2443... |
Línea 2469... |
| 2443 |
$userProgressTopic->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndTopicId($currentUser->id, $slide->topic_id);
|
2469 |
$userProgressTopic->view_slides = $userProgressMapper->fetchCountAllSlideCompletedByUserIdAndTopicId($currentUser->id, $topic->id);
|
| 2444 |
|
2470 |
|