Proyectos de Subversion LeadersLinked - Services

Rev

Rev 250 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 250 Rev 283
Línea 30... Línea 30...
30
use LeadersLinked\Model\Application;
30
use LeadersLinked\Model\Application;
31
use LeadersLinked\Validator\PasswordStrengthCheck;
31
use LeadersLinked\Validator\PasswordStrengthCheck;
Línea 32... Línea 32...
32
 
32
 
33
use LeadersLinked\Mapper\CompanyMapper;
33
use LeadersLinked\Mapper\CompanyMapper;
34
use LeadersLinked\Model\Company;
34
use LeadersLinked\Model\Company;
35
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
35
use LeadersLinked\Mapper\MicrolearningTopicMapper;
36
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
36
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
37
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
37
use LeadersLinked\Mapper\MicrolearningSlideMapper;
38
use LeadersLinked\Model\CompanyMicrolearningSlide;
38
use LeadersLinked\Model\MicrolearningSlide;
39
use LeadersLinked\Mapper\CompanyMicrolearningUserLogMapper;
39
use LeadersLinked\Mapper\MicrolearningUserLogMapper;
40
use LeadersLinked\Mapper\CompanyMicrolearningUserProgressMapper;
40
use LeadersLinked\Mapper\MicrolearningUserProgressMapper;
41
use LeadersLinked\Mapper\CompanyMicrolearningQuizMapper;
41
use LeadersLinked\Mapper\MicrolearningQuizMapper;
42
use LeadersLinked\Mapper\CompanyMicrolearningQuestionMapper;
42
use LeadersLinked\Mapper\MicrolearningQuestionMapper;
43
use LeadersLinked\Mapper\CompanyMicrolearningAnswerMapper;
43
use LeadersLinked\Mapper\MicrolearningAnswerMapper;
44
use LeadersLinked\Model\CompanyMicrolearningUserProgress;
44
use LeadersLinked\Model\MicrolearningUserProgress;
45
use LeadersLinked\Model\CompanyMicrolearningUserLog;
45
use LeadersLinked\Model\MicrolearningUserLog;
46
use LeadersLinked\Mapper\DeviceHistoryMapper;
46
use LeadersLinked\Mapper\DeviceHistoryMapper;
47
use LeadersLinked\Model\DeviceHistory;
47
use LeadersLinked\Model\DeviceHistory;
48
use LeadersLinked\Mapper\PushMapper;
48
use LeadersLinked\Mapper\PushMapper;
49
use LeadersLinked\Model\Push;
49
use LeadersLinked\Model\Push;
50
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleUserMapper;
50
use LeadersLinked\Mapper\MicrolearningCapsuleUserMapper;
51
use LeadersLinked\Mapper\CompanyServiceMapper;
51
use LeadersLinked\Mapper\CompanyServiceMapper;
52
use LeadersLinked\Model\Service;
52
use LeadersLinked\Model\Service;
53
use LeadersLinked\Model\CompanyService;
53
use LeadersLinked\Model\CompanyService;
54
use LeadersLinked\Model\CompanyMicrolearningCapsuleUser;
54
use LeadersLinked\Model\MicrolearningCapsuleUser;
55
use LeadersLinked\Model\CompanyMicrolearningUserQuiz;
55
use LeadersLinked\Model\MicrolearningUserQuiz;
56
use LeadersLinked\Mapper\CompanyMicrolearningUserQuizMapper;
56
use LeadersLinked\Mapper\MicrolearningUserQuizMapper;
57
use LeadersLinked\Mapper\CompanyMicrolearningUserMapper;
57
use LeadersLinked\Mapper\MicrolearningUserMapper;
58
use LeadersLinked\Model\CompanyMicrolearningUser;
58
use LeadersLinked\Model\MicrolearningUser;
59
use LeadersLinked\Mapper\PushTemplateMapper;
59
use LeadersLinked\Mapper\PushTemplateMapper;
60
use LeadersLinked\Model\PushTemplate;
60
use LeadersLinked\Model\PushTemplate;
61
use LeadersLinked\Mapper\SyncLogMapper;
61
use LeadersLinked\Mapper\SyncLogMapper;
62
use LeadersLinked\Model\SyncLog;
62
use LeadersLinked\Model\SyncLog;
63
use LeadersLinked\Model\CompanyMicrolearningExtendUser;
63
use LeadersLinked\Model\MicrolearningExtendUser;
64
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserMapper;
64
use LeadersLinked\Mapper\MicrolearningExtendUserMapper;
65
use LeadersLinked\Model\CompanyMicrolearningExtendUserCompany;
65
use LeadersLinked\Model\MicrolearningExtendUserCompany;
66
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleCommentMapper;
66
use LeadersLinked\Mapper\MicrolearningCapsuleCommentMapper;
67
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserCompanyMapper;
67
use LeadersLinked\Mapper\MicrolearningExtendUserCompanyMapper;
68
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserFunctionMapper;
68
use LeadersLinked\Mapper\MicrolearningExtendUserFunctionMapper;
69
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserGroupMapper;
69
use LeadersLinked\Mapper\MicrolearningExtendUserGroupMapper;
70
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserInstitutionMapper;
70
use LeadersLinked\Mapper\MicrolearningExtendUserInstitutionMapper;
71
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserPartnerMapper;
71
use LeadersLinked\Mapper\MicrolearningExtendUserPartnerMapper;
72
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserProgramMapper;
72
use LeadersLinked\Mapper\MicrolearningExtendUserProgramMapper;
73
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserStudentTypeMapper;
73
use LeadersLinked\Mapper\MicrolearningExtendUserStudentTypeMapper;
74
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserSectorMapper;
74
use LeadersLinked\Mapper\MicrolearningExtendUserSectorMapper;
75
use Nullix\CryptoJsAes\CryptoJsAes;
75
use Nullix\CryptoJsAes\CryptoJsAes;
76
use LeadersLinked\Model\CompanyMicrolearningTopic;
76
use LeadersLinked\Model\MicrolearningTopic;
77
use LeadersLinked\Model\CompanyMicrolearningCapsule;
77
use LeadersLinked\Model\MicrolearningCapsule;
78
use LeadersLinked\Model\UserDeleted;
78
use LeadersLinked\Model\UserDeleted;
79
use LeadersLinked\Mapper\UserDeletedMapper;
79
use LeadersLinked\Mapper\UserDeletedMapper;
80
use LeadersLinked\Mapper\ApplicationVariantMapper;
80
use LeadersLinked\Mapper\ApplicationVariantMapper;
Línea 340... Línea 340...
340
        error_log('$rawdata = ' . $rawdata );
340
        error_log('$rawdata = ' . $rawdata );
Línea 341... Línea 341...
341
        
341
        
Línea 342... Línea 342...
342
        $request = $this->getRequest();
342
        $request = $this->getRequest();
343
        
-
 
344
        if($request->isPost()) {
343
        
Línea 345... Línea 344...
345
            //print_r($_POST);
344
        if($request->isPost()) {
346
            
345
 
347
            
346
            
348
            $application_id = filter_var($this->params()->fromPost('application_id', 0), FILTER_SANITIZE_NUMBER_INT);
347
            $application_id = filter_var($this->params()->fromPost('application_id', 0), FILTER_SANITIZE_NUMBER_INT);
Línea 616... Línea 615...
616
                $device->ip = Functions::getUserIP();
615
                $device->ip = Functions::getUserIP();
617
                $deviceMapper->update($device);
616
                $deviceMapper->update($device);
618
            }
617
            }
Línea 619... Línea 618...
619
            
618
            
620
            //Cargamos la fecha máxima del cambio
619
            //Cargamos la fecha máxima del cambio
621
            $companyMicrolearningUserMapper = CompanyMicrolearningUserMapper::getInstance($this->adapter);
620
            $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
