Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17269 Rev 17270
Línea 889... Línea 889...
889
                } catch (\Exception $e) {
889
                } catch (\Exception $e) {
890
                    $this->logger->err('Validation step failed: ' . $e->getMessage());
890
                    $this->logger->err('Validation step failed: ' . $e->getMessage());
891
                    throw $e;
891
                    throw $e;
892
                }
892
                }
893
            }
893
            }
-
 
894
 
-
 
895
            if($step == 'process') {
-
 
896
                // get the key from the post
-
 
897
                $key = Functions::sanitizeFilterString($this->params()->fromPost('key')); 
-
 
898
                if(!$key) {
-
 
899
                    return new JsonModel([
-
 
900
                        'success' => false,
-
 
901
                        'data' => 'ERROR_CACHE_KEY_EMPTY'
-
 
902
                    ]); 
-
 
903
                }
-
 
904
                // get the value from the cache
-
 
905
                $value = $this->cache->getItem($key);
-
 
906
                $this->logger->info('Value: ' . print_r($value, true));
-
 
907
                // if the value is not found, return an error
-
 
908
                if(!$value) {
-
 
909
                    return new JsonModel([
-
 
910
                        'success' => false,
-
 
911
                        'data' => 'ERROR_CACHE_NOT_FOUND'
-
 
912
                    ]); 
-
 
913
                }
-
 
914
                
-
 
915
                // unserialize the value
-
 
916
                $records = unserialize($value);
-
 
917
                $this->logger->info('Records: ' . print_r($records, true));
-
 
918
                // if the value is not found, return an error
-
 
919
                if(!$records) {
-
 
920
                    return new JsonModel([
-
 
921
                        'success' => false,
-
 
922
                        'data' => 'ERROR_CACHE_INVALID'
-
 
923
                    ]);
-
 
924
                }
-
 
925
    
-
 
926
                // get the network, company, company follower
-
 
927
                $networkMapper = NetworkMapper::getInstance($this->adapter);
-
 
928
                $companyMapper = CompanyMapper::getInstance($this->adapter);
-
 
929
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
-
 
930
                
-
 
931
                // get the connection, user, user password, topic user
-
 
932
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
933
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
934
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
-
 
935
                $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
-
 
936
                
-
 
937
                // get the microlearning extend user, microlearning extend user company, microlearning extend user function, microlearning extend user group, microlearning extend user institution, microlearning extend user program, microlearning extend user partner, microlearning extend user sector, microlearning extend user student type, microlearning extend user country
-
 
938
                $microlearningExtendUserMapper = MicrolearningExtendUserMapper::getInstance($this->adapter);
-
 
939
                $microlearningExtendUserCompanyMapper = MicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
-
 
940
                $microlearningExtendUserFunctionMapper = MicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
-
 
941
                $microlearningExtendUserGroupMapper = MicrolearningExtendUserGroupMapper::getInstance($this->adapter);
-
 
942
                $microlearningExtendUserInstitutionMapper = MicrolearningExtendUserInstitutionMapper::getInstance($this->adapter);
-
 
943
                $microlearningExtendUserProgramMapper = MicrolearningExtendUserProgramMapper::getInstance($this->adapter);
-
 
944
                $microlearningExtendUserPartnerMapper = MicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
-
 
945
                $microlearningExtendUserSectorMapper = MicrolearningExtendUserSectorMapper::getInstance($this->adapter);
-
 
946
                $microlearningExtendUserStudentTypeMapper = MicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
-
 
947
                $microlearningExtendUserCountryMapper = MicrolearningExtendUserCountryMapper::getInstance($this->adapter);
-
 
948
    
-
 
949
                // get the network default, user default for connection, company for follower
-
 
950
                $networkDefault = $networkMapper->fetchOneByDefault();
-
 
951
                $userDefaultForConnection = $userMapper->fetchOneDefaultForConnection();
-
 
952
                
-
 
953
                $companyForFollower = $companyMapper->fetchOneDefaultForFollowers();
-
 
954
                
-
 
955
                // create the csv
-
 
956
                $csv = "FIRST NAME|LAST NAME|EMAIL|STATUS\r\n";
-
 
957
                
-
 
958
                // get the users processed, users assigned, user ids
-
 
959
                $users_processed = 0;
-
 
960
                $users_assigned = 0;
-
 
961
                $user_ids = [];
-
 
962
                foreach($records as $record)
-
 
963
                {
-
 
964
                    $first_name = $record['first_name'];
-
 
965
                    $last_name = $record['last_name'];
-
 
966
                    $password = $record['password'];
-
 
967
                    $email = $record['email'];
-
 
968
                    $company = $record['company'];
-
 
969
                    $function = $record['function'];
-
 
970
                    $group = $record['group'];
-
 
971
                    $institution = $record['institution'];
-
 
972
                    $program = $record['program'];
-
 
973
                    $partner = $record['partner'];
-
 
974
                    $sector = $record['sector'];
-
 
975
                    $studentType = $record['studentType'];
-
 
976
                    $country = $record['country'];
-
 
977
                    $isAdult = strtolower(trim( $record['isAdult'])) == User::IS_ADULT_YES;
-
 
978
    
-
 
979
                    $user = $userMapper->fetchOneByEmail($email);
-
 
980
    
-
 
981
                    // if the user is not found, create the user
-
 
982
                    if(!$user) {    
-
 
983
                        // if the password is not empty, create the user
-
 
984
                        if($password) {
-
 
985
                            $password_hash = password_hash($password, PASSWORD_DEFAULT);
-
 
986
                            
-
 
987
                            $user = new User();
-
 
988
                            
-
 
989
                            $user->network_id = $currentNetwork->id;
-
 
990
                            $user->blocked = User::BLOCKED_NO;
-
 
991
                            $user->email_verified = User::EMAIL_VERIFIED_YES;
-
 
992
                            $user->email = $email;
-
 
993
                            $user->first_name = $first_name;
-
 
994
                            $user->last_name = $last_name;
-
 
995
                            $user->password = $password_hash;
-
 
996
                            $user->login_attempt = 0;
-
 
997
                            $user->usertype_id = UserType::USER;
-
 
998
                            $user->status = User::STATUS_ACTIVE;
-
 
999
                            $user->is_adult = $isAdult ? User::IS_ADULT_YES : User::IS_ADULT_NO;
-
 
1000
                            
-
 
1001
                            $result = $userMapper->insert($user);
-
 
1002
                            if($result) {
-
 
1003
                                $userPassword = new UserPassword();
-
 
1004
                                $userPassword->user_id = $user->id;
-
 
1005
                                $userPassword->password = $password_hash;
-
 
1006
                                $userPasswordMapper->insert($userPassword);
-
 
1007
                                
-
 
1008
                                
-
 
1009
                                $csv .= "$first_name|$last_name|$email|CREATE USER \r\n";
-
 
1010
                            } else {
-
 
1011
                                $csv .= "$first_name|$last_name|$email|FAIL CREATE USER \r\n";
-
 
1012
                                
-
 
1013
                                continue;
-
 
1014
                            } 
-
 
1015
                            
-
 
1016
                        }
-
 
1017
                    } else {
-
 
1018
                        $user->is_adult = $isAdult ? User::IS_ADULT_YES : User::IS_ADULT_NO;
-
 
1019
                        if($user->email_verified == User::EMAIL_VERIFIED_NO || $user->status != User::STATUS_ACTIVE) {
-
 
1020
                            $user->email_verified = User::EMAIL_VERIFIED_YES;
-
 
1021
                            $user->status != User::STATUS_ACTIVE;
-
 
1022
                            
-
 
1023
                            
-
 
1024
                        }
-
 
1025
                        if(!$userMapper->update($user)) {
-
 
1026
                            $csv .= "$first_name|$last_name|$email|FAIL UPDATE USER \r\n";
-
 
1027
                            continue;
-
 
1028
                        }
-
 
1029
                            
-
 
1030
                        
-
 
1031
                    }
-
 
1032
                    
-
 
1033
        
-
 
1034
                    $user_id_in_default_network = 0;
-
 
1035
                    if($user->is_adult == User::IS_ADULT_YES) {
-
 
1036
                        
-
 
1037
                        if($currentNetwork->default == Network::DEFAULT_YES) {
-
 
1038
                            
-
 
1039
                            $user_id_in_default_network = $user->id;
-
 
1040
                            
-
 
1041
                            
-
 
1042
                            
-
 
1043
                        } else {
-
 
1044
                            
-
 
1045
                            $userInDefaultNetwork = $userMapper->fetchOneByEmailAndNetworkId($user->email, $networkDefault->id);
-
 
1046
                            if($userInDefaultNetwork) {
-
 
1047
                                $user_id_in_default_network = $userInDefaultNetwork->id;
-
 
1048
                            
-
 
1049
                                if($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
-
 
1050
                                    $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
-
 
1051
                                    $userInDefaultNetwork->status != User::STATUS_ACTIVE;
-
 
1052
                                    
-
 
1053
                                    if(!$userMapper->update($userInDefaultNetwork)) {
-
 
1054
                                        $csv .= "$first_name|$last_name|$email|FAIL UPDATE USER IN DEFAULT NETWORK \r\n";
-
 
1055
                                        continue;
-
 
1056
                                    }
-
 
1057
                                }
-
 
1058
                                
-
 
1059
                                
-
 
1060
                            } else {
-
 
1061
                                $userInDefaultNetwork = new User();
-
 
1062
                                $userInDefaultNetwork->network_id = $networkDefault->id;
-
 
1063
                                $userInDefaultNetwork->blocked = User::BLOCKED_NO;
-
 
1064
                                $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
-
 
1065
                                $userInDefaultNetwork->email = $email;
-
 
1066
                                $userInDefaultNetwork->first_name = $first_name;
-
 
1067
                                $userInDefaultNetwork->last_name = $last_name;
-
 
1068
                                $userInDefaultNetwork->password = $password_hash;
-
 
1069
                                $userInDefaultNetwork->login_attempt = 0;
-
 
1070
                                $userInDefaultNetwork->usertype_id = UserType::USER;
-
 
1071
                                $userInDefaultNetwork->status = User::STATUS_ACTIVE;
-
 
1072
                                $userInDefaultNetwork->is_adult = $isAdult == User::IS_ADULT_YES;
-
 
1073
                                $result = $userMapper->insert($userInDefaultNetwork);
-
 
1074
                                if($result) {
-
 
1075
                                    $user_id_in_default_network = $userInDefaultNetwork->id;
-
 
1076
                                    
-
 
1077
                                    
-
 
1078
                                    $userPassword = new UserPassword();
-
 
1079
                                    $userPassword->user_id = $userInDefaultNetwork->id;
-
 
1080
                                    $userPassword->password = $password_hash;
-
 
1081
                                    $userPasswordMapper->insert($userPassword);
-
 
1082
                                    
-
 
1083
                                    $csv .= "$first_name|$last_name|$email|CREATE USER IN DEFAULT NETWORK \r\n";
-
 
1084
                                } else {
-
 
1085
                                    $csv .= "$first_name|$last_name|$email|FAIL CREATE USER IN DEFAULT NETWORK \r\n";
-
 
1086
                                }
-
 
1087
                                
-
 
1088
                            }
-
 
1089
                            
-
 
1090
                            
-
 
1091
                        }
-
 
1092
                    }
-
 
1093
        
-
 
1094
                    if($user_id_in_default_network) {
-
 
1095
                        
-
 
1096
                        if($userDefaultForConnection) {
-
 
1097
                        
-
 
1098
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($userDefaultForConnection->id, $user_id_in_default_network);
-
 
1099
                            if($connection) {
-
 
1100
                                if($connection->status != Connection::STATUS_ACCEPTED) {
-
 
1101
                                    $connection->status = Connection::STATUS_ACCEPTED;
-
 
1102
                                    $connectionMapper->update($connection);
-
 
1103
                                    
-
 
1104
                                }
-
 
1105
                                
-
 
1106
                                
-
 
1107
                            } else {
-
 
1108
                                $connection = new Connection();
-
 
1109
                                $connection->request_to = $user_id_in_default_network;
-
 
1110
                                $connection->request_from = $userDefaultForConnection->id;
-
 
1111
                                $connection->status = Connection::STATUS_ACCEPTED;
-
 
1112
                                $connectionMapper->insert($connection);
-
 
1113
                            }
-
 
1114
                        }
-
 
1115
                        
-
 
1116
                        if($companyForFollower) {
-
 
1117
                            $companyFollower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($companyForFollower->id, $user_id_in_default_network);
-
 
1118
                            if(!$companyFollower) {
-
 
1119
                                $companyFollower = new CompanyFollower();
-
 
1120
                                $companyFollower->company_id = $companyForFollower->id;
-
 
1121
                                $companyFollower->follower_id = $user_id_in_default_network;
-
 
1122
                                
-
 
1123
                                $companyFollowerMapper->insert($companyFollower);
-
 
1124
                                
-
 
1125
                                
-
 
1126
                            }
-
 
1127
                        }
-
 
1128
                        
-
 
1129
                        
-
 
1130
                    }
-
 
1131
                        
-
 
1132
                    
-
 
1133
                    if(!in_array($user->id, $user_ids)) {
-
 
1134
                        array_push($user_ids, $user->id);
-
 
1135
                    }
-
 
1136
                    
-
 
1137
                    /*
-
 
1138
                    echo '$filterCompany = ' . $filterCompany . PHP_EOL;
-
 
1139
                    echo '$filterFunctio = ' . $filterFunction . PHP_EOL;
-
 
1140
                    echo '$filterGroup = ' . $filterGroup . PHP_EOL;
-
 
1141
                    echo '$filterInstitution = ' . $filterInstitution . PHP_EOL;
-
 
1142
                    echo '$filterPartner = ' . $filterPartner . PHP_EOL;
-
 
1143
                    echo '$filterProgram = ' . $filterProgram . PHP_EOL;
-
 
1144
                    echo '$filterSector = ' . $filterSector . PHP_EOL;
-
 
1145
                    echo '$filterStudentType = ' . $filterStudentType . PHP_EOL;
-
 
1146
                    */
-
 
1147
                    
-
 
1148
                    
-
 
1149
                    $extendUser = $microlearningExtendUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
-
 
1150
                    if(!$extendUser) {
-
 
1151
                        $extendUser = new MicrolearningExtendUser();
-
 
1152
                        $extendUser->company_id = $currentCompany->id;
-
 
1153
                        $extendUser->user_id = $user->id;
-
 
1154
                    }
-
 
1155
                    
-
 
1156
                    
-
 
1157
                    if($company) {
-
 
1158
                        $record = $microlearningExtendUserCompanyMapper->fetchOneByCompanyIdAndName($currentCompany->id, $company);
-
 
1159
        
-
 
1160
                        if(!$record) {
-
 
1161
                            $record = new MicrolearningExtendUserCompany();
-
 
1162
                            $record->company_id = $currentCompany->id;
-
 
1163
                            $record->name = $company;
-
 
1164
                                    
-
 
1165
                            $microlearningExtendUserCompanyMapper->insert($record);
-
 
1166
                        }
-
 
1167
                    
-
 
1168
    
-
 
1169
                        
-
 
1170
                                
-
 
1171
                        if($record->id) {
-
 
1172
                            $extendUser->extend_company_id = $record->id;
-
 
1173
                        }
-
 
1174
                    }
-
 
1175
                            
-
 
1176
                    if($function) {
-
 
1177
                        $record = $microlearningExtendUserFunctionMapper->fetchOneByCompanyIdAndName($currentCompany->id, $function);
-
 
1178
                        if(!$record) {
-
 
1179
                            $record = new MicrolearningExtendUserFunction();
-
 
1180
                            $record->company_id = $currentCompany->id;
-
 
1181
                            $record->name = $function;
-
 
1182
                                    
-
 
1183
                            $microlearningExtendUserFunctionMapper->insert($record);
-
 
1184
                        }
-
 
1185
                                
-
 
1186
                        if($record->id) {
-
 
1187
                            $extendUser->extend_function_id = $record->id;
-
 
1188
                        }
-
 
1189
                    }
-
 
1190
                            
-
 
1191
                    if($group) {
-
 
1192
                        $record = $microlearningExtendUserGroupMapper->fetchOneByCompanyIdAndName($currentCompany->id, $group);
-
 
1193
                        if(!$record) {
-
 
1194
                            $record = new MicrolearningExtendUserGroup();
-
 
1195
                            $record->company_id = $currentCompany->id;
-
 
1196
                            $record->name = $group;
-
 
1197
                                    
-
 
1198
                            $microlearningExtendUserGroupMapper->insert($record);
-
 
1199
                        }
-
 
1200
                                
-
 
1201
                        if($record->id) {
-
 
1202
                            $extendUser->extend_group_id = $record->id;
-
 
1203
                        }
-
 
1204
                    }
-
 
1205
                            
-
 
1206
                    if($institution) {
-
 
1207
                        $record = $microlearningExtendUserInstitutionMapper->fetchOneByCompanyIdAndName($currentCompany->id, $institution);
-
 
1208
                        if(!$record) {
-
 
1209
                            $record = new MicrolearningExtendUserInstitution();
-
 
1210
                            $record->company_id = $currentCompany->id;
-
 
1211
                            $record->name = $institution;
-
 
1212
                                    
-
 
1213
                            $microlearningExtendUserInstitutionMapper->insert($record);
-
 
1214
                        }
-
 
1215
                                
-
 
1216
                        if($record->id) {
-
 
1217
                            $extendUser->extend_institution_id = $record->id;
-
 
1218
                        }
-
 
1219
                    }
-
 
1220
                            
-
 
1221
                    if($program) {
-
 
1222
                        $record = $microlearningExtendUserProgramMapper->fetchOneByCompanyIdAndName($currentCompany->id, $program);
-
 
1223
                        if(!$record) {
-
 
1224
                            $record = new MicrolearningExtendUserProgram();
-
 
1225
                            $record->company_id = $currentCompany->id;
-
 
1226
                            $record->name = $program;
-
 
1227
                                    
-
 
1228
                            $microlearningExtendUserProgramMapper->insert($record);
-
 
1229
                        }
-
 
1230
                                
-
 
1231
                        if($record->id) {
-
 
1232
                            $extendUser->extend_program_id = $record->id;
-
 
1233
                        }
-
 
1234
                    }
-
 
1235
                            
-
 
1236
                    if($partner) {
-
 
1237
                        
-
 
1238
                    
-
 
1239
                        $record = $microlearningExtendUserPartnerMapper->fetchOneByCompanyIdAndName($currentCompany->id, $partner);
-
 
1240
                        if(!$record) {
-
 
1241
                            $record = new MicrolearningExtendUserPartner();
-
 
1242
                            $record->company_id = $currentCompany->id;
-
 
1243
                            $record->name = $partner;
-
 
1244
                                    
-
 
1245
                            $microlearningExtendUserPartnerMapper->insert($record);
-
 
1246
                        }
-
 
1247
                                
-
 
1248
                        if($record->id) {
-
 
1249
                            $extendUser->extend_partner_id = $record->id;
-
 
1250
                        }
-
 
1251
                    }
-
 
1252
                            
-
 
1253
                    if($sector) {
-
 
1254
                        $record = $microlearningExtendUserSectorMapper->fetchOneByCompanyIdAndName($currentCompany->id, $sector);
-
 
1255
                        if(!$record) {
-
 
1256
                            $record = new MicrolearningExtendUserSector();
-
 
1257
                            $record->company_id = $currentCompany->id;
-
 
1258
                            $record->name = $sector;
-
 
1259
                                    
-
 
1260
                            $microlearningExtendUserSectorMapper->insert($record);
-
 
1261
                        }
-
 
1262
                                
-
 
1263
                        if($record->id) {
-
 
1264
                            $extendUser->extend_sector_id = $record->id;
-
 
1265
                        }
-
 
1266
                    }
-
 
1267
                            
-
 
1268
                    if($studentType) {
-
 
1269
                        $record = $microlearningExtendUserStudentTypeMapper->fetchOneByCompanyIdAndName($currentCompany->id, $studentType);
-
 
1270
                        if(!$record) {
-
 
1271
                            $record = new MicrolearningExtendUserStudentType();
-
 
1272
                            $record->company_id = $currentCompany->id;
-
 
1273
                            $record->name = $studentType;
-
 
1274
                                    
-
 
1275
                            $microlearningExtendUserStudentTypeMapper->insert($record);
-
 
1276
                        }
-
 
1277
                        if($record->id) {
-
 
1278
                            $extendUser->extend_student_type_id = $record->id;
-
 
1279
                        }
-
 
1280
                    }
-
 
1281
                    
-
 
1282
                    if($country) {
-
 
1283
                        $record = $microlearningExtendUserCountryMapper->fetchOneByCompanyIdAndName($currentCompany->id, $country);
-
 
1284
                        if(!$record) {
-
 
1285
                            $record = new MicrolearningExtendUserCountry();
-
 
1286
                            $record->company_id = $currentCompany->id;
-
 
1287
                            $record->name = $country;
-
 
1288
                            
-
 
1289
                            $microlearningExtendUserCountryMapper->insert($record);
-
 
1290
                        }
-
 
1291
                        if($record->id) {
-
 
1292
                            $extendUser->extend_country_id = $record->id;
-
 
1293
                        }
-
 
1294
                    }
-
 
1295
                    
-
 
1296
    
-
 
1297
                    
-
 
1298
    
-
 
1299
                            
-
 
1300
                    if($extendUser->id) {
-
 
1301
                        $result =   $microlearningExtendUserMapper->update($extendUser);
-
 
1302
                    } else {
-
 
1303
                        $result = $microlearningExtendUserMapper->insert($extendUser);
-
 
1304
                    }
-
 
1305
                
-
 
1306
                
-
 
1307
                    
-
 
1308
                }
-
 
1309
                
-
 
1310
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
-
 
1311
                
-
 
1312
                
-
 
1313
                $users_processed = 0;
-
 
1314
                $users_previous = 0;
-
 
1315
                foreach($user_ids as $user_id)
-
 
1316
                {
-
 
1317
                    $user = $userMapper->fetchOne($user_id);
-
 
1318
                    $first_name = $user->first_name;
-
 
1319
                    $last_name = $user->last_name;
-
 
1320
                    $email = $user->email;
-
 
1321
                    
-
 
1322
                    
-
 
1323
                    $users_processed++;
-
 
1324
                    $topicUser = $topicUserMapper->fetchOneByUserIdAndTopicId($user_id, $topic->id);
-
 
1325
                    if($topicUser) {
-
 
1326
                        $users_previous++;
-
 
1327
                        $csv .= "$first_name|$last_name|$email|PREVIOUS FOUND \r\n";
-
 
1328
                    } else {
-
 
1329
                        $topicUser = new MicrolearningTopicUser();
-
 
1330
                        $topicUser->company_id = $topic->company_id;
-
 
1331
                        $topicUser->topic_id = $topic->id;
-
 
1332
                        $topicUser->topic_id = $topic->id;
-
 
1333
                        $topicUser->user_id = $user_id;
-
 
1334
                        $topicUser->access = MicrolearningTopicUser::ACCESS_UNLIMITED;
-
 
1335
                        
-
 
1336
                        if($topicUserMapper->insert($topicUser)) {
-
 
1337
                            
-
 
1338
                            $notification = new Notification();
-
 
1339
                            $notification->company_id = $topic->company_id;
-
 
1340
                            $notification->user_id = $user_id;
-
 
1341
                            $notification->topic_id = $topic->id;
-
 
1342
                            $notification->topic_id = $topic->id;
-
 
1343
                            $notification->type = Notification::TYPE_NEW_MICROLEARNING_CAPSULE;
-
 
1344
                            $notification->message  = 'LABEL_NOTIFICATION_NEW_MICROLEARNING_CAPSULE' . ' : ' . $topic->name;
-
 
1345
                            $notification->url      = '/microlearning/topics/' . $topic->uuid .  '/detail';
-
 
1346
                            
-
 
1347
                            $notificationMapper->insert($notification);
-
 
1348
                            
-
 
1349
                            
-
 
1350
                            $csv .= "$first_name|$last_name|$email|CAPSULE USER ASSIGNED\r\n";
-
 
1351
                            $users_assigned++;  
-
 
1352
                            
-
 
1353
                            
-
 
1354
                            $topicUser = $topicUserMapper->fetchOne($topicUser->id);
-
 
1355
                            if($topicUser) {
-
 
1356
                                $microlearningUserMapper = MicrolearningUserMapper::getInstance($this->adapter);
-
 
1357
                                $microlearningUser = $microlearningUserMapper->fetchOneByUserIdAndCompanyId($topicUser->user_id, $topicUser->company_id);
-
 
1358
                                if($microlearningUser) {
-
 
1359
                                    $microlearningUser->updated_on = $topicUser->updated_on;
-
 
1360
                                    
-
 
1361
                                    $microlearningUserMapper->update($microlearningUser);
-
 
1362
                                    
-
 
1363
                                } else {
-
 
1364
                                    $microlearningUser = new MicrolearningUser();
-
 
1365
                                    $microlearningUser->company_id = $topicUser->company_id;
-
 
1366
                                    $microlearningUser->user_id = $topicUser->user_id;
-
 
1367
                                    $microlearningUser->added_on = $topicUser->added_on;
-
 
1368
                                    $microlearningUser->updated_on = $topicUser->updated_on;
-
 
1369
                                    
-
 
1370
                                    $microlearningUserMapper->insert($microlearningUser);
-
 
1371
                                } 
-
 
1372
                            }
-
 
1373
                        } else {
-
 
1374
                            $csv .= "$first_name|$last_name|$email|CAPSULE USER PREVIOUS \r\n";
-
 
1375
                        }
-
 
1376
                        
-
 
1377
                    }
-
 
1378
                    
-
 
1379
                    
-
 
1380
                    
-
 
1381
                }
-
 
1382
                
-
 
1383
                $users_in_the_topic = $topicUserMapper->fetchCountByCompanyIdAndTopicId($topic->company_id, $topic->id);
-
 
1384
                
-
 
1385
                return new JsonModel([
-
 
1386
                    'success' => true, 
-
 
1387
                    'data' => [
-
 
1388
                        'users_assigned' => $users_assigned, 
-
 
1389
                        'users_processed' => $users_processed,
-
 
1390
                        'users_in_the_topic' => $users_in_the_topic,
-
 
1391
                        'users_previous' => $users_previous,
-
 
1392
                        'csv_base64_content' => base64_encode($csv),
-
 
1393
                        'csv_filename' => 'topic-users-' .date('Y-m-d-h-i-s').  '.csv'
-
 
1394
                    ]
-
 
1395
                ]); 
-
 
1396
                
-
 
1397
                
-
 
1398
                
-
 
1399
                
-
 
1400
            }
Línea 894... Línea 1401...
894
            
1401
            
895
            return new JsonModel([
1402
            return new JsonModel([
896
                'success' => false,
1403
                'success' => false,
897
                'data' => 'ERROR_PARAMETERS_ARE_INVALID'
1404
                'data' => 'ERROR_PARAMETERS_ARE_INVALID'
898
            ]);
-
 
899
            
1405
            ]);
900
        } catch (\Exception $e) {
1406
        } catch (\Exception $e) {
901
            $this->logger->err('Fatal error in uploadAction: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
1407
            $this->logger->err('Fatal error in uploadAction: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
902
            return new JsonModel([
1408
            return new JsonModel([
903
                'success' => false,
1409
                'success' => false,