Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16769 Rev 16983
Línea 740... Línea 740...
740
                            'data' => 'ERROR_UPLOAD_FILE'
740
                            'data' => 'ERROR_UPLOAD_FILE'
741
                        ]);
741
                        ]);
742
                    }
742
                    }
Línea 743... Línea -...
743
                    
-
 
-
 
743
                    
744
                   
744
                   
-
 
745
                    $count_users = 0;
-
 
746
                    $users = [];
Línea 745... Línea 747...
745
                    
747
                    $count_errors = 0;
746
                    $users = [];
748
                    $errors = [];
Línea 747... Línea 749...
747
                    
749
                    
-
 
750
                    
Línea 748... Línea 751...
748
                    
751
                    $spreadsheet = IOFactory::load($final_filename);
749
                    $spreadsheet = IOFactory::load($final_filename);
752
                    $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
750
                    $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
753
                    
751
                    
754
                    $emails = [];
Línea 767... Línea 770...
767
                        K = Sector	
770
                        K = Sector	
768
                        L = Tipo de Estudiante	
771
                        L = Tipo de Estudiante	
769
                        M = País	
772
                        M = País	
770
                        N = Es adulto
773
                        N = Es adulto
771
                        */
774
                        */
-
 
775
                        $row++;
Línea 772... Línea 776...
772
                        
776
                        
773
                        
777
                        
774
                        $first_name = Functions::sanitizeFilterString($record['A']);
778
                        $first_name = Functions::sanitizeFilterString($record['A']);
Línea 786... Línea 790...
786
                        $studentType = isset($record['L']) ? Functions::sanitizeFilterString($record['L']) : '';
790
                        $studentType = isset($record['L']) ? Functions::sanitizeFilterString($record['L']) : '';
787
                        $country =  isset($record['M']) ? Functions::sanitizeFilterString($record['M']) : '';
791
                        $country =  isset($record['M']) ? Functions::sanitizeFilterString($record['M']) : '';
788
                        $isAdult = isset($record['N']) ? Functions::sanitizeFilterString($record['N']) : '';
792
                        $isAdult = isset($record['N']) ? Functions::sanitizeFilterString($record['N']) : '';
Línea -... Línea 793...
-
 
793
 
-
 
794
                        
-
 
795
                        if($row == 1) {
Línea 789... Línea 796...
789
 
796
                            continue;
790
                        
797
                        }
-
 
798
                        
-
 
799
                        //||  empty($password)
-
 
800
                        if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
791
                        
801
                           
-
 
802
                            
792
                        //||  empty($password)
803
                            
Línea 793... Línea 804...
793
                        if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
804
                            continue;
Línea 794... Línea 805...
794
                            continue;
805
                            
Línea 801... Línea 812...
801
                                $assigned_capsules =  $capsuleUserMapper->fetchCountByCompanyIdAndTopicIdAndUserId($topic->company_id, $topic->id, $user->id);
812
                                $assigned_capsules =  $capsuleUserMapper->fetchCountByCompanyIdAndTopicIdAndUserId($topic->company_id, $topic->id, $user->id);
802
                            } else {
813
                            } else {
803
                                $assigned_capsules = 0;
814
                                $assigned_capsules = 0;
804
                            }
815
                            }
Línea -... Línea 816...
-
 
816
                            
-
 
817
                            $count_users++;
805
                            
818
                            
806
                            array_push($emails, $email);
819
                            array_push($emails, $email);
-
 
820
                            array_push($users, [
807
                            array_push($users, [
821
                                'id' => $count_users,
808
                                'first_name' => $first_name,
822
                                'first_name' => $first_name,
809
                                'last_name' => $last_name,
823
                                'last_name' => $last_name,
810
                                'password'  => $password,
824
                                'password'  => $password,
811
                                'email' => $email,
825
                                'email' => $email,
Línea 819... Línea 833...
819
                                'sector' => $sector, 
833
                                'sector' => $sector, 
820
                                'studentType' => $studentType,
834
                                'studentType' => $studentType,
821
                                'country' => $country,
835
                                'country' => $country,
822
                                'isAdult' => $isAdult,
836
                                'isAdult' => $isAdult,
823
                            ]);
837
                            ]);
-
 
838
                        } else {
-
 
839
                            $count_errors++;
-
 
840
                            array_push($errors,[
-
 
841
                                'id' => $count_errors,
-
 
842
                                'first_name' => $first_name,
-
 
843
                                'last_name' => $last_name,
-
 
844
                                'password'  => $password,
-
 
845
                                'email' => $email,
-
 
846
                                'status' => 'DUPLICATE IN EXCEL'
-
 
847
                            ]);
824
                        }