Línea 622... Línea 621...
622
            $max_date_changes_db = $companyMicrolearningUserMapper->fetchMaxDateChanges($user->id);
621
            $max_date_changes_db = $microlearningUserMapper->fetchMaxDateChanges($user->id);
623
            
622
            
624
            
623
            
625
 
624
 
626
            
625
            
627
            //Si la fecha es vacia agregamos la fecha máxima de la asignación de la capsula
626
            //Si la fecha es vacia agregamos la fecha máxima de la asignación de la capsula
628
            if(!$max_date_changes_db) {
627
            if(!$max_date_changes_db) {
Línea 650... Línea 649...
650
                foreach($companyUsers as $company_id => $update_on)
649
                foreach($companyUsers as $company_id => $update_on)
651
                {
650
                {
Línea 652... Línea 651...
652
                    
651
                    
Línea 653... Línea 652...
653
                    $max_date_changes_db = $max_date_changes_db < $update_on ? $update_on : $max_date_changes_db;
652
                    $max_date_changes_db = $max_date_changes_db < $update_on ? $update_on : $max_date_changes_db;
654
                    
653
                    
655
                    $companyMicrolearningUser = new CompanyMicrolearningUser();
654
                    $microlearningUser = new MicrolearningUser();
656
                    $companyMicrolearningUser->company_id = $company_id;
655
                    $microlearningUser->company_id = $company_id;
657
                    $companyMicrolearningUser->user_id = $user->id;
656
                    $microlearningUser->user_id = $user->id;
Línea 658... Línea 657...
658
                    $companyMicrolearningUser->added_on = $update_on;
657
                    $microlearningUser->added_on = $update_on;
659
                    $companyMicrolearningUser->updated_on = $update_on;
658
                    $microlearningUser->updated_on = $update_on;
660
                    
659
                    
Línea 661... Línea 660...
661
                    $companyMicrolearningUserMapper->insert($companyMicrolearningUser);
660
                    $microlearningUserMapper->insert($microlearningUser);
662
                }
661
                }
Línea 673... Línea 672...
673
            //Si la que tiene el dispositivo es diferente a la fecha máxima almacenada
672
            //Si la que tiene el dispositivo es diferente a la fecha máxima almacenada
674
            $newCapsules = 0;
673
            $newCapsules = 0;
675
            if($max_date_changes != $max_date_changes_db) {
674
            if($max_date_changes != $max_date_changes_db) {
676
                if(is_array($ids)) {
675
                if(is_array($ids)) {
677
                    /*
676
                    /*
678
                    $companyMicrolearningTopicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
677
                    $microlearningTopicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
679
                    $companyMicrolearningTopics = $companyMicrolearningTopicMapper->fetchAllActive();
678
                    $microlearningTopics = $microlearningTopicMapper->fetchAllActive();
Línea 680... Línea 679...
680
                        
679
                        
681
                    $topics = [];
680
                    $topics = [];
682
                    foreach($companyMicrolearningTopics as $topic)
681
                    foreach($microlearningTopics as $topic)
683
                    {
682
                    {
684
                        $topics[$topic->id] = $topic->uuid;
683
                        $topics[$topic->id] = $topic->uuid;
Línea 685... Línea 684...
685
                    }
684
                    }
686
                        
685
                        
Línea 687... Línea 686...
687
                    $companyMicrolearningCapsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
686
                    $microlearningCapsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
688
                    $companyMicrolearningCapsules = $companyMicrolearningCapsuleMapper->fetchAllActive();
687
                    $microlearningCapsules = $microlearningCapsuleMapper->fetchAllActive();
689
                        
688
                        
690
                    $capsules = [];
689
                    $capsules = [];
691
                    foreach($companyMicrolearningCapsules as $capsule)
690
                    foreach($microlearningCapsules as $capsule)
692
                    {                            
691
                    {                            
Línea 693... Línea 692...
693
                        $capsules[$capsule->id] = $capsule->uuid;
692
                        $capsules[$capsule->id] = $capsule->uuid;
694
                    }
693
                    }
Línea 695... Línea 694...
695
                    */
694
                    */
696
                    
695
                    
Línea 697... Línea 696...
697
                    $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
696
                    $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
698
                    $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
699
                    
-
 
700
                        
697
                    $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
701
                    $companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
698
                    
Línea 702... Línea 699...
702
                    $userCapsules = $companyMicrolearningCapsuleUserMapper->fetchAllActiveByUserId($user->id);
699
                        
703
                        
700
                    $microlearningCapsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
Línea 704... Línea 701...
704
                    
701
                    $userCapsules = $microlearningCapsuleUserMapper->fetchAllActiveByUserId($user->id);
705
                    //print_r($user_capsules); 
702
                        
706
                    
703
 
707
                    foreach($userCapsules as $userCapsule) 
704
                    foreach($userCapsules as $userCapsule) 
708
                    {
705
                    {
709
                        
706
                        
710
                        $topic  = $topicMapper->fetchOne($userCapsule->topic_id);
707
                        $topic  = $topicMapper->fetchOne($userCapsule->topic_id);
Línea 747... Línea 744...
747
                        $pushTemplate = $pushTemplateMapper-> fetchOneByCodeDefault(PushTemplate::ID_MICRO_LEARNING_NEW_CONTENT);
744
                        $pushTemplate = $pushTemplateMapper-> fetchOneByCodeDefault(PushTemplate::ID_MICRO_LEARNING_NEW_CONTENT);
Línea 748... Línea 745...
748
                        
745
                        
Línea 749... Línea -...
749
                    }
-
 
750
                    
-
 
751
                    
-
 
752
                    //echo 'PushTemplate' . PHP_EOL;
-
 
753
                    //print_r($pushTemplate);
-
 
754
  
-
 
755
                    
-
 
756
                    
746
                    }
757
                    //echo 'Application';
747
                    
758
                    //print_r($application);
748
                    
759
                    if($pushTemplate && $application) {
749
                    if($pushTemplate && $application) {
760
                         $push = new Push();
750
                         $push = new Push();
Línea 781... Línea 771...
781
                                    'new_capsules' => strval($newCapsules),
771
                                    'new_capsules' => strval($newCapsules),
782
                                ]
772
                                ]
783
                            ]
773
                            ]
784
                        ]);
774
                        ]);
Línea 785... Línea -...
785
                        
-
 
786
                        
-
 
787
                        //print_r($push);
-
 
788
                        
775
                        
789
                        $pushMapper->insert($push);
776
                        $pushMapper->insert($push);
790
                    }
777
                    }
791
                }
778
                }
792
                
-
 
793
                /*
-
 
794
                if(!$is_foreground) {
-
 
795
                    $dataSync = $this->getSyncData($user,false, false);
-
 
796
                }
-
 
797
                */
779
 
798
            }
-
 
799
           
780
            }
800
            
-
 
801
            //error_log('$max_date_changes_db = ' . $max_date_changes_db);
-
 
802
            
781
  
803
            $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $max_date_changes_db);
782
            $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $max_date_changes_db);
804
            if($dt) {
783
            if($dt) {
805
                $max_date_changes_db = $dt->format($serviceDatetimeFormat);
784
                $max_date_changes_db = $dt->format($serviceDatetimeFormat);
806
            } else {
785
            } else {
807
                $max_date_changes_db = '';
786
                $max_date_changes_db = '';
Línea 808... Línea 787...
808
            }
787
            }
Línea 809... Línea 788...
809
            
788
            
810
            $ratingAndComments = [];
789
            $ratingAndComments = [];
Línea 811... Línea 790...
811
            
790
            
812
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
791
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
Línea 813... Línea 792...
813
            $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
792
            $capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
814
            
793
            
815
            $companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
794
            $microlearningCapsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
816
            $userCapsules = $companyMicrolearningCapsuleUserMapper->fetchAllActiveByUserId($user->id);
