Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 656 Rev 657
Línea 587... Línea 587...
587
        $userProgress->updated_on = $now;
587
        $userProgress->updated_on = $now;
Línea 588... Línea 588...
588
 
588
 
589
        return $this->insert($userProgress);
589
        return $this->insert($userProgress);
Línea -... Línea 590...
-
 
590
    }
-
 
591
 
-
 
592
    /**
-
 
593
     * Marca una cápsula como completada por un usuario.
-
 
594
     *
-
 
595
     * @param int $user_id ID del usuario
-
 
596
     * @param int $topic_id ID del tema
-
 
597
     * @param int $capsule_id ID de la cápsula
590
    }
598
     * @return bool true si se marcó como completada correctamente, false en caso de error
591
 
599
     */
592
    public function markCapsuleCompleted($user_id, $topic_id, $capsule_id)
-
 
593
    {
-
 
594
        $data = [
-
 
595
            'user_id'       => $user_id,
-
 
596
            'topic_id'      => $topic_id,
600
    public function markCapsuleCompleted($user_id, $topic_id, $capsule_id)
597
            'capsule_id'    => $capsule_id,
-
 
598
            'completed_at'  => date('Y-m-d H:i:s'),
601
    {
599
        ];
602
        $now = date('Y-m-d H:i:s');
600
 
603
        
-
 
604
        // Verifica si ya existe algún progreso de cápsula
601
        // Verifica si ya existe algún progreso de cápsula
605
        $userProgress = $this->fetchOneByUserIdAndCapsuleId($user_id, $capsule_id);
-
 
606
        
-
 
607
        if ($userProgress) {
-
 
608
            // Si ya existe, actualizar el progreso
-
 
609
            $userProgress->progress = 100;
602
        $exists = $this->fetchOneByUserIdAndCapsuleId($user_id, $capsule_id);
610
            $userProgress->completed = 1;
603
        if ($exists) {
611
            $userProgress->updated_on = $now;
Línea -... Línea 612...
-
 
612
            return $this->update($userProgress);
-
 
613
        }
-
 
614
 
-
 
615
        // Si no existe, crear nuevo progreso
-
 
616
        $userProgress = new MicrolearningUserProgress();
-
 
617
        $userProgress->user_id = $user_id;
-
 
618
        $userProgress->topic_id = $topic_id;
-
 
619
        $userProgress->capsule_id = $capsule_id;
-
 
620
        $userProgress->type = MicrolearningUserProgress::TYPE_CAPSULE;
-
 
621
        $userProgress->progress = 100;
-
 
622
        $userProgress->completed = 1;
604
            return; // ya registrado
623
        $userProgress->added_on = $now;
605
        }
624
        $userProgress->updated_on = $now;
Línea -... Línea 625...
-
 
625
 
-
 
626
        return $this->insert($userProgress);
-
 
627
    }
-
 
628
 
-
 
629
    /**
-
 
630
     * Marca un tema/tópico como completado por un usuario.
-
 
631
     *
606
 
632
     * @param int $user_id ID del usuario
607
        return $this->insert($data);
633
     * @param int $topic_id ID del tema
608
    }
-
 
609
 
-
 
610
    public function markTopicCompleted($user_id, $topic_id)
-
 
611
    {
-
 
612
        $data = [
634
     * @return bool true si se marcó como completado correctamente, false en caso de error
613
            'user_id'      => $user_id,
-
 
614
            'topic_id'     => $topic_id,
635
     */
615
            'topic_closed' => 1,
636
    public function markTopicCompleted($user_id, $topic_id)
616
            'closed_at'    => date('Y-m-d H:i:s'),
637
    {
-
 
638
        $now = date('Y-m-d H:i:s');
617
        ];
639
        
-
 
640
        // Verifica si ya existe algún progreso del tema
-
 
641
        $userProgress = $this->fetchOneByUserIdAndTopicId($user_id, $topic_id);
-
 
642
        
-
 
643
        if ($userProgress) {
618
 
644
            // Si ya existe, actualizar el progreso
619
        // Verifica si ya existe algún progreso de topic
645
            $userProgress->progress = 100;
Línea -... Línea 646...
-
 
646
            $userProgress->completed = 1;
-
 
647
            $userProgress->updated_on = $now;
-
 
648
            return $this->update($userProgress);
-
 
649
        }
-
 
650
 
-
 
651
        // Si no existe, crear nuevo progreso
-
 
652
        $userProgress = new MicrolearningUserProgress();
-
 
653
        $userProgress->user_id = $user_id;
-
 
654
        $userProgress->topic_id = $topic_id;
-
 
655
        $userProgress->type = MicrolearningUserProgress::TYPE_TOPIC;
620
        $exists = $this->fetchOneByUserIdAndTopicId($user_id, $topic_id);
656
        $userProgress->progress = 100;
621
        if ($exists) {
657
        $userProgress->completed = 1;
Línea 622... Línea 658...
622
            return; // ya registrado
658
        $userProgress->added_on = $now;
623
        }
659
        $userProgress->updated_on = $now;
624
 
660
 
Línea 644... Línea 680...
644
 
680
 
645
        // Comparar si el número de diapositivas vistas es igual al total
681
        // Comparar si el número de diapositivas vistas es igual al total
646
        return $viewedSlides >= $totalSlides;
682
        return $viewedSlides >= $totalSlides;
Línea -... Línea 683...
-
 
683
    }
-
 
684
 
-
 
685
    /**
-
 
686
     * Verifica si un usuario ha completado todas las cápsulas disponibles en un tema específico.
-
 
687
     *
-
 
688
     * @param int $user_id ID del usuario
-
 
689
     * @param int $topic_id ID del tema
-
 
690
     * @return bool true si el usuario ha completado todas las cápsulas del tema, false en caso contrario
-
 
691
     * @throws \InvalidArgumentException Si alguno de los IDs es inválido
647
    }
692
     * @throws \RuntimeException Si hay un error en la base de datos
648
 
693
     */
649
    public function hasCompletedAllCapsulesInTopic($user_id, $topic_id)
694
    public function hasCompletedAllCapsulesInTopic($user_id, $topic_id)
650
    {
695
    {
Línea -... Línea 696...
-
 
696
        $capsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
697
        $allCapsules = $capsuleMapper->fetchAllByTopicId($topic_id);
-
 
698
 
-
 
699
        if (empty($allCapsules)) {
651
        $capsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
700
            return false;
-
 
701
        }
652
        $allCapsules = $capsuleMapper->fetchAllByTopicId($topic_id);
702
 
653
 
703
        $select = $this->sql->select(self::_TABLE);
654
        $select = $this->sql->select(self::_TABLE);
704
        $select->columns(['total' => new Expression('COUNT(*)')]);
655
        $select->where->equalTo('user_id', $user_id);
705
        $select->where->equalTo('user_id', $user_id);
656
        $select->where->equalTo('topic_id', $topic_id);
706
        $select->where->equalTo('topic_id', $topic_id);
657
        $select->where->equalTo('type', MicrolearningUserProgress::TYPE_CAPSULE);
707
        $select->where->equalTo('type', MicrolearningUserProgress::TYPE_CAPSULE);
658
        $select->where->equalTo('completed', 1);
708
        $select->where->equalTo('completed', 1);
659
 
709
  
660
        $record = $this->executeFetchOneArray($select);
-
 
661
        return count($record) >= count($allCapsules);
710
        $record = $this->executeFetchOneArray($select);
662
    }
711
        return intval($record['total']) >= count($allCapsules);