848
                        }
Línea 837... Línea 861...
837
                        'success' => true,
861
                        'success' => true,
838
                        'data' => [
862
                        'data' => [
839
                            'key' => $key,
863
                            'key' => $key,
840
                            'topic' => $topic->name,
864
                            'topic' => $topic->name,
841
                            'capsule' => $capsule->name,
865
                            'capsule' => $capsule->name,
-
 
866
                            'items' => [
842
                            'items' => $users,
867
                                'ok' => $users,
-
 
868
                                'error' => $errors,
-
 
869
                            ],     
843
                        ]
870
                        ]
844
                    ]);
871
                    ]);
Línea 884... Línea 911...
884
                        'success' => false,
911
                        'success' => false,
885
                        'data' => 'ERROR_CACHE_INVALID'
912
                        'data' => 'ERROR_CACHE_INVALID'
886
                    ]);
913
                    ]);
887
                }
914
                }
Línea -... Línea 915...
-
 
915
                
-
 
916
            
Línea 888... Línea 917...
888
                
917
                
889
                
918
                
890
                $networkMapper = NetworkMapper::getInstance($this->adapter);
919
                $networkMapper = NetworkMapper::getInstance($this->adapter);
Línea 918... Línea 947...
918
                
947
                
919
                
948
                
Línea -... Línea 949...
-
 
949
                $companyForFollower = $companyMapper->fetchOneDefaultForFollowers();
-
 
950
                //print_r($companyForFollower);
Línea 920... Línea 951...
920
                $companyForFollower = $companyMapper->fetchOneDefaultForFollowers();
951
                
921
                //print_r($companyForFollower);
952
                $csv = "FIRST NAME|LAST NAME|EMAIL|STATUS\r\n";
922
                
953
                
923
           
954
           
Línea 969... Línea 1000...
969
                            if($result) {
1000
                            if($result) {
970
                                $userPassword = new UserPassword();
1001
                                $userPassword = new UserPassword();
971
                                $userPassword->user_id = $user->id;
1002
                                $userPassword->user_id = $user->id;
972
                                $userPassword->password = $password_hash;
1003
                                $userPassword->password = $password_hash;
973
                                $userPasswordMapper->insert($userPassword);
1004
                                $userPasswordMapper->insert($userPassword);
-
 
1005
                                
-
 
1006
                                
-
 
1007
                                $csv .= "$first_name|$last_name|$email|CREATE USER \r\n";
974
                            } else {
1008
                            } else {
-
 
1009
                                $csv .= "$first_name|$last_name|$email|FAIL CREATE USER \r\n";
-
 
1010
                                
975
                                continue;
1011
                                continue;
976
                            } 
1012
                            } 
Línea 977... Línea 1013...
977
                            
1013
                            
978
                        }
1014
                        }
Línea 983... Línea 1019...
983
                            $user->status != User::STATUS_ACTIVE;
1019
                            $user->status != User::STATUS_ACTIVE;
Línea 984... Línea 1020...
984
                            
1020
                            
985
                            
1021
                            
-
 
1022
                        }
986
                        }