795
            $userCapsules = $microlearningCapsuleUserMapper->fetchAllActiveByUserId($user->id);
Línea 897... Línea 876...
897
            $user = $currentUserPlugin->getUser();
876
            $user = $currentUserPlugin->getUser();
Línea 898... Línea 877...
898
            
877
            
Línea 899... Línea 878...
899
            $dataSync = $this->getSyncData($user,false, false);
878
            $dataSync = $this->getSyncData($user,false, false);
900
            
879
            
901
            //Cargamos la fecha máxima del cambio
880
            //Cargamos la fecha máxima del cambio
Línea 902... Línea 881...
902
            $companyMicrolearningUserMapper = CompanyMicrolearningUserMapper::getInstance($this->adapter);
881
            $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
903
            $max_date_changes_db = $companyMicrolearningUserMapper->fetchMaxDateChanges($user->id);
882
            $max_date_changes_db = $microlearningUserMapper->fetchMaxDateChanges($user->id);
904
            
883
            
905
            //Si la fecha es vacia agregamos la fecha máxima de la asignación de la capsula
884
            //Si la fecha es vacia agregamos la fecha máxima de la asignación de la capsula
906
            if(!$max_date_changes_db) {
885
            if(!$max_date_changes_db) {
907
                $companyUsers = [];
886
                $companyUsers = [];
908
                $companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
887
                $microlearningCapsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
Línea 928... Línea 907...
928
                foreach($companyUsers as $company_id => $update_on)
907
                foreach($companyUsers as $company_id => $update_on)
929
                {
908
                {
Línea 930... Línea 909...
930
                    
909
                    
Línea 931... Línea 910...
931
                    $max_date_changes_db = $max_date_changes_db < $update_on ? $update_on : $max_date_changes_db;
910
                    $max_date_changes_db = $max_date_changes_db < $update_on ? $update_on : $max_date_changes_db;
932
                    
911
                    
933
                    $companyMicrolearningUser = new CompanyMicrolearningUser();
912
                    $microlearningUser = new MicrolearningUser();
934
                    $companyMicrolearningUser->company_id = $company_id;
913
                    $microlearningUser->company_id = $company_id;
935
                    $companyMicrolearningUser->user_id = $user->id;
914
                    $microlearningUser->user_id = $user->id;
Línea 936... Línea 915...
936
                    $companyMicrolearningUser->added_on = $update_on;
915
                    $microlearningUser->added_on = $update_on;
937
                    $companyMicrolearningUser->updated_on = $update_on;
916
                    $microlearningUser->updated_on = $update_on;
938
                    
917
                    
Línea 939... Línea 918...
939
                    $companyMicrolearningUserMapper->insert($companyMicrolearningUser);
918
                    $microlearningUserMapper->insert($microlearningUser);
940
                }
919
                }
Línea 1256... Línea 1235...
1256
                        }
1235
                        }
1257
                    }
1236
                    }
Línea 1258... Línea 1237...
1258
                    
1237
                    
1259
                    
1238
                    
1260
                    $companyUsers = [];
1239
                    $companyUsers = [];
1261
                    $companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
1240
                    $microlearningCapsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
1262
                    $capsules = $companyMicrolearningCapsuleUserMapper->fetchAllActiveByUserId($user->id);
1241
                    $capsules = $microlearningCapsuleUserMapper->fetchAllActiveByUserId($user->id);
Línea 1275... Línea 1254...
1275
                            
1254
                            
Línea 1276... Línea 1255...
1276
                        }
1255
                        }
Línea 1277... Línea 1256...
1277
                        
1256
                        
Línea 1278... Línea 1257...
1278
                    }
1257
                    }
1279
                    
1258
                    
Línea 1280... Línea 1259...
1280
                    $companyMicrolearningUserMapper = CompanyMicrolearningUserMapper::getInstance($this->adapter);
1259
                    $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
1281
                    
1260
                    
1282
                    $maxDateChanges = $companyMicrolearningUserMapper->fetchMaxDateChanges($user->id);
1261
                    $maxDateChanges = $microlearningUserMapper->fetchMaxDateChanges($user->id);
Línea 1283... Línea 1262...
1283
                    if(!$maxDateChanges) {
1262
                    if(!$maxDateChanges) {
Línea 1284... Línea 1263...
1284
                        
1263
                        
1285
                       
1264
                       
1286
                        $maxDateChanges = ''; 
1265
                        $maxDateChanges = ''; 
1287
                        foreach($companyUsers as $company_id => $update_on)
1266
                        foreach($companyUsers as $company_id => $update_on)
1288
                        {
1267
                        {
Línea 1289... Línea 1268...
1289
                            
1268
                            
1290
                            $maxDateChanges = $maxDateChanges < $update_on ? $update_on : $maxDateChanges;
1269
                            $maxDateChanges = $maxDateChanges < $update_on ? $update_on : $maxDateChanges;
Línea 1291... Línea 1270...
1291
                            
1270
                            
Línea 1652... Línea 1631...
1652
            $data           = $this->params()->fromPost('data', '');
1631
            $data           = $this->params()->fromPost('data', '');
1653
            $application_id = filter_var($this->params()->fromPost('application_id', 0), FILTER_SANITIZE_NUMBER_INT);
1632
            $application_id = filter_var($this->params()->fromPost('application_id', 0), FILTER_SANITIZE_NUMBER_INT);
1654
            $variant_id     = filter_var($this->params()->fromPost('variant_id', 0), FILTER_SANITIZE_NUMBER_INT);
1633
            $variant_id     = filter_var($this->params()->fromPost('variant_id', 0), FILTER_SANITIZE_NUMBER_INT);
Línea 1655... Línea -...
1655
           
-
 
1656
            
-
 
1657
            //error_log('device_uuid = ' . $device_uuid);
-
 
1658
            //error_log('sync_id = ' . $sync_id);
-
 
1659
            //error_log(print_r($data, true));
-
 
1660
            
-
 
1661
            
-
 
Línea 1662... Línea 1634...
1662
            //$rawdata = file_get_contents("php://input");
1634
           
Línea 1663... Línea 1635...
1663
           // error_log('$rawdata = ' . $rawdata );
1635
            
1664
           
1636
           
Línea 1836... Línea 1808...
1836
                            'fatal' => true
1808
                            'fatal' => true
1837
                        ]
1809
                        ]
1838
                    ]);
1810
                    ]);
1839
                }
1811
                }
Línea 1840... Línea 1812...
1840
                
1812
                
1841
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1813
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
1842
                $topic_uuid = isset($data['topic_uuid']) ? Functions::sanitizeFilterString($data['topic_uuid']) :  '';
1814
                $topic_uuid = isset($data['topic_uuid']) ? Functions::sanitizeFilterString($data['topic_uuid']) :  '';
1843
                if($topic_uuid) {
1815
                if($topic_uuid) {
Línea 1844... Línea 1816...
1844
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
1816
                    $topic = $topicMapper->fetchOneByUuid($topic_uuid);
Línea 1866... Línea 1838...
1866
                } else {
1838
                } else {
1867
                    $topic = null;
1839
                    $topic = null;
1868
                }
1840
                }
Línea 1869... Línea 1841...
1869
                
1841
                
1870
                $capsule_uuid     = isset($data['capsule_uuid']) ? Functions::sanitizeFilterString($data['capsule_uuid']) :  '';
1842
                $capsule_uuid     = isset($data['capsule_uuid']) ? Functions::sanitizeFilterString($data['capsule_uuid']) :  '';
1871
                $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1843
                $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
Línea 1872... Línea 1844...
1872
                if($capsule_uuid) {
1844
                if($capsule_uuid) {
1873
                   
1845
                   
1874
                    $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
1846
                    $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
Línea 1896... Línea 1868...
1896
                }
1868
                }
