Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Sepe often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Sepe, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class Sepe |
||
| 7 | {
|
||
| 8 | |||
| 9 | /** |
||
| 10 | * @param crearCentroInput[] $crearCentroInput |
||
| 11 | * |
||
| 12 | * @return array |
||
| 13 | */ |
||
| 14 | public function crearCentro($crearCentroInput) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * |
||
| 107 | * @return array |
||
| 108 | */ |
||
| 109 | public function obtenerDatosCentro() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param $crearAccionInput |
||
| 200 | * @return array |
||
| 201 | */ |
||
| 202 | public function crearAccion($crearAccionInput) |
||
| 203 | {
|
||
| 204 | /* Tracking Log */ |
||
| 205 | $tableLog = Database::get_main_table('plugin_sepe_log');
|
||
| 206 | $paramsLog = array( |
||
| 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 | |||
| 236 | View Code Duplication | if (empty($actionOrigin) || empty($actionCode)) {
|
|
| 237 | error_log('2 - error en parametros - l244');
|
||
| 238 | return array( |
||
| 239 | "RESPUESTA_OBT_ACCION" => array( |
||
| 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 | $sql = "SELECT action_origin FROM $table |
||
| 250 | WHERE action_origin='".$actionOrigin."' AND action_code='".$actionCode."';"; |
||
| 251 | $rs = Database::query($sql); |
||
| 252 | |||
| 253 | if (Database::num_rows($rs) > 0) {
|
||
| 254 | return array( |
||
| 255 | "RESPUESTA_OBT_ACCION" => array( |
||
| 256 | "CODIGO_RETORNO"=>"1", |
||
| 257 | "ETIQUETA_ERROR"=>"Acción existente", |
||
| 258 | "ACCION_FORMATIVA"=>$crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 259 | ) |
||
| 260 | ); |
||
| 261 | |||
| 262 | } |
||
| 263 | |||
| 264 | $startDate = self::fixDate($startDate); |
||
| 265 | $endDate = self::fixDate($endDate); |
||
| 266 | |||
| 267 | $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) |
||
| 268 | VALUES ('".$actionOrigin."','".$actionCode."','".$situation."','".$specialtyOrigin."','".$professionalArea."','".$specialtyCode."','".$duration."','".$startDate."','".$endDate."','".$fullItineraryIndicator."','".$financingType."','".$attendeesCount."','".$actionName."','".$globalInfo."','".$schedule."','".$requerements."','".$contactAction."')";
|
||
| 269 | |||
| 270 | $rs = Database::query($sql); |
||
| 271 | View Code Duplication | if (!$rs) {
|
|
| 272 | return array( |
||
| 273 | "RESPUESTA_OBT_ACCION" => array( |
||
| 274 | "CODIGO_RETORNO"=>"-1", |
||
| 275 | "ETIQUETA_ERROR"=>"Problema base de datos - insertando acciones formativas", |
||
| 276 | "ACCION_FORMATIVA"=>$crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 277 | ) |
||
| 278 | ); |
||
| 279 | } |
||
| 280 | $actionId = Database::insert_id(); |
||
| 281 | |||
| 282 | // DATOS ESPECIALIDADES DE LA ACCION |
||
| 283 | $table = Database::get_main_table('plugin_sepe_specialty');
|
||
| 284 | |||
| 285 | $specialties = $crearAccionInput->ACCION_FORMATIVA->ESPECIALIDADES_ACCION; |
||
| 286 | foreach ($specialties as $specialtyList) {
|
||
| 287 | if (!is_array($specialtyList)) {
|
||
| 288 | $auxList = array(); |
||
| 289 | $auxList[] = $specialtyList; |
||
| 290 | $specialtyList = $auxList; |
||
| 291 | } |
||
| 292 | foreach ($specialtyList as $specialty) {
|
||
| 293 | $specialtyOrigin = $specialty->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD; |
||
| 294 | $professionalArea = $specialty->ID_ESPECIALIDAD->AREA_PROFESIONAL; |
||
| 295 | $specialtyCode = $specialty->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD; |
||
| 296 | $centerOrigin = $specialty->CENTRO_IMPARTICION->ORIGEN_CENTRO; |
||
| 297 | $centerCode = $specialty->CENTRO_IMPARTICION->CODIGO_CENTRO; |
||
| 298 | $startDate = $specialty->FECHA_INICIO; |
||
| 299 | $endDate = $specialty->FECHA_FIN; |
||
| 300 | |||
| 301 | $modalityImpartition = $specialty->MODALIDAD_IMPARTICION; |
||
| 302 | $classroomHours = $specialty->DATOS_DURACION->HORAS_PRESENCIAL; |
||
| 303 | $distanceHours = $specialty->DATOS_DURACION->HORAS_TELEFORMACION; |
||
| 304 | |||
| 305 | $morningParticipansNumber = null; |
||
| 306 | $morningAccessNumber = null; |
||
| 307 | $morningTotalDuration = null; |
||
| 308 | |||
| 309 | View Code Duplication | if (isset($specialty->USO->HORARIO_MANANA)) {
|
|
| 310 | $morningParticipansNumber = $specialty->USO->HORARIO_MANANA->NUM_PARTICIPANTES; |
||
| 311 | $morningAccessNumber = $specialty->USO->HORARIO_MANANA->NUMERO_ACCESOS; |
||
| 312 | $morningTotalDuration = $specialty->USO->HORARIO_MANANA->DURACION_TOTAL; |
||
| 313 | } |
||
| 314 | |||
| 315 | $afternoonParticipantNumber = null; |
||
| 316 | $afternoonAccessNumber = null; |
||
| 317 | $afternoonTotalDuration = null; |
||
| 318 | |||
| 319 | View Code Duplication | if (isset($specialty->USO->HORARIO_TARDE)) {
|
|
| 320 | $afternoonParticipantNumber = $specialty->USO->HORARIO_TARDE->NUM_PARTICIPANTES; |
||
| 321 | $afternoonAccessNumber = $specialty->USO->HORARIO_TARDE->NUMERO_ACCESOS; |
||
| 322 | $afternoonTotalDuration = $specialty->USO->HORARIO_TARDE->DURACION_TOTAL; |
||
| 323 | } |
||
| 324 | |||
| 325 | $nightParticipantsNumber = null; |
||
| 326 | $nightAccessNumber = null; |
||
| 327 | $nightTotalDuration = null; |
||
| 328 | |||
| 329 | View Code Duplication | if (isset($specialty->USO->HORARIO_NOCHE)) {
|
|
| 330 | $nightParticipantsNumber = $specialty->USO->HORARIO_NOCHE->NUM_PARTICIPANTES; |
||
| 331 | $nightAccessNumber = $specialty->USO->HORARIO_NOCHE->NUMERO_ACCESOS; |
||
| 332 | $nightTotalDuration = $specialty->USO->HORARIO_NOCHE->DURACION_TOTAL; |
||
| 333 | } |
||
| 334 | |||
| 335 | $attendeesCount = null; |
||
| 336 | $learningActivityCount = null; |
||
| 337 | $attemptCount = null; |
||
| 338 | $evaluationActivityCount = null; |
||
| 339 | |||
| 340 | if (isset($specialty->USO->SEGUIMIENTO_EVALUACION)) {
|
||
| 341 | $attendeesCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUM_PARTICIPANTES; |
||
| 342 | $learningActivityCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_APRENDIZAJE; |
||
| 343 | $attemptCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_INTENTOS; |
||
| 344 | $evaluationActivityCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_EVALUACION; |
||
| 345 | } |
||
| 346 | |||
| 347 | $startDate = self::fixDate($startDate); |
||
| 348 | $endDate = self::fixDate($endDate); |
||
| 349 | |||
| 350 | $params = array( |
||
| 351 | 'action_id' => $actionId, |
||
| 352 | 'specialty_origin' => $specialtyOrigin, |
||
| 353 | 'professional_area' => $professionalArea, |
||
| 354 | 'specialty_code' =>$specialtyCode , |
||
| 355 | 'center_origin' => $centerOrigin, |
||
| 356 | 'center_code' => $centerCode, |
||
| 357 | 'start_date' => $startDate , |
||
| 358 | 'end_date' => $endDate, |
||
| 359 | 'modality_impartition' => $modalityImpartition, |
||
| 360 | 'classroom_hours' => $classroomHours, |
||
| 361 | 'distance_hours' => $distanceHours, |
||
| 362 | 'mornings_participants_number' => $morningParticipansNumber, |
||
| 363 | 'mornings_access_number' => $morningAccessNumber, |
||
| 364 | 'morning_total_duration' => $morningTotalDuration, |
||
| 365 | 'afternoon_participants_number' => $afternoonParticipantNumber, |
||
| 366 | 'afternoon_access_number' => $afternoonAccessNumber, |
||
| 367 | 'afternoon_total_duration' => $afternoonTotalDuration, |
||
| 368 | 'night_participants_number' => $nightParticipantsNumber, |
||
| 369 | 'night_access_number' => $nightAccessNumber, |
||
| 370 | 'night_total_duration' => $nightTotalDuration, |
||
| 371 | 'attendees_count' => $attendeesCount, |
||
| 372 | 'learning_activity_count' => $learningActivityCount , |
||
| 373 | 'attempt_count' => $attemptCount, |
||
| 374 | 'evaluation_activity_count' => $evaluationActivityCount |
||
| 375 | ); |
||
| 376 | |||
| 377 | $specialtyId = Database::insert($table, $params); |
||
| 378 | |||
| 379 | View Code Duplication | if (empty($specialtyId)) {
|
|
| 380 | return array( |
||
| 381 | "RESPUESTA_OBT_ACCION" => array( |
||
| 382 | "CODIGO_RETORNO" => "-1", |
||
| 383 | "ETIQUETA_ERROR" => "Problema base de datos - insertando datos de especialidad de la accion", |
||
| 384 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 385 | ) |
||
| 386 | ); |
||
| 387 | } |
||
| 388 | |||
| 389 | |||
| 390 | if ($specialtyId) {
|
||
| 391 | $tableSpecialtyClassroom = Database::get_main_table('plugin_sepe_specialty_classroom');
|
||
| 392 | $tableCenters = Database::get_main_table('plugin_sepe_centers');
|
||
| 393 | foreach ($specialty->CENTROS_SESIONES_PRESENCIALES->CENTRO_PRESENCIAL as $centroList) {
|
||
| 394 | if (!is_array($centroList)) {
|
||
| 395 | $auxList = array(); |
||
| 396 | $auxList[] = $centroList; |
||
| 397 | $centroList = $auxList; |
||
| 398 | } |
||
| 399 | foreach ($centroList as $centro) {
|
||
| 400 | $centerOrigin = $centro->ORIGEN_CENTRO; |
||
| 401 | $centerCode = $centro->CODIGO_CENTRO; |
||
| 402 | $sql = "SELECT id FROM $tableCenters WHERE center_origin='".$centerOrigin."' AND center_code='".$centerCode."';"; |
||
| 403 | $res = Database::query($sql); |
||
| 404 | View Code Duplication | if (Database::num_rows($res)>0) {
|
|
| 405 | $aux_row = Database::fetch_assoc($res); |
||
| 406 | $centerId = $aux_row['id']; |
||
| 407 | } else {
|
||
| 408 | $sql = "INSERT INTO $tableCenters (center_origin, center_code) |
||
| 409 | VALUES ('" . $centerOrigin . "','" . $centerCode . "');";
|
||
| 410 | Database::query($sql); |
||
| 411 | $centerId = Database::insert_id(); |
||
| 412 | } |
||
| 413 | $sql = "INSERT INTO $tableSpecialtyClassroom (specialty_id, center_id) |
||
| 414 | VALUES ('" . $specialtyId . "','" . $centerId . "')";
|
||
| 415 | Database::query($sql); |
||
| 416 | $id = Database::insert_id(); |
||
| 417 | |||
| 418 | View Code Duplication | if (empty($id)) {
|
|
| 419 | return array( |
||
| 420 | "RESPUESTA_OBT_ACCION" => array( |
||
| 421 | "CODIGO_RETORNO" => "-1", |
||
| 422 | "ETIQUETA_ERROR" => "Problema base de datos - insertando centro presenciales", |
||
| 423 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 424 | ) |
||
| 425 | ); |
||
| 426 | } |
||
| 427 | } |
||
| 428 | } |
||
| 429 | |||
| 430 | $tableTutors = Database::get_main_table('plugin_sepe_tutors');
|
||
| 431 | $tableSpecialityTutors = Database::get_main_table('plugin_sepe_specialty_tutors');
|
||
| 432 | |||
| 433 | if (!empty($specialty->TUTORES_FORMADORES)) {
|
||
| 434 | foreach ($specialty->TUTORES_FORMADORES as $tutorList) {
|
||
| 435 | if (!is_array($tutorList)) {
|
||
| 436 | $auxList = array(); |
||
| 437 | $auxList[] = $tutorList; |
||
| 438 | $tutorList = $auxList; |
||
| 439 | } |
||
| 440 | foreach ($tutorList as $tutor) {
|
||
| 441 | $documentType = $tutor->ID_TUTOR->TIPO_DOCUMENTO; |
||
| 442 | $documentNumber = $tutor->ID_TUTOR->NUM_DOCUMENTO; |
||
| 443 | $documentLetter = $tutor->ID_TUTOR->LETRA_NIF; |
||
| 444 | $tutorAccreditation = $tutor->ACREDITACION_TUTOR; |
||
| 445 | $professionalExperience = $tutor->EXPERIENCIA_PROFESIONAL; |
||
| 446 | $teachingCompetence = $tutor->COMPETENCIA_DOCENTE; |
||
| 447 | $experienceTeleforming = $tutor->EXPERIENCIA_MODALIDAD_TELEFORMACION; |
||
| 448 | $trainingTeleforming = $tutor->FORMACION_MODALIDAD_TELEFORMACION; |
||
| 449 | |||
| 450 | /* check tutor not exists */ |
||
| 451 | $sql = "SELECT id FROM $tableTutors WHERE |
||
| 452 | document_type='".$documentType."' AND document_number='".$documentNumber."' AND document_letter='".$documentLetter."';"; |
||
| 453 | $res = Database::query($sql); |
||
| 454 | View Code Duplication | if (Database::num_rows($res)>0) {
|
|
| 455 | $aux_row = Database::fetch_assoc($res); |
||
| 456 | $tutorId = $aux_row['id']; |
||
| 457 | } else {
|
||
| 458 | $sql = "INSERT INTO $tableTutors (document_type, document_number, document_letter) |
||
| 459 | VALUES ('" . $documentType . "','" . $documentNumber . "','" . $documentLetter . "');";
|
||
| 460 | Database::query($sql); |
||
| 461 | $tutorId = Database::insert_id(); |
||
| 462 | } |
||
| 463 | View Code Duplication | if (empty($tutorId)) {
|
|
| 464 | return array( |
||
| 465 | "RESPUESTA_OBT_ACCION" => array( |
||
| 466 | "CODIGO_RETORNO" => "-1", |
||
| 467 | "ETIQUETA_ERROR" => "Problema base de datos - insertando tutores", |
||
| 468 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 469 | ) |
||
| 470 | ); |
||
| 471 | } |
||
| 472 | $sql = "INSERT INTO $tableSpecialityTutors (specialty_id, tutor_id, tutor_accreditation, professional_experience, teaching_competence, experience_teleforming, training_teleforming) |
||
| 473 | VALUES ('" . $specialtyId . "','" . $tutorId . "','" . $tutorAccreditation . "','" . $professionalExperience . "','" . $teachingCompetence . "','" . $experienceTeleforming . "','" . $trainingTeleforming . "');";
|
||
| 474 | Database::query($sql); |
||
| 475 | } |
||
| 476 | } |
||
| 477 | } |
||
| 478 | } |
||
| 479 | } |
||
| 480 | } |
||
| 481 | // DATOS PARTICIPANTES |
||
| 482 | $tableParticipants = Database::get_main_table('plugin_sepe_participants');
|
||
| 483 | $tableTutorsCompany = Database::get_main_table('plugin_sepe_tutors_company');
|
||
| 484 | $participants = $crearAccionInput->ACCION_FORMATIVA->PARTICIPANTES; |
||
| 485 | foreach ($participants as $participantList) {
|
||
| 486 | if (!is_array($participantList)) {
|
||
| 487 | $auxList = array(); |
||
| 488 | $auxList[] = $participantList; |
||
| 489 | $participantList = $auxList; |
||
| 490 | } |
||
| 491 | foreach ($participantList as $participant) {
|
||
| 492 | $documentType = $participant->ID_PARTICIPANTE->TIPO_DOCUMENTO; |
||
| 493 | $documentNumber = $participant->ID_PARTICIPANTE->NUM_DOCUMENTO; |
||
| 494 | $documentLetter = $participant->ID_PARTICIPANTE->LETRA_NIF; |
||
| 495 | $keyCompetence = $participant->INDICADOR_COMPETENCIAS_CLAVE; |
||
| 496 | $contractId = null; |
||
| 497 | $companyFiscalNumber = null; |
||
| 498 | $documentTypeCompany = null; |
||
| 499 | $documentNumberCompany = null; |
||
| 500 | $documentLetterCompany = null; |
||
| 501 | $documentTypeTraining = null; |
||
| 502 | $documentNumberTraining = null; |
||
| 503 | $documentLetterTraining = null; |
||
| 504 | $tutorIdCompany = null; |
||
| 505 | $tutorIdTraining = null; |
||
| 506 | |||
| 507 | if (isset($participant->CONTRATO_FORMACION)) {
|
||
| 508 | $contractId = isset($participant->CONTRATO_FORMACION->ID_CONTRATO_CFA) ? $participant->CONTRATO_FORMACION->ID_CONTRATO_CFA : null; |
||
| 509 | $companyFiscalNumber = isset($participant->CONTRATO_FORMACION->CIF_EMPRESA) ? $participant->CONTRATO_FORMACION->CIF_EMPRESA : null; |
||
| 510 | $documentTypeCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO : null; |
||
| 511 | $documentNumberCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO : null; |
||
| 512 | $documentLetterCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF : null; |
||
| 513 | View Code Duplication | if (!empty($documentTypeCompany) || !empty($documentNumberCompany) || !empty($documentLetterCompany)) {
|
|
| 514 | $tmp_e = Database::query('SELECT id FROM '.$tableTutorsCompany.' WHERE document_type="'.$documentTypeCompany.'" AND document_number="'.$documentNumberCompany.'" AND document_letter="'.$documentLetterCompany.'";');
|
||
| 515 | if (Database::num_rows($tmp_e)>0) {
|
||
| 516 | $row_tmp = Database::fetch_assoc($tmp_e); |
||
| 517 | $tutorIdCompany = $row_tmp['id']; |
||
| 518 | Database::query("UPDATE $tableTutorsCompany SET company='1' WHERE id='".$tutorIdCompany."'");
|
||
| 519 | } else {
|
||
| 520 | $params_tmp = array( |
||
| 521 | 'document_type' => $documentTypeCompany, |
||
| 522 | 'document_number' => $documentNumberCompany, |
||
| 523 | 'document_letter' => $documentLetterCompany, |
||
| 524 | 'company' => '1' |
||
| 525 | ); |
||
| 526 | $tutorIdCompany = Database::insert($tableTutorsCompany, $params_tmp); |
||
| 527 | } |
||
| 528 | } |
||
| 529 | |||
| 530 | $documentTypeTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO : null; |
||
| 531 | $documentNumberTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO : null; |
||
| 532 | $documentLetterTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF : null; |
||
| 533 | View Code Duplication | if (!empty($documentTypeTraining) || !empty($documentNumberTraining) || !empty($documentLetterTraining)) {
|
|
| 534 | $tmp_f = Database::query('SELECT id FROM '.$tableTutorsCompany.' WHERE document_type="'.$documentTypeTraining.'" AND document_number="'.$documentNumberTraining.'" AND document_letter="'.$documentLetterTraining.'";');
|
||
| 535 | if (Database::num_rows($tmp_f)>0) {
|
||
| 536 | $row_tmp = Database::fetch_assoc($tmp_f); |
||
| 537 | $tutorIdTraining = $row_tmp['id']; |
||
| 538 | Database::query("UPDATE $tableTutorsCompany SET training='1' WHERE id='".$tutorIdTraining."'");
|
||
| 539 | } else {
|
||
| 540 | $params_tmp = array( |
||
| 541 | 'document_type' => $documentTypeTraining, |
||
| 542 | 'document_number' => $documentNumberTraining, |
||
| 543 | 'document_letter' => $documentLetterTraining, |
||
| 544 | 'training' => '1' |
||
| 545 | ); |
||
| 546 | $tutorIdTraining = Database::insert($tableTutorsCompany, $params_tmp); |
||
| 547 | } |
||
| 548 | } |
||
| 549 | } |
||
| 550 | |||
| 551 | $params = array( |
||
| 552 | 'action_id' => $actionId, |
||
| 553 | 'document_type' => $documentType, |
||
| 554 | 'document_number' => $documentNumber, |
||
| 555 | 'document_letter' => $documentLetter, |
||
| 556 | 'key_competence' => $keyCompetence, |
||
| 557 | 'contract_id' => $contractId, |
||
| 558 | 'company_fiscal_number' => $companyFiscalNumber, |
||
| 559 | 'company_tutor_id' => $tutorIdCompany, |
||
| 560 | 'training_tutor_id' => $tutorIdTraining |
||
| 561 | ); |
||
| 562 | $participantId = Database::insert($tableParticipants, $params); |
||
| 563 | View Code Duplication | if (empty($participantId)) {
|
|
| 564 | return array( |
||
| 565 | "RESPUESTA_OBT_ACCION" => array( |
||
| 566 | "CODIGO_RETORNO" => "-1", |
||
| 567 | "ETIQUETA_ERROR" => "Problema base de datos - insertando participantes", |
||
| 568 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 569 | ) |
||
| 570 | ); |
||
| 571 | } |
||
| 572 | |||
| 573 | $participantId = Database::insert_id(); |
||
| 574 | |||
| 575 | foreach ($participant->ESPECIALIDADES_PARTICIPANTE as $valueList) {
|
||
| 576 | if (!is_array($participantList)) {
|
||
| 577 | $auxList = array(); |
||
| 578 | $auxList[] = $valueList; |
||
| 579 | $valueList = $auxList; |
||
| 580 | } |
||
| 581 | foreach ($valueList as $value) {
|
||
| 582 | $specialtyOrigin = null; |
||
| 583 | $professionalArea = null; |
||
| 584 | $specialtyCode = null; |
||
| 585 | |||
| 586 | if (isset($value->ID_ESPECIALIDAD)) {
|
||
| 587 | $specialtyOrigin = $value->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD; |
||
| 588 | $professionalArea = $value->ID_ESPECIALIDAD->AREA_PROFESIONAL; |
||
| 589 | $specialtyCode = $value->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD; |
||
| 590 | } |
||
| 591 | |||
| 592 | $registrationDate = $value->FECHA_ALTA; |
||
| 593 | $leavingDate = $value->FECHA_BAJA; |
||
| 594 | |||
| 595 | $centerOrigin = null; |
||
| 596 | $centerCode = null; |
||
| 597 | $startDate = null; |
||
| 598 | $endDate = null; |
||
| 599 | |||
| 600 | if (!empty($value->EVALUACION_FINAL)) {
|
||
| 601 | $startDate = isset($value->EVALUACION_FINAL->FECHA_INICIO) ? $value->EVALUACION_FINAL->FECHA_INICIO : null; |
||
| 602 | $endDate = isset($value->EVALUACION_FINAL->FECHA_FIN) ? $value->EVALUACION_FINAL->FECHA_FIN : null; |
||
| 603 | if (!empty($value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION)) {
|
||
| 604 | $centerOrigin = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->ORIGEN_CENTRO; |
||
| 605 | $centerCode = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->CODIGO_CENTRO; |
||
| 606 | } |
||
| 607 | } |
||
| 608 | |||
| 609 | $finalResult = null; |
||
| 610 | $finalQualification = null; |
||
| 611 | $finalScore = null; |
||
| 612 | |||
| 613 | if (isset($value->RESULTADOS)) {
|
||
| 614 | $finalResult = isset($value->RESULTADOS->RESULTADO_FINAL) ? $value->RESULTADOS->RESULTADO_FINAL : null; |
||
| 615 | $finalQualification = isset($value->RESULTADOS->CALIFICACION_FINAL) ? $value->RESULTADOS->CALIFICACION_FINAL : null; |
||
| 616 | $finalScore = isset($value->RESULTADOS->PUNTUACION_FINAL) ? $value->RESULTADOS->PUNTUACION_FINAL : null; |
||
| 617 | } |
||
| 618 | |||
| 619 | $registrationDate = self::fixDate($registrationDate); |
||
| 620 | $leavingDate = self::fixDate($leavingDate); |
||
| 621 | |||
| 622 | $startDate = self::fixDate($startDate); |
||
| 623 | $endDate = self::fixDate($endDate); |
||
| 624 | |||
| 625 | $table_aux = Database::get_main_table('plugin_sepe_participants_specialty');
|
||
| 626 | $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) |
||
| 627 | VALUES ('" . $participantId . "','" . $specialtyOrigin . "','" . $professionalArea . "','" . $specialtyCode . "','" . $registrationDate . "','" . $leavingDate . "','" . $centerOrigin . "','" . $centerCode . "','" . $startDate . "','" . $endDate . "','" . $finalResult . "','" . $finalQualification . "','" . $finalScore . "');";
|
||
| 628 | Database::query($sql); |
||
| 629 | $participantSpecialtyId = Database::insert_id(); |
||
| 630 | View Code Duplication | if (empty($participantSpecialtyId)) {
|
|
| 631 | return array( |
||
| 632 | "RESPUESTA_OBT_ACCION" => array( |
||
| 633 | "CODIGO_RETORNO" => "-1", |
||
| 634 | "ETIQUETA_ERROR" => "Problema base de datos - insertando especialidad participante", |
||
| 635 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 636 | ) |
||
| 637 | ); |
||
| 638 | } |
||
| 639 | |||
| 640 | foreach ($value->TUTORIAS_PRESENCIALES as $tutorialList) {
|
||
| 641 | if (!is_array($tutorialList)) {
|
||
| 642 | $auxList = array(); |
||
| 643 | $auxList[] = $tutorialList; |
||
| 644 | $tutorialList = $auxList; |
||
| 645 | } |
||
| 646 | foreach ($tutorialList as $tutorial) {
|
||
| 647 | $centerOrigin = $tutorial->CENTRO_PRESENCIAL_TUTORIA->ORIGEN_CENTRO; |
||
| 648 | $centerCode = $tutorial->CENTRO_PRESENCIAL_TUTORIA->CODIGO_CENTRO; |
||
| 649 | $startDate = $tutorial->FECHA_INICIO; |
||
| 650 | $endDate = $tutorial->FECHA_FIN; |
||
| 651 | |||
| 652 | $startDate = self::fixDate($startDate); |
||
| 653 | $endDate = self::fixDate($endDate); |
||
| 654 | |||
| 655 | $table_aux2 = Database::get_main_table('plugin_sepe_participants_specialty_tutorials');
|
||
| 656 | $sql = "INSERT INTO $table_aux2 (participant_specialty_id,center_origin,center_code,start_date,end_date) |
||
| 657 | VALUES ('" . $participantSpecialtyId . "','" . $centerOrigin . "','" . $centerCode . "','" . $startDate . "','" . $endDate . "');";
|
||
| 658 | $rs = Database::query($sql); |
||
| 659 | View Code Duplication | if (!$rs) {
|
|
| 660 | return array( |
||
| 661 | "RESPUESTA_OBT_ACCION" => array( |
||
| 662 | "CODIGO_RETORNO" => "-1", |
||
| 663 | "ETIQUETA_ERROR" => "Problema base de datos - insertando tutorias presenciales participante", |
||
| 664 | "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'] |
||
| 665 | ) |
||
| 666 | ); |
||
| 667 | } |
||
| 668 | } |
||
| 669 | } |
||
| 670 | } |
||
| 671 | } |
||
| 672 | } |
||
| 673 | } |
||
| 674 | |||
| 675 | $obtenerAccionInput = new stdClass(); |
||
| 676 | $obtenerAccionInput->ID_ACCION = new stdClass(); |
||
| 677 | $obtenerAccionInput->ID_ACCION->ORIGEN_ACCION = $actionOrigin; |
||
| 678 | $obtenerAccionInput->ID_ACCION->CODIGO_ACCION = $actionCode; |
||
| 679 | |||
| 680 | $result = self::obtenerAccion($obtenerAccionInput); |
||
| 681 | return $result; |
||
| 682 | } |
||
| 683 | |||
| 684 | public function obtenerAccion($obtenerAccionInput) |
||
| 1079 | |||
| 1080 | public function obtenerListaAcciones() |
||
| 1130 | |||
| 1131 | public function eliminarAccion($eliminarAccionInput) |
||
| 1176 | |||
| 1177 | // yyyy-mm-dd to dd/mm/yyyy |
||
| 1178 | View Code Duplication | public static function undoFixDate($date) |
|
| 1189 | |||
| 1190 | // dd/mm/yyyy to yyyy-mm-dd |
||
| 1191 | View Code Duplication | public static function fixDate($date) |
|
| 1202 | |||
| 1203 | protected function checkAuth() |
||
| 1210 | } |
||
| 1211 |
This method has been deprecated.