Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 655 Rev 656
Línea 551... Línea 551...
551
        
551
        
Línea 552... Línea 552...
552
        return $record['total'];
552
        return $record['total'];
Línea -... Línea 553...
-
 
553
        
-
 
554
    }
-
 
555
    
-
 
556
    /**
-
 
557
     * Marca una diapositiva como vista por un usuario.
-
 
558
     *
-
 
559
     * @param int $user_id ID del usuario
-
 
560
     * @param int $topic_id ID del tema
-
 
561
     * @param int $capsule_id ID de la cápsula
-
 
562
     * @param int $slide_id ID de la diapositiva
-
 
563
     * @return bool true si se marcó como vista correctamente o ya estaba vista, false en caso de error
553
        
564
     * @throws \InvalidArgumentException Si alguno de los IDs es inválido
554
    }
565
     * @throws \RuntimeException Si hay un error en la base de datos
555
    
566
     */
556
    public function markSlideViewed($user_id, $topic_id, $capsule_id, $slide_id)
567
    public function markSlideViewed($user_id, $topic_id, $capsule_id, $slide_id)
557
    {
568
    {
558
        // Verifica si ya existe el registro
569
        // Verifica si ya existe el registro
559
        $exists = $this->fetchOneByUserIdAndSlideId($user_id, $slide_id);
570
        $exists = $this->fetchOneByUserIdAndSlideId($user_id, $slide_id);
Línea 560... Línea 571...
560
        if ($exists) {
571
        if ($exists) {
-
 
572
            return true; // ya está registrado, consideramos esto un éxito
-
 
573
        }
561
            return; // ya registrado
574
 
562
        }
575
        $now = date('Y-m-d H:i:s');
563
 
576
        
564
        $now = $this->getDatebaseNow();
577
        // Crear nuevo progreso
565
        $userProgress = new \LeadersLinked\Model\MicrolearningUserProgress();
578
        $userProgress = new MicrolearningUserProgress();
566
        $userProgress->user_id = $user_id;
579
        $userProgress->user_id = $user_id;
567
        $userProgress->topic_id = $topic_id;
580
        $userProgress->topic_id = $topic_id;
568
        $userProgress->capsule_id = $capsule_id;
581
        $userProgress->capsule_id = $capsule_id;
569
        $userProgress->slide_id = $slide_id;
-
 
570
        $userProgress->type = MicrolearningUserProgress::TYPE_SLIDE;
-
 
571
        $userProgress->progress = 100;
-
 
572
        $userProgress->completed = 1;
-
 
573
        $userProgress->returning = 0;
582
        $userProgress->slide_id = $slide_id;
574
        $userProgress->returning_after_completed = 0; // Regr
583
        $userProgress->type = MicrolearningUserProgress::TYPE_SLIDE;
Línea 575... Línea 584...
575
        $userProgress->total_slides = 0;
584
        $userProgress->progress = 100;
576
        $userProgress->view_slides = 0;
585
        $userProgress->completed = 1;
Línea 577... Línea 586...
577
        $userProgress->added_on = $now;
586
        $userProgress->added_on = $now;
578
        $userProgress->updated_on = $now;
587
        $userProgress->updated_on = $now;
-
 
588
 
-
 
589
        return $this->insert($userProgress);
-
 
590
    }
-
 
591
 
-
 
592
    public function markCapsuleCompleted($user_id, $topic_id, $capsule_id)
-
 
593
    {
-
 
594
        $data = [
579
 
595
            'user_id'       => $user_id,
580
        return $this->insert($userProgress);
596
            'topic_id'      => $topic_id,
581
    }
597
            'capsule_id'    => $capsule_id,
582
 
598
            'completed_at'  => date('Y-m-d H:i:s'),
583
    public function markCapsuleCompleted($user_id, $topic_id, $capsule_id)
599
        ];
Línea 584... Línea -...
584
    {
-
 
585
        // Verifica si ya existe algún progreso de cápsula
-
 
586
        $exists = $this->fetchOneByUseridAndCapsuleId($user_id, $capsule_id);
-
 
587
        if ($exists) {
-
 
588
            return; // ya registrado
-
 
589
        }
-
 
590
 
-
 
591
        $now = $this->getDatebaseNow();
-
 
592
        $userProgress = new \LeadersLinked\Model\MicrolearningUserProgress();
-
 
593
        $userProgress->user_id = $user_id;
-
 
594
        $userProgress->topic_id = $topic_id;
-
 
595
        $userProgress->capsule_id = $capsule_id;
-
 
596
        $userProgress->type = \LeadersLinked\Model\MicrolearningUserProgress::TYPE_CAPSULE;
-
 
597
        $userProgress->progress = 100;
-
 
598
        $userProgress->completed = 1;
-
 
599
        $userProgress->returning = 0;
600
 
600
        $userProgress->returning_after_completed = 0;
601
        // Verifica si ya existe algún progreso de cápsula
Línea 601... Línea 602...
601
        $userProgress->total_slides = 0;
602
        $exists = $this->fetchOneByUserIdAndCapsuleId($user_id, $capsule_id);
602
        $userProgress->view_slides = 0;
603
        if ($exists) {
-
 
604
            return; // ya registrado
-
 
605
        }
-
 
606
 
-
 
607
        return $this->insert($data);
-
 
608
    }
-
 
609
 
-
 
610
    public function markTopicCompleted($user_id, $topic_id)
603
        $userProgress->added_on = $now;
611
    {
604
        $userProgress->updated_on = $now;
612
        $data = [
605
 
613
            'user_id'      => $user_id,
606
        return $this->insert($userProgress);
614
            'topic_id'     => $topic_id,
607
    }
615
            'topic_closed' => 1,
Línea 608... Línea -...
608
 
-
 
609
    public function markTopicCompleted($user_id, $topic_id)
-
 
610
    {
-
 
611
        // Verifica si ya existe algún progreso de topic
-
 
612
        $exists = $this->fetchOneByUserIdAndTopicId($user_id, $topic_id);
-
 
613
        if ($exists) {
-
 
614
            return; // ya registrado
-
 
615
        }
-
 
616
 
-
 
617
        $now = $this->getDatebaseNow();
-
 
618
        $userProgress = new \LeadersLinked\Model\MicrolearningUserProgress();
-
 
619
        $userProgress->user_id = $user_id;
-
 
620
        $userProgress->topic_id = $topic_id;
-
 
621
        $userProgress->type = \LeadersLinked\Model\MicrolearningUserProgress::TYPE_TOPIC;
-
 
622
        $userProgress->progress = 100;
616
            'closed_at'    => date('Y-m-d H:i:s'),
623
        $userProgress->completed = 1;
617
        ];
Línea -... Línea 618...
-
 
618
 
-
 
619
        // Verifica si ya existe algún progreso de topic
-
 
620
        $exists = $this->fetchOneByUserIdAndTopicId($user_id, $topic_id);
-
 
621
        if ($exists) {
-
 
622
            return; // ya registrado
-
 
623
        }
-
 
624
 
-
 
625
        return $this->insert($data);
624
        $userProgress->returning = 0;
626
    }
625
        $userProgress->returning_after_completed = 0;
627
 
626
        $userProgress->total_slides = 0;
-
 
627
        $userProgress->view_slides = 0;
-
 
628
        $userProgress->added_on = $now;
-
 
629
        $userProgress->updated_on = $now;
-
 
630
 
-
 
631
        return $this->insert($userProgress);
-
 
632
    }