Línea 1897... Línea 1869...
1897
                
1869
                
Línea 1898... Línea 1870...
1898
                if($capsule) {
1870
                if($capsule) {
1899
       
1871
       
1900
                    $capsuleActive = true;
1872
                    $capsuleActive = true;
Línea 1901... Línea 1873...
1901
                    $capsuleMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
1873
                    $capsuleMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
1902
                    $capsuleUser = $capsuleMapper->fetchOneByUserIdAndCapsuleId($user->id, $capsule->id);
1874
                    $capsuleUser = $capsuleMapper->fetchOneByUserIdAndCapsuleId($user->id, $capsule->id);
Línea 1903... Línea 1875...
1903
                    
1875
                    
Línea 1904... Línea 1876...
1904
                    
1876
                    
1905
                    $now = date('Y-m-d H:i:s');
1877
                    $now = date('Y-m-d H:i:s');
1906
                    if($capsuleUser && in_array($capsuleUser->access, [CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED,CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD ])) {
1878
                    if($capsuleUser && in_array($capsuleUser->access, [MicrolearningCapsuleUser::ACCESS_UNLIMITED,MicrolearningCapsuleUser::ACCESS_PAY_PERIOD ])) {
1907
                        
1879
                        
Línea 1928... Línea 1900...
1928
                    }
1900
                    }
1929
                }
1901
                }
Línea 1930... Línea 1902...
1930
                
1902
                
1931
               
1903
               
Línea 1932... Línea 1904...
1932
                
1904
                
Línea 1965... Línea 1937...
1965
        
1937
        
1966
                if($sync_type == 'microlearning-quiz') {
1938
                if($sync_type == 'microlearning-quiz') {
Línea 1967... Línea 1939...
1967
                    $ok = true;
1939
                    $ok = true;
1968
                    
1940
                    
Línea 1969... Línea 1941...
1969
                    $quiz_uuid = isset($data['quiz_uuid']) ? $data['quiz_uuid'] : '';
1941
                    $quiz_uuid = isset($data['quiz_uuid']) ? $data['quiz_uuid'] : '';
1970
                    $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
1942
                    $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
1971
                    
1943
                    
1972
                    $quiz = $quizMapper->fetchOneByUuid($quiz_uuid);
1944
                    $quiz = $quizMapper->fetchOneByUuid($quiz_uuid);
Línea 2006... Línea 1978...
2006
                        $ok = false;
1978
                        $ok = false;
2007
                    }
1979
                    }
Línea 2008... Línea 1980...
2008
                    
1980
                    
2009
 
1981
 
2010
                    if(isset($data['pass'])) {
1982
                    if(isset($data['pass'])) {
2011
                        $status = $data['pass'] == 'yes' ? CompanyMicrolearningUserQuiz::STATUS_PASS : CompanyMicrolearningUserQuiz::STATUS_FAIL;
1983
                        $status = $data['pass'] == 'yes' ? MicrolearningUserQuiz::STATUS_PASS : MicrolearningUserQuiz::STATUS_FAIL;
2012
                    } else {
1984
                    } else {
Línea 2047... Línea 2019...
2047
                        
2019
                        
Línea 2048... Línea 2020...
2048
                        
2020
                        
2049
                    }
2021
                    }
2050
 
2022
 
2051
                    
2023
                    
2052
                    $userQuiz = new CompanyMicrolearningUserQuiz();
2024
                    $userQuiz = new MicrolearningUserQuiz();
2053
                    $userQuiz->company_id = $company->id;
2025
                    $userQuiz->company_id = $company->id;
Línea 2059... Línea 2031...
2059
                    $userQuiz->added_on = $added_on;
2031
                    $userQuiz->added_on = $added_on;
2060
                    $userQuiz->points = $points;
2032
                    $userQuiz->points = $points;
2061
                    $userQuiz->status = $status;
2033
                    $userQuiz->status = $status;
2062
                    $userQuiz->response = json_encode($array_response);
2034
                    $userQuiz->response = json_encode($array_response);
Línea 2063... Línea 2035...
2063
                    
2035
                    
Línea 2064... Línea 2036...
2064
                    $userQuizMapper = CompanyMicrolearningUserQuizMapper::getInstance($this->adapter);
2036
                    $userQuizMapper = MicrolearningUserQuizMapper::getInstance($this->adapter);
2065
                    
2037
                    
