Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 283 Rev 590
Línea 6... Línea 6...
6
use LeadersLinked\Mapper\Common\MapperCommon;
6
use LeadersLinked\Mapper\Common\MapperCommon;
7
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Model\MicrolearningUserProgress;
8
use LeadersLinked\Model\MicrolearningUserProgress;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Db\Sql\Expression;
10
use Laminas\Db\Sql\Expression;
11
 
-
 
-
 
11
use LeadersLinked\Mapper\MicrolearningSlideMapper;
-
 
12
use LeadersLinked\Mapper\MicrolearningTopicCapsuleMapper;
Línea 12... Línea 13...
12
 
13
 
13
class MicrolearningUserProgressMapper extends MapperCommon
14
class MicrolearningUserProgressMapper extends MapperCommon
14
{
15
{
Línea 131... Línea 132...
131
        
132
        
Línea 132... Línea 133...
132
        $select->limit(1);
133
        $select->limit(1);
133
        
134
        
-
 
135
        return $this->executeFetchOneObject($select, $prototype);
-
 
136
    }
-
 
137
 
-
 
138
    /**
-
 
139
     * Fetch all progress data by user id and slide id
-
 
140
     * @param int $userId
-
 
141
     * @param int $slideId
-
 
142
     * @return MicrolearningUserProgress[]
-
 
143
     */
-
 
144
    public function fetchAllProgressDataByUserIdAndSlideId($userId, $slideId)
-
 
145
    {
-
 
146
        $select = $this->sql->select();
-
 
147
        $select->from(self::_TABLE);
-
 
148
        $select->where->equalTo('user_id', $userId);
Línea 134... Línea 149...
134
        return $this->executeFetchOneObject($select, $prototype);
149
        $select->where->equalTo('slide_id', $slideId);
135
    }
150
    }
136
    
151
    
137
    /**
152
    /**
Línea 494... Línea 509...
494
        
509
        
Línea 495... Línea 510...
495
        return $record['total'];
510
        return $record['total'];
Línea -... Línea 511...
-
 
511
        
496
        
512
    }
-
 
513
    
-
 
514
    public function markSlideViewed($user_id, $topic_id, $capsule_id, $slide_id)
-
 
515
    {
-
 
516
        $data = [
-
 
517
            'user_id'    => $user_id,
-
 
518
            'topic_id'   => $topic_id,
497
    }
519
            'capsule_id' => $capsule_id,
Línea -... Línea 520...
-
 
520
            'slide_id'   => $slide_id,
-
 
521
            'viewed_at'  => date('Y-m-d H:i:s'),
-
 
522
        ];
-
 
523
 
-
 
524
        // Verifica si ya existe el registro
-
 
525
        $exists = $this->fetchOneByUserIdAndSlideId($user_id, $slide_id);
-
 
526
        if ($exists) {
-
 
527
            return; // ya registrado
-
 
528
        }
-
 
529
 
-
 
530
        return $this->insert($data);
-
 
531
    }
-
 
532
 
-
 
533
    public function markCapsuleCompleted($user_id, $topic_id, $capsule_id)
-
 
534
    {
-
 
535
        $data = [
-
 
536
            'user_id'       => $user_id,
-
 
537
            'topic_id'      => $topic_id,
-
 
538
            'capsule_id'    => $capsule_id,
-
 
539
            'completed_at'  => date('Y-m-d H:i:s'),
-
 
540
        ];
-
 
541
 
-
 
542
        // Verifica si ya existe algún progreso de cápsula
-
 
543
        $exists = $this->fetchOneByUserIdAndCapsuleId($user_id, $capsule_id);
-
 
544
        if ($exists) {
-
 
545
            return; // ya registrado
-
 
546
        }
-
 
547
 
-
 
548
        return $this->insert($data);
-
 
549
    }
-
 
550
 
-
 
551
    public function markTopicCompleted($user_id, $topic_id)
-
 
552
    {
-
 
553
        $data = [
-
 
554
            'user_id'      => $user_id,
-
 
555
            'topic_id'     => $topic_id,
-
 
556
            'topic_closed' => 1,
-
 
557
            'closed_at'    => date('Y-m-d H:i:s'),
-
 
558
        ];
-
 
559
 
-
 
560
        // Verifica si ya existe algún progreso de topic
-
 
561
        $exists = $this->fetchOneByUserIdAndTopicId($user_id, $topic_id);
-
 
562
        if ($exists) {
-
 
563
            return; // ya registrado
-
 
564
        }
-
 
565
 
-
 
566
        return $this->insert($data);
-
 
567
    }
-
 
568
 
-
 
569
    public function hasViewedAllSlidesInCapsule($user_id, $capsule_id)
-
 
570
    {
-
 
571
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
572
        $allSlides = $slideMapper->fetchAllByCapsuleId($capsule_id);
-
 
573
 
-
 
574
        $select = $this->sql->select(self::_TABLE);
-
 
575
        $select->where->equalTo('user_id', $user_id);
-
 
576
        $select->where->equalTo('capsule_id', $capsule_id);
-
 
577
        $select->where->equalTo('type', MicrolearningUserProgress::TYPE_SLIDE);
-
 
578
        $select->where->equalTo('viewed_at', 1);
-
 
579
 
-
 
580
        $record = $this->executeFetchOneArray($select);
-
 
581
        return count($record) >= count($allSlides);
-
 
582
    }
-
 
583
 
-
 
584
    public function hasCompletedAllCapsulesInTopic($user_id, $topic_id)
-
 
585
    {
-
 
586
        $capsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
587
        $allCapsules = $capsuleMapper->fetchAllByTopicId($topic_id);
-
 
588
 
-
 
589
        $select = $this->sql->select(self::_TABLE);
498
    
590
        $select->where->equalTo('user_id', $user_id);
-
 
591
        $select->where->equalTo('topic_id', $topic_id);
-
 
592
        $select->where->equalTo('type', MicrolearningUserProgress::TYPE_CAPSULE);
-
 
593
        $select->where->equalTo('completed', 1);
Línea 499... Línea -...
499
    
-
 
500
    
594
 
501
 
595
        $record = $this->executeFetchOneArray($select);