-
 
633
 
-
 
634
    public function hasViewedAllSlidesInCapsule($user_id, $capsule_id)
-
 
635
    {
-
 
636
        // Get total number of slides in capsule
-
 
637
        $select = $this->sql->select('microlearning_slide');
-
 
638
        $select->columns(['total' => new \Laminas\Db\Sql\Expression('COUNT(*)')]);
628
    /**
639
        $select->where->equalTo('capsule_id', $capsule_id);
-
 
640
        
-
 
641
        $result = $this->executeFetchOneArray($select);
-
 
642
        $totalSlides = intval($result['total']);
629
     * Verifica si un usuario ha visto todas las diapositivas de una cápsula específica.
643
        
-
 
644
        if ($totalSlides === 0) {
-
 
Línea -... Línea 630...
-
 
630
     *
645
            return false;
631
     * @param int $user_id ID del usuario
646
        }
632
     * @param int $capsule_id ID de la cápsula
Línea -... Línea 633...
-
 
633
     * @return bool true si ha visto todas las diapositivas, false en caso contrario
647
 
634
     * @throws \InvalidArgumentException Si alguno de los IDs es inválido
648
        // Get number of completed slides for this user and capsule
635
     */
Línea 649... Línea 636...
649
        $select = $this->sql->select(self::_TABLE);
636
    public function hasViewedAllSlidesInCapsule($user_id, $capsule_id)
650
        $select->columns(['total' => new \Laminas\Db\Sql\Expression('COUNT(*)')]);
637
    {
651
        $select->where->equalTo('user_id', $user_id);
638
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);