1023
                        if(!$userMapper->update($user)) {
987
                        if(!$userMapper->update($user)) {
1024
                            $csv .= "$first_name|$last_name|$email|FAIL UPDATE USER \r\n";
Línea 988... Línea 1025...
988
                            continue;
1025
                            continue;
Línea 1010... Línea 1047...
1010
                                if($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
1047
                                if($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
1011
                                    $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
1048
                                    $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
1012
                                    $userInDefaultNetwork->status != User::STATUS_ACTIVE;
1049
                                    $userInDefaultNetwork->status != User::STATUS_ACTIVE;
Línea 1013... Línea 1050...
1013
                                    
1050
                                    
-
 
1051
                                    if(!$userMapper->update($userInDefaultNetwork)) {
1014
                                    if(!$userMapper->update($userInDefaultNetwork)) {
1052
                                        $csv .= "$first_name|$last_name|$email|FAIL UPDATE USER IN DEFAULT NETWORK \r\n";
1015
                                        continue;
1053
                                        continue;
1016
                                    }
1054
                                    }
Línea 1037... Línea 1075...
1037
                                    
1075
                                    
1038
                                    $userPassword = new UserPassword();
1076
                                    $userPassword = new UserPassword();
1039
                                    $userPassword->user_id = $userInDefaultNetwork->id;
1077
                                    $userPassword->user_id = $userInDefaultNetwork->id;
1040
                                    $userPassword->password = $password_hash;
1078
                                    $userPassword->password = $password_hash;
-
 
1079
                                    $userPasswordMapper->insert($userPassword);
-
 
1080
                                    
-
 
1081
                                    $csv .= "$first_name|$last_name|$email|CREATE USER IN DEFAULT NETWORK \r\n";
-
 
1082
                                } else {
1041
                                    $userPasswordMapper->insert($userPassword);
1083
                                    $csv .= "$first_name|$last_name|$email|FAIL CREATE USER IN DEFAULT NETWORK \r\n";
Línea 1042... Línea 1084...
1042
                                }
1084
                                }
Línea 1266... Línea 1308...
1266
                
1308
                
1267
                $users_processed = 0;
1309
                $users_processed = 0;
1268
                $users_previous = 0;
1310
                $users_previous = 0;
1269
                foreach($user_ids as $user_id)
1311
                foreach($user_ids as $user_id)
-
 
1312
                {
-
 
1313
                    $user = $userMapper->fetchOne($user_id);
-
 
1314
                    $first_name = $user->first_name;
-
 
1315
                    $last_name = $user->last_name;
-
 
1316
                    $email = $user->email;
Línea 1270... Línea 1317...
1270
                {
1317
                    
1271
                    
1318
                    
1272
                    $users_processed++;
1319
                    $users_processed++;
1273
                    $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($user_id, $capsule->id);
1320
                    $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($user_id, $capsule->id);
-
 
1321
                    if($capsuleUser) {
1274
                    if($capsuleUser) {
1322
                        $users_previous++;
1275
                        $users_previous++;
1323
                        $csv .= "$first_name|$last_name|$email|PREVIOUS FOUND \r\n";
1276
                    } else {
1324
                    } else {
1277
                        $capsuleUser = new CompanyMicrolearningCapsuleUser();
1325
                        $capsuleUser = new CompanyMicrolearningCapsuleUser();
1278
                        $capsuleUser->company_id = $capsule->company_id;
1326
                        $capsuleUser->company_id = $capsule->company_id;
1279
                        $capsuleUser->topic_id = $capsule->topic_id;
1327
                        $capsuleUser->topic_id = $capsule->topic_id;
1280
                        $capsuleUser->capsule_id = $capsule->id;
1328
                        $capsuleUser->capsule_id = $capsule->id;
Línea 1281... Línea 1329...
1281
                        $capsuleUser->user_id = $user_id;
1329
                        $capsuleUser->user_id = $user_id;
-
 
1330
                        $capsuleUser->access = CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED;
1282
                        $capsuleUser->access = CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED;
1331
                        
Línea 1283... Línea 1332...
1283
                        
1332
                        if($capsuleUserMapper->insert($capsuleUser)) {
1284
                        if($capsuleUserMapper->insert($capsuleUser)) {
1333
                            $csv .= "$first_name|$last_name|$email|CAPSULE USER ASSIGNED\r\n";
Línea 1302... Línea 1351...
1302
                                    $companyMicrolearningUser->updated_on = $capsuleUser->updated_on;
1351
                                    $companyMicrolearningUser->updated_on = $capsuleUser->updated_on;
Línea 1303... Línea 1352...
1303
                                    
1352
                                    
1304
                                    $companyMicrolearningUserMapper->insert($companyMicrolearningUser);
1353
                                    $companyMicrolearningUserMapper->insert($companyMicrolearningUser);
1305
                                } 
1354
                                } 
-
 
1355
                            }
-
 
1356
                        } else {
1306
                            }
1357
                            $csv .= "$first_name|$last_name|$email|CAPSULE USER PREVIOUS \r\n";
Línea 1307... Línea 1358...
1307
                        }
1358
                        }
Línea 1318... Línea 1369...
1318
                    'success' => true, 
1369
                    'success' => true, 
1319
                    'data' => [
1370
                    'data' => [
1320
                        'users_assigned' => $users_assigned, 
1371
                        'users_assigned' => $users_assigned, 
1321
                        'users_processed' => $users_processed,
1372
                        'users_processed' => $users_processed,
1322
                        'users_in_the_capsule' => $users_in_the_capsule,
1373
                        'users_in_the_capsule' => $users_in_the_capsule,
1323
                        'users_previous' => $users_previous
1374
                        'users_previous' => $users_previous,
-
 
1375
                        'csv_base64_content' => base64_encode($csv),
-
 
1376
                        'csv_filename' => 'capsule-users-' .date('Y-m-d-h-i-s').  '.csv'
1324
                    ]
1377
                    ]
1325
                ]); 
1378
                ]);