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