2066
                    if($userQuizMapper->insert($userQuiz)) {
2038
                    if($userQuizMapper->insert($userQuiz)) {
2067
                        return new JsonModel([
2039
                        return new JsonModel([
Línea 2088... Línea 2060...
2088
      
2060
      
2089
                    
2061
                    
2090
                    $type = isset($data['type']) ? $data['type'] : '';
2062
                    $type = isset($data['type']) ? $data['type'] : '';
2091
                    switch($type)
2063
                    switch($type)
2092
                    {
2064
                    {
2093
                        case CompanyMicrolearningUserProgress::TYPE_TOPIC : 
2065
                        case MicrolearningUserProgress::TYPE_TOPIC : 
2094
                            if(!$topic) {
2066
                            if(!$topic) {
2095
                                $ok = false;
2067
                                $ok = false;
Línea 2096... Línea 2068...
2096
                            }
2068
                            }
2097
                            break;
2069
                            break;
2098
                            
2070
                            
2099
                        case CompanyMicrolearningUserProgress::TYPE_CAPSULE :
2071
                        case MicrolearningUserProgress::TYPE_CAPSULE :
2100
                            if(!$topic || !$capsule) {
2072
                            if(!$topic || !$capsule) {
Línea 2101... Línea 2073...
2101
                                $ok = false;
2073
                                $ok = false;
2102
                            }
2074
                            }
2103
                            break;
2075
                            break;
2104
                            
2076
                            
2105
                        case CompanyMicrolearningUserProgress::TYPE_SLIDE :
2077
                        case MicrolearningUserProgress::TYPE_SLIDE :
Línea 2147... Línea 2119...
2147
                    //$view_slides                = isset($data['view_slides'])               ? intval($data['view_slides'], 10) :  0;
2119
                    //$view_slides                = isset($data['view_slides'])               ? intval($data['view_slides'], 10) :  0;
2148
                    $returning                  = isset($data['returning'])                 ? intval($data['returning'], 10) :  0;
2120
                    $returning                  = isset($data['returning'])                 ? intval($data['returning'], 10) :  0;
2149
                    $returning_after_completed  = isset($data['returning_after_completed']) ? intval($data['returning_after_completed'], 10) :  0;
2121
                    $returning_after_completed  = isset($data['returning_after_completed']) ? intval($data['returning_after_completed'], 10) :  0;
2150
                    $completed                  = isset($data['completed'])                 ? intval($data['completed'], 10) :  0;
2122
                    $completed                  = isset($data['completed'])                 ? intval($data['completed'], 10) :  0;
Línea 2151... Línea 2123...
2151
 
2123
 
2152
                    $progressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
2124
                    $progressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
2153
                    $recordProgress = null;
2125
                    $recordProgress = null;
2154
                    switch($type) {
2126
                    switch($type) {
2155
                        case CompanyMicrolearningUserProgress::TYPE_TOPIC  :
2127
                        case MicrolearningUserProgress::TYPE_TOPIC  :
Línea 2156... Línea 2128...
2156
                            $recordProgress = $progressMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);
2128
                            $recordProgress = $progressMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);
Línea 2157... Línea 2129...
2157
                            
2129
                            
2158
                            break;
2130
                            break;
2159
                                            
2131
                                            
Línea 2160... Línea 2132...
2160
                        case CompanyMicrolearningUserProgress::TYPE_CAPSULE  :
2132
                        case MicrolearningUserProgress::TYPE_CAPSULE  :
2161
                            $recordProgress = $progressMapper->fetchOneByUseridAndCapsuleId($user->id, $capsule->id);
2133
                            $recordProgress = $progressMapper->fetchOneByUseridAndCapsuleId($user->id, $capsule->id);
2162
                            break;
2134
                            break;
Línea 2163... Línea 2135...
2163
                                            
2135
                                            
2164
                        case CompanyMicrolearningUserProgress::TYPE_SLIDE  :
2136
                        case MicrolearningUserProgress::TYPE_SLIDE  :
2165
                            $recordProgress = $progressMapper->fetchOneByUserIdAndSlideId($user->id, $slide->id);
2137
                            $recordProgress = $progressMapper->fetchOneByUserIdAndSlideId($user->id, $slide->id);
Línea 2166... Línea 2138...
2166
                            break;
2138
                            break;
2167
                            
2139
                            
Línea 2168... Línea 2140...
2168
                        default : 
2140
                        default : 
2169
                            $recordProgress= null;
2141
                            $recordProgress= null;
2170
                    }
2142
                    }
2171
 
2143
 
Línea 2183... Línea 2155...
2183
                    }
2155
                    }
2184
                    $recordProgress->returning                  = $returning;
2156
                    $recordProgress->returning                  = $returning;
2185
                    $recordProgress->returning_after_completed  = $returning_after_completed;
2157
                    $recordProgress->returning_after_completed  = $returning_after_completed;
2186
                    $recordProgress->completed                  = $completed;
2158
                    $recordProgress->completed                  = $completed;
Línea 2187... Línea 2159...
2187
                                    
2159
                                    
Línea 2188... Línea 2160...
2188
                    if($type == CompanyMicrolearningUserProgress::TYPE_TOPIC ) {
2160
                    if($type == MicrolearningUserProgress::TYPE_TOPIC ) {
2189
                        
2161
                        
2190
                        $capsule_ids = [];
2162
                        $capsule_ids = [];
2191
                        $companyMicrolearningCapsuleUser = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
2163
                        $microlearningCapsuleUser = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
2192
                        $records =  $companyMicrolearningCapsuleUser->fetchAllActiveByUserId($user->id);
2164
                        $records =  $microlearningCapsuleUser->fetchAllActiveByUserId($user->id);
2193
                        foreach($records as $record) 
2165
                        foreach($records as $record) 
2194
                        {
2166
                        {
2195
                            if($now >= $record->paid_from || $now <= $capsuleUser->paid_to) {
2167
                            if($now >= $record->paid_from || $now <= $capsuleUser->paid_to) {
Línea 2211... Línea 2183...
2211
                        
2183
                        
2212
                        $recordProgress->progress       = $total_slides > 0 ? (($view_slides * 100) / $total_slides) : 0;
2184
                        $recordProgress->progress       = $total_slides > 0 ? (($view_slides * 100) / $total_slides) : 0;
2213
                        $recordProgress->total_slides   = $total_slides;
2185
                        $recordProgress->total_slides   = $total_slides;
2214
                        $recordProgress->view_slides    = $view_slides;
2186
                        $recordProgress->view_slides    = $view_slides;
2215
                    } 
2187
                    } 
2216
                    else if($type == CompanyMicrolearningUserProgress::TYPE_CAPSULE ) {
2188
                    else if($type == MicrolearningUserProgress::TYPE_CAPSULE ) {
2217
                        $view_slides    = $progressMapper->fetchCountAllSlideViewedByUserIdAndCapsuleId($user->id, $capsule->id);
2189
                        $view_slides    = $progressMapper->fetchCountAllSlideViewedByUserIdAndCapsuleId($user->id, $capsule->id);
Línea 2218... Línea 2190...
2218
                        $total_slides   = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($topic->company_id, $capsule->topic_id, $capsule->id);
2190
                        $total_slides   = $slideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($topic->company_id, $capsule->topic_id, $capsule->id);
2219
       
2191
       
Línea 2281... Línea 2253...
2281
                                'message' => 'ERROR_INVALID_PARAMETERS 3',
2253
                                'message' => 'ERROR_INVALID_PARAMETERS 3',
2282
                            ]
2254
                            ]
2283
                        ]);
2255
                        ]);
2284
                    }
2256
                    }
Línea 2285... Línea 2257...
2285
                                
2257
                                
2286
                    $userLog = new CompanyMicrolearningUserLog();
2258
                    $userLog = new MicrolearningUserLog();
2287
                    $userLog->activity      = $activity;
2259
                    $userLog->activity      = $activity;
2288
                    $userLog->user_id       = $user->id;
2260
                    $userLog->user_id       = $user->id;
2289
                    $userLog->company_id    = $topic->company_id;
2261
                    $userLog->company_id    = $topic->company_id;
2290
                    $userLog->topic_id      = $topic->id;
2262
                    $userLog->topic_id      = $topic->id;
2291
                    $userLog->capsule_id    = $capsule ? $capsule->id : null;
2263
                    $userLog->capsule_id    = $capsule ? $capsule->id : null;
2292
                    $userLog->slide_id      = $slide ? $slide->id : null;
2264
                    $userLog->slide_id      = $slide ? $slide->id : null;
Línea 2293... Línea 2265...
2293
                    $userLog->added_on      = $added_on;
2265
                    $userLog->added_on      = $added_on;
2294
 
2266
 
2295
       
2267
       
2296
                    
2268
                    
2297
                    $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
2269
                    $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
2298
                    if($userLogMapper->insert($userLog)) {
2270
                    if($userLogMapper->insert($userLog)) {
Línea 2368... Línea 2340...
2368
                            'message' => 'ERROR_INVALID_PARAMETERS 4',
2340
                            'message' => 'ERROR_INVALID_PARAMETERS 4',
2369
                        ]
2341
                        ]
2370
                    ]);
2342
                    ]);
2371
                }
2343
                }
Línea 2372... Línea 2344...
2372
                
2344
                
2373
                $userLog = new CompanyMicrolearningUserLog();
2345
                $userLog = new MicrolearningUserLog();
2374
                $userLog->company_id = null;
2346
                $userLog->company_id = null;
2375
                $userLog->user_id = $user->id;
2347
                $userLog->user_id = $user->id;
2376
                $userLog->activity = $activity;
2348
                $userLog->activity = $activity;
Línea 2377... Línea 2349...
2377
                $userLog->added_on = $added_on;
2349
                $userLog->added_on = $added_on;
2378
                
2350
                
2379
 
2351
 
2380
                $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
2352
                $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
