Sepe.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. <?php
  2. /**
  3. * Class Sepe
  4. */
  5. class Sepe
  6. {
  7. /**
  8. * @param crearCentroInput[] $crearCentroInput
  9. *
  10. * @return array
  11. */
  12. public function crearCentro($crearCentroInput)
  13. {
  14. /* Tracking log */
  15. $tableLog = Database::get_main_table('plugin_sepe_log');
  16. $paramsLog = array(
  17. 'ip' => $_SERVER['REMOTE_ADDR'],
  18. 'action' => "crearCentro",
  19. 'fecha' => date("Y-m-d H:i:s")
  20. );
  21. Database::insert($tableLog, $paramsLog);
  22. /* End tracking log */
  23. // Code
  24. $crearCentroInput = $crearCentroInput->DATOS_IDENTIFICATIVOS;
  25. $centerOrigin = $crearCentroInput->ID_CENTRO->ORIGEN_CENTRO;
  26. $centerCode = $crearCentroInput->ID_CENTRO->CODIGO_CENTRO;
  27. $centerName = $crearCentroInput->NOMBRE_CENTRO;
  28. $urlPlatform = $crearCentroInput->URL_PLATAFORMA;
  29. $urlTracking = $crearCentroInput->URL_SEGUIMIENTO;
  30. $phone = $crearCentroInput->TELEFONO;
  31. $mail = $crearCentroInput->EMAIL;
  32. if (empty($centerOrigin) ||
  33. empty($centerCode) ||
  34. empty($centerName) ||
  35. empty($urlPlatform) ||
  36. empty($urlTracking) ||
  37. empty($phone) ||
  38. empty($mail)
  39. ) {
  40. error_log('no data');
  41. return array(
  42. "RESPUESTA_DATOS_CENTRO" => array(
  43. "CODIGO_RETORNO" => "2",
  44. "ETIQUETA_ERROR" => "Error en parametro",
  45. "DATOS_IDENTIFICATIVOS" => $crearCentroInput
  46. )
  47. );
  48. }
  49. $table = Database::get_main_table('plugin_sepe_center');
  50. // Check if exists data in table
  51. if (Database::count_rows($table) > 0) {
  52. // Check if exists actions
  53. $table_actions = Database::get_main_table('plugin_sepe_actions');
  54. if (Database::count_rows($table_actions) > 0) {
  55. return array(
  56. "RESPUESTA_DATOS_CENTRO" => array(
  57. "CODIGO_RETORNO" => "1",
  58. "ETIQUETA_ERROR" => "Centro con acciones",
  59. "DATOS_IDENTIFICATIVOS" => $crearCentroInput
  60. )
  61. );
  62. } else {
  63. $sql = "DELETE FROM $table";
  64. Database::query($sql);
  65. }
  66. }
  67. $params = array(
  68. 'center_origin' => $centerOrigin,
  69. 'center_code' => $centerCode,
  70. 'center_name' => $centerName,
  71. 'url' => $urlPlatform,
  72. 'tracking_url' => $urlTracking,
  73. 'phone' => $phone,
  74. 'mail' => $mail,
  75. );
  76. $id = Database::insert($table, $params);
  77. if (empty($id)) {
  78. return array(
  79. "RESPUESTA_DATOS_CENTRO" => array(
  80. "CODIGO_RETORNO" => "-1",
  81. "ETIQUETA_ERROR" => "Problema base de datos",
  82. "DATOS_IDENTIFICATIVOS" => $crearCentroInput
  83. )
  84. );
  85. } else {
  86. return array(
  87. "RESPUESTA_DATOS_CENTRO" => array(
  88. "CODIGO_RETORNO" => "0",
  89. "ETIQUETA_ERROR" => "Correcto",
  90. "DATOS_IDENTIFICATIVOS" => $crearCentroInput
  91. )
  92. );
  93. }
  94. }
  95. /**
  96. *
  97. * @return array
  98. */
  99. public function obtenerDatosCentro()
  100. {
  101. /* Tracking Log */
  102. $tableLog = Database::get_main_table('plugin_sepe_log');
  103. $paramsLog = array(
  104. 'ip' => $_SERVER['REMOTE_ADDR'],
  105. 'action' => "obtenerDatosCentro",
  106. 'fecha' => date("Y-m-d H:i:s")
  107. );
  108. Database::insert($tableLog, $paramsLog);
  109. /* End tracking log */
  110. // Code
  111. $table = Database::get_main_table('plugin_sepe_center');
  112. // Comprobamos si existen datos almacenados previamente
  113. if (Database::count_rows($table) > 0) {
  114. //Hay datos en la tabla;
  115. $sql = "SELECT * FROM $table;";
  116. $rs = Database::query($sql);
  117. if (!$rs) {
  118. return array(
  119. "CODIGO_RETORNO" => "-1",
  120. "ETIQUETA_ERROR" => "Problema acceso base de datos",
  121. "DATOS_IDENTIFICATIVOS" => ''
  122. );
  123. } else {
  124. $row = Database::fetch_assoc($rs);
  125. $centerOrigin = $row['center_origin'];
  126. $centerCode = $row['center_code'];
  127. $centerName = $row['center_name'];
  128. $urlPlatform = $row['url'];
  129. $urlTracking = $row['tracking_url'];
  130. $phone = $row['phone'];
  131. $mail = $row['mail'];
  132. $data = new stdClass();
  133. $data->ID_CENTRO = new stdClass();
  134. $data->ID_CENTRO->ORIGEN_CENTRO = $centerOrigin;
  135. $data->ID_CENTRO->CODIGO_CENTRO = $centerCode;
  136. $data->NOMBRE_CENTRO = $centerName;
  137. $data->URL_PLATAFORMA = $urlPlatform;
  138. $data->URL_SEGUIMIENTO = $urlTracking;
  139. $data->TELEFONO = $phone;
  140. $data->EMAIL = $mail;
  141. $obj = new stdClass();
  142. $obj->CODIGO_RETORNO = 0;
  143. $obj->ETIQUETA_ERROR = 'Correcto';
  144. $obj->DATOS_IDENTIFICATIVOS = new SoapVar($data, SOAP_ENC_OBJECT);
  145. $result = new stdClass();
  146. $result->RESPUESTA_DATOS_CENTRO = new SoapVar($obj, SOAP_ENC_OBJECT);
  147. return $result;
  148. }
  149. } else {
  150. $data = new stdClass();
  151. $data->ID_CENTRO = new stdClass();
  152. $data->ID_CENTRO->ORIGEN_CENTRO = '';
  153. $data->ID_CENTRO->CODIGO_CENTRO = '';
  154. $data->NOMBRE_CENTRO = '';
  155. $data->URL_PLATAFORMA = '';
  156. $data->URL_SEGUIMIENTO = '';
  157. $data->TELEFONO = '';
  158. $data->EMAIL = '';
  159. $obj = new stdClass();
  160. $obj->CODIGO_RETORNO = 0;
  161. $obj->ETIQUETA_ERROR = 'Correcto';
  162. $obj->DATOS_IDENTIFICATIVOS = new SoapVar($data, SOAP_ENC_OBJECT);
  163. $result = new stdClass();
  164. $result->RESPUESTA_DATOS_CENTRO = new SoapVar($obj, SOAP_ENC_OBJECT);
  165. //error_log('Sin datos en la BD');
  166. /*
  167. $data = new stdClass();
  168. $obj = new stdClass();
  169. $obj->CODIGO_RETORNO = '-1';
  170. $obj->ETIQUETA_ERROR = 'Sin datos';
  171. $obj->DATOS_IDENTIFICATIVOS = new SoapVar($data, SOAP_ENC_OBJECT);
  172. $result = new stdClass();
  173. $result->RESPUESTA_DATOS_CENTRO = new SoapVar($obj, SOAP_ENC_OBJECT);
  174. */
  175. return $result;
  176. }
  177. }
  178. /**
  179. * @param $crearAccionInput
  180. * @return array
  181. */
  182. public function crearAccion($crearAccionInput)
  183. {
  184. /* Tracking Log */
  185. $tableLog = Database::get_main_table('plugin_sepe_log');
  186. $paramsLog = array(
  187. 'ip' => $_SERVER['REMOTE_ADDR'],
  188. 'action' => "crearAccion",
  189. 'fecha' => date("Y-m-d H:i:s")
  190. );
  191. Database::insert($tableLog, $paramsLog);
  192. /* End tracking log */
  193. $array = json_decode(json_encode($crearAccionInput), true);
  194. $crearAccionInputArray = (array) $array;
  195. // Code
  196. $actionOrigin = $crearAccionInput->ACCION_FORMATIVA->ID_ACCION->ORIGEN_ACCION;
  197. $actionCode = $crearAccionInput->ACCION_FORMATIVA->ID_ACCION->CODIGO_ACCION;
  198. $situation = $crearAccionInput->ACCION_FORMATIVA->SITUACION;
  199. $specialtyOrigin = $crearAccionInput->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL->ORIGEN_ESPECIALIDAD;
  200. $professionalArea = $crearAccionInput->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL->AREA_PROFESIONAL;
  201. $specialtyCode = $crearAccionInput->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL->CODIGO_ESPECIALIDAD;
  202. $duration = $crearAccionInput->ACCION_FORMATIVA->DURACION;
  203. $startDate = $crearAccionInput->ACCION_FORMATIVA->FECHA_INICIO;
  204. $endDate = $crearAccionInput->ACCION_FORMATIVA->FECHA_FIN;
  205. $fullItineraryIndicator = $crearAccionInput->ACCION_FORMATIVA->IND_ITINERARIO_COMPLETO;
  206. $financingType = $crearAccionInput->ACCION_FORMATIVA->TIPO_FINANCIACION;
  207. $attendeesCount = $crearAccionInput->ACCION_FORMATIVA->NUMERO_ASISTENTES;
  208. $actionName = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->DENOMINACION_ACCION;
  209. $globalInfo = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->INFORMACION_GENERAL;
  210. $schedule = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->HORARIOS;
  211. $requerements = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->REQUISITOS;
  212. $contactAction = $crearAccionInput->ACCION_FORMATIVA->DESCRIPCION_ACCION->CONTACTO_ACCION;
  213. if (empty($actionOrigin) || empty($actionCode)) {
  214. error_log('2 - error en parametros - l244');
  215. return array(
  216. "RESPUESTA_OBT_ACCION" => array(
  217. "CODIGO_RETORNO"=>"2",
  218. "ETIQUETA_ERROR"=>"Error en parametro",
  219. "ACCION_FORMATIVA"=> $crearAccionInputArray['ACCION_FORMATIVA']
  220. )
  221. );
  222. }
  223. // Comprobamos si existen datos almacenados previamente
  224. $table = Database::get_main_table('plugin_sepe_actions');
  225. $sql = "SELECT action_origin FROM $table
  226. WHERE action_origin='".$actionOrigin."' AND action_code='".$actionCode."';";
  227. $rs = Database::query($sql);
  228. if (Database::num_rows($rs) > 0) {
  229. return array(
  230. "RESPUESTA_OBT_ACCION" => array(
  231. "CODIGO_RETORNO"=>"1",
  232. "ETIQUETA_ERROR"=>"Acción existente",
  233. "ACCION_FORMATIVA"=>$crearAccionInputArray['ACCION_FORMATIVA']
  234. )
  235. );
  236. }
  237. $startDate = self::fixDate($startDate);
  238. $endDate = self::fixDate($endDate);
  239. $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)
  240. VALUES ('".$actionOrigin."','".$actionCode."','".$situation."','".$specialtyOrigin."','".$professionalArea."','".$specialtyCode."','".$duration."','".$startDate."','".$endDate."','".$fullItineraryIndicator."','".$financingType."','".$attendeesCount."','".$actionName."','".$globalInfo."','".$schedule."','".$requerements."','".$contactAction."')";
  241. $rs = Database::query($sql);
  242. if (!$rs) {
  243. return array(
  244. "RESPUESTA_OBT_ACCION" => array(
  245. "CODIGO_RETORNO"=>"-1",
  246. "ETIQUETA_ERROR"=>"Problema base de datos - insertando acciones formativas",
  247. "ACCION_FORMATIVA"=>$crearAccionInputArray['ACCION_FORMATIVA']
  248. )
  249. );
  250. }
  251. $actionId = Database::insert_id();
  252. // DATOS ESPECIALIDADES DE LA ACCION
  253. $table = Database::get_main_table('plugin_sepe_specialty');
  254. $specialties = $crearAccionInput->ACCION_FORMATIVA->ESPECIALIDADES_ACCION;
  255. foreach ($specialties as $specialtyList) {
  256. if (!is_array($specialtyList)) {
  257. $auxList = array();
  258. $auxList[] = $specialtyList;
  259. $specialtyList = $auxList;
  260. }
  261. foreach ($specialtyList as $specialty) {
  262. $specialtyOrigin = $specialty->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD;
  263. $professionalArea = $specialty->ID_ESPECIALIDAD->AREA_PROFESIONAL;
  264. $specialtyCode = $specialty->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD;
  265. $centerOrigin = $specialty->CENTRO_IMPARTICION->ORIGEN_CENTRO;
  266. $centerCode = $specialty->CENTRO_IMPARTICION->CODIGO_CENTRO;
  267. $startDate = $specialty->FECHA_INICIO;
  268. $endDate = $specialty->FECHA_FIN;
  269. $modalityImpartition = $specialty->MODALIDAD_IMPARTICION;
  270. $classroomHours = $specialty->DATOS_DURACION->HORAS_PRESENCIAL;
  271. $distanceHours = $specialty->DATOS_DURACION->HORAS_TELEFORMACION;
  272. $morningParticipansNumber = null;
  273. $morningAccessNumber = null;
  274. $morningTotalDuration = null;
  275. if (isset($specialty->USO->HORARIO_MANANA)) {
  276. $morningParticipansNumber = $specialty->USO->HORARIO_MANANA->NUM_PARTICIPANTES;
  277. $morningAccessNumber = $specialty->USO->HORARIO_MANANA->NUMERO_ACCESOS;
  278. $morningTotalDuration = $specialty->USO->HORARIO_MANANA->DURACION_TOTAL;
  279. }
  280. $afternoonParticipantNumber = null;
  281. $afternoonAccessNumber = null;
  282. $afternoonTotalDuration = null;
  283. if (isset($specialty->USO->HORARIO_TARDE)) {
  284. $afternoonParticipantNumber = $specialty->USO->HORARIO_TARDE->NUM_PARTICIPANTES;
  285. $afternoonAccessNumber = $specialty->USO->HORARIO_TARDE->NUMERO_ACCESOS;
  286. $afternoonTotalDuration = $specialty->USO->HORARIO_TARDE->DURACION_TOTAL;
  287. }
  288. $nightParticipantsNumber = null;
  289. $nightAccessNumber = null;
  290. $nightTotalDuration = null;
  291. if (isset($specialty->USO->HORARIO_NOCHE)) {
  292. $nightParticipantsNumber = $specialty->USO->HORARIO_NOCHE->NUM_PARTICIPANTES;
  293. $nightAccessNumber = $specialty->USO->HORARIO_NOCHE->NUMERO_ACCESOS;
  294. $nightTotalDuration = $specialty->USO->HORARIO_NOCHE->DURACION_TOTAL;
  295. }
  296. $attendeesCount = null;
  297. $learningActivityCount = null;
  298. $attemptCount = null;
  299. $evaluationActivityCount = null;
  300. if (isset($specialty->USO->SEGUIMIENTO_EVALUACION)) {
  301. $attendeesCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUM_PARTICIPANTES;
  302. $learningActivityCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_APRENDIZAJE;
  303. $attemptCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_INTENTOS;
  304. $evaluationActivityCount = $specialty->USO->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_EVALUACION;
  305. }
  306. $startDate = self::fixDate($startDate);
  307. $endDate = self::fixDate($endDate);
  308. $params = array(
  309. 'action_id' => $actionId,
  310. 'specialty_origin' => $specialtyOrigin,
  311. 'professional_area' => $professionalArea,
  312. 'specialty_code' =>$specialtyCode ,
  313. 'center_origin' => $centerOrigin,
  314. 'center_code' => $centerCode,
  315. 'start_date' => $startDate ,
  316. 'end_date' => $endDate,
  317. 'modality_impartition' => $modalityImpartition,
  318. 'classroom_hours' => $classroomHours,
  319. 'distance_hours' => $distanceHours,
  320. 'mornings_participants_number' => $morningParticipansNumber,
  321. 'mornings_access_number' => $morningAccessNumber,
  322. 'morning_total_duration' => $morningTotalDuration,
  323. 'afternoon_participants_number' => $afternoonParticipantNumber,
  324. 'afternoon_access_number' => $afternoonAccessNumber,
  325. 'afternoon_total_duration' => $afternoonTotalDuration,
  326. 'night_participants_number' => $nightParticipantsNumber,
  327. 'night_access_number' => $nightAccessNumber,
  328. 'night_total_duration' => $nightTotalDuration,
  329. 'attendees_count' => $attendeesCount,
  330. 'learning_activity_count' => $learningActivityCount ,
  331. 'attempt_count' => $attemptCount,
  332. 'evaluation_activity_count' => $evaluationActivityCount
  333. );
  334. $specialtyId = Database::insert($table, $params);
  335. if (empty($specialtyId)) {
  336. return array(
  337. "RESPUESTA_OBT_ACCION" => array(
  338. "CODIGO_RETORNO" => "-1",
  339. "ETIQUETA_ERROR" => "Problema base de datos - insertando datos de especialidad de la accion",
  340. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA']
  341. )
  342. );
  343. }
  344. if ($specialtyId) {
  345. $tableSpecialtyClassroom = Database::get_main_table('plugin_sepe_specialty_classroom');
  346. $tableCenters = Database::get_main_table('plugin_sepe_centers');
  347. foreach ($specialty->CENTROS_SESIONES_PRESENCIALES->CENTRO_PRESENCIAL as $centroList) {
  348. if (!is_array($centroList)) {
  349. $auxList = array();
  350. $auxList[] = $centroList;
  351. $centroList = $auxList;
  352. }
  353. foreach ($centroList as $centro) {
  354. $centerOrigin = $centro->ORIGEN_CENTRO;
  355. $centerCode = $centro->CODIGO_CENTRO;
  356. $sql = "SELECT id FROM $tableCenters WHERE center_origin='".$centerOrigin."' AND center_code='".$centerCode."';";
  357. $res = Database::query($sql);
  358. if (Database::num_rows($res)>0) {
  359. $aux_row = Database::fetch_assoc($res);
  360. $centerId = $aux_row['id'];
  361. } else {
  362. $sql = "INSERT INTO $tableCenters (center_origin, center_code)
  363. VALUES ('" . $centerOrigin . "','" . $centerCode . "');";
  364. Database::query($sql);
  365. $centerId = Database::insert_id();
  366. }
  367. $sql = "INSERT INTO $tableSpecialtyClassroom (specialty_id, center_id)
  368. VALUES ('" . $specialtyId . "','" . $centerId . "')";
  369. Database::query($sql);
  370. $id = Database::insert_id();
  371. if (empty($id)) {
  372. return array(
  373. "RESPUESTA_OBT_ACCION" => array(
  374. "CODIGO_RETORNO" => "-1",
  375. "ETIQUETA_ERROR" => "Problema base de datos - insertando centro presenciales",
  376. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA']
  377. )
  378. );
  379. }
  380. }
  381. }
  382. $tableTutors = Database::get_main_table('plugin_sepe_tutors');
  383. $tableSpecialityTutors = Database::get_main_table('plugin_sepe_specialty_tutors');
  384. if (!empty($specialty->TUTORES_FORMADORES)) {
  385. foreach ($specialty->TUTORES_FORMADORES as $tutorList) {
  386. if (!is_array($tutorList)) {
  387. $auxList = array();
  388. $auxList[] = $tutorList;
  389. $tutorList = $auxList;
  390. }
  391. foreach ($tutorList as $tutor) {
  392. $documentType = $tutor->ID_TUTOR->TIPO_DOCUMENTO;
  393. $documentNumber = $tutor->ID_TUTOR->NUM_DOCUMENTO;
  394. $documentLetter = $tutor->ID_TUTOR->LETRA_NIF;
  395. $tutorAccreditation = $tutor->ACREDITACION_TUTOR;
  396. $professionalExperience = $tutor->EXPERIENCIA_PROFESIONAL;
  397. $teachingCompetence = $tutor->COMPETENCIA_DOCENTE;
  398. $experienceTeleforming = $tutor->EXPERIENCIA_MODALIDAD_TELEFORMACION;
  399. $trainingTeleforming = $tutor->FORMACION_MODALIDAD_TELEFORMACION;
  400. /* check tutor not exists */
  401. $sql = "SELECT id FROM $tableTutors WHERE
  402. document_type='".$documentType."' AND document_number='".$documentNumber."' AND document_letter='".$documentLetter."';";
  403. $res = Database::query($sql);
  404. if (Database::num_rows($res)>0) {
  405. $aux_row = Database::fetch_assoc($res);
  406. $tutorId = $aux_row['id'];
  407. } else {
  408. $sql = "INSERT INTO $tableTutors (document_type, document_number, document_letter)
  409. VALUES ('" . $documentType . "','" . $documentNumber . "','" . $documentLetter . "');";
  410. Database::query($sql);
  411. $tutorId = Database::insert_id();
  412. }
  413. if (empty($tutorId)) {
  414. return array(
  415. "RESPUESTA_OBT_ACCION" => array(
  416. "CODIGO_RETORNO" => "-1",
  417. "ETIQUETA_ERROR" => "Problema base de datos - insertando tutores",
  418. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA']
  419. )
  420. );
  421. }
  422. $sql = "INSERT INTO $tableSpecialityTutors (specialty_id, tutor_id, tutor_accreditation, professional_experience, teaching_competence, experience_teleforming, training_teleforming)
  423. VALUES ('" . $specialtyId . "','" . $tutorId . "','" . $tutorAccreditation . "','" . $professionalExperience . "','" . $teachingCompetence . "','" . $experienceTeleforming . "','" . $trainingTeleforming . "');";
  424. Database::query($sql);
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. // DATOS PARTICIPANTES
  432. $tableParticipants = Database::get_main_table('plugin_sepe_participants');
  433. $tableTutorsCompany = Database::get_main_table('plugin_sepe_tutors_company');
  434. $participants = $crearAccionInput->ACCION_FORMATIVA->PARTICIPANTES;
  435. foreach ($participants as $participantList) {
  436. if (!is_array($participantList)) {
  437. $auxList = array();
  438. $auxList[] = $participantList;
  439. $participantList = $auxList;
  440. }
  441. foreach ($participantList as $participant) {
  442. $documentType = $participant->ID_PARTICIPANTE->TIPO_DOCUMENTO;
  443. $documentNumber = $participant->ID_PARTICIPANTE->NUM_DOCUMENTO;
  444. $documentLetter = $participant->ID_PARTICIPANTE->LETRA_NIF;
  445. $keyCompetence = $participant->INDICADOR_COMPETENCIAS_CLAVE;
  446. $contractId = null;
  447. $companyFiscalNumber = null;
  448. $documentTypeCompany = null;
  449. $documentNumberCompany = null;
  450. $documentLetterCompany = null;
  451. $documentTypeTraining = null;
  452. $documentNumberTraining = null;
  453. $documentLetterTraining = null;
  454. $tutorIdCompany = null;
  455. $tutorIdTraining = null;
  456. if (isset($participant->CONTRATO_FORMACION)) {
  457. $contractId = isset($participant->CONTRATO_FORMACION->ID_CONTRATO_CFA) ? $participant->CONTRATO_FORMACION->ID_CONTRATO_CFA : null;
  458. $companyFiscalNumber = isset($participant->CONTRATO_FORMACION->CIF_EMPRESA) ? $participant->CONTRATO_FORMACION->CIF_EMPRESA : null;
  459. $documentTypeCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO : null;
  460. $documentNumberCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO : null;
  461. $documentLetterCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF : null;
  462. if (!empty($documentTypeCompany) || !empty($documentNumberCompany) || !empty($documentLetterCompany)) {
  463. $tmp_e = Database::query('SELECT id FROM '.$tableTutorsCompany.' WHERE document_type="'.$documentTypeCompany.'" AND document_number="'.$documentNumberCompany.'" AND document_letter="'.$documentLetterCompany.'";');
  464. if (Database::num_rows($tmp_e)>0) {
  465. $row_tmp = Database::fetch_assoc($tmp_e);
  466. $tutorIdCompany = $row_tmp['id'];
  467. Database::query("UPDATE $tableTutorsCompany SET company='1' WHERE id='".$tutorIdCompany."'");
  468. } else {
  469. $params_tmp = array(
  470. 'document_type' => $documentTypeCompany,
  471. 'document_number' => $documentNumberCompany,
  472. 'document_letter' => $documentLetterCompany,
  473. 'company' => '1'
  474. );
  475. $tutorIdCompany = Database::insert($tableTutorsCompany, $params_tmp);
  476. }
  477. }
  478. $documentTypeTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO : null;
  479. $documentNumberTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO : null;
  480. $documentLetterTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF : null;
  481. if (!empty($documentTypeTraining) || !empty($documentNumberTraining) || !empty($documentLetterTraining)) {
  482. $tmp_f = Database::query('SELECT id FROM '.$tableTutorsCompany.' WHERE document_type="'.$documentTypeTraining.'" AND document_number="'.$documentNumberTraining.'" AND document_letter="'.$documentLetterTraining.'";');
  483. if (Database::num_rows($tmp_f)>0) {
  484. $row_tmp = Database::fetch_assoc($tmp_f);
  485. $tutorIdTraining = $row_tmp['id'];
  486. Database::query("UPDATE $tableTutorsCompany SET training='1' WHERE id='".$tutorIdTraining."'");
  487. } else {
  488. $params_tmp = array(
  489. 'document_type' => $documentTypeTraining,
  490. 'document_number' => $documentNumberTraining,
  491. 'document_letter' => $documentLetterTraining,
  492. 'training' => '1'
  493. );
  494. $tutorIdTraining = Database::insert($tableTutorsCompany, $params_tmp);
  495. }
  496. }
  497. }
  498. $params = array(
  499. 'action_id' => $actionId,
  500. 'document_type' => $documentType,
  501. 'document_number' => $documentNumber,
  502. 'document_letter' => $documentLetter,
  503. 'key_competence' => $keyCompetence,
  504. 'contract_id' => $contractId,
  505. 'company_fiscal_number' => $companyFiscalNumber,
  506. 'company_tutor_id' => $tutorIdCompany,
  507. 'training_tutor_id' => $tutorIdTraining
  508. );
  509. $participantId = Database::insert($tableParticipants, $params);
  510. if (empty($participantId)) {
  511. return array(
  512. "RESPUESTA_OBT_ACCION" => array(
  513. "CODIGO_RETORNO" => "-1",
  514. "ETIQUETA_ERROR" => "Problema base de datos - insertando participantes",
  515. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA']
  516. )
  517. );
  518. }
  519. $participantId = Database::insert_id();
  520. foreach ($participant->ESPECIALIDADES_PARTICIPANTE as $valueList) {
  521. if (!is_array($participantList)) {
  522. $auxList = array();
  523. $auxList[] = $valueList;
  524. $valueList = $auxList;
  525. }
  526. foreach ($valueList as $value) {
  527. $specialtyOrigin = null;
  528. $professionalArea = null;
  529. $specialtyCode = null;
  530. if (isset($value->ID_ESPECIALIDAD)) {
  531. $specialtyOrigin = $value->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD;
  532. $professionalArea = $value->ID_ESPECIALIDAD->AREA_PROFESIONAL;
  533. $specialtyCode = $value->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD;
  534. }
  535. $registrationDate = $value->FECHA_ALTA;
  536. $leavingDate = $value->FECHA_BAJA;
  537. $centerOrigin = null;
  538. $centerCode = null;
  539. $startDate = null;
  540. $endDate = null;
  541. if (!empty($value->EVALUACION_FINAL)) {
  542. $startDate = isset($value->EVALUACION_FINAL->FECHA_INICIO) ? $value->EVALUACION_FINAL->FECHA_INICIO : null;
  543. $endDate = isset($value->EVALUACION_FINAL->FECHA_FIN) ? $value->EVALUACION_FINAL->FECHA_FIN : null;
  544. if (!empty($value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION)) {
  545. $centerOrigin = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->ORIGEN_CENTRO;
  546. $centerCode = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->CODIGO_CENTRO;
  547. }
  548. }
  549. $finalResult = null;
  550. $finalQualification = null;
  551. $finalScore = null;
  552. if (isset($value->RESULTADOS)) {
  553. $finalResult = isset($value->RESULTADOS->RESULTADO_FINAL) ? $value->RESULTADOS->RESULTADO_FINAL : null;
  554. $finalQualification = isset($value->RESULTADOS->CALIFICACION_FINAL) ? $value->RESULTADOS->CALIFICACION_FINAL : null;
  555. $finalScore = isset($value->RESULTADOS->PUNTUACION_FINAL) ? $value->RESULTADOS->PUNTUACION_FINAL : null;
  556. }
  557. $registrationDate = self::fixDate($registrationDate);
  558. $leavingDate = self::fixDate($leavingDate);
  559. $startDate = self::fixDate($startDate);
  560. $endDate = self::fixDate($endDate);
  561. $table_aux = Database::get_main_table('plugin_sepe_participants_specialty');
  562. $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)
  563. VALUES ('" . $participantId . "','" . $specialtyOrigin . "','" . $professionalArea . "','" . $specialtyCode . "','" . $registrationDate . "','" . $leavingDate . "','" . $centerOrigin . "','" . $centerCode . "','" . $startDate . "','" . $endDate . "','" . $finalResult . "','" . $finalQualification . "','" . $finalScore . "');";
  564. Database::query($sql);
  565. $participantSpecialtyId = Database::insert_id();
  566. if (empty($participantSpecialtyId)) {
  567. return array(
  568. "RESPUESTA_OBT_ACCION" => array(
  569. "CODIGO_RETORNO" => "-1",
  570. "ETIQUETA_ERROR" => "Problema base de datos - insertando especialidad participante",
  571. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA']
  572. )
  573. );
  574. }
  575. foreach ($value->TUTORIAS_PRESENCIALES as $tutorialList) {
  576. if (!is_array($tutorialList)) {
  577. $auxList = array();
  578. $auxList[] = $tutorialList;
  579. $tutorialList = $auxList;
  580. }
  581. foreach ($tutorialList as $tutorial) {
  582. $centerOrigin = $tutorial->CENTRO_PRESENCIAL_TUTORIA->ORIGEN_CENTRO;
  583. $centerCode = $tutorial->CENTRO_PRESENCIAL_TUTORIA->CODIGO_CENTRO;
  584. $startDate = $tutorial->FECHA_INICIO;
  585. $endDate = $tutorial->FECHA_FIN;
  586. $startDate = self::fixDate($startDate);
  587. $endDate = self::fixDate($endDate);
  588. $table_aux2 = Database::get_main_table('plugin_sepe_participants_specialty_tutorials');
  589. $sql = "INSERT INTO $table_aux2 (participant_specialty_id,center_origin,center_code,start_date,end_date)
  590. VALUES ('" . $participantSpecialtyId . "','" . $centerOrigin . "','" . $centerCode . "','" . $startDate . "','" . $endDate . "');";
  591. $rs = Database::query($sql);
  592. if (!$rs) {
  593. return array(
  594. "RESPUESTA_OBT_ACCION" => array(
  595. "CODIGO_RETORNO" => "-1",
  596. "ETIQUETA_ERROR" => "Problema base de datos - insertando tutorias presenciales participante",
  597. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA']
  598. )
  599. );
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }
  607. $obtenerAccionInput = new stdClass();
  608. $obtenerAccionInput->ID_ACCION = new stdClass();
  609. $obtenerAccionInput->ID_ACCION->ORIGEN_ACCION = $actionOrigin;
  610. $obtenerAccionInput->ID_ACCION->CODIGO_ACCION = $actionCode;
  611. $result = self::obtenerAccion($obtenerAccionInput);
  612. return $result;
  613. }
  614. public function obtenerAccion($obtenerAccionInput)
  615. {
  616. /* Tracking Log */
  617. $tableLog = Database::get_main_table('plugin_sepe_log');
  618. $paramsLog = array(
  619. 'ip' => $_SERVER['REMOTE_ADDR'],
  620. 'action' => "obtenerAccion",
  621. 'fecha' => date("Y-m-d H:i:s")
  622. );
  623. Database::insert($tableLog, $paramsLog);
  624. /* End tracking log */
  625. $actionOrigin = $obtenerAccionInput->ID_ACCION->ORIGEN_ACCION;
  626. $actionCode = $obtenerAccionInput->ID_ACCION->CODIGO_ACCION;
  627. if (empty($actionOrigin) || empty($actionCode)) {
  628. return array(
  629. "RESPUESTA_OBT_ACCION" => array(
  630. "CODIGO_RETORNO" => "2",
  631. "ETIQUETA_ERROR" => "Error en parametro",
  632. "ACCION_FORMATIVA" => ""
  633. )
  634. );
  635. }
  636. $table = Database::get_main_table('plugin_sepe_actions');
  637. $tableCenters = Database::get_main_table('plugin_sepe_centers');
  638. $classRoomTable = Database::get_main_table('plugin_sepe_specialty_classroom');
  639. $tutorTable = Database::get_main_table('plugin_sepe_tutors');
  640. $specialityTutorTable = Database::get_main_table('plugin_sepe_specialty_tutors');
  641. $participantsSpecialityTable = Database::get_main_table('plugin_sepe_participants_specialty');
  642. $participantsSpecialityTutorialsTable = Database::get_main_table('plugin_sepe_participants_specialty_tutorials');
  643. $tableTutorsCompany = Database::get_main_table('plugin_sepe_tutors_company');
  644. // Comprobamos si existen datos almacenados previamente
  645. $sql = "SELECT *
  646. FROM $table
  647. WHERE
  648. action_origin='".$actionOrigin."' AND
  649. action_code='".$actionCode."';";
  650. $rs = Database::query($sql);
  651. if (Database::num_rows($rs) > 0) {
  652. $row = Database::fetch_assoc($rs);
  653. $mainSpecialty = array(
  654. 'ORIGEN_ESPECIALIDAD' => $row['specialty_origin'],
  655. 'AREA_PROFESIONAL' => $row['professional_area'],
  656. 'CODIGO_ESPECIALIDAD' => $row['specialty_code']
  657. );
  658. $actionDescription = array(
  659. 'DENOMINACION_ACCION' => $row['action_name'],
  660. 'INFORMACION_GENERAL' => $row['global_info'],
  661. 'HORARIOS' => $row['schedule'],
  662. 'REQUISITOS' => $row['requirements'],
  663. 'CONTACTO_ACCION' => $row['contact_action']
  664. );
  665. $tableSpeciality = Database::get_main_table('plugin_sepe_specialty');
  666. $tableParticipants = Database::get_main_table('plugin_sepe_participants');
  667. $sql = "SELECT * FROM $tableSpeciality
  668. WHERE action_id ='".$row['id']."'";
  669. $rs = Database::query($sql);
  670. $specialty = array();
  671. if (Database::num_rows($rs) > 0) {
  672. while ($aux = Database::fetch_assoc($rs)) {
  673. $specialtyId = $aux['id'];
  674. $sql = "SELECT * FROM $classRoomTable
  675. WHERE specialty_id='" . $specialtyId . "'";
  676. $resultClassroom = Database::query($sql);
  677. if (Database::num_rows($resultClassroom) === 0) {
  678. return array(
  679. "RESPUESTA_OBT_ACCION" => array(
  680. "CODIGO_RETORNO" => "-1",
  681. "ETIQUETA_ERROR" => "Problema base de datos - consulta de centros presenciales",
  682. "ACCION_FORMATIVA" => ''
  683. )
  684. );
  685. }
  686. $classroomCenterList = new ArrayObject();
  687. while ($tmp = Database::fetch_assoc($resultClassroom)) {
  688. $sql = "SELECT * FROM $tableCenters WHERE id='".$tmp['center_id']."';";
  689. $resultCenter = Database::query($sql);
  690. $auxCenter = Database::fetch_assoc($resultCenter);
  691. $classroomCenter = new stdClass();
  692. $classroomCenter->ORIGEN_CENTRO = $auxCenter['center_origin'];
  693. $classroomCenter->CODIGO_CENTRO = $auxCenter['center_code'];
  694. $classroomCenter = new SoapVar($classroomCenter, SOAP_ENC_OBJECT, null, null, 'CENTRO_PRESENCIAL');
  695. $classroomCenterList->append($classroomCenter);
  696. }
  697. $sql = "SELECT * FROM $specialityTutorTable
  698. WHERE specialty_id='" . $specialtyId . "'";
  699. $resultSpecialtyTutor = Database::query($sql);
  700. $trainingTutors = new ArrayObject();
  701. if (Database::num_rows($resultSpecialtyTutor)) {
  702. while ($tmp_aux = Database::fetch_assoc($resultSpecialtyTutor)) {
  703. $sql = "SELECT * FROM $tutorTable
  704. WHERE id='" . $tmp_aux['tutor_id'] . "'
  705. LIMIT 1";
  706. $rs_tutor = Database::query($sql);
  707. if (Database::num_rows($rs_tutor)) {
  708. $tmp = Database::fetch_assoc($rs_tutor);
  709. $obj = new stdClass();
  710. $obj->ID_TUTOR = new stdClass();
  711. $obj->ID_TUTOR->TIPO_DOCUMENTO = $tmp['document_type'];
  712. $obj->ID_TUTOR->NUM_DOCUMENTO = $tmp['document_number'];
  713. $obj->ID_TUTOR->LETRA_NIF = $tmp['document_letter'];
  714. $obj->ACREDITACION_TUTOR = $tmp_aux['tutor_accreditation'];
  715. $obj->EXPERIENCIA_PROFESIONAL = $tmp_aux['professional_experience'];
  716. $obj->COMPETENCIA_DOCENTE = $tmp_aux['teaching_competence'];
  717. $obj->EXPERIENCIA_MODALIDAD_TELEFORMACION = $tmp_aux['experience_teleforming'];
  718. $obj->FORMACION_MODALIDAD_TELEFORMACION = $tmp_aux['training_teleforming'];
  719. $obj = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'TUTOR_FORMADOR');
  720. $trainingTutors->append($obj);
  721. }
  722. }
  723. }
  724. $params = new ArrayObject();
  725. $idEspecialidad = new stdClass();
  726. $idEspecialidad->ORIGEN_ESPECIALIDAD = $aux['specialty_origin'];
  727. $idEspecialidad->AREA_PROFESIONAL = $aux['professional_area'];
  728. $idEspecialidad->CODIGO_ESPECIALIDAD = $aux['specialty_code'];
  729. $params[0] = new SoapVar($idEspecialidad, SOAP_ENC_OBJECT, NULL, null, 'ID_ESPECIALIDAD', null);
  730. $centroImparticion = new stdClass();
  731. $centroImparticion->ORIGEN_CENTRO = $aux['center_origin'];
  732. $centroImparticion->CODIGO_CENTRO = $aux['center_code'];
  733. $params[1] = new SoapVar($centroImparticion, SOAP_ENC_OBJECT, NULL, null, 'CENTRO_IMPARTICION', null);
  734. $params[2] = new SoapVar(self::undoFixDate($aux['start_date']), XSD_STRING, NULL, null, 'FECHA_INICIO', null);
  735. $params[3] = new SoapVar(self::undoFixDate($aux['end_date']), XSD_STRING, NULL, null, 'FECHA_FIN', null);
  736. $params[4] = new SoapVar($aux['modality_impartition'], XSD_STRING, NULL, null, 'MODALIDAD_IMPARTICION', null);
  737. $obj = new stdClass();
  738. $obj->HORAS_PRESENCIAL = $aux['classroom_hours'];
  739. $obj->HORAS_TELEFORMACION = $aux['distance_hours'];
  740. $params[5] = new SoapVar($obj, SOAP_ENC_OBJECT, NULL, null, 'DATOS_DURACION', null);
  741. $params[6] = new SoapVar($classroomCenterList, SOAP_ENC_OBJECT, null, null, 'CENTROS_SESIONES_PRESENCIALES', null);
  742. $params[7] = new SoapVar($trainingTutors, SOAP_ENC_OBJECT, null, null, 'TUTORES_FORMADORES', null);
  743. $obj = new stdClass();
  744. if (!empty($aux['mornings_participants_number']) ||
  745. !empty($aux['mornings_access_number']) ||
  746. !empty($aux['morning_total_duration'])
  747. ) {
  748. $obj->HORARIO_MANANA = new stdClass();
  749. $obj->HORARIO_MANANA->NUM_PARTICIPANTES = $aux['mornings_participants_number'];
  750. $obj->HORARIO_MANANA->NUMERO_ACCESOS = $aux['mornings_access_number'];
  751. $obj->HORARIO_MANANA->DURACION_TOTAL = $aux['morning_total_duration'];
  752. }
  753. if (!empty($aux['afternoon_participants_number']) ||
  754. !empty($aux['afternoon_access_number']) ||
  755. !empty($aux['afternoon_total_duration'])
  756. ) {
  757. $obj->HORARIO_TARDE = new stdClass();
  758. $obj->HORARIO_TARDE->NUM_PARTICIPANTES = $aux['afternoon_participants_number'];
  759. $obj->HORARIO_TARDE->NUMERO_ACCESOS = $aux['afternoon_access_number'];
  760. $obj->HORARIO_TARDE->DURACION_TOTAL = $aux['afternoon_total_duration'];
  761. }
  762. if (!empty($aux['night_participants_number']) ||
  763. !empty($aux['night_access_number']) ||
  764. !empty($aux['night_total_duration'])
  765. ) {
  766. $obj->HORARIO_NOCHE = new stdClass();
  767. $obj->HORARIO_NOCHE->NUM_PARTICIPANTES = $aux['night_participants_number'];
  768. $obj->HORARIO_NOCHE->NUMERO_ACCESOS = $aux['night_access_number'];
  769. $obj->HORARIO_NOCHE->DURACION_TOTAL = $aux['night_total_duration'];
  770. }
  771. if (!empty($aux['attendees_count']) ||
  772. !empty($aux['learning_activity_count']) ||
  773. !empty($aux['attempt_count']) ||
  774. !empty($aux['evaluation_activity_count'])
  775. ) {
  776. $obj->SEGUIMIENTO_EVALUACION = new stdClass();
  777. $obj->SEGUIMIENTO_EVALUACION->NUM_PARTICIPANTES = $aux['attendees_count'];
  778. $obj->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_APRENDIZAJE = $aux['learning_activity_count'];
  779. $obj->SEGUIMIENTO_EVALUACION->NUMERO_INTENTOS = $aux['attempt_count'];
  780. $obj->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_EVALUACION = $aux['evaluation_activity_count'];
  781. }
  782. $params[8] = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'USO', null);
  783. $specialty[] = new SoapVar($params, SOAP_ENC_OBJECT, null, null, 'ESPECIALIDAD');
  784. }
  785. } else {
  786. return array(
  787. "RESPUESTA_OBT_ACCION" => array(
  788. "CODIGO_RETORNO"=>"-1",
  789. "ETIQUETA_ERROR"=>"Problema base de datos - consulta especialidad de accion",
  790. "ACCION_FORMATIVA"=>''
  791. )
  792. );
  793. }
  794. $sql = "SELECT * FROM $tableParticipants
  795. WHERE action_id ='".$row['id']."'";
  796. $resultParticipants = Database::query($sql);
  797. $specialtyMainParticipant = array();
  798. if (Database::num_rows($resultParticipants)) {
  799. while ($aux = Database::fetch_assoc($resultParticipants)) {
  800. $participantId = $aux['id'];
  801. $sql = "SELECT * FROM $participantsSpecialityTable
  802. WHERE participant_id='" . $participantId . "'";
  803. $resultParticipantSpecialty = Database::query($sql);
  804. $namespace = null;
  805. $specialtyParticipant = array();
  806. while ($tmp = Database::fetch_assoc($resultParticipantSpecialty)) {
  807. $participantSpecialtyId = $tmp['id'];
  808. $sql = "SELECT * FROM $participantsSpecialityTutorialsTable
  809. WHERE participant_specialty_id='" . $participantSpecialtyId . "'";
  810. $resultTutorials = Database::query($sql);
  811. $classroomTutorials = new ArrayObject();
  812. while ($tmp2 = Database::fetch_assoc($resultTutorials)) {
  813. $obj = new stdClass();
  814. $obj->CENTRO_PRESENCIAL_TUTORIA = new stdClass();
  815. $obj->CENTRO_PRESENCIAL_TUTORIA->ORIGEN_CENTRO = $tmp2['center_origin'];
  816. $obj->CENTRO_PRESENCIAL_TUTORIA->CODIGO_CENTRO = $tmp2['center_code'];
  817. $startDate = self::undoFixDate($tmp2['start_date']);
  818. if (!empty($startDate)) {
  819. $obj->FECHA_INICIO = $startDate;
  820. }
  821. $endDate = self::undoFixDate($tmp2['end_date']);
  822. if (!empty($endDate)) {
  823. $obj->FECHA_FIN = $endDate;
  824. }
  825. $obj = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'TUTORIA_PRESENCIAL');
  826. $classroomTutorials->append($obj);
  827. }
  828. $obj = new stdClass();
  829. $obj->ID_ESPECIALIDAD = new stdClass();
  830. $obj->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD = $tmp['specialty_origin'];
  831. $obj->ID_ESPECIALIDAD->AREA_PROFESIONAL = $tmp['professional_area'];
  832. $obj->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD = $tmp['specialty_code'];
  833. $registrationDate = self::undoFixDate($tmp['registration_date']);
  834. // @todo check which is correct send 0000/00/00 or empty
  835. if (!empty($registrationDate)) {
  836. $obj->FECHA_ALTA = $registrationDate;
  837. }
  838. $leavingDate = self::undoFixDate($tmp['leaving_date']);
  839. if (!empty($leavingDate)) {
  840. $obj->FECHA_BAJA = $leavingDate;
  841. }
  842. $obj->TUTORIAS_PRESENCIALES = new SoapVar($classroomTutorials, SOAP_ENC_OBJECT, null, null, 'TUTORIAS_PRESENCIALES', null);
  843. $obj->EVALUACION_FINAL = new stdClass();
  844. if (!empty($tmp['center_origin']) && !empty($tmp['center_code'])) {
  845. $obj->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION = new stdClass();
  846. $obj->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->ORIGEN_CENTRO = $tmp['center_origin'];
  847. $obj->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->CODIGO_CENTRO = $tmp['center_code'];
  848. }
  849. $startDate = self::undoFixDate($tmp['start_date']);
  850. if (!empty($startDate)) {
  851. $obj->EVALUACION_FINAL->FECHA_INICIO = $startDate;
  852. }
  853. $endDate = self::undoFixDate($tmp['end_date']);
  854. if (!empty($endDate)) {
  855. $obj->EVALUACION_FINAL->FECHA_FIN = $endDate;
  856. }
  857. $obj->RESULTADOS = new stdClass();
  858. if (isset($tmp['final_result']) && $tmp['final_result'] != '') {
  859. $obj->RESULTADOS->RESULTADO_FINAL = $tmp['final_result'];
  860. }
  861. if (isset($tmp['final_qualification']) && $tmp['final_qualification'] != '') {
  862. $obj->RESULTADOS->CALIFICACION_FINAL = $tmp['final_qualification'];
  863. }
  864. if (isset($tmp['final_score']) && $tmp['final_score'] != '') {
  865. $obj->RESULTADOS->PUNTUACION_FINAL = $tmp['final_score'];
  866. }
  867. $specialtyParticipant[] = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'ESPECIALIDAD');
  868. }
  869. $params = new stdClass();
  870. $params->ID_PARTICIPANTE = new stdClass();
  871. $params->ID_PARTICIPANTE->TIPO_DOCUMENTO = $aux['document_type'];
  872. $params->ID_PARTICIPANTE->NUM_DOCUMENTO = $aux['document_number'];
  873. $params->ID_PARTICIPANTE->LETRA_NIF = $aux['document_letter'];
  874. $params->INDICADOR_COMPETENCIAS_CLAVE = $aux['key_competence'];
  875. $params->CONTRATO_FORMACION = new stdClass();
  876. if (!empty($aux['contract_id'])) {
  877. $params->CONTRATO_FORMACION->ID_CONTRATO_CFA = $aux['contract_id'];
  878. }
  879. if (!empty($aux['company_fiscal_number'])) {
  880. $params->CONTRATO_FORMACION->CIF_EMPRESA = $aux['company_fiscal_number'];
  881. }
  882. if (!empty($aux['company_tutor_id'])) {
  883. $resultCompany = Database::query("SELECT * FROM $tableTutorsCompany WHERE id='".$aux['company_tutor_id']."';");
  884. $auxCompany = Database::fetch_assoc($resultCompany);
  885. if (!empty($auxCompany['document_type']) ||
  886. !empty($auxCompany['document_number']) ||
  887. !empty($auxCompany['document_letter'])
  888. ) {
  889. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA = new stdClass();
  890. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO = $auxCompany['document_type'];
  891. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO = $auxCompany['document_number'];
  892. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF = $auxCompany['document_letter'];
  893. }
  894. }
  895. if (!empty($aux['training_tutor_id'])) {
  896. $resultTraining = Database::query("SELECT * FROM $tableTutorsCompany WHERE id='".$aux['training_tutor_id']."';");
  897. $auxTraining = Database::fetch_assoc($resultTraining);
  898. if (!empty($auxTraining['document_type']) ||
  899. !empty($auxTraining['document_number']) ||
  900. !empty($auxTraining['document_letter'])
  901. ) {
  902. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION = new stdClass();
  903. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO = $auxTraining['document_type'];
  904. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO = $auxTraining['document_number'];
  905. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF = $auxTraining['document_letter'];
  906. }
  907. }
  908. $params->ESPECIALIDADES_PARTICIPANTE = new SoapVar(
  909. $specialtyParticipant,
  910. SOAP_ENC_OBJECT,
  911. null,
  912. null,
  913. 'ESPECIALIDADES_PARTICIPANTE'
  914. );
  915. $specialtyMainParticipant[] = new SoapVar(
  916. $params,
  917. SOAP_ENC_OBJECT,
  918. null,
  919. null,
  920. 'PARTICIPANTE'
  921. );
  922. }
  923. }
  924. $result = new stdClass();
  925. $result->RESPUESTA_OBT_ACCION = new stdClass();
  926. $result->RESPUESTA_OBT_ACCION->CODIGO_RETORNO = 0;
  927. $result->RESPUESTA_OBT_ACCION->ETIQUETA_ERROR = 'Correcto';
  928. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA = new stdClass();
  929. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ACCION = new stdClass();
  930. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ACCION->ORIGEN_ACCION = $actionOrigin;
  931. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ACCION->CODIGO_ACCION = $actionCode;
  932. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->SITUACION = $row['situation'];
  933. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL = $mainSpecialty;
  934. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->DURACION = $row['duration'];
  935. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->FECHA_INICIO = self::undoFixDate($row['start_date']);
  936. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->FECHA_FIN = self::undoFixDate($row['end_date']);
  937. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->IND_ITINERARIO_COMPLETO = $row['full_itinerary_indicator'];
  938. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->TIPO_FINANCIACION = $row['financing_type'];
  939. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->NUMERO_ASISTENTES = $row['attendees_count'];
  940. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->DESCRIPCION_ACCION = $actionDescription;
  941. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ESPECIALIDADES_ACCION = $specialty;
  942. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->PARTICIPANTES = $specialtyMainParticipant;
  943. return $result;
  944. } else {
  945. // Existe la accion
  946. return array(
  947. "RESPUESTA_OBT_ACCION" => array(
  948. "CODIGO_RETORNO" => "1",
  949. "ETIQUETA_ERROR" => "Acción inexistente",
  950. "ACCION_FORMATIVA" => ""
  951. )
  952. );
  953. }
  954. }
  955. public function obtenerListaAcciones()
  956. {
  957. /* Tracking Log */
  958. $tableLog = Database::get_main_table('plugin_sepe_log');
  959. $paramsLog = array(
  960. 'ip' => $_SERVER['REMOTE_ADDR'],
  961. 'action' => "obtenerListaAcciones",
  962. 'fecha' => date("Y-m-d H:i:s")
  963. );
  964. Database::insert($tableLog, $paramsLog);
  965. /* End tracking log */
  966. $table = Database::get_main_table('plugin_sepe_actions');
  967. $sql = "SELECT action_origin, action_code FROM $table";
  968. $rs = Database::query($sql);
  969. if (!$rs) {
  970. error_log('Problema base de datos ');
  971. return array(
  972. "RESPUESTA_OBT_LISTA_ACCIONES" => array(
  973. "CODIGO_RETORNO" => "-1",
  974. "ETIQUETA_ERROR" => "Problema base de datos - consulta acciones disponible",
  975. "LISTA_ACCIONES" => ''
  976. )
  977. );
  978. }
  979. $list = array();
  980. if (Database::num_rows($rs)) {
  981. while ($row = Database::fetch_assoc($rs)) {
  982. $params = new stdClass();
  983. $params->ORIGEN_ACCION = $row['action_origin'];
  984. $params->CODIGO_ACCION = $row['action_code'];
  985. $list[] = new SoapVar($params, SOAP_ENC_OBJECT);
  986. }
  987. }
  988. $result = new stdClass();
  989. $result->RESPUESTA_OBT_LISTA_ACCIONES = new stdClass();
  990. $result->RESPUESTA_OBT_LISTA_ACCIONES->CODIGO_RETORNO = 0;
  991. $result->RESPUESTA_OBT_LISTA_ACCIONES->ETIQUETA_ERROR = 'Correcto';
  992. if (!empty($list)) {
  993. $result->RESPUESTA_OBT_LISTA_ACCIONES->ID_ACCION = $list;
  994. }
  995. return $result;
  996. }
  997. public function eliminarAccion($eliminarAccionInput)
  998. {
  999. /* Tracking Log */
  1000. $tableLog = Database::get_main_table('plugin_sepe_log');
  1001. $paramsLog = array(
  1002. 'ip' => $_SERVER['REMOTE_ADDR'],
  1003. 'action' => "eliminarAccion",
  1004. 'fecha' => date("Y-m-d H:i:s")
  1005. );
  1006. Database::insert($tableLog, $paramsLog);
  1007. /* End tracking log */
  1008. $actionOrigin = $eliminarAccionInput->ID_ACCION->ORIGEN_ACCION;
  1009. $actionCode = $eliminarAccionInput->ID_ACCION->CODIGO_ACCION;
  1010. if (empty($actionOrigin) || empty($actionCode)) {
  1011. return array(
  1012. "RESPUESTA_ELIMINAR_ACCION" => array(
  1013. "CODIGO_RETORNO" => "2",
  1014. "ETIQUETA_ERROR" => "Error en parametro"
  1015. )
  1016. );
  1017. }
  1018. $table = Database::get_main_table('plugin_sepe_actions');
  1019. $sql = "DELETE FROM $table
  1020. WHERE action_origin='".$actionOrigin."' AND action_code='".$actionCode."';";
  1021. $rs = Database::query($sql);
  1022. if (!$rs) {
  1023. return array(
  1024. "RESPUESTA_ELIMINAR_ACCION" => array(
  1025. "CODIGO_RETORNO" => "-1",
  1026. "ETIQUETA_ERROR" => "Problema base de datos - consulta acciones disponible"
  1027. )
  1028. );
  1029. }
  1030. return array(
  1031. "RESPUESTA_ELIMINAR_ACCION" => array(
  1032. "CODIGO_RETORNO" => "0",
  1033. "ETIQUETA_ERROR" => "Correcto"
  1034. )
  1035. );
  1036. }
  1037. // yyyy-mm-dd to dd/mm/yyyy
  1038. public static function undoFixDate($date)
  1039. {
  1040. if ($date == '0000-00-00' || empty($date)) {
  1041. return null;
  1042. }
  1043. $date = explode('-', $date);
  1044. //
  1045. $date = $date[2].'/'.$date[1].'/'.$date[0];
  1046. return $date;
  1047. }
  1048. // dd/mm/yyyy to yyyy-mm-dd
  1049. public static function fixDate($date)
  1050. {
  1051. if ($date == '00/00/0000' || empty($date)) {
  1052. return null;
  1053. }
  1054. $date = explode('/', $date);
  1055. // Year-month-day
  1056. $date = $date[2].'-'.$date[1].'-'.$date[0];
  1057. return $date;
  1058. }
  1059. protected function checkAuth()
  1060. {
  1061. if (!$this->authenticated) {
  1062. // HTML_Output::error(403);
  1063. error_log('403');
  1064. }
  1065. }
  1066. }