| Conditions | 63 |
| Paths | 0 |
| Total Lines | 488 |
| Code Lines | 362 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 201 | public function crearAccion($crearAccionInput) |
||
| 202 | { |
||
| 203 | /* Tracking Log */ |
||
| 204 | $tableLog = Database::get_main_table('plugin_sepe_log'); |
||
| 205 | $paramsLog = array( |
||
| 206 | 'ip' => $_SERVER['REMOTE_ADDR'], |
||
| 207 | 'action' => "crearAccion", |
||
| 208 | 'fecha' => date("Y-m-d H:i:s") |
||
| 209 | ); |
||
| 210 | Database::insert($tableLog, $paramsLog); |
||
| 211 | /* End tracking log */ |
||
| 212 | |||
| 213 | $array = json_decode(json_encode($crearAccionInput), true); |
||
| 214 | $crearAccionInputArray = (array) $array; |
||
| 215 | // Code |
||
| 216 | $actionOrigin = $crearAccionInput->ACCION_FORMATIVA->ID_ACCION->ORIGEN_ACCION; |
||
| 217 | $actionCode = $crearAccionInput->ACCION_FORMATIVA->ID_ACCION->CODIGO_ACCION; |
||
| 218 | $situation = $crearAccionInput->ACCION_FORMATIVA->SITUACION; |
||
| 219 | $specialtyOrigin = $crearAccionInput->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL->ORIGEN_ESPECIALIDAD; |
||
| 220 | $professionalArea = $crearAccionInput->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL->AREA_PROFESIONAL; |
||
| 221 | $specialtyCode = $crearAccionInput->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL->CODIGO_ESPECIALIDAD; |
||
| 222 | $duration = $crearAccionInput->ACCION_FORMATIVA->DURACION; |
||
| 223 | $startDate = $crearAccionInput->ACCION_FORMATIVA->FECHA_INICIO; |
||
| 224 | $endDate = $crearAccionInput->ACCION_FORMATIVA->FECHA_FIN; |
||
| 225 | $fullItineraryIndicator = $crearAccionInput->ACCION_FORMATIVA->IND_ITINERARIO_COMPLETO; |
||
| 226 | $financingType = $crearAccionInput->ACCION_FORMATIVA->TIPO_FINANCIACION; |
||
| 227 | $attendeesCount = $crearAccionInput->ACCION_FORMATIVA->NUMERO_ASISTENTES; |
||
| 228 | $actionName = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->DENOMINACION_ACCION; |
||
| 229 | $globalInfo = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->INFORMACION_GENERAL; |
||
| 230 | $schedule = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->HORARIOS; |
||
| 231 | $requerements = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->REQUISITOS; |
||
| 232 | $contactAction = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->CONTACTO_ACCION; |
||
| 233 | |||
| 234 | |||
| 235 | if (empty($actionOrigin) || empty($actionCode)) { |
||
| 236 | error_log('2 - error en parametros - l244'); |
||
| 237 | return array( |
||
| 238 | "RESPUESTA_OBT_ACCION" => array( |
||
| 239 | "CODIGO_RETORNO"=>"2", |
||
| 240 | "ETIQUETA_ERROR"=>"Error en parametro", |
||
| 241 | "ACCION_FORMATIVA"=> $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 242 | ) |
||
| 243 | ); |
||
| 244 | } |
||
| 245 | |||
| 246 | // Comprobamos si existen datos almacenados previamente |
||
| 247 | $table = Database::get_main_table('plugin_sepe_actions'); |
||
| 248 | $sql = "SELECT action_origin FROM $table |
||
| 249 | WHERE action_origin='".$actionOrigin."' AND action_code='".$actionCode."';"; |
||
| 250 | $rs = Database::query($sql); |
||
| 251 | |||
| 252 | if (Database::num_rows($rs) > 0) { |
||
| 253 | return array( |
||
| 254 | "RESPUESTA_OBT_ACCION" => array( |
||
| 255 | "CODIGO_RETORNO"=>"1", |
||
| 256 | "ETIQUETA_ERROR"=>"Acción existente", |
||
| 257 | "ACCION_FORMATIVA"=>$crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 258 | ) |
||
| 259 | ); |
||
| 260 | } |
||
| 261 | |||
| 262 | $startDate = self::fixDate($startDate); |
||
| 263 | $endDate = self::fixDate($endDate); |
||
| 264 | |||
| 265 | $sql = "INSERT INTO $table (action_origin, action_code, situation, specialty_origin, professional_area, specialty_code, duration, start_date, end_date, full_itinerary_indicator, financing_type, attendees_count, action_name, global_info, schedule, requirements, contact_action) |
||
| 266 | VALUES ('".$actionOrigin."','".$actionCode."','".$situation."','".$specialtyOrigin."','".$professionalArea."','".$specialtyCode."','".$duration."','".$startDate."','".$endDate."','".$fullItineraryIndicator."','".$financingType."','".$attendeesCount."','".$actionName."','".$globalInfo."','".$schedule."','".$requerements."','".$contactAction."')"; |
||
| 267 | |||
| 268 | $rs = Database::query($sql); |
||
| 269 | if (!$rs) { |
||
| 270 | return array( |
||
| 271 | "RESPUESTA_OBT_ACCION" => array( |
||
| 272 | "CODIGO_RETORNO"=>"-1", |
||
| 273 | "ETIQUETA_ERROR"=>"Problema base de datos - insertando acciones formativas", |
||
| 274 | "ACCION_FORMATIVA"=>$crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 275 | ) |
||
| 276 | ); |
||
| 277 | } |
||
| 278 | $actionId = Database::insert_id(); |
||
| 279 | |||
| 280 | // DATOS ESPECIALIDADES DE LA ACCION |
||
| 281 | $table = Database::get_main_table('plugin_sepe_specialty'); |
||
| 282 | |||
| 283 | $specialties = $crearAccionInput->ACCION_FORMATIVA->ESPECIALIDADES_ACCION; |
||
| 284 | foreach ($specialties as $specialtyList) { |
||
| 285 | if (!is_array($specialtyList)) { |
||
| 286 | $auxList = array(); |
||
| 287 | $auxList[] = $specialtyList; |
||
| 288 | $specialtyList = $auxList; |
||
| 289 | } |
||
| 290 | foreach ($specialtyList as $specialty) { |
||
| 291 | $specialtyOrigin = $specialty->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD; |
||
| 292 | $professionalArea = $specialty->ID_ESPECIALIDAD->AREA_PROFESIONAL; |
||
| 293 | $specialtyCode = $specialty->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD; |
||
| 294 | $centerOrigin = $specialty->CENTRO_IMPARTICION->ORIGEN_CENTRO; |
||
| 295 | $centerCode = $specialty->CENTRO_IMPARTICION->CODIGO_CENTRO; |
||
| 296 | $startDate = $specialty->FECHA_INICIO; |
||
| 297 | $endDate = $specialty->FECHA_FIN; |
||
| 298 | |||
| 299 | $modalityImpartition = $specialty->MODALIDAD_IMPARTICION; |
||
| 300 | $classroomHours = $specialty->DATOS_DURACION->HORAS_PRESENCIAL; |
||
| 301 | $distanceHours = $specialty->DATOS_DURACION->HORAS_TELEFORMACION; |
||
| 302 | |||
| 303 | $morningParticipansNumber = null; |
||
| 304 | $morningAccessNumber = null; |
||
| 305 | $morningTotalDuration = null; |
||
| 306 | |||
| 307 | if (isset($specialty->USO->HORARIO_MANANA)) { |
||
| 308 | $morningParticipansNumber = $specialty->USO->HORARIO_MANANA->NUM_PARTICIPANTES; |
||
| 309 | $morningAccessNumber = $specialty->USO->HORARIO_MANANA->NUMERO_ACCESOS; |
||
| 310 | $morningTotalDuration = $specialty->USO->HORARIO_MANANA->DURACION_TOTAL; |
||
| 311 | } |
||
| 312 | |||
| 313 | $afternoonParticipantNumber = null; |
||
| 314 | $afternoonAccessNumber = null; |
||
| 315 | $afternoonTotalDuration = null; |
||
| 316 | |||
| 317 | if (isset($specialty->USO->HORARIO_TARDE)) { |
||
| 318 | $afternoonParticipantNumber = $specialty->USO->HORARIO_TARDE->NUM_PARTICIPANTES; |
||
| 319 | $afternoonAccessNumber = $specialty->USO->HORARIO_TARDE->NUMERO_ACCESOS; |
||
| 320 | $afternoonTotalDuration = $specialty->USO->HORARIO_TARDE->DURACION_TOTAL; |
||
| 321 | } |
||
| 322 | |||
| 323 | $nightParticipantsNumber = null; |
||
| 324 | $nightAccessNumber = null; |
||
| 325 | $nightTotalDuration = null; |
||
| 326 | |||
| 327 | if (isset($specialty->USO->HORARIO_NOCHE)) { |
||
| 328 | $nightParticipantsNumber = $specialty->USO->HORARIO_NOCHE->NUM_PARTICIPANTES; |
||
| 329 | $nightAccessNumber = $specialty->USO->HORARIO_NOCHE->NUMERO_ACCESOS; |
||
| 330 | $nightTotalDuration = $specialty->USO->HORARIO_NOCHE->DURACION_TOTAL; |
||
| 331 | } |
||
| 332 | |||
| 333 | $attendeesCount = null; |
||
| 334 | $learningActivityCount = null; |
||
| 335 | $attemptCount = null; |
||
| 336 | $evaluationActivityCount = null; |
||
| 337 | |||
| 338 | if (isset($specialty->USO->SEGUIMIENTO_EVALUACION)) { |
||
| 339 | $attendeesCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUM_PARTICIPANTES; |
||
| 340 | $learningActivityCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_APRENDIZAJE; |
||
| 341 | $attemptCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_INTENTOS; |
||
| 342 | $evaluationActivityCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_EVALUACION; |
||
| 343 | } |
||
| 344 | |||
| 345 | $startDate = self::fixDate($startDate); |
||
| 346 | $endDate = self::fixDate($endDate); |
||
| 347 | |||
| 348 | $params = array( |
||
| 349 | 'action_id' => $actionId, |
||
| 350 | 'specialty_origin' => $specialtyOrigin, |
||
| 351 | 'professional_area' => $professionalArea, |
||
| 352 | 'specialty_code' =>$specialtyCode, |
||
| 353 | 'center_origin' => $centerOrigin, |
||
| 354 | 'center_code' => $centerCode, |
||
| 355 | 'start_date' => $startDate, |
||
| 356 | 'end_date' => $endDate, |
||
| 357 | 'modality_impartition' => $modalityImpartition, |
||
| 358 | 'classroom_hours' => $classroomHours, |
||
| 359 | 'distance_hours' => $distanceHours, |
||
| 360 | 'mornings_participants_number' => $morningParticipansNumber, |
||
| 361 | 'mornings_access_number' => $morningAccessNumber, |
||
| 362 | 'morning_total_duration' => $morningTotalDuration, |
||
| 363 | 'afternoon_participants_number' => $afternoonParticipantNumber, |
||
| 364 | 'afternoon_access_number' => $afternoonAccessNumber, |
||
| 365 | 'afternoon_total_duration' => $afternoonTotalDuration, |
||
| 366 | 'night_participants_number' => $nightParticipantsNumber, |
||
| 367 | 'night_access_number' => $nightAccessNumber, |
||
| 368 | 'night_total_duration' => $nightTotalDuration, |
||
| 369 | 'attendees_count' => $attendeesCount, |
||
| 370 | 'learning_activity_count' => $learningActivityCount, |
||
| 371 | 'attempt_count' => $attemptCount, |
||
| 372 | 'evaluation_activity_count' => $evaluationActivityCount |
||
| 373 | ); |
||
| 374 | |||
| 375 | $specialtyId = Database::insert($table, $params); |
||
| 376 | |||
| 377 | if (empty($specialtyId)) { |
||
| 378 | return array( |
||
| 379 | "RESPUESTA_OBT_ACCION" => array( |
||
| 380 | "CODIGO_RETORNO" => "-1", |
||
| 381 | "ETIQUETA_ERROR" => "Problema base de datos - insertando datos de especialidad de la accion", |
||
| 382 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 383 | ) |
||
| 384 | ); |
||
| 385 | } |
||
| 386 | |||
| 387 | |||
| 388 | if ($specialtyId) { |
||
| 389 | $tableSpecialtyClassroom = Database::get_main_table('plugin_sepe_specialty_classroom'); |
||
| 390 | $tableCenters = Database::get_main_table('plugin_sepe_centers'); |
||
| 391 | foreach ($specialty->CENTROS_SESIONES_PRESENCIALES->CENTRO_PRESENCIAL as $centroList) { |
||
| 392 | if (!is_array($centroList)) { |
||
| 393 | $auxList = array(); |
||
| 394 | $auxList[] = $centroList; |
||
| 395 | $centroList = $auxList; |
||
| 396 | } |
||
| 397 | foreach ($centroList as $centro) { |
||
| 398 | $centerOrigin = $centro->ORIGEN_CENTRO; |
||
| 399 | $centerCode = $centro->CODIGO_CENTRO; |
||
| 400 | $sql = "SELECT id FROM $tableCenters |
||
| 401 | WHERE center_origin='".$centerOrigin."' AND center_code='".$centerCode."';"; |
||
| 402 | $res = Database::query($sql); |
||
| 403 | if (Database::num_rows($res) > 0) { |
||
| 404 | $aux_row = Database::fetch_assoc($res); |
||
| 405 | $centerId = $aux_row['id']; |
||
| 406 | } else { |
||
| 407 | $sql = "INSERT INTO $tableCenters (center_origin, center_code) |
||
| 408 | VALUES ('".$centerOrigin."','".$centerCode."');"; |
||
| 409 | Database::query($sql); |
||
| 410 | $centerId = Database::insert_id(); |
||
| 411 | } |
||
| 412 | $sql = "INSERT INTO $tableSpecialtyClassroom (specialty_id, center_id) |
||
| 413 | VALUES ('".$specialtyId."','".$centerId."')"; |
||
| 414 | Database::query($sql); |
||
| 415 | $id = Database::insert_id(); |
||
| 416 | |||
| 417 | if (empty($id)) { |
||
| 418 | return array( |
||
| 419 | "RESPUESTA_OBT_ACCION" => array( |
||
| 420 | "CODIGO_RETORNO" => "-1", |
||
| 421 | "ETIQUETA_ERROR" => "Problema base de datos - insertando centro presenciales", |
||
| 422 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 423 | ) |
||
| 424 | ); |
||
| 425 | } |
||
| 426 | } |
||
| 427 | } |
||
| 428 | |||
| 429 | $tableTutors = Database::get_main_table('plugin_sepe_tutors'); |
||
| 430 | $tableSpecialityTutors = Database::get_main_table('plugin_sepe_specialty_tutors'); |
||
| 431 | |||
| 432 | if (!empty($specialty->TUTORES_FORMADORES)) { |
||
| 433 | foreach ($specialty->TUTORES_FORMADORES as $tutorList) { |
||
| 434 | if (!is_array($tutorList)) { |
||
| 435 | $auxList = array(); |
||
| 436 | $auxList[] = $tutorList; |
||
| 437 | $tutorList = $auxList; |
||
| 438 | } |
||
| 439 | foreach ($tutorList as $tutor) { |
||
| 440 | $documentType = $tutor->ID_TUTOR->TIPO_DOCUMENTO; |
||
| 441 | $documentNumber = $tutor->ID_TUTOR->NUM_DOCUMENTO; |
||
| 442 | $documentLetter = $tutor->ID_TUTOR->LETRA_NIF; |
||
| 443 | $tutorAccreditation = $tutor->ACREDITACION_TUTOR; |
||
| 444 | $professionalExperience = $tutor->EXPERIENCIA_PROFESIONAL; |
||
| 445 | $teachingCompetence = $tutor->COMPETENCIA_DOCENTE; |
||
| 446 | $experienceTeleforming = $tutor->EXPERIENCIA_MODALIDAD_TELEFORMACION; |
||
| 447 | $trainingTeleforming = $tutor->FORMACION_MODALIDAD_TELEFORMACION; |
||
| 448 | |||
| 449 | /* check tutor not exists */ |
||
| 450 | $sql = "SELECT id FROM $tableTutors WHERE |
||
| 451 | document_type='".$documentType."' AND |
||
| 452 | document_number='".$documentNumber."' AND |
||
| 453 | document_letter='".$documentLetter."';"; |
||
| 454 | $res = Database::query($sql); |
||
| 455 | if (Database::num_rows($res) > 0) { |
||
| 456 | $aux_row = Database::fetch_assoc($res); |
||
| 457 | $tutorId = $aux_row['id']; |
||
| 458 | } else { |
||
| 459 | $sql = "INSERT INTO $tableTutors (document_type, document_number, document_letter) |
||
| 460 | VALUES ('".$documentType."','".$documentNumber."','".$documentLetter."');"; |
||
| 461 | Database::query($sql); |
||
| 462 | $tutorId = Database::insert_id(); |
||
| 463 | } |
||
| 464 | if (empty($tutorId)) { |
||
| 465 | return array( |
||
| 466 | "RESPUESTA_OBT_ACCION" => array( |
||
| 467 | "CODIGO_RETORNO" => "-1", |
||
| 468 | "ETIQUETA_ERROR" => "Problema base de datos - insertando tutores", |
||
| 469 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 470 | ) |
||
| 471 | ); |
||
| 472 | } |
||
| 473 | $sql = "INSERT INTO $tableSpecialityTutors (specialty_id, tutor_id, tutor_accreditation, professional_experience, teaching_competence, experience_teleforming, training_teleforming) |
||
| 474 | VALUES ('".$specialtyId."','".$tutorId."','".$tutorAccreditation."','".$professionalExperience."','".$teachingCompetence."','".$experienceTeleforming."','".$trainingTeleforming."');"; |
||
| 475 | Database::query($sql); |
||
| 476 | } |
||
| 477 | } |
||
| 478 | } |
||
| 479 | } |
||
| 480 | } |
||
| 481 | } |
||
| 482 | // DATOS PARTICIPANTES |
||
| 483 | $tableParticipants = Database::get_main_table('plugin_sepe_participants'); |
||
| 484 | $tableTutorsCompany = Database::get_main_table('plugin_sepe_tutors_company'); |
||
| 485 | $participants = $crearAccionInput->ACCION_FORMATIVA->PARTICIPANTES; |
||
| 486 | foreach ($participants as $participantList) { |
||
| 487 | if (!is_array($participantList)) { |
||
| 488 | $auxList = array(); |
||
| 489 | $auxList[] = $participantList; |
||
| 490 | $participantList = $auxList; |
||
| 491 | } |
||
| 492 | foreach ($participantList as $participant) { |
||
| 493 | $documentType = $participant->ID_PARTICIPANTE->TIPO_DOCUMENTO; |
||
| 494 | $documentNumber = $participant->ID_PARTICIPANTE->NUM_DOCUMENTO; |
||
| 495 | $documentLetter = $participant->ID_PARTICIPANTE->LETRA_NIF; |
||
| 496 | $keyCompetence = $participant->INDICADOR_COMPETENCIAS_CLAVE; |
||
| 497 | $contractId = null; |
||
| 498 | $companyFiscalNumber = null; |
||
| 499 | $documentTypeCompany = null; |
||
| 500 | $documentNumberCompany = null; |
||
| 501 | $documentLetterCompany = null; |
||
| 502 | $documentTypeTraining = null; |
||
| 503 | $documentNumberTraining = null; |
||
| 504 | $documentLetterTraining = null; |
||
| 505 | $tutorIdCompany = null; |
||
| 506 | $tutorIdTraining = null; |
||
| 507 | |||
| 508 | if (isset($participant->CONTRATO_FORMACION)) { |
||
| 509 | $contractId = isset($participant->CONTRATO_FORMACION->ID_CONTRATO_CFA) ? $participant->CONTRATO_FORMACION->ID_CONTRATO_CFA : null; |
||
| 510 | $companyFiscalNumber = isset($participant->CONTRATO_FORMACION->CIF_EMPRESA) ? $participant->CONTRATO_FORMACION->CIF_EMPRESA : null; |
||
| 511 | $documentTypeCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO : null; |
||
| 512 | $documentNumberCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO : null; |
||
| 513 | $documentLetterCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF : null; |
||
| 514 | if (!empty($documentTypeCompany) || !empty($documentNumberCompany) || !empty($documentLetterCompany)) { |
||
| 515 | $tmp_e = Database::query('SELECT id FROM '.$tableTutorsCompany.' WHERE document_type="'.$documentTypeCompany.'" AND document_number="'.$documentNumberCompany.'" AND document_letter="'.$documentLetterCompany.'";'); |
||
| 516 | if (Database::num_rows($tmp_e) > 0) { |
||
| 517 | $row_tmp = Database::fetch_assoc($tmp_e); |
||
| 518 | $tutorIdCompany = $row_tmp['id']; |
||
| 519 | Database::query("UPDATE $tableTutorsCompany SET company='1' WHERE id='".$tutorIdCompany."'"); |
||
| 520 | } else { |
||
| 521 | $params_tmp = array( |
||
| 522 | 'document_type' => $documentTypeCompany, |
||
| 523 | 'document_number' => $documentNumberCompany, |
||
| 524 | 'document_letter' => $documentLetterCompany, |
||
| 525 | 'company' => '1' |
||
| 526 | ); |
||
| 527 | $tutorIdCompany = Database::insert($tableTutorsCompany, $params_tmp); |
||
| 528 | } |
||
| 529 | } |
||
| 530 | |||
| 531 | $documentTypeTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO : null; |
||
| 532 | $documentNumberTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO : null; |
||
| 533 | $documentLetterTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF : null; |
||
| 534 | if (!empty($documentTypeTraining) || !empty($documentNumberTraining) || !empty($documentLetterTraining)) { |
||
| 535 | $tmp_f = Database::query(' |
||
| 536 | SELECT id FROM '.$tableTutorsCompany.' |
||
| 537 | WHERE |
||
| 538 | document_type="'.$documentTypeTraining.'" AND |
||
| 539 | document_number="'.$documentNumberTraining.'" AND |
||
| 540 | document_letter="'.$documentLetterTraining.'";' |
||
| 541 | ); |
||
| 542 | if (Database::num_rows($tmp_f) > 0) { |
||
| 543 | $row_tmp = Database::fetch_assoc($tmp_f); |
||
| 544 | $tutorIdTraining = $row_tmp['id']; |
||
| 545 | Database::query("UPDATE $tableTutorsCompany SET training='1' WHERE id='".$tutorIdTraining."'"); |
||
| 546 | } else { |
||
| 547 | $params_tmp = array( |
||
| 548 | 'document_type' => $documentTypeTraining, |
||
| 549 | 'document_number' => $documentNumberTraining, |
||
| 550 | 'document_letter' => $documentLetterTraining, |
||
| 551 | 'training' => '1' |
||
| 552 | ); |
||
| 553 | $tutorIdTraining = Database::insert($tableTutorsCompany, $params_tmp); |
||
| 554 | } |
||
| 555 | } |
||
| 556 | } |
||
| 557 | |||
| 558 | $params = array( |
||
| 559 | 'action_id' => $actionId, |
||
| 560 | 'document_type' => $documentType, |
||
| 561 | 'document_number' => $documentNumber, |
||
| 562 | 'document_letter' => $documentLetter, |
||
| 563 | 'key_competence' => $keyCompetence, |
||
| 564 | 'contract_id' => $contractId, |
||
| 565 | 'company_fiscal_number' => $companyFiscalNumber, |
||
| 566 | 'company_tutor_id' => $tutorIdCompany, |
||
| 567 | 'training_tutor_id' => $tutorIdTraining |
||
| 568 | ); |
||
| 569 | $participantId = Database::insert($tableParticipants, $params); |
||
| 570 | if (empty($participantId)) { |
||
| 571 | return array( |
||
| 572 | "RESPUESTA_OBT_ACCION" => array( |
||
| 573 | "CODIGO_RETORNO" => "-1", |
||
| 574 | "ETIQUETA_ERROR" => "Problema base de datos - insertando participantes", |
||
| 575 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 576 | ) |
||
| 577 | ); |
||
| 578 | } |
||
| 579 | |||
| 580 | $participantId = Database::insert_id(); |
||
| 581 | |||
| 582 | foreach ($participant->ESPECIALIDADES_PARTICIPANTE as $valueList) { |
||
| 583 | if (!is_array($participantList)) { |
||
| 584 | $auxList = array(); |
||
| 585 | $auxList[] = $valueList; |
||
| 586 | $valueList = $auxList; |
||
| 587 | } |
||
| 588 | foreach ($valueList as $value) { |
||
| 589 | $specialtyOrigin = null; |
||
| 590 | $professionalArea = null; |
||
| 591 | $specialtyCode = null; |
||
| 592 | |||
| 593 | if (isset($value->ID_ESPECIALIDAD)) { |
||
| 594 | $specialtyOrigin = $value->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD; |
||
| 595 | $professionalArea = $value->ID_ESPECIALIDAD->AREA_PROFESIONAL; |
||
| 596 | $specialtyCode = $value->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD; |
||
| 597 | } |
||
| 598 | |||
| 599 | $registrationDate = $value->FECHA_ALTA; |
||
| 600 | $leavingDate = $value->FECHA_BAJA; |
||
| 601 | |||
| 602 | $centerOrigin = null; |
||
| 603 | $centerCode = null; |
||
| 604 | $startDate = null; |
||
| 605 | $endDate = null; |
||
| 606 | |||
| 607 | if (!empty($value->EVALUACION_FINAL)) { |
||
| 608 | $startDate = isset($value->EVALUACION_FINAL->FECHA_INICIO) ? $value->EVALUACION_FINAL->FECHA_INICIO : null; |
||
| 609 | $endDate = isset($value->EVALUACION_FINAL->FECHA_FIN) ? $value->EVALUACION_FINAL->FECHA_FIN : null; |
||
| 610 | if (!empty($value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION)) { |
||
| 611 | $centerOrigin = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->ORIGEN_CENTRO; |
||
| 612 | $centerCode = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->CODIGO_CENTRO; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | $finalResult = null; |
||
| 617 | $finalQualification = null; |
||
| 618 | $finalScore = null; |
||
| 619 | |||
| 620 | if (isset($value->RESULTADOS)) { |
||
| 621 | $finalResult = isset($value->RESULTADOS->RESULTADO_FINAL) ? $value->RESULTADOS->RESULTADO_FINAL : null; |
||
| 622 | $finalQualification = isset($value->RESULTADOS->CALIFICACION_FINAL) ? $value->RESULTADOS->CALIFICACION_FINAL : null; |
||
| 623 | $finalScore = isset($value->RESULTADOS->PUNTUACION_FINAL) ? $value->RESULTADOS->PUNTUACION_FINAL : null; |
||
| 624 | } |
||
| 625 | |||
| 626 | $registrationDate = self::fixDate($registrationDate); |
||
| 627 | $leavingDate = self::fixDate($leavingDate); |
||
| 628 | |||
| 629 | $startDate = self::fixDate($startDate); |
||
| 630 | $endDate = self::fixDate($endDate); |
||
| 631 | |||
| 632 | $table_aux = Database::get_main_table('plugin_sepe_participants_specialty'); |
||
| 633 | $sql = "INSERT INTO $table_aux (participant_id,specialty_origin,professional_area,specialty_code,registration_date,leaving_date,center_origin,center_code,start_date,end_date,final_result,final_qualification,final_score) |
||
| 634 | VALUES ('".$participantId."','".$specialtyOrigin."','".$professionalArea."','".$specialtyCode."','".$registrationDate."','".$leavingDate."','".$centerOrigin."','".$centerCode."','".$startDate."','".$endDate."','".$finalResult."','".$finalQualification."','".$finalScore."');"; |
||
| 635 | Database::query($sql); |
||
| 636 | $participantSpecialtyId = Database::insert_id(); |
||
| 637 | if (empty($participantSpecialtyId)) { |
||
| 638 | return array( |
||
| 639 | "RESPUESTA_OBT_ACCION" => array( |
||
| 640 | "CODIGO_RETORNO" => "-1", |
||
| 641 | "ETIQUETA_ERROR" => "Problema base de datos - insertando especialidad participante", |
||
| 642 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 643 | ) |
||
| 644 | ); |
||
| 645 | } |
||
| 646 | |||
| 647 | foreach ($value->TUTORIAS_PRESENCIALES as $tutorialList) { |
||
| 648 | if (!is_array($tutorialList)) { |
||
| 649 | $auxList = array(); |
||
| 650 | $auxList[] = $tutorialList; |
||
| 651 | $tutorialList = $auxList; |
||
| 652 | } |
||
| 653 | foreach ($tutorialList as $tutorial) { |
||
| 654 | $centerOrigin = $tutorial->CENTRO_PRESENCIAL_TUTORIA->ORIGEN_CENTRO; |
||
| 655 | $centerCode = $tutorial->CENTRO_PRESENCIAL_TUTORIA->CODIGO_CENTRO; |
||
| 656 | $startDate = $tutorial->FECHA_INICIO; |
||
| 657 | $endDate = $tutorial->FECHA_FIN; |
||
| 658 | |||
| 659 | $startDate = self::fixDate($startDate); |
||
| 660 | $endDate = self::fixDate($endDate); |
||
| 661 | |||
| 662 | $table_aux2 = Database::get_main_table('plugin_sepe_participants_specialty_tutorials'); |
||
| 663 | $sql = "INSERT INTO $table_aux2 (participant_specialty_id,center_origin,center_code,start_date,end_date) |
||
| 664 | VALUES ('".$participantSpecialtyId."','".$centerOrigin."','".$centerCode."','".$startDate."','".$endDate."');"; |
||
| 665 | $rs = Database::query($sql); |
||
| 666 | if (!$rs) { |
||
| 667 | return array( |
||
| 668 | "RESPUESTA_OBT_ACCION" => array( |
||
| 669 | "CODIGO_RETORNO" => "-1", |
||
| 670 | "ETIQUETA_ERROR" => "Problema base de datos - insertando tutorias presenciales participante", |
||
| 671 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 672 | ) |
||
| 673 | ); |
||
| 674 | } |
||
| 675 | } |
||
| 676 | } |
||
| 677 | } |
||
| 678 | } |
||
| 679 | } |
||
| 680 | } |
||
| 681 | |||
| 682 | $obtenerAccionInput = new stdClass(); |
||
| 683 | $obtenerAccionInput->ID_ACCION = new stdClass(); |
||
| 684 | $obtenerAccionInput->ID_ACCION->ORIGEN_ACCION = $actionOrigin; |
||
| 685 | $obtenerAccionInput->ID_ACCION->CODIGO_ACCION = $actionCode; |
||
| 686 | |||
| 687 | $result = self::obtenerAccion($obtenerAccionInput); |
||
| 688 | return $result; |
||
| 689 | } |
||
| 1311 |