2381
                if($userLogMapper->insert($userLog)) {
2353
                if($userLogMapper->insert($userLog)) {
2382
                    return new JsonModel([
2354
                    return new JsonModel([
Línea 2416... Línea 2388...
2416
    {
2388
    {
2417
        $request = $this->getRequest();
2389
        $request = $this->getRequest();
Línea 2418... Línea 2390...
2418
        
2390
        
Línea 2419... Línea -...
2419
        if($request->isPost()) {
-
 
2420
            
-
 
2421
            $rawdata = file_get_contents("php://input");
-
 
-
 
2391
        if($request->isPost()) {
Línea 2422... Línea 2392...
2422
            error_log('$rawdata = ' . $rawdata );
2392
            
Línea 2423... Línea 2393...
2423
            error_log(print_r($_POST, true));
2393
           
2424
            
2394
            
Línea 2517... Línea 2487...
2517
            $answers = [];
2487
            $answers = [];
Línea 2518... Línea 2488...
2518
            
2488
            
2519
            $userMapper = UserMapper::getInstance($this->adapter);
2489
            $userMapper = UserMapper::getInstance($this->adapter);
2520
            $companyMapper = CompanyMapper::getInstance($this->adapter);
2490
            $companyMapper = CompanyMapper::getInstance($this->adapter);
2521
            $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
2491
            $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
2522
            $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
2492
            $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
2523
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
2493
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
2524
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
2494
            $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
2525
            $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
2495
            $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
2526
            $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
2496
            $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
2527
            $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
2497
            $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
Línea 2528... Línea 2498...
2528
            $answerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
2498
            $answerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
2529
            
2499
            
Línea 2530... Línea 2500...
2530
            
2500
            
2531
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
2501
            $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
2532
            $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
2502
            $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
Línea 2691... Línea 2661...
2691
                                $topics[$topic_uuid] = $topic;
2661
                                $topics[$topic_uuid] = $topic;
2692
                            }
2662
                            }
2693
                        }
2663
                        }
Línea 2694... Línea 2664...
2694
                        
2664
                        
2695
                        if(!$topic) {
-
 
2696
                            error_log(print_r($record, true));
2665
                        if(!$topic) {
2697
                            
2666
 
2698
                            array_push($result_sync_ids, [
2667
                            array_push($result_sync_ids, [
2699
                                'success' => false,
2668
                                'success' => false,
2700
                                'sync_id' => $sync_id,
2669
                                'sync_id' => $sync_id,
2701
                                'message' => 'ERROR_TOPIC_NOT_FOUND',
2670
                                'message' => 'ERROR_TOPIC_NOT_FOUND',
Línea 2727... Línea 2696...
2727
                            if($capsule) {
2696
                            if($capsule) {
2728
                                $capsules[$capsule_uuid] = $capsule;
2697
                                $capsules[$capsule_uuid] = $capsule;
2729
                            }
2698
                            }
2730
                        }
2699
                        }
2731
                        if(!$capsule) {
2700
                        if(!$capsule) {
2732
                            error_log(print_r($record, true));
-
 
2733
                            
2701
 
2734
                            array_push($result_sync_ids, [
2702
                            array_push($result_sync_ids, [
2735
                                'success' => false,
2703
                                'success' => false,
2736
                                'sync_id' => $sync_id,
2704
                                'sync_id' => $sync_id,
2737
                                'message' => 'ERROR_CAPSULE_NOT_FOUND',
2705
                                'message' => 'ERROR_CAPSULE_NOT_FOUND',
2738
                            ]);
2706
                            ]);
Línea 2767... Línea 2735...
2767
                            }
2735
                            }
Línea 2768... Línea 2736...
2768
                        
2736
                        
Línea 2769... Línea 2737...
2769
                        }
2737
                        }
2770
                        
2738
                        
Línea 2771... Línea 2739...
2771
                        $now = date('Y-m-d H:i:s');
2739
                        $now = date('Y-m-d H:i:s');
Línea 2772... Línea 2740...
2772
                        if($capsuleUser && in_array($capsuleUser->access, [CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED,CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD ])) {
2740
                        if($capsuleUser && in_array($capsuleUser->access, [MicrolearningCapsuleUser::ACCESS_UNLIMITED,MicrolearningCapsuleUser::ACCESS_PAY_PERIOD ])) {
2773
                            
2741
                            
2774
                            
2742
                            
2775
                            if($capsuleUser->access == CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
2743
                            if($capsuleUser->access == MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
Línea 2805... Línea 2773...
2805
                            if($slide) {
2773
                            if($slide) {
2806
                                $slides[$slide_uuid] = $slide;
2774
                                $slides[$slide_uuid] = $slide;
2807
                            }
2775
                            }
2808
                        }
2776
                        }
2809
                        if(!$slide) {
2777
                        if(!$slide) {
2810
                            error_log(print_r($record, true));
-
 
2811
                            
2778
  
2812
                            array_push($result_sync_ids, [
2779
                            array_push($result_sync_ids, [
2813
                                'success' => false,
2780
                                'success' => false,
2814
                                'sync_id' => $sync_id,
2781
                                'sync_id' => $sync_id,
2815
                                'message' => 'ERROR_SLIDE_NOT_FOUND',
2782
                                'message' => 'ERROR_SLIDE_NOT_FOUND',
2816
                            ]);
2783
                            ]);
Línea 2874... Línea 2841...
2874
                        } else {
2841
                        } else {
2875
                            $ok = false;
2842
                            $ok = false;
2876
                        }
2843
                        }
Línea 2877... Línea 2844...
2877
 
2844
 
2878
                        if(isset($record['pass'])) {
2845
                        if(isset($record['pass'])) {
2879
                            $status = $record['pass'] == 'yes' ? CompanyMicrolearningUserQuiz::STATUS_PASS : CompanyMicrolearningUserQuiz::STATUS_FAIL;
2846
                            $status = $record['pass'] == 'yes' ? MicrolearningUserQuiz::STATUS_PASS : MicrolearningUserQuiz::STATUS_FAIL;
2880
                        } else {
2847
                        } else {
2881
                            $ok = false;
2848
                            $ok = false;
Línea 2882... Línea 2849...
2882
                        }
2849
                        }
Línea 2942... Línea 2909...
2942
                                'value' => $value,
2909
                                'value' => $value,
2943
                                'points' => $points
2910
                                'points' => $points
2944
                            ]);
2911
                            ]);
2945
                        }
2912
                        }
Línea 2946... Línea 2913...
2946
                        
2913
                        
2947
                        $userQuiz = new CompanyMicrolearningUserQuiz();
2914
                        $userQuiz = new MicrolearningUserQuiz();
2948
                        $userQuiz->company_id = $company->id;
2915
                        $userQuiz->company_id = $company->id;
2949
                        $userQuiz->topic_id = $topic->id;
2916
                        $userQuiz->topic_id = $topic->id;
2950
                        $userQuiz->capsule_id = $capsule->id;
2917
                        $userQuiz->capsule_id = $capsule->id;
2951
                        $userQuiz->slide_id = $slide->id;
2918
                        $userQuiz->slide_id = $slide->id;
Línea 2954... Línea 2921...
2954
                        $userQuiz->added_on = $added_on;
2921
                        $userQuiz->added_on = $added_on;
2955
                        $userQuiz->points = $points;
2922
                        $userQuiz->points = $points;
2956
                        $userQuiz->status = $status;
2923
                        $userQuiz->status = $status;
2957
                        $userQuiz->response = json_encode($array_response);
2924
                        $userQuiz->response = json_encode($array_response);
Línea 2958... Línea 2925...
2958
                        
2925
                        
Línea 2959... Línea 2926...
2959
                        $userQuizMapper = CompanyMicrolearningUserQuizMapper::getInstance($this->adapter);
2926
                        $userQuizMapper = MicrolearningUserQuizMapper::getInstance($this->adapter);
2960
                        
2927
                        
2961
                        if($userQuizMapper->insert($userQuiz)) {
2928
                        if($userQuizMapper->insert($userQuiz)) {
2962
                            array_push($result_sync_ids, [
2929
                            array_push($result_sync_ids, [
Línea 2977... Línea 2944...
2977
                        $ok = true;
2944
                        $ok = true;
Línea 2978... Línea 2945...
2978
                        
2945
                        
2979
                        $type = isset($record['type']) ? $record['type'] : '';
2946
                        $type = isset($record['type']) ? $record['type'] : '';
2980
                        switch($type)
2947
                        switch($type)
2981
                        {
2948
                        {
2982
                            case CompanyMicrolearningUserProgress::TYPE_TOPIC :
2949
                            case MicrolearningUserProgress::TYPE_TOPIC :
2983
                                if(!$topic) {
2950
                                if(!$topic) {
2984
                                    $ok = false;
2951
                                    $ok = false;
2985
                                }
2952
                                }
Línea 2986... Línea 2953...
2986
                                break;
2953
                                break;
2987
                                
2954
                                
2988
                            case CompanyMicrolearningUserProgress::TYPE_CAPSULE :
2955
                            case MicrolearningUserProgress::TYPE_CAPSULE :
2989
                                if(!$topic || !$capsule) {
2956
                                if(!$topic || !$capsule) {
2990
                                    $ok = false;
2957
                                    $ok = false;
Línea 2991... Línea 2958...
2991
                                }
2958
                                }
2992
                                break;
2959
                                break;
2993
                                
2960
                                
2994
                            case CompanyMicrolearningUserProgress::TYPE_SLIDE :
2961
                            case MicrolearningUserProgress::TYPE_SLIDE :
2995
                                if(!$topic || !$capsule || !$slide) {
2962
                                if(!$topic || !$capsule || !$slide) {
Línea 3036... Línea 3003...
3036
                        $completed                  = isset($record['completed'])                 ? intval($record['completed'], 10) :  0;
3003
                        $completed                  = isset($record['completed'])                 ? intval($record['completed'], 10) :  0;
Línea 3037... Línea 3004...
3037
                        
3004
                        
3038
  
3005
  
3039
                        $recordProgress = null;
3006
                        $recordProgress = null;
3040
                        switch($type) {
3007
                        switch($type) {
Línea 3041... Línea 3008...
3041
                            case CompanyMicrolearningUserProgress::TYPE_TOPIC  :
3008
                            case MicrolearningUserProgress::TYPE_TOPIC  :
Línea 3042... Línea 3009...
3042
                                $recordProgress = $userProgressMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);
3009
                                $recordProgress = $userProgressMapper->fetchOneByUserIdAndTopicId($user->id, $topic->id);
3043
                                
3010
                                
3044
                                break;
3011
                                break;
Línea 3045... Línea 3012...
3045
                                
3012
                                
3046
                            case CompanyMicrolearningUserProgress::TYPE_CAPSULE  :
3013
                            case MicrolearningUserProgress::TYPE_CAPSULE  :
3047
                                $recordProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($user->id, $capsule->id);
3014
                                $recordProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($user->id, $capsule->id);
Línea 3048... Línea 3015...
3048
                                break;
3015
                                break;
3049
                                
3016
                                
3050
                            case CompanyMicrolearningUserProgress::TYPE_SLIDE  :
3017
                            case MicrolearningUserProgress::TYPE_SLIDE  :
Línea 3051... Línea 3018...
3051
                                $recordProgress = $userProgressMapper->fetchOneByUserIdAndSlideId($user->id, $slide->id);
3018
                                $recordProgress = $userProgressMapper->fetchOneByUserIdAndSlideId($user->id, $slide->id);
3052
                                break;
3019
                                break;
Línea 3053... Línea 3020...
3053
                                
3020
                                
3054
                            default :
3021
                            default :
3055
                                $recordProgress= null;
3022
                                $recordProgress= null;
3056
                        }
3023
                        }
Línea 3083... Línea 3050...
3083
                        }*/
3050
                        }*/
3084
                        $recordProgress->returning                  = $returning;
3051
                        $recordProgress->returning                  = $returning;
3085
                        $recordProgress->returning_after_completed  = $returning_after_completed;
3052
                        $recordProgress->returning_after_completed  = $returning_after_completed;
3086
                        $recordProgress->completed                  = $completed;
3053
                        $recordProgress->completed                  = $completed;
Línea 3087... Línea 3054...
3087
                        
3054
                        
Línea 3088... Línea 3055...
3088
                        if($type == CompanyMicrolearningUserProgress::TYPE_TOPIC ) {
3055
                        if($type == MicrolearningUserProgress::TYPE_TOPIC ) {
3089
                            
3056
                            
3090
                            $capsule_ids = [];
3057
                            $capsule_ids = [];
3091
                            $companyMicrolearningCapsuleUser = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
3058
                            $microlearningCapsuleUser = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
3092
                            $records =  $companyMicrolearningCapsuleUser->fetchAllActiveByUserId($user->id);
3059
                            $records =  $microlearningCapsuleUser->fetchAllActiveByUserId($user->id);
3093
                            foreach($records as $record)
3060
                            foreach($records as $record)
3094
                            {
3061
                            {
3095
                                if($now >= $record->paid_from || $now <= $capsuleUser->paid_to) {
3062
                                if($now >= $record->paid_from || $now <= $capsuleUser->paid_to) {
Línea 3101... Línea 3068...
3101
          
3068
          
3102
                            $recordProgress->progress       = $progress;
3069
                            $recordProgress->progress       = $progress;
3103
                            $recordProgress->total_slides   = $total_slides;
3070
                            $recordProgress->total_slides   = $total_slides;
3104
                            $recordProgress->view_slides    = $view_slides;
3071
                            $recordProgress->view_slides    = $view_slides;
3105
                        }
3072
                        }
Línea 3106... Línea 3073...
3106
                        else if($type == CompanyMicrolearningUserProgress::TYPE_CAPSULE ) {
3073
                        else if($type == MicrolearningUserProgress::TYPE_CAPSULE ) {
3107
 
3074
 
3108
                            $recordProgress->progress       = $progress;
3075
                            $recordProgress->progress       = $progress;
3109
                            $recordProgress->total_slides   = $total_slides;
3076
                            $recordProgress->total_slides   = $total_slides;
Línea 3177... Línea 3144...
3177
                        }
3144
                        }
Línea 3178... Línea 3145...
3178
            
3145
            
Línea 3179... Línea 3146...
3179
            
3146
            
3180
                        if($insert) {
3147
                        if($insert) {
3181
                        
3148
                        
3182
                            $userLog = new CompanyMicrolearningUserLog();
3149
                            $userLog = new MicrolearningUserLog();
3183
                            $userLog->activity      = $activity;
3150
                            $userLog->activity      = $activity;
3184
                            $userLog->user_id       = $user->id;
3151
                            $userLog->user_id       = $user->id;
Línea 3287... Línea 3254...
3287
                        $insert = true;
3254
                        $insert = true;
3288
                    }
3255
                    }
Línea 3289... Línea 3256...
3289
                    
3256
                    
3290
                    
3257
                    
3291
                    if($insert) {
3258
                    if($insert) {
3292
                        $userLog = new CompanyMicrolearningUserLog();
3259
                        $userLog = new MicrolearningUserLog();
3293
                        $userLog->company_id = null;
3260
                        $userLog->company_id = null;
3294
                        $userLog->user_id = $user->id;
3261
                        $userLog->user_id = $user->id;
Línea 3295... Línea 3262...
3295
                        $userLog->activity = $activity;
3262
                        $userLog->activity = $activity;
3296
                        $userLog->added_on = $added_on;
3263
                        $userLog->added_on = $added_on;
3297
                        
3264
                        
3298
                        
3265
                        
3299
                        $userLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
3266
                        $userLogMapper = MicrolearningUserLogMapper::getInstance($this->adapter);
3300
                        if($userLogMapper->insert($userLog)) {
3267
                        if($userLogMapper->insert($userLog)) {
Línea 3541... Línea 3508...
3541
        
3508
        
3542
        $companies = [];
3509
        $companies = [];
Línea 3543... Línea 3510...
3543
        $companyMapper = CompanyMapper::getInstance($this->adapter);
3510
        $companyMapper = CompanyMapper::getInstance($this->adapter);
3544
        
3511
        
Línea 3545... Línea 3512...
3545
        $topics = [];
3512
        $topics = [];
3546
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
3513
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
Línea 3547... Línea 3514...
3547
        
3514
        
3548
        $capsules = [];
3515
        $capsules = [];
Línea 3549... Línea 3516...
3549
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
3516
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
3550
        
3517
        
Línea 3551... Línea 3518...
3551
        $slides = [];
3518
        $slides = [];
3552
        $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
3519
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
Línea 3553... Línea 3520...
3553
        
3520
        
3554
        $quizzes = [];
3521
        $quizzes = [];
Línea 3555... Línea 3522...
3555
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
3522
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
Línea 3556... Línea 3523...
3556
 
3523
 
Línea 3557... Línea 3524...
3557
        $questions = [];
3524
        $questions = [];
3558
        $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
3525
        $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
Línea 3636... Línea 3603...
3636
            }
3603
            }
3637
        }
3604
        }
Línea 3638... Línea 3605...
3638
        
3605
        
Línea 3639... Línea 3606...
3639
        if($includeProgress) {
3606
        if($includeProgress) {
3640
        
3607
        
3641
            $userProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
3608
            $userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
3642
            $records = $userProgressMapper->fetchAllByUserId($user->id);
3609
            $records = $userProgressMapper->fetchAllByUserId($user->id);
3643
            foreach($records as $record)
3610
            foreach($records as $record)
Línea 3722... Línea 3689...
3722
        $capsules_with_access   = [];
3689
        $capsules_with_access   = [];
3723
        $quizzes_with_access    = [];
3690
        $quizzes_with_access    = [];
3724
        $quizzes                = [];
3691
        $quizzes                = [];
Línea 3725... Línea 3692...
3725
        
3692
        
3726
        
3693
        
3727
        $capsuleCommentMapper = CompanyMicrolearningCapsuleCommentMapper::getInstance($this->adapter);
3694
        $capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter);
Línea 3728... Línea 3695...
3728
        $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
3695
        $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
3729
        $records = $capsuleUserMapper->fetchAllActiveByUserId($user->id);
3696
        $records = $capsuleUserMapper->fetchAllActiveByUserId($user->id);
3730
        
3697
        
3731
 
3698
 
3732
        foreach($records as $record) 
3699
        foreach($records as $record) 
3733
        {
3700
        {
3734
            if($record->access != CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED && $record->access != CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
3701
            if($record->access != MicrolearningCapsuleUser::ACCESS_UNLIMITED && $record->access != MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
3735
                continue;
3702
                continue;
3736
            }
3703
            }
3737
            if($record->access == CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
3704
            if($record->access == MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
Línea 3752... Línea 3719...
3752
            if(!in_array($record->capsule_id,$capsules_with_access)) {
3719
            if(!in_array($record->capsule_id,$capsules_with_access)) {
3753
                array_push($capsules_with_access, $record->capsule_id);
3720
                array_push($capsules_with_access, $record->capsule_id);
3754
            }
3721
            }
3755
        }
3722
        }
Línea 3756... Línea -...
3756
       
-
 
3757
 /*
-
 
3758
        echo '$companies_with_access ' . PHP_EOL;
-
 
3759
        print_r($companies_with_access);
3723
       
3760
        
-
 
3761
        echo '$topics_with_access ' . PHP_EOL;
-
 
3762
        print_r($topics_with_access);
-
 
3763
        
-
 
3764
        echo '$capsules_with_access' . PHP_EOL;
-
 
3765
        print_r($capsules_with_access);
-
 
Línea 3766... Línea 3724...
3766
        */
3724
 
3767
        
3725
        
3768
        $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
3726
        $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
3769
        foreach($companies_with_access as $company_id)
3727
        foreach($companies_with_access as $company_id)
Línea 3770... Línea -...
3770
        {
-
 
3771
            $companyService =  $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company_id, Service::MICRO_LEARNING);
3728
        {
3772
            
3729
            $companyService =  $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company_id, Service::MICRO_LEARNING);
3773
            //print_r($companyService); exit;
3730
            
3774
            
3731
 
Línea 3802... Línea 3759...
3802
                    
3759
                    
3803
                    $record_slides = [];
3760
                    $record_slides = [];
3804
                    $slides = $slideMapper->fetchAllByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $capsule->topic_id, $capsule->id);
3761
                    $slides = $slideMapper->fetchAllByCompanyIdAndTopicIdAndCapsuleId($capsule->company_id, $capsule->topic_id, $capsule->id);
3805
                    foreach($slides as $slide)
3762
                    foreach($slides as $slide)
3806
                    {
3763
                    {
3807
                        if($slide->type == CompanyMicrolearningSlide::TYPE_QUIZ) {
3764
                        if($slide->type == MicrolearningSlide::TYPE_QUIZ) {
3808
                            if(!in_array($slide->quiz_id, $quizzes_with_access)) {
3765
                            if(!in_array($slide->quiz_id, $quizzes_with_access)) {
3809
                                array_push($quizzes_with_access, $slide->quiz_id);
3766
                                array_push($quizzes_with_access, $slide->quiz_id);
Línea 3810... Línea 3767...
3810
                            }
3767
                            }
Línea 3961... Línea 3918...
3961
                'added_on'      => $dtAddedOn->format($serviceDatetimeFormat),
3918
                'added_on'      => $dtAddedOn->format($serviceDatetimeFormat),
3962
                'updated_on'    => $dtUpdatedOn->format($serviceDatetimeFormat),
3919
                'updated_on'    => $dtUpdatedOn->format($serviceDatetimeFormat),
3963
            ]);
3920
            ]);
3964
        }
3921
        }
Línea 3965... Línea 3922...
3965
        
3922
        
3966
        $companyExtendUserMapper = CompanyMicrolearningExtendUserMapper::getInstance($this->adapter);
3923
        $companyExtendUserMapper = MicrolearningExtendUserMapper::getInstance($this->adapter);
3967
        $companyExtendUserCompanyMapper = CompanyMicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
3924
        $companyExtendUserCompanyMapper = MicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
3968
        $companyExtendUserFunctionMapper = CompanyMicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
3925
        $companyExtendUserFunctionMapper = MicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
3969
        $companyExtendUserGroupMapper = CompanyMicrolearningExtendUserGroupMapper::getInstance($this->adapter);
3926
        $companyExtendUserGroupMapper = MicrolearningExtendUserGroupMapper::getInstance($this->adapter);
3970
        $companyExtendUserInstitutionMapper = CompanyMicrolearningExtendUserInstitutionMapper::getInstance($this->adapter);
3927
        $companyExtendUserInstitutionMapper = MicrolearningExtendUserInstitutionMapper::getInstance($this->adapter);
3971
        $companyExtendUserPartnerMapper = CompanyMicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
3928
        $companyExtendUserPartnerMapper = MicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
3972
        $companyExtendUserProgramMapper = CompanyMicrolearningExtendUserProgramMapper::getInstance($this->adapter);
3929
        $companyExtendUserProgramMapper = MicrolearningExtendUserProgramMapper::getInstance($this->adapter);
3973
        $companyExtendUserStudentTypeMapper = CompanyMicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
3930
        $companyExtendUserStudentTypeMapper = MicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
Línea 3974... Línea 3931...
3974
        $companyExtendUserSectorMapper = CompanyMicrolearningExtendUserSectorMapper::getInstance($this->adapter);
3931
        $companyExtendUserSectorMapper = MicrolearningExtendUserSectorMapper::getInstance($this->adapter);
3975
 
3932
 
3976
        $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
3933
        $companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
3977
        foreach($companies_with_access as $company_id)
3934
        foreach($companies_with_access as $company_id)
3978
        {
3935
        {
3979
            $companyService =  $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company_id, Service::MICRO_LEARNING);
-
 
3980
            
-
 
3981
            //print_r($companyService); exit;
3936
            $companyService =  $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company_id, Service::MICRO_LEARNING);
3982
            
3937
 
3983
            if(!$companyService) {
3938
            if(!$companyService) {
Línea 3984... Línea -...
3984
                continue;
-
 
3985
            }
3939
                continue;
3986
            
3940
            }
3987
            
3941
            
3988
            if(isset($companies[$companyService->company_id])) {
3942
            if(isset($companies[$companyService->company_id])) {
3989
                $company = $companies[$companyService->company_id];
3943
                $company = $companies[$companyService->company_id];