ParserDatabaseBruto.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3. class ParserDatabaseBruto
  4. {
  5. protected $idLicitacion = 0;
  6. protected $fechaInicioParser = "";
  7. protected $CI;
  8. protected $nombreLog = "";
  9. public function __construct()
  10. {
  11. $this->CI = &get_instance();
  12. $this->CI->load->model("Parser_model");
  13. }
  14. public function setDatosParser($arrayDatosSucios, $fecha, $datosPerfil)
  15. {
  16. $this->fechaInicioParser = $fecha;
  17. $this->nombreLog = "setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $this->fechaInicioParser;
  18. if (!empty($arrayDatosSucios)) {
  19. foreach ($arrayDatosSucios as $nombreArchivo => $datosArchivo) {
  20. guardar_log($this->nombreLog, "ARCHIVO ---" . $nombreArchivo, false);
  21. foreach ($datosArchivo as $row) {
  22. $idLicitacion = $this->setInicioLicitacion($row['general']);
  23. if ($idLicitacion['result']) {
  24. $this->idLicitacion = $idLicitacion['id'];
  25. $this->setDatosSingular($row, "contractInfo", "BRUTO_contract_folder", $this->idLicitacion, "ContractInfo", "id_ajena_licitacion");
  26. $this->setDatosSingular($row, "tenderingProcess", "BRUTO_tendering_process", $this->idLicitacion, "TenderingProcess", "id_ajena_licitacion");
  27. $this->setProcurementProject($row['procurementProject']);
  28. $this->setProcurementProjectLot($row['procurementProjectLot']);
  29. $this->setTenderingTerms($row['tenderingTerms']);
  30. $this->setLocatedContractingParty($row['locatedContractingParty']);
  31. $this->setParty($row['party']);
  32. $this->setValidNoticeInfo($row['validNoticeInfo']);
  33. $this->setDatosMultiples($row, "tenderingResult", "BRUTO_tender_result", $this->idLicitacion, "TenderResult", "id_ajena_licitacion");
  34. $this->setDatosMultiples($row, "legalDocs", "BRUTO_legal_documents", $this->idLicitacion, "LegalDocs", 'id_ajena_licitacion');
  35. $this->setDatosMultiples($row, "technicalDocs", "BRUTO_technical_documents", $this->idLicitacion, "TechnicalDocs", "id_ajena_licitacion");
  36. $this->setDatosMultiples($row, "generalDocs", "BRUTO_general_documents", $this->idLicitacion, "GeneralDocs", "id_ajena_licitacion");
  37. $this->setDatosMultiples($row, "additionalDocs", "BRUTO_additional_documents", $this->idLicitacion, "AdditionalDocs", "id_ajena_licitacion");
  38. }
  39. }
  40. }
  41. }
  42. return;
  43. }
  44. private function setInicioLicitacion($datosInicioLicitacion): array
  45. {
  46. $result = array("result" => false, "id" => 0);
  47. $insertLicitacion = $this->CI->Parser_model->setInicioLicitacion($datosInicioLicitacion);
  48. if ($insertLicitacion) {
  49. $result = array("result" => true, "id" => $insertLicitacion);
  50. guardar_log($this->nombreLog, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'] . " - BBDD Licitación ID " . $insertLicitacion, "false");
  51. } else {
  52. $result = array("result" => true, "id" => 0);
  53. guardar_log($this->nombreLog, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'], "false", 2);
  54. }
  55. return $result;
  56. }
  57. private function setLocatedContractingParty($contractInfo): void
  58. {
  59. $locatedContractingPartyId = $this->setDatosSingular($contractInfo, "locatedContractingParty", "BRUTO_located_contracting_party", $this->idLicitacion, "locatedContractingParty", "id_ajena_licitacion");
  60. $this->setDatosMultiples($contractInfo, "activity", "BRUTO_located_contracting_party_activity", $locatedContractingPartyId, "locatedContractingParty_Activity", "id_ajena_lcp");
  61. }
  62. private function setParty($partyInfo): void
  63. {
  64. $partyId = $this->setDatosSingular($partyInfo, "party", "BRUTO_party", $this->idLicitacion, "PartyInfo", "id_ajena_licitacion");
  65. $this->setDatosMultiples($partyInfo, "partyIdentification", "BRUTO_party_party_idenfitication", $partyId, "PartyInfo_PartyIdentification", "id_ajena_party");
  66. }
  67. private function setProcurementProject($procurementInfo): void
  68. {
  69. $procurementProjectId = $this->setDatosSingular($procurementInfo, "budget", "BRUTO_procurement_project", $this->idLicitacion, "ProcurementProject", "id_ajena_licitacion");
  70. $this->setDatosMultiples($procurementInfo, "itemClass", "BRUTO_procurement_project_itemClass", $procurementProjectId, "ProcurementProject_ItemClass", "id_ajena_pp");
  71. }
  72. private function setProcurementProjectLot($procurementLotInfo): void
  73. {
  74. $resultInsert = 0;
  75. if (!empty($procurementLotInfo)) {
  76. $aux = 0;
  77. foreach ($procurementLotInfo as $row) {
  78. $setInsert = array();
  79. $setInsert[$aux] = $row;
  80. $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
  81. unset($setInsert[$aux]['itemClassification']);
  82. if (!empty($setInsert)) {
  83. $resultInsert = insertBucle($setInsert, "BRUTO_procurement_project_lot", $this->nombreLog);
  84. if (array_key_exists('itemClassification', $row)) {
  85. $this->setDatosMultiples($row, "itemClassification", "BRUTO_procurement_project_lot_item", $resultInsert, "ProcurementLotItem", "id_ajena_ppl");
  86. }
  87. }
  88. $aux++;
  89. }
  90. if ($resultInsert) {
  91. $result = array("result" => true);
  92. guardar_log($this->nombreLog, "ProcurementLot Finalizada Inserción", "false");
  93. } else {
  94. $result = array("result" => true, "id" => 0);
  95. guardar_log($this->nombreLog, "ProcurementLot Fallida", "false", 2);
  96. }
  97. } else {
  98. guardar_log($this->nombreLog, "ProcurementLot vacio", "false");
  99. }
  100. }
  101. private function setTenderingTerms($tenderingTermsInfo): void
  102. {
  103. $resultInsert = 0;
  104. if (!empty($tenderingTermsInfo)) {
  105. $setInsert = array();
  106. $setInsert['tenderingTerms'][0] = $tenderingTermsInfo[0];
  107. $setInsert['tenderingTerms'][0]['id_ajena_licitacion'] = $this->idLicitacion;
  108. if (!empty($setInsert)) {
  109. $resultInsert = insertBucle($setInsert['tenderingTerms'], "BRUTO_tendering_terms", $this->nombreLog);
  110. if ($resultInsert > 0) {
  111. $this->setDatosMultiples($tenderingTermsInfo, 1, "BRUTO_tendering_terms_awarding_terms", $resultInsert, "TenderingTermsAwardingTerms", "id_ajena_tt");
  112. $this->setDatosMultiples($tenderingTermsInfo, 2, "BRUTO_tendering_terms_qualification_request", $resultInsert, "TenderingTermsQualificationRequest", "id_ajena_tt");
  113. $this->setDatosMultiples($tenderingTermsInfo, 3, "BRUTO_tendering_terms_financial_evaluation", $resultInsert, "TenderingTermsFinancialEvaluation", "id_ajena_ttfe");
  114. $this->setDatosMultiples($tenderingTermsInfo, 4, "BRUTO_tendering_terms_specific_terms", $resultInsert, "TenderingTermsSpecificRequirement", "id_ajena_tt");
  115. }
  116. }
  117. if ($resultInsert) {
  118. $result = array("result" => true);
  119. guardar_log($this->nombreLog, "TenderingTerms Finalizada Inserción", "false");
  120. } else {
  121. $result = array("result" => true, "id" => 0);
  122. guardar_log($this->nombreLog, "TenderingTerms Fallida", "false", 2);
  123. }
  124. } else {
  125. guardar_log($this->nombreLog, "TenderingTerms vacio", "false");
  126. }
  127. }
  128. private function setValidNoticeInfo($validNoticeInfo): void
  129. {
  130. $resultInsert = 0;
  131. if (!empty($validNoticeInfo)) {
  132. $aux = 0;
  133. foreach ($validNoticeInfo as $row) {
  134. $setInsert = array();
  135. $setInsert[$aux] = $row;
  136. $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
  137. unset($setInsert[$aux]['documento']);
  138. unset($setInsert[$aux]['fechas']);
  139. if (!empty($setInsert)) {
  140. $resultInsert = insertBucle($setInsert, "BRUTO_valid_notice_info", $this->nombreLog);
  141. if ($resultInsert > 0) {
  142. $this->setDatosMultiples($row, "documento", "BRUTO_valid_notice_info_documento", $resultInsert, "validNoticeInfoFechas", "id_ajena_vni");
  143. $this->setDatosMultiples($row, "fechas", "BRUTO_valid_notice_info_fecha", $resultInsert, "validNoticeInfoDocumento", "id_ajena_vni");
  144. }
  145. }
  146. $aux++;
  147. }
  148. if ($resultInsert) {
  149. $result = array("result" => true);
  150. guardar_log($this->nombreLog, "validNoticeInfo Finalizada Inserción", "false");
  151. } else {
  152. $result = array("result" => true, "id" => 0);
  153. guardar_log($this->nombreLog, "validNoticeInfo Fallida", "false", 2);
  154. }
  155. } else {
  156. guardar_log($this->nombreLog, "validNoticeInfo vacio", "false");
  157. }
  158. }
  159. private function setDatosSingular($arrayDatos, $arrayKey, $tabla, $idAjena = 0, $nodoLog, $txtIdAjena): int
  160. {
  161. $insertedId = 0;
  162. if (!empty($arrayDatos) && array_key_exists($arrayKey, $arrayDatos)) {
  163. $arrayInsertar = array();
  164. $arrayInsertar[0] = $arrayDatos[$arrayKey];
  165. if ($idAjena > 0) {
  166. $arrayInsertar[0][$txtIdAjena] = $idAjena;
  167. }
  168. $insertedId = insertBucle($arrayInsertar, $tabla, $this->nombreLog);
  169. if ($insertedId == 0) {
  170. guardar_log($this->nombreLog, $nodoLog . " Fallido", "false");
  171. } else {
  172. guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
  173. }
  174. } else {
  175. guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
  176. }
  177. return $insertedId;
  178. }
  179. private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $idAjena = 0, $nodoLog, $txtIdAjena): void
  180. {
  181. $setInsert = array();
  182. $resultInsert = 0;
  183. if (array_key_exists($arrayKey, $arrayDatos)) {
  184. if (!empty($arrayDatos[$arrayKey])) {
  185. $aux = 0;
  186. foreach ($arrayDatos[$arrayKey] as $row) {
  187. $setInsert[$aux] = $row;
  188. if ($idAjena > 0) {
  189. $setInsert[$aux][$txtIdAjena] = $idAjena;
  190. }
  191. $aux++;
  192. }
  193. if (!empty($setInsert)) {
  194. $resultInsert = insertBucle($setInsert, $tabla, $this->nombreLog);
  195. }
  196. if ($resultInsert) {
  197. $result = array("result" => true);
  198. guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
  199. } else {
  200. $result = array("result" => true, "id" => 0);
  201. guardar_log($this->nombreLog, $nodoLog . " Fallida", "false", 2);
  202. }
  203. } else {
  204. guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
  205. }
  206. } else {
  207. guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
  208. }
  209. }
  210. }
  211. /* End of file ParserSetDatabase.php */
  212. /* Location: ./application/libraries/ParserSetDatabase.php */