Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 634 Rev 635
Línea 658... Línea 658...
658
            $capsulesData = [];
658
            $capsulesData = [];
Línea 659... Línea 659...
659
            
659
            
660
            $storage = Storage::getInstance($this->config, $this->adapter);
660
            $storage = Storage::getInstance($this->config, $this->adapter);
Línea 661... Línea 661...
661
            $path = $storage->getPathMicrolearningCapsule();
661
            $path = $storage->getPathMicrolearningCapsule();
662
            
662
            
663
            foreach($accessGranted->capsules as $capsule_id)
663
            foreach($accessGranted->topics as $topic_id)
664
            {
-
 
665
                // 1. Verificar progreso
664
            {
666
                $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
665
                $topic = $topicMapper->fetchOne($topic_id);
667
                if(!$userProgress) {
666
                if(!$topic) {
Línea 668... Línea -...
668
                    continue;
-
 
669
                }
-
 
670
                
-
 
671
                if(!$userProgress->completed) {
-
 
672
                    continue;
-
 
673
                }
667
                    continue;
674
                
-
 
675
                // 2. Obtener detalles de la cápsula
-
 
676
                $capsule = $capsuleMapper->fetchOne($capsule_id);
-
 
Línea 677... Línea 668...
677
                if(!$capsule) {
668
                }
678
                    continue;
669
                
679
                }
670
                $capsules = $topicCapsuleMapper->fetchAllActiveByTopicId($topic_id) ?? [];
680
                
671
                
681
                // 3. Filtrar por nombre
672
                foreach($capsules as $capsule) {
682
                if($name) {
-
 
683
                    if(empty($name) || stripos($capsule->name, $name) === false) {
673
                    $capsule = $capsuleMapper->fetchOne($capsule->capsule_id);
684
                        continue;
-
 
685
                    }
-
 
686
                }
-
 
687
                
674
                    if(!$capsule) {
688
                // 4. Obtener Tópico asociado válido
-
 
689
                $topic = null;
675
                        continue;
690
                $topic_uuid_for_links = null;
676
                    }
691
                $relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
-
 
692
                if ($relation && in_array($relation->topic_id, $accessGranted->topics)) {
677
                    
-
 
678
                    $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
-
 
679
                    if($userProgress && $userProgress->completed) {
-
 
680
                        continue;
-
 
681
                    }
-
 
682
                    
693
                    $topic = $topicMapper->fetchOne($relation->topic_id);
683
                    if($name) {
-
 
684
                        if(empty($name) || stripos($capsule->name, $name) === false) {
-
 
685
                            continue;
-
 
686
                        }
Línea 694... Línea -...
694
                    if ($topic) {
-
 
695
                        $topic_uuid_for_links = $topic->uuid;
-
 
696
                    }
-
 
697
                }
-
 
698
 
-
 
699
                // 5. Obtener datos de comentarios
-
 
700
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
-
 
701
                
687
                    }
702
                // 6. Construir enlace slides
688
                    
703
                $link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
689
                    $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id,  $capsule->id);
704
                
690
                    $link_slides = $topic->uuid ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
705
                // 7. Añadir al array de resultados
691
 
706
                array_push($capsulesData, [
-
 
707
                    'uuid'              => $capsule->uuid,
692
                    array_push($capsulesData, [
708
                    'name'              => $capsule->name ? $capsule->name : '',
693
                        'uuid'              => $capsule->uuid,
709
                    'description'       => $capsule->description ? $capsule->description : '',
694
                        'name'              => $capsule->name ? $capsule->name : '',
710
                    'image'             => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image)  : '',
695
                        'description'       => $capsule->description ? $capsule->description : '',
711
                    'position'          => $capsule->order,
696
                        'image'             => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image)  : '',
712
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
697
                        'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
713
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
698
                        'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
714
                    'link_slides'       => $link_slides,
699
                        'link_slides'       => $link_slides,
715
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
700
                        'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
-
 
701
                        'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
716
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
702
                        'progress'          => $userProgress->progress,
717
                    'progress'          => $userProgress->progress,
703
                        'added_on'          => $capsule->added_on,
Línea 718... Línea 704...
718
                    'added_on'          => $capsule->added_on,
704
                        'last_access_on'    => $userProgress->updated_on,
719
                    'last_access_on'    => $userProgress->updated_on,
705
                        'updated_on'        => $capsule->updated_on,
720
                    'updated_on'        => $capsule->updated_on,
706
                    ]);
721
                ]);
707
                }
722
            }
708
            }
723
            
709
            
Línea 759... Línea 745...
759
                        if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; }
745
                        if($result < 0) { return 1; } else if($result > 0) { return -1; } else { return 0; }
760
                    });
746
                    });
761
                }
747
                }
762
            }
748
            }
Línea 763... Línea -...
763
            
-
 
764
            
-
 
765
            
-
 
766
                
-
 
767
         
749
            
