Sepe.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  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 = [
  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 [
  42. "RESPUESTA_DATOS_CENTRO" => [
  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 [
  56. "RESPUESTA_DATOS_CENTRO" => [
  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 = [
  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 [
  79. "RESPUESTA_DATOS_CENTRO" => [
  80. "CODIGO_RETORNO" => "-1",
  81. "ETIQUETA_ERROR" => "Problema base de datos",
  82. "DATOS_IDENTIFICATIVOS" => $crearCentroInput,
  83. ],
  84. ];
  85. } else {
  86. return [
  87. "RESPUESTA_DATOS_CENTRO" => [
  88. "CODIGO_RETORNO" => "0",
  89. "ETIQUETA_ERROR" => "Correcto",
  90. "DATOS_IDENTIFICATIVOS" => $crearCentroInput,
  91. ],
  92. ];
  93. }
  94. }
  95. /**
  96. * @return stdClass
  97. */
  98. public function obtenerDatosCentro()
  99. {
  100. /* Tracking Log */
  101. $tableLog = Database::get_main_table('plugin_sepe_log');
  102. $paramsLog = [
  103. 'ip' => $_SERVER['REMOTE_ADDR'],
  104. 'action' => "obtenerDatosCentro",
  105. 'fecha' => date("Y-m-d H:i:s"),
  106. ];
  107. Database::insert($tableLog, $paramsLog);
  108. /* End tracking log */
  109. // Code
  110. $table = Database::get_main_table('plugin_sepe_center');
  111. // Comprobamos si existen datos almacenados previamente
  112. if (Database::count_rows($table) > 0) {
  113. //Hay datos en la tabla;
  114. $sql = "SELECT * FROM $table;";
  115. $rs = Database::query($sql);
  116. if (!$rs) {
  117. return [
  118. "CODIGO_RETORNO" => "-1",
  119. "ETIQUETA_ERROR" => "Problema acceso base de datos",
  120. "DATOS_IDENTIFICATIVOS" => '',
  121. ];
  122. } else {
  123. $row = Database::fetch_assoc($rs);
  124. $centerOrigin = $row['center_origin'];
  125. $centerCode = $row['center_code'];
  126. $centerName = $row['center_name'];
  127. $urlPlatform = $row['url'];
  128. $urlTracking = $row['tracking_url'];
  129. $phone = $row['phone'];
  130. $mail = $row['mail'];
  131. $data = new stdClass();
  132. $data->ID_CENTRO = new stdClass();
  133. $data->ID_CENTRO->ORIGEN_CENTRO = $centerOrigin;
  134. $data->ID_CENTRO->CODIGO_CENTRO = $centerCode;
  135. $data->NOMBRE_CENTRO = $centerName;
  136. $data->URL_PLATAFORMA = $urlPlatform;
  137. $data->URL_SEGUIMIENTO = $urlTracking;
  138. $data->TELEFONO = $phone;
  139. $data->EMAIL = $mail;
  140. $obj = new stdClass();
  141. $obj->CODIGO_RETORNO = 0;
  142. $obj->ETIQUETA_ERROR = 'Correcto';
  143. $obj->DATOS_IDENTIFICATIVOS = new SoapVar($data, SOAP_ENC_OBJECT);
  144. $result = new stdClass();
  145. $result->RESPUESTA_DATOS_CENTRO = new SoapVar($obj, SOAP_ENC_OBJECT);
  146. return $result;
  147. }
  148. } else {
  149. $data = new stdClass();
  150. $data->ID_CENTRO = new stdClass();
  151. $data->ID_CENTRO->ORIGEN_CENTRO = '';
  152. $data->ID_CENTRO->CODIGO_CENTRO = '';
  153. $data->NOMBRE_CENTRO = '';
  154. $data->URL_PLATAFORMA = '';
  155. $data->URL_SEGUIMIENTO = '';
  156. $data->TELEFONO = '';
  157. $data->EMAIL = '';
  158. $obj = new stdClass();
  159. $obj->CODIGO_RETORNO = 0;
  160. $obj->ETIQUETA_ERROR = 'Correcto';
  161. $obj->DATOS_IDENTIFICATIVOS = new SoapVar($data, SOAP_ENC_OBJECT);
  162. $result = new stdClass();
  163. $result->RESPUESTA_DATOS_CENTRO = new SoapVar($obj, SOAP_ENC_OBJECT);
  164. //error_log('Sin datos en la BD');
  165. /*
  166. $data = new stdClass();
  167. $obj = new stdClass();
  168. $obj->CODIGO_RETORNO = '-1';
  169. $obj->ETIQUETA_ERROR = 'Sin datos';
  170. $obj->DATOS_IDENTIFICATIVOS = new SoapVar($data, SOAP_ENC_OBJECT);
  171. $result = new stdClass();
  172. $result->RESPUESTA_DATOS_CENTRO = new SoapVar($obj, SOAP_ENC_OBJECT);
  173. */
  174. return $result;
  175. }
  176. }
  177. /**
  178. * @param $crearAccionInput
  179. *
  180. * @return array
  181. */
  182. public function crearAccion($crearAccionInput)
  183. {
  184. /* Tracking Log */
  185. $tableLog = Database::get_main_table('plugin_sepe_log');
  186. $paramsLog = [
  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 [
  216. "RESPUESTA_OBT_ACCION" => [
  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 [
  230. "RESPUESTA_OBT_ACCION" => [
  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 [
  244. "RESPUESTA_OBT_ACCION" => [
  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 = [];
  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 = [
  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 [
  337. "RESPUESTA_OBT_ACCION" => [
  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 = [];
  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
  357. WHERE center_origin='".$centerOrigin."' AND center_code='".$centerCode."';";
  358. $res = Database::query($sql);
  359. if (Database::num_rows($res) > 0) {
  360. $aux_row = Database::fetch_assoc($res);
  361. $centerId = $aux_row['id'];
  362. } else {
  363. $sql = "INSERT INTO $tableCenters (center_origin, center_code)
  364. VALUES ('".$centerOrigin."','".$centerCode."');";
  365. Database::query($sql);
  366. $centerId = Database::insert_id();
  367. }
  368. $sql = "INSERT INTO $tableSpecialtyClassroom (specialty_id, center_id)
  369. VALUES ('".$specialtyId."','".$centerId."')";
  370. Database::query($sql);
  371. $id = Database::insert_id();
  372. if (empty($id)) {
  373. return [
  374. "RESPUESTA_OBT_ACCION" => [
  375. "CODIGO_RETORNO" => "-1",
  376. "ETIQUETA_ERROR" => "Problema base de datos - insertando centro presenciales",
  377. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'],
  378. ],
  379. ];
  380. }
  381. }
  382. }
  383. $tableTutors = Database::get_main_table('plugin_sepe_tutors');
  384. $tableSpecialityTutors = Database::get_main_table('plugin_sepe_specialty_tutors');
  385. if (!empty($specialty->TUTORES_FORMADORES)) {
  386. foreach ($specialty->TUTORES_FORMADORES as $tutorList) {
  387. if (!is_array($tutorList)) {
  388. $auxList = [];
  389. $auxList[] = $tutorList;
  390. $tutorList = $auxList;
  391. }
  392. foreach ($tutorList as $tutor) {
  393. $documentType = $tutor->ID_TUTOR->TIPO_DOCUMENTO;
  394. $documentNumber = $tutor->ID_TUTOR->NUM_DOCUMENTO;
  395. $documentLetter = $tutor->ID_TUTOR->LETRA_NIF;
  396. $tutorAccreditation = $tutor->ACREDITACION_TUTOR;
  397. $professionalExperience = $tutor->EXPERIENCIA_PROFESIONAL;
  398. $teachingCompetence = $tutor->COMPETENCIA_DOCENTE;
  399. $experienceTeleforming = $tutor->EXPERIENCIA_MODALIDAD_TELEFORMACION;
  400. $trainingTeleforming = $tutor->FORMACION_MODALIDAD_TELEFORMACION;
  401. /* check tutor not exists */
  402. $sql = "SELECT id FROM $tableTutors WHERE
  403. document_type='".$documentType."' AND
  404. document_number='".$documentNumber."' AND
  405. document_letter='".$documentLetter."';";
  406. $res = Database::query($sql);
  407. if (Database::num_rows($res) > 0) {
  408. $aux_row = Database::fetch_assoc($res);
  409. $tutorId = $aux_row['id'];
  410. } else {
  411. $sql = "INSERT INTO $tableTutors (document_type, document_number, document_letter)
  412. VALUES ('".$documentType."','".$documentNumber."','".$documentLetter."');";
  413. Database::query($sql);
  414. $tutorId = Database::insert_id();
  415. }
  416. if (empty($tutorId)) {
  417. return [
  418. "RESPUESTA_OBT_ACCION" => [
  419. "CODIGO_RETORNO" => "-1",
  420. "ETIQUETA_ERROR" => "Problema base de datos - insertando tutores",
  421. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'],
  422. ],
  423. ];
  424. }
  425. $sql = "INSERT INTO $tableSpecialityTutors (specialty_id, tutor_id, tutor_accreditation, professional_experience, teaching_competence, experience_teleforming, training_teleforming)
  426. VALUES ('".$specialtyId."','".$tutorId."','".$tutorAccreditation."','".$professionalExperience."','".$teachingCompetence."','".$experienceTeleforming."','".$trainingTeleforming."');";
  427. Database::query($sql);
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. // DATOS PARTICIPANTES
  435. $tableParticipants = Database::get_main_table('plugin_sepe_participants');
  436. $tableTutorsCompany = Database::get_main_table('plugin_sepe_tutors_company');
  437. $participants = $crearAccionInput->ACCION_FORMATIVA->PARTICIPANTES;
  438. foreach ($participants as $participantList) {
  439. if (!is_array($participantList)) {
  440. $auxList = [];
  441. $auxList[] = $participantList;
  442. $participantList = $auxList;
  443. }
  444. foreach ($participantList as $participant) {
  445. $documentType = $participant->ID_PARTICIPANTE->TIPO_DOCUMENTO;
  446. $documentNumber = $participant->ID_PARTICIPANTE->NUM_DOCUMENTO;
  447. $documentLetter = $participant->ID_PARTICIPANTE->LETRA_NIF;
  448. $keyCompetence = $participant->INDICADOR_COMPETENCIAS_CLAVE;
  449. $contractId = null;
  450. $companyFiscalNumber = null;
  451. $documentTypeCompany = null;
  452. $documentNumberCompany = null;
  453. $documentLetterCompany = null;
  454. $documentTypeTraining = null;
  455. $documentNumberTraining = null;
  456. $documentLetterTraining = null;
  457. $tutorIdCompany = null;
  458. $tutorIdTraining = null;
  459. if (isset($participant->CONTRATO_FORMACION)) {
  460. $contractId = isset($participant->CONTRATO_FORMACION->ID_CONTRATO_CFA) ? $participant->CONTRATO_FORMACION->ID_CONTRATO_CFA : null;
  461. $companyFiscalNumber = isset($participant->CONTRATO_FORMACION->CIF_EMPRESA) ? $participant->CONTRATO_FORMACION->CIF_EMPRESA : null;
  462. $documentTypeCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO : null;
  463. $documentNumberCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO : null;
  464. $documentLetterCompany = isset($participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF : null;
  465. if (!empty($documentTypeCompany) || !empty($documentNumberCompany) || !empty($documentLetterCompany)) {
  466. $tmp_e = Database::query('SELECT id FROM '.$tableTutorsCompany.' WHERE document_type="'.$documentTypeCompany.'" AND document_number="'.$documentNumberCompany.'" AND document_letter="'.$documentLetterCompany.'";');
  467. if (Database::num_rows($tmp_e) > 0) {
  468. $row_tmp = Database::fetch_assoc($tmp_e);
  469. $tutorIdCompany = $row_tmp['id'];
  470. Database::query("UPDATE $tableTutorsCompany SET company='1' WHERE id='".$tutorIdCompany."'");
  471. } else {
  472. $params_tmp = [
  473. 'document_type' => $documentTypeCompany,
  474. 'document_number' => $documentNumberCompany,
  475. 'document_letter' => $documentLetterCompany,
  476. 'company' => '1',
  477. ];
  478. $tutorIdCompany = Database::insert($tableTutorsCompany, $params_tmp);
  479. }
  480. }
  481. $documentTypeTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO : null;
  482. $documentNumberTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO : null;
  483. $documentLetterTraining = isset($participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF) ? $participant->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF : null;
  484. if (!empty($documentTypeTraining) || !empty($documentNumberTraining) || !empty($documentLetterTraining)) {
  485. $tmp_f = Database::query(
  486. '
  487. SELECT id FROM '.$tableTutorsCompany.'
  488. WHERE
  489. document_type="'.$documentTypeTraining.'" AND
  490. document_number="'.$documentNumberTraining.'" AND
  491. document_letter="'.$documentLetterTraining.'";'
  492. );
  493. if (Database::num_rows($tmp_f) > 0) {
  494. $row_tmp = Database::fetch_assoc($tmp_f);
  495. $tutorIdTraining = $row_tmp['id'];
  496. Database::query("UPDATE $tableTutorsCompany SET training='1' WHERE id='".$tutorIdTraining."'");
  497. } else {
  498. $params_tmp = [
  499. 'document_type' => $documentTypeTraining,
  500. 'document_number' => $documentNumberTraining,
  501. 'document_letter' => $documentLetterTraining,
  502. 'training' => '1',
  503. ];
  504. $tutorIdTraining = Database::insert($tableTutorsCompany, $params_tmp);
  505. }
  506. }
  507. }
  508. $params = [
  509. 'action_id' => $actionId,
  510. 'document_type' => $documentType,
  511. 'document_number' => $documentNumber,
  512. 'document_letter' => $documentLetter,
  513. 'key_competence' => $keyCompetence,
  514. 'contract_id' => $contractId,
  515. 'company_fiscal_number' => $companyFiscalNumber,
  516. 'company_tutor_id' => $tutorIdCompany,
  517. 'training_tutor_id' => $tutorIdTraining,
  518. ];
  519. $participantId = Database::insert($tableParticipants, $params);
  520. if (empty($participantId)) {
  521. return [
  522. "RESPUESTA_OBT_ACCION" => [
  523. "CODIGO_RETORNO" => "-1",
  524. "ETIQUETA_ERROR" => "Problema base de datos - insertando participantes",
  525. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'],
  526. ],
  527. ];
  528. }
  529. $participantId = Database::insert_id();
  530. foreach ($participant->ESPECIALIDADES_PARTICIPANTE as $valueList) {
  531. if (!is_array($participantList)) {
  532. $auxList = [];
  533. $auxList[] = $valueList;
  534. $valueList = $auxList;
  535. }
  536. foreach ($valueList as $value) {
  537. $specialtyOrigin = null;
  538. $professionalArea = null;
  539. $specialtyCode = null;
  540. if (isset($value->ID_ESPECIALIDAD)) {
  541. $specialtyOrigin = $value->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD;
  542. $professionalArea = $value->ID_ESPECIALIDAD->AREA_PROFESIONAL;
  543. $specialtyCode = $value->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD;
  544. }
  545. $registrationDate = $value->FECHA_ALTA;
  546. $leavingDate = $value->FECHA_BAJA;
  547. $centerOrigin = null;
  548. $centerCode = null;
  549. $startDate = null;
  550. $endDate = null;
  551. if (!empty($value->EVALUACION_FINAL)) {
  552. $startDate = isset($value->EVALUACION_FINAL->FECHA_INICIO) ? $value->EVALUACION_FINAL->FECHA_INICIO : null;
  553. $endDate = isset($value->EVALUACION_FINAL->FECHA_FIN) ? $value->EVALUACION_FINAL->FECHA_FIN : null;
  554. if (!empty($value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION)) {
  555. $centerOrigin = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->ORIGEN_CENTRO;
  556. $centerCode = $value->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->CODIGO_CENTRO;
  557. }
  558. }
  559. $finalResult = null;
  560. $finalQualification = null;
  561. $finalScore = null;
  562. if (isset($value->RESULTADOS)) {
  563. $finalResult = isset($value->RESULTADOS->RESULTADO_FINAL) ? $value->RESULTADOS->RESULTADO_FINAL : null;
  564. $finalQualification = isset($value->RESULTADOS->CALIFICACION_FINAL) ? $value->RESULTADOS->CALIFICACION_FINAL : null;
  565. $finalScore = isset($value->RESULTADOS->PUNTUACION_FINAL) ? $value->RESULTADOS->PUNTUACION_FINAL : null;
  566. }
  567. $registrationDate = self::fixDate($registrationDate);
  568. $leavingDate = self::fixDate($leavingDate);
  569. $startDate = self::fixDate($startDate);
  570. $endDate = self::fixDate($endDate);
  571. $table_aux = Database::get_main_table('plugin_sepe_participants_specialty');
  572. $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)
  573. VALUES ('".$participantId."','".$specialtyOrigin."','".$professionalArea."','".$specialtyCode."','".$registrationDate."','".$leavingDate."','".$centerOrigin."','".$centerCode."','".$startDate."','".$endDate."','".$finalResult."','".$finalQualification."','".$finalScore."');";
  574. Database::query($sql);
  575. $participantSpecialtyId = Database::insert_id();
  576. if (empty($participantSpecialtyId)) {
  577. return [
  578. "RESPUESTA_OBT_ACCION" => [
  579. "CODIGO_RETORNO" => "-1",
  580. "ETIQUETA_ERROR" => "Problema base de datos - insertando especialidad participante",
  581. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'],
  582. ],
  583. ];
  584. }
  585. foreach ($value->TUTORIAS_PRESENCIALES as $tutorialList) {
  586. if (!is_array($tutorialList)) {
  587. $auxList = [];
  588. $auxList[] = $tutorialList;
  589. $tutorialList = $auxList;
  590. }
  591. foreach ($tutorialList as $tutorial) {
  592. $centerOrigin = $tutorial->CENTRO_PRESENCIAL_TUTORIA->ORIGEN_CENTRO;
  593. $centerCode = $tutorial->CENTRO_PRESENCIAL_TUTORIA->CODIGO_CENTRO;
  594. $startDate = $tutorial->FECHA_INICIO;
  595. $endDate = $tutorial->FECHA_FIN;
  596. $startDate = self::fixDate($startDate);
  597. $endDate = self::fixDate($endDate);
  598. $table_aux2 = Database::get_main_table('plugin_sepe_participants_specialty_tutorials');
  599. $sql = "INSERT INTO $table_aux2 (participant_specialty_id,center_origin,center_code,start_date,end_date)
  600. VALUES ('".$participantSpecialtyId."','".$centerOrigin."','".$centerCode."','".$startDate."','".$endDate."');";
  601. $rs = Database::query($sql);
  602. if (!$rs) {
  603. return [
  604. "RESPUESTA_OBT_ACCION" => [
  605. "CODIGO_RETORNO" => "-1",
  606. "ETIQUETA_ERROR" => "Problema base de datos - insertando tutorias presenciales participante",
  607. "ACCION_FORMATIVA" => $crearAccionInputArray['ACCION_FORMATIVA'],
  608. ],
  609. ];
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. $obtenerAccionInput = new stdClass();
  618. $obtenerAccionInput->ID_ACCION = new stdClass();
  619. $obtenerAccionInput->ID_ACCION->ORIGEN_ACCION = $actionOrigin;
  620. $obtenerAccionInput->ID_ACCION->CODIGO_ACCION = $actionCode;
  621. $result = self::obtenerAccion($obtenerAccionInput);
  622. return $result;
  623. }
  624. public function obtenerAccion($obtenerAccionInput)
  625. {
  626. /* Tracking Log */
  627. $tableLog = Database::get_main_table('plugin_sepe_log');
  628. $paramsLog = [
  629. 'ip' => $_SERVER['REMOTE_ADDR'],
  630. 'action' => "obtenerAccion",
  631. 'fecha' => date("Y-m-d H:i:s"),
  632. ];
  633. Database::insert($tableLog, $paramsLog);
  634. /* End tracking log */
  635. $actionOrigin = $obtenerAccionInput->ID_ACCION->ORIGEN_ACCION;
  636. $actionCode = $obtenerAccionInput->ID_ACCION->CODIGO_ACCION;
  637. if (empty($actionOrigin) || empty($actionCode)) {
  638. return [
  639. "RESPUESTA_OBT_ACCION" => [
  640. "CODIGO_RETORNO" => "2",
  641. "ETIQUETA_ERROR" => "Error en parametro",
  642. "ACCION_FORMATIVA" => "",
  643. ],
  644. ];
  645. }
  646. $table = Database::get_main_table('plugin_sepe_actions');
  647. $tableCenters = Database::get_main_table('plugin_sepe_centers');
  648. $classRoomTable = Database::get_main_table('plugin_sepe_specialty_classroom');
  649. $tutorTable = Database::get_main_table('plugin_sepe_tutors');
  650. $specialityTutorTable = Database::get_main_table('plugin_sepe_specialty_tutors');
  651. $participantsSpecialityTable = Database::get_main_table('plugin_sepe_participants_specialty');
  652. $participantsSpecialityTutorialsTable = Database::get_main_table('plugin_sepe_participants_specialty_tutorials');
  653. $tableTutorsCompany = Database::get_main_table('plugin_sepe_tutors_company');
  654. // Comprobamos si existen datos almacenados previamente
  655. $sql = "SELECT *
  656. FROM $table
  657. WHERE
  658. action_origin='".$actionOrigin."' AND
  659. action_code='".$actionCode."';";
  660. $rs = Database::query($sql);
  661. if (Database::num_rows($rs) > 0) {
  662. $row = Database::fetch_assoc($rs);
  663. $mainSpecialty = [
  664. 'ORIGEN_ESPECIALIDAD' => $row['specialty_origin'],
  665. 'AREA_PROFESIONAL' => $row['professional_area'],
  666. 'CODIGO_ESPECIALIDAD' => $row['specialty_code'],
  667. ];
  668. $actionDescription = [
  669. 'DENOMINACION_ACCION' => $row['action_name'],
  670. 'INFORMACION_GENERAL' => $row['global_info'],
  671. 'HORARIOS' => $row['schedule'],
  672. 'REQUISITOS' => $row['requirements'],
  673. 'CONTACTO_ACCION' => $row['contact_action'],
  674. ];
  675. $tableSpeciality = Database::get_main_table('plugin_sepe_specialty');
  676. $tableParticipants = Database::get_main_table('plugin_sepe_participants');
  677. $sql = "SELECT * FROM $tableSpeciality
  678. WHERE action_id ='".$row['id']."'";
  679. $rs = Database::query($sql);
  680. $specialty = [];
  681. if (Database::num_rows($rs) > 0) {
  682. while ($aux = Database::fetch_assoc($rs)) {
  683. $specialtyId = $aux['id'];
  684. $sql = "SELECT * FROM $classRoomTable
  685. WHERE specialty_id='".$specialtyId."'";
  686. $resultClassroom = Database::query($sql);
  687. if (Database::num_rows($resultClassroom) === 0) {
  688. return [
  689. "RESPUESTA_OBT_ACCION" => [
  690. "CODIGO_RETORNO" => "-1",
  691. "ETIQUETA_ERROR" => "Problema base de datos - consulta de centros presenciales",
  692. "ACCION_FORMATIVA" => '',
  693. ],
  694. ];
  695. }
  696. $classroomCenterList = new ArrayObject();
  697. while ($tmp = Database::fetch_assoc($resultClassroom)) {
  698. $sql = "SELECT * FROM $tableCenters WHERE id='".$tmp['center_id']."';";
  699. $resultCenter = Database::query($sql);
  700. $auxCenter = Database::fetch_assoc($resultCenter);
  701. $classroomCenter = new stdClass();
  702. $classroomCenter->ORIGEN_CENTRO = $auxCenter['center_origin'];
  703. $classroomCenter->CODIGO_CENTRO = $auxCenter['center_code'];
  704. $classroomCenter = new SoapVar(
  705. $classroomCenter,
  706. SOAP_ENC_OBJECT,
  707. null,
  708. null,
  709. 'CENTRO_PRESENCIAL'
  710. );
  711. $classroomCenterList->append($classroomCenter);
  712. }
  713. $sql = "SELECT * FROM $specialityTutorTable
  714. WHERE specialty_id='".$specialtyId."'";
  715. $resultSpecialtyTutor = Database::query($sql);
  716. $trainingTutors = new ArrayObject();
  717. if (Database::num_rows($resultSpecialtyTutor)) {
  718. while ($tmp_aux = Database::fetch_assoc($resultSpecialtyTutor)) {
  719. $sql = "SELECT * FROM $tutorTable
  720. WHERE id='".$tmp_aux['tutor_id']."'
  721. LIMIT 1";
  722. $rs_tutor = Database::query($sql);
  723. if (Database::num_rows($rs_tutor)) {
  724. $tmp = Database::fetch_assoc($rs_tutor);
  725. $obj = new stdClass();
  726. $obj->ID_TUTOR = new stdClass();
  727. $obj->ID_TUTOR->TIPO_DOCUMENTO = $tmp['document_type'];
  728. $obj->ID_TUTOR->NUM_DOCUMENTO = $tmp['document_number'];
  729. $obj->ID_TUTOR->LETRA_NIF = $tmp['document_letter'];
  730. $obj->ACREDITACION_TUTOR = $tmp_aux['tutor_accreditation'];
  731. $obj->EXPERIENCIA_PROFESIONAL = $tmp_aux['professional_experience'];
  732. $obj->COMPETENCIA_DOCENTE = $tmp_aux['teaching_competence'];
  733. $obj->EXPERIENCIA_MODALIDAD_TELEFORMACION = $tmp_aux['experience_teleforming'];
  734. $obj->FORMACION_MODALIDAD_TELEFORMACION = $tmp_aux['training_teleforming'];
  735. $obj = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'TUTOR_FORMADOR');
  736. $trainingTutors->append($obj);
  737. }
  738. }
  739. }
  740. $params = new ArrayObject();
  741. $idEspecialidad = new stdClass();
  742. $idEspecialidad->ORIGEN_ESPECIALIDAD = $aux['specialty_origin'];
  743. $idEspecialidad->AREA_PROFESIONAL = $aux['professional_area'];
  744. $idEspecialidad->CODIGO_ESPECIALIDAD = $aux['specialty_code'];
  745. $params[0] = new SoapVar(
  746. $idEspecialidad,
  747. SOAP_ENC_OBJECT,
  748. null,
  749. null,
  750. 'ID_ESPECIALIDAD',
  751. null
  752. );
  753. $centroImparticion = new stdClass();
  754. $centroImparticion->ORIGEN_CENTRO = $aux['center_origin'];
  755. $centroImparticion->CODIGO_CENTRO = $aux['center_code'];
  756. $params[1] = new SoapVar(
  757. $centroImparticion,
  758. SOAP_ENC_OBJECT,
  759. null,
  760. null,
  761. 'CENTRO_IMPARTICION',
  762. null
  763. );
  764. $params[2] = new SoapVar(
  765. self::undoFixDate($aux['start_date']),
  766. XSD_STRING,
  767. null,
  768. null,
  769. 'FECHA_INICIO',
  770. null
  771. );
  772. $params[3] = new SoapVar(
  773. self::undoFixDate($aux['end_date']),
  774. XSD_STRING,
  775. null,
  776. null,
  777. 'FECHA_FIN',
  778. null
  779. );
  780. $params[4] = new SoapVar(
  781. $aux['modality_impartition'],
  782. XSD_STRING,
  783. null,
  784. null,
  785. 'MODALIDAD_IMPARTICION',
  786. null
  787. );
  788. $obj = new stdClass();
  789. $obj->HORAS_PRESENCIAL = $aux['classroom_hours'];
  790. $obj->HORAS_TELEFORMACION = $aux['distance_hours'];
  791. $params[5] = new SoapVar(
  792. $obj,
  793. SOAP_ENC_OBJECT,
  794. null,
  795. null,
  796. 'DATOS_DURACION',
  797. null
  798. );
  799. $params[6] = new SoapVar(
  800. $classroomCenterList,
  801. SOAP_ENC_OBJECT,
  802. null,
  803. null,
  804. 'CENTROS_SESIONES_PRESENCIALES',
  805. null
  806. );
  807. $params[7] = new SoapVar(
  808. $trainingTutors,
  809. SOAP_ENC_OBJECT,
  810. null,
  811. null,
  812. 'TUTORES_FORMADORES',
  813. null
  814. );
  815. $obj = new stdClass();
  816. if (!empty($aux['mornings_participants_number']) ||
  817. !empty($aux['mornings_access_number']) ||
  818. !empty($aux['morning_total_duration'])
  819. ) {
  820. $obj->HORARIO_MANANA = new stdClass();
  821. $obj->HORARIO_MANANA->NUM_PARTICIPANTES = $aux['mornings_participants_number'];
  822. $obj->HORARIO_MANANA->NUMERO_ACCESOS = $aux['mornings_access_number'];
  823. $obj->HORARIO_MANANA->DURACION_TOTAL = $aux['morning_total_duration'];
  824. }
  825. if (!empty($aux['afternoon_participants_number']) ||
  826. !empty($aux['afternoon_access_number']) ||
  827. !empty($aux['afternoon_total_duration'])
  828. ) {
  829. $obj->HORARIO_TARDE = new stdClass();
  830. $obj->HORARIO_TARDE->NUM_PARTICIPANTES = $aux['afternoon_participants_number'];
  831. $obj->HORARIO_TARDE->NUMERO_ACCESOS = $aux['afternoon_access_number'];
  832. $obj->HORARIO_TARDE->DURACION_TOTAL = $aux['afternoon_total_duration'];
  833. }
  834. if (!empty($aux['night_participants_number']) ||
  835. !empty($aux['night_access_number']) ||
  836. !empty($aux['night_total_duration'])
  837. ) {
  838. $obj->HORARIO_NOCHE = new stdClass();
  839. $obj->HORARIO_NOCHE->NUM_PARTICIPANTES = $aux['night_participants_number'];
  840. $obj->HORARIO_NOCHE->NUMERO_ACCESOS = $aux['night_access_number'];
  841. $obj->HORARIO_NOCHE->DURACION_TOTAL = $aux['night_total_duration'];
  842. }
  843. if (!empty($aux['attendees_count']) ||
  844. !empty($aux['learning_activity_count']) ||
  845. !empty($aux['attempt_count']) ||
  846. !empty($aux['evaluation_activity_count'])
  847. ) {
  848. $obj->SEGUIMIENTO_EVALUACION = new stdClass();
  849. $obj->SEGUIMIENTO_EVALUACION->NUM_PARTICIPANTES = $aux['attendees_count'];
  850. $obj->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_APRENDIZAJE = $aux['learning_activity_count'];
  851. $obj->SEGUIMIENTO_EVALUACION->NUMERO_INTENTOS = $aux['attempt_count'];
  852. $obj->SEGUIMIENTO_EVALUACION->NUMERO_ACTIVIDADES_EVALUACION = $aux['evaluation_activity_count'];
  853. }
  854. $params[8] = new SoapVar(
  855. $obj,
  856. SOAP_ENC_OBJECT,
  857. null,
  858. null,
  859. 'USO',
  860. null
  861. );
  862. $specialty[] = new SoapVar(
  863. $params,
  864. SOAP_ENC_OBJECT,
  865. null,
  866. null,
  867. 'ESPECIALIDAD'
  868. );
  869. }
  870. } else {
  871. return [
  872. "RESPUESTA_OBT_ACCION" => [
  873. "CODIGO_RETORNO" => "-1",
  874. "ETIQUETA_ERROR" => "Problema base de datos - consulta especialidad de accion",
  875. "ACCION_FORMATIVA" => '',
  876. ],
  877. ];
  878. }
  879. $sql = "SELECT * FROM $tableParticipants
  880. WHERE action_id ='".$row['id']."'";
  881. $resultParticipants = Database::query($sql);
  882. $specialtyMainParticipant = [];
  883. if (Database::num_rows($resultParticipants)) {
  884. while ($aux = Database::fetch_assoc($resultParticipants)) {
  885. $participantId = $aux['id'];
  886. $sql = "SELECT * FROM $participantsSpecialityTable
  887. WHERE participant_id='".$participantId."'";
  888. $resultParticipantSpecialty = Database::query($sql);
  889. $namespace = null;
  890. $specialtyParticipant = [];
  891. while ($tmp = Database::fetch_assoc($resultParticipantSpecialty)) {
  892. $participantSpecialtyId = $tmp['id'];
  893. $sql = "SELECT * FROM $participantsSpecialityTutorialsTable
  894. WHERE participant_specialty_id='".$participantSpecialtyId."'";
  895. $resultTutorials = Database::query($sql);
  896. $classroomTutorials = new ArrayObject();
  897. while ($tmp2 = Database::fetch_assoc($resultTutorials)) {
  898. $obj = new stdClass();
  899. $obj->CENTRO_PRESENCIAL_TUTORIA = new stdClass();
  900. $obj->CENTRO_PRESENCIAL_TUTORIA->ORIGEN_CENTRO = $tmp2['center_origin'];
  901. $obj->CENTRO_PRESENCIAL_TUTORIA->CODIGO_CENTRO = $tmp2['center_code'];
  902. $startDate = self::undoFixDate($tmp2['start_date']);
  903. if (!empty($startDate)) {
  904. $obj->FECHA_INICIO = $startDate;
  905. }
  906. $endDate = self::undoFixDate($tmp2['end_date']);
  907. if (!empty($endDate)) {
  908. $obj->FECHA_FIN = $endDate;
  909. }
  910. $obj = new SoapVar(
  911. $obj,
  912. SOAP_ENC_OBJECT,
  913. null,
  914. null,
  915. 'TUTORIA_PRESENCIAL'
  916. );
  917. $classroomTutorials->append($obj);
  918. }
  919. $obj = new stdClass();
  920. $obj->ID_ESPECIALIDAD = new stdClass();
  921. $obj->ID_ESPECIALIDAD->ORIGEN_ESPECIALIDAD = $tmp['specialty_origin'];
  922. $obj->ID_ESPECIALIDAD->AREA_PROFESIONAL = $tmp['professional_area'];
  923. $obj->ID_ESPECIALIDAD->CODIGO_ESPECIALIDAD = $tmp['specialty_code'];
  924. $registrationDate = self::undoFixDate($tmp['registration_date']);
  925. // @todo check which is correct send 0000/00/00 or empty
  926. if (!empty($registrationDate)) {
  927. $obj->FECHA_ALTA = $registrationDate;
  928. }
  929. $leavingDate = self::undoFixDate($tmp['leaving_date']);
  930. if (!empty($leavingDate)) {
  931. $obj->FECHA_BAJA = $leavingDate;
  932. }
  933. $obj->TUTORIAS_PRESENCIALES = new SoapVar(
  934. $classroomTutorials,
  935. SOAP_ENC_OBJECT,
  936. null,
  937. null,
  938. 'TUTORIAS_PRESENCIALES',
  939. null
  940. );
  941. $obj->EVALUACION_FINAL = new stdClass();
  942. if (!empty($tmp['center_origin']) && !empty($tmp['center_code'])) {
  943. $obj->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION = new stdClass();
  944. $obj->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->ORIGEN_CENTRO = $tmp['center_origin'];
  945. $obj->EVALUACION_FINAL->CENTRO_PRESENCIAL_EVALUACION->CODIGO_CENTRO = $tmp['center_code'];
  946. }
  947. $startDate = self::undoFixDate($tmp['start_date']);
  948. if (!empty($startDate)) {
  949. $obj->EVALUACION_FINAL->FECHA_INICIO = $startDate;
  950. }
  951. $endDate = self::undoFixDate($tmp['end_date']);
  952. if (!empty($endDate)) {
  953. $obj->EVALUACION_FINAL->FECHA_FIN = $endDate;
  954. }
  955. $obj->RESULTADOS = new stdClass();
  956. if (isset($tmp['final_result']) && $tmp['final_result'] != '') {
  957. $obj->RESULTADOS->RESULTADO_FINAL = $tmp['final_result'];
  958. }
  959. if (isset($tmp['final_qualification']) && $tmp['final_qualification'] != '') {
  960. $obj->RESULTADOS->CALIFICACION_FINAL = $tmp['final_qualification'];
  961. }
  962. if (isset($tmp['final_score']) && $tmp['final_score'] != '') {
  963. $obj->RESULTADOS->PUNTUACION_FINAL = $tmp['final_score'];
  964. }
  965. $specialtyParticipant[] = new SoapVar(
  966. $obj,
  967. SOAP_ENC_OBJECT,
  968. null,
  969. null,
  970. 'ESPECIALIDAD'
  971. );
  972. }
  973. $params = new stdClass();
  974. $params->ID_PARTICIPANTE = new stdClass();
  975. $params->ID_PARTICIPANTE->TIPO_DOCUMENTO = $aux['document_type'];
  976. $params->ID_PARTICIPANTE->NUM_DOCUMENTO = $aux['document_number'];
  977. $params->ID_PARTICIPANTE->LETRA_NIF = $aux['document_letter'];
  978. $params->INDICADOR_COMPETENCIAS_CLAVE = $aux['key_competence'];
  979. $params->CONTRATO_FORMACION = new stdClass();
  980. if (!empty($aux['contract_id'])) {
  981. $params->CONTRATO_FORMACION->ID_CONTRATO_CFA = $aux['contract_id'];
  982. }
  983. if (!empty($aux['company_fiscal_number'])) {
  984. $params->CONTRATO_FORMACION->CIF_EMPRESA = $aux['company_fiscal_number'];
  985. }
  986. if (!empty($aux['company_tutor_id'])) {
  987. $resultCompany = Database::query("SELECT * FROM $tableTutorsCompany WHERE id='".$aux['company_tutor_id']."';");
  988. $auxCompany = Database::fetch_assoc($resultCompany);
  989. if (!empty($auxCompany['document_type']) ||
  990. !empty($auxCompany['document_number']) ||
  991. !empty($auxCompany['document_letter'])
  992. ) {
  993. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA = new stdClass();
  994. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->TIPO_DOCUMENTO = $auxCompany['document_type'];
  995. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->NUM_DOCUMENTO = $auxCompany['document_number'];
  996. $params->CONTRATO_FORMACION->ID_TUTOR_EMPRESA->LETRA_NIF = $auxCompany['document_letter'];
  997. }
  998. }
  999. if (!empty($aux['training_tutor_id'])) {
  1000. $resultTraining = Database::query("SELECT * FROM $tableTutorsCompany WHERE id='".$aux['training_tutor_id']."';");
  1001. $auxTraining = Database::fetch_assoc($resultTraining);
  1002. if (!empty($auxTraining['document_type']) ||
  1003. !empty($auxTraining['document_number']) ||
  1004. !empty($auxTraining['document_letter'])
  1005. ) {
  1006. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION = new stdClass();
  1007. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION->TIPO_DOCUMENTO = $auxTraining['document_type'];
  1008. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION->NUM_DOCUMENTO = $auxTraining['document_number'];
  1009. $params->CONTRATO_FORMACION->ID_TUTOR_FORMACION->LETRA_NIF = $auxTraining['document_letter'];
  1010. }
  1011. }
  1012. $params->ESPECIALIDADES_PARTICIPANTE = new SoapVar(
  1013. $specialtyParticipant,
  1014. SOAP_ENC_OBJECT,
  1015. null,
  1016. null,
  1017. 'ESPECIALIDADES_PARTICIPANTE'
  1018. );
  1019. $specialtyMainParticipant[] = new SoapVar(
  1020. $params,
  1021. SOAP_ENC_OBJECT,
  1022. null,
  1023. null,
  1024. 'PARTICIPANTE'
  1025. );
  1026. }
  1027. }
  1028. $result = new stdClass();
  1029. $result->RESPUESTA_OBT_ACCION = new stdClass();
  1030. $result->RESPUESTA_OBT_ACCION->CODIGO_RETORNO = 0;
  1031. $result->RESPUESTA_OBT_ACCION->ETIQUETA_ERROR = 'Correcto';
  1032. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA = new stdClass();
  1033. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ACCION = new stdClass();
  1034. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ACCION->ORIGEN_ACCION = $actionOrigin;
  1035. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ACCION->CODIGO_ACCION = $actionCode;
  1036. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->SITUACION = $row['situation'];
  1037. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ID_ESPECIALIDAD_PRINCIPAL = $mainSpecialty;
  1038. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->DURACION = $row['duration'];
  1039. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->FECHA_INICIO = self::undoFixDate($row['start_date']);
  1040. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->FECHA_FIN = self::undoFixDate($row['end_date']);
  1041. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->IND_ITINERARIO_COMPLETO = $row['full_itinerary_indicator'];
  1042. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->TIPO_FINANCIACION = $row['financing_type'];
  1043. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->NUMERO_ASISTENTES = $row['attendees_count'];
  1044. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->DESCRIPCION_ACCION = $actionDescription;
  1045. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->ESPECIALIDADES_ACCION = $specialty;
  1046. $result->RESPUESTA_OBT_ACCION->ACCION_FORMATIVA->PARTICIPANTES = $specialtyMainParticipant;
  1047. return $result;
  1048. } else {
  1049. // Existe la accion
  1050. return [
  1051. "RESPUESTA_OBT_ACCION" => [
  1052. "CODIGO_RETORNO" => "1",
  1053. "ETIQUETA_ERROR" => "Acción inexistente",
  1054. "ACCION_FORMATIVA" => "",
  1055. ],
  1056. ];
  1057. }
  1058. }
  1059. public function obtenerListaAcciones()
  1060. {
  1061. /* Tracking Log */
  1062. $tableLog = Database::get_main_table('plugin_sepe_log');
  1063. $paramsLog = [
  1064. 'ip' => $_SERVER['REMOTE_ADDR'],
  1065. 'action' => "obtenerListaAcciones",
  1066. 'fecha' => date("Y-m-d H:i:s"),
  1067. ];
  1068. Database::insert($tableLog, $paramsLog);
  1069. /* End tracking log */
  1070. $table = Database::get_main_table('plugin_sepe_actions');
  1071. $sql = "SELECT action_origin, action_code FROM $table";
  1072. $rs = Database::query($sql);
  1073. if (!$rs) {
  1074. error_log('Problema base de datos ');
  1075. return [
  1076. "RESPUESTA_OBT_LISTA_ACCIONES" => [
  1077. "CODIGO_RETORNO" => "-1",
  1078. "ETIQUETA_ERROR" => "Problema base de datos - consulta acciones disponible",
  1079. "LISTA_ACCIONES" => '',
  1080. ],
  1081. ];
  1082. }
  1083. $list = [];
  1084. if (Database::num_rows($rs)) {
  1085. while ($row = Database::fetch_assoc($rs)) {
  1086. $params = new stdClass();
  1087. $params->ORIGEN_ACCION = $row['action_origin'];
  1088. $params->CODIGO_ACCION = $row['action_code'];
  1089. $list[] = new SoapVar($params, SOAP_ENC_OBJECT);
  1090. }
  1091. }
  1092. $result = new stdClass();
  1093. $result->RESPUESTA_OBT_LISTA_ACCIONES = new stdClass();
  1094. $result->RESPUESTA_OBT_LISTA_ACCIONES->CODIGO_RETORNO = 0;
  1095. $result->RESPUESTA_OBT_LISTA_ACCIONES->ETIQUETA_ERROR = 'Correcto';
  1096. if (!empty($list)) {
  1097. $result->RESPUESTA_OBT_LISTA_ACCIONES->ID_ACCION = $list;
  1098. }
  1099. return $result;
  1100. }
  1101. public function eliminarAccion($eliminarAccionInput)
  1102. {
  1103. /* Tracking Log */
  1104. $tableLog = Database::get_main_table('plugin_sepe_log');
  1105. $paramsLog = [
  1106. 'ip' => $_SERVER['REMOTE_ADDR'],
  1107. 'action' => "eliminarAccion",
  1108. 'fecha' => date("Y-m-d H:i:s"),
  1109. ];
  1110. Database::insert($tableLog, $paramsLog);
  1111. /* End tracking log */
  1112. $actionOrigin = $eliminarAccionInput->ID_ACCION->ORIGEN_ACCION;
  1113. $actionCode = $eliminarAccionInput->ID_ACCION->CODIGO_ACCION;
  1114. if (empty($actionOrigin) || empty($actionCode)) {
  1115. return [
  1116. "RESPUESTA_ELIMINAR_ACCION" => [
  1117. "CODIGO_RETORNO" => "2",
  1118. "ETIQUETA_ERROR" => "Error en parametro",
  1119. ],
  1120. ];
  1121. }
  1122. $table = Database::get_main_table('plugin_sepe_actions');
  1123. $sql = "DELETE FROM $table
  1124. WHERE action_origin='".$actionOrigin."' AND action_code='".$actionCode."';";
  1125. $rs = Database::query($sql);
  1126. if (!$rs) {
  1127. return [
  1128. "RESPUESTA_ELIMINAR_ACCION" => [
  1129. "CODIGO_RETORNO" => "-1",
  1130. "ETIQUETA_ERROR" => "Problema base de datos - consulta acciones disponible",
  1131. ],
  1132. ];
  1133. }
  1134. return [
  1135. "RESPUESTA_ELIMINAR_ACCION" => [
  1136. "CODIGO_RETORNO" => "0",
  1137. "ETIQUETA_ERROR" => "Correcto",
  1138. ],
  1139. ];
  1140. }
  1141. // yyyy-mm-dd to dd/mm/yyyy
  1142. public static function undoFixDate($date)
  1143. {
  1144. if ($date == '0000-00-00' || empty($date)) {
  1145. return null;
  1146. }
  1147. $date = explode('-', $date);
  1148. $date = $date[2].'/'.$date[1].'/'.$date[0];
  1149. return $date;
  1150. }
  1151. // dd/mm/yyyy to yyyy-mm-dd
  1152. public static function fixDate($date)
  1153. {
  1154. if ($date == '00/00/0000' || empty($date)) {
  1155. return null;
  1156. }
  1157. $date = explode('/', $date);
  1158. // Year-month-day
  1159. $date = $date[2].'-'.$date[1].'-'.$date[0];
  1160. return $date;
  1161. }
  1162. protected function checkAuth()
  1163. {
  1164. if (!$this->authenticated) {
  1165. error_log('403');
  1166. }
  1167. }
  1168. }