768
            return new JsonModel([
750
            return new JsonModel([
769
                'success' => true,
751
                'success' => true,
770
                'data' => $capsulesData
752
                'data' => $capsulesData
Línea 808... Línea 790...
808
            $capsulesData = [];
790
            $capsulesData = [];
Línea 809... Línea 791...
809
            
791
            
810
            $storage = Storage::getInstance($this->config, $this->adapter);
792
            $storage = Storage::getInstance($this->config, $this->adapter);
Línea 811... Línea 793...
811
            $path = $storage->getPathMicrolearningCapsule();
793
            $path = $storage->getPathMicrolearningCapsule();
812
            
794
            
813
            foreach($accessGranted->capsules as $capsule_id)
-
 
814
            {
-
 
815
                // 1. Verificar progreso
-
 
816
                $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
-
 
817
                if(!$userProgress || $userProgress->completed) { // Si no hay progreso o ya está completada
-
 
818
                    continue;
-
 
819
                }
-
 
820
 
795
            foreach($accessGranted->topics as $topic_id)
821
                // 2. Obtener detalles de la cápsula
796
            {
822
                $capsule = $capsuleMapper->fetchOne($capsule_id);
797
                $topic = $topicMapper->fetchOne($topic_id);
823
                if(!$capsule) {
798
                if(!$topic) {
Línea 824... Línea 799...
824
                    continue;
799
                    continue;
-
 
800
                }
825
                }
801
                
826
                
802
                $capsules = $topicCapsuleMapper->fetchAllActiveByTopicId($topic_id) ?? [];
-
 
803
                
827
                // 3. Filtrar por nombre
804
                foreach($capsules as $capsule) {
828
                if($name) {
805
                    $capsule = $capsuleMapper->fetchOne($capsule->capsule_id);
829
                    if(empty($name) || stripos($capsule->name, $name) === false) {
-
 
830
                        continue;
806
                    if(!$capsule) {
831
                    }
-
 
832
                }
-
 
833
                
-
 
834
                // 4. Obtener Tópico asociado válido
807
                        continue;
835
                $topic = null;
-
 
836
                $topic_uuid_for_links = null;
808
                    }
837
                $relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
809
                    
838
                if ($relation && in_array($relation->topic_id, $accessGranted->topics)) {
-
 
839
                    $topic = $topicMapper->fetchOne($relation->topic_id);
810
                    $userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
840
                    if ($topic) {
-
 
Línea 841... Línea 811...
841
                        $topic_uuid_for_links = $topic->uuid;
811
                    if($userProgress && !$userProgress->completed) {
842
                    }
812
                        continue;
-
 
813
                    }
-
 
814
 
-
 
815
                    if($name) {
843
                }
816
                        if(empty($name) || stripos($capsule->name, $name) === false) {
844
 
817
                            continue;
845
                // 5. Obtener datos de comentarios
818
                        }
846
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id,  $capsule->id);
819
                    }
847
                
-
 
848
                // 6. Construir enlace slides
820
                    
849
                $link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
821
                    $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id,  $capsule->id);
850
                
822
                    $link_slides = $topic->uuid ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid,  'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
851
                // 7. Añadir al array de resultados
823
 
852
                array_push($capsulesData, [
824
                    array_push($capsulesData, [
853
                    'uuid'              => $capsule->uuid,
-
 
854
                    'name'              => $capsule->name ? $capsule->name : '',
825
                        'uuid'              => $capsule->uuid,
855
                    'description'       => $capsule->description ? $capsule->description : '',
826
                        'name'              => $capsule->name ? $capsule->name : '',
856
                    'image'             => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image)  : '',
827
                        'description'       => $capsule->description ? $capsule->description : '',
857
                    'position'          => $capsule->order,
828
                        'image'             => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image)  : '',
858
                    'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
829
                        'link_comments'     => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
859
                    'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
830
                        'link_comment_add'  => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
860
                    'link_slides'       => $link_slides,
831
                        'link_slides'       => $link_slides,
861
                    'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
832
                        'total_comments'    => strval($dataCountAndRatingAverage['total_comments']),
862
                    'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
833
                        'total_rating'      => strval($dataCountAndRatingAverage['total_rating']),
-
 
834
                        'progress'          => $userProgress->progress,
863
                    'progress'          => $userProgress->progress,
835
                        'added_on'          => $capsule->added_on,
864
                    'last_access_on'    => $userProgress->updated_on,
836
                        'last_access_on'    => $userProgress->updated_on,
Línea 865... Línea 837...
865
                    'added_on'          => $capsule->added_on,
837
                        'updated_on'        => $capsule->updated_on,
866
                    'updated_on'        => $capsule->updated_on,
838
                    ]);
867
                ]);
839
                }
868
            }
840
            }
869
            
841
            
870
            // 8. Ordenar (lógica de ordenación permanece igual, usando $capsulesData)
842
            // 8. Ordenar