123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <?php
- defined('BASEPATH') or exit('No direct script access allowed');
-
- class ParserDatabaseBruto
- {
- protected $idLicitacion = 0;
- protected $fechaInicioParser = "";
- protected $CI;
- protected $nombreLog = "";
-
- public function __construct()
- {
- $this->CI = &get_instance();
- $this->CI->load->model("Parser_model");
- }
-
- public function setDatosParser($arrayDatosSucios, $fecha, $datosPerfil)
- {
- $this->fechaInicioParser = $fecha;
- $this->nombreLog = "setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $this->fechaInicioParser;
-
- if (!empty($arrayDatosSucios)) {
-
- foreach ($arrayDatosSucios as $nombreArchivo => $datosArchivo) {
- guardar_log($this->nombreLog, "ARCHIVO ---" . $nombreArchivo, false);
-
- $this->setDatosMultiples($datosArchivo, "general", "bruto_datos_iniciales", "DatosIniciales");
-
- $this->setDatosMultiples($datosArchivo, "contractInfo", "BRUTO_contract_folder", "ContractInfo");
-
- $this->setDocumentosSingle($datosArchivo, "tenderingProcess", ["BRUTO_tendering_process", "mapa_nivel_tendering_process"], "TenderingProcess");
-
- $this->setProcurementProjectArray($datosArchivo);
-
- $this->setProcurementProjectLotArray($datosArchivo);
-
- $this->setTenderingTerms($datosArchivo);
-
- /*$this->setDatosMultiples($datosArchivo['tenderingTerms'], 1, "bruto_tendering_terms", "TenderingTerms");
-
- $this->setDatosMultiples($datosArchivo['tenderingTerms'], 2, "bruto_tendering_terms", "TenderingTerms");
-
- $this->setDatosMultiples($datosArchivo['tenderingTerms'], 3, "bruto_tendering_terms", "TenderingTerms");
-
- $this->setDatosMultiples($datosArchivo['tenderingTerms'], 4, "bruto_tendering_terms", "TenderingTerms");*/
-
- $this->setLocatedContractingParty($datosArchivo); //, "locatedContractingParty", "BRUTO_located_contracting_party", "locatedContractingParty");
-
- $this->setParty($datosArchivo);
-
- /*$this->setDatosMultiples($datosArchivo, "validNoticeInfo", "BRUTO_valid_notice_info", "ValideNoticeInfo");
-
- $this->setDatosMultiples($datosArchivo['validNoticeInfo'], "documento", "BRUTO_valid_notice_info_documento", "validNoticeInfoDocumento");
-
- $this->setDatosMultiples($datosArchivo['validNoticeInfo'], "fechas", "BRUTO_valid_notice_info_fecha", "validNoticeInfoFechas");*/
-
- $this->setInsertArryByArray($datosArchivo, "tenderingResult", ["BRUTO_tender_result", "mapa_nivel_tender_result"], "TenderResult");
-
- $this->setDocumentosSingle($datosArchivo, "legalDocs", ["BRUTO_legal_documents", "mapa_nivel_legal_docs"], "legalDocs");
-
- $this->setDocumentosSingle($datosArchivo, "technicalDocs", ["BRUTO_technical_documents", "mapa_nivel_technical_docs"], "TechnicalDocs");
-
- $this->setInsertArryByArray($datosArchivo, "generalDocs", ["BRUTO_general_documents", "mapa_nivel_general_docs"], "GeneralDocs");
-
- $this->setInsertArryByArray($datosArchivo, "additionalDocs", ["BRUTO_additional_documents", "mapa_nivel_additional_docs"], "additionalDocs");
- }
- }
-
- return;
- }
-
- private function setProcurementProjectArray($procurementProjectData)
- {
- $result = array();
- $coleccionMapaProcProject = array();
- $countColeccionProcProject = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_procurement_project");
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapaProcProject[] = $dataField->campo_bbdd;
- }
- $countColeccionProcProject = count($coleccionMapaProcProject);
-
- foreach ($procurementProjectData['procurementProject'] as $rowData) {
- $budget = $rowData['budget'];
- if ($countColeccionProcProject > count($budget)) {
- foreach ($coleccionMapaProcProject as $dataField) {
- if (!array_key_exists($dataField, $budget)) {
- $budget[$dataField] = "";
- }
- }
- }
-
- if (array_key_exists('itemClass', $rowData)) {
- foreach ($rowData['itemClass'] as $itemClass) {
- $result['itemClass'][] = $itemClass;
- }
- }
-
- $result['budget'][] = $budget;
-
- }
-
- $this->setDatosMultiples($result, "budget", "bruto_procurement_project", "ProcurementProject");
-
- $this->setDatosMultiples($result, "itemClass", "bruto_procurement_project_itemclass", "ProcurementProject_ItemClass");
- }
-
- private function setProcurementProjectLotArray($datosToSet)
- {
- $result = array();
- $coleccionMapa = array();
- $countColeccion = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_procurement_project_lot");
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapa[] = $dataField->campo_bbdd;
- }
- $countColeccion = count($coleccionMapa);
-
- foreach ($datosToSet['procurementProjectLot'] as $rowData) {
- if ($rowData != null) {
-
- foreach ($rowData['lot'] as $loteIndividual) {
- $procurementProjectLot = $loteIndividual;
- if ($countColeccion > count($procurementProjectLot)) {
- foreach ($coleccionMapa as $dataField) {
- if (!array_key_exists($dataField, $procurementProjectLot)) {
- $procurementProjectLot[$dataField] = "";
- }
- }
- }
- $result['procurementProjectLot'][] = $procurementProjectLot;
- }
-
- if (array_key_exists('itemClassification', $rowData)) {
- foreach ($rowData['itemClassification'] as $itemClass) {
- $result['itemClassification'][] = $itemClass;
- }
- }
-
- }
-
- }
-
- $this->setDatosMultiples($result, "procurementProjectLot", "bruto_procurement_project_lot", "procurementProjectLot");
-
- $this->setDatosMultiples($result, "itemClassification", "bruto_procurement_project_lot_item", "procurementProjectLot_itemClassification");
- }
-
- private function setTenderingTerms($datosToSet)
- {
- $result = array();
- $coleccionMapa = array();
- $countColeccion = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_tendering_terms");
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapa[] = $dataField->campo_bbdd;
- }
- $countColeccion = count($coleccionMapa);
-
- foreach ($datosToSet['tenderingTerms'] as $rowData) {
- if ($rowData != null) {
-
- if (array_key_exists('tenderingTerm', $rowData)) {
- $tenderTerms = $rowData['tenderingTerm'];
- if ($countColeccion > count($tenderTerms)) {
- foreach ($coleccionMapa as $dataField) {
- if (!array_key_exists($dataField, $tenderTerms)) {
- $tenderTerms[$dataField] = "";
- }
- }
- }
- $result['tenderingTerm'][] = $tenderTerms;
-
- }
-
- if (array_key_exists('awardingCriteria', $rowData)) {
- foreach ($rowData['awardingCriteria'] as $itemClass) {
- $result['awardingCriteria'][] = $itemClass;
- }
- }
-
- if (array_key_exists('TendererQualificationRequest', $rowData)) {
- foreach ($rowData['TendererQualificationRequest'] as $itemClass) {
- $result['TendererQualificationRequest'][] = $itemClass;
- }
- }
-
- if (array_key_exists('FinancialEvaluationCriteria', $rowData)) {
- foreach ($rowData['FinancialEvaluationCriteria'] as $itemClass) {
- $result['FinancialEvaluationCriteria'][] = $itemClass;
- }
- }
-
- if (array_key_exists('SpecificTendererRequirement', $rowData)) {
- foreach ($rowData['SpecificTendererRequirement'] as $itemClass) {
- $result['SpecificTendererRequirement'][] = $itemClass;
- }
- }
-
- }
-
- }
-
- $this->setDatosMultiples($result, "tenderingTerm", "bruto_tendering_terms", "tenderingTerm");
-
- $this->setDatosMultiples($result, "awardingCriteria", "bruto_tendering_terms_awarding_terms", "awardingCriteria");
-
- $this->setDatosMultiples($result, "FinancialEvaluationCriteria", "bruto_tendering_terms_financial_evaluation", "FinancialEvaluationCriteria");
-
- $this->setDatosMultiples($result, "TendererQualificationRequest", "bruto_tendering_terms_qualification_request", "TendererQualificationRequest");
-
- $this->setDatosMultiples($result, "SpecificTendererRequirement", "bruto_tendering_terms_specific_terms", "SpecificTendererRequirement");
-
- }
-
- private function setLocatedContractingParty($datosToSet)
- {
- $result = array();
- $coleccionMapa = array();
- $countColeccion = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_located_contracting_party");
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapa[] = $dataField->campo_bbdd;
- }
- $countColeccion = count($coleccionMapa);
-
- foreach ($datosToSet['locatedContractingParty'] as $rowData) {
- $locatedContractingParty = $rowData['locatedContractingParty'];
- if ($countColeccion > count($locatedContractingParty)) {
- foreach ($coleccionMapa as $dataField) {
- if (!array_key_exists($dataField, $locatedContractingParty)) {
- $locatedContractingParty[$dataField] = "";
- }
- }
- }
-
- if (array_key_exists('activity', $rowData)) {
- foreach ($rowData['activity'] as $itemClass) {
- $result['activity'][] = $itemClass;
- }
- }
-
- $result['locatedContractingParty'][] = $locatedContractingParty;
-
- }
-
- $this->setDatosMultiples($result, "locatedContractingParty", "bruto_located_contracting_party", "LocatedContractingParty");
-
- $this->setDatosMultiples($result, "activity", "bruto_located_contracting_party_activity", "LocatedContractingParty_Activity");
- }
-
- private function setParty($datosToSet)
- {
- $result = array();
- $coleccionMapa = array();
- $countColeccion = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_party");
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapa[] = $dataField->campo_bbdd;
- }
- $countColeccion = count($coleccionMapa);
-
- foreach ($datosToSet['party'] as $rowData) {
- $party = $rowData['party'];
- if ($countColeccion > count($party)) {
- foreach ($coleccionMapa as $dataField) {
- if (!array_key_exists($dataField, $party)) {
- $party[$dataField] = "";
- }
- }
- }
-
- if (array_key_exists('partyIdentification', $rowData)) {
- foreach ($rowData['partyIdentification'] as $itemClass) {
- $result['partyIdentification'][] = $itemClass;
- }
- }
-
- $result['party'][] = $party;
-
- }
-
- $this->setDatosMultiples($result, "party", "bruto_party", "Party");
-
- $this->setDatosMultiples($result, "partyIdentification", "bruto_party_party_idenfitication", "Party_PartyIdentification");
- }
-
- private function setDocumentosSingle($datosToSet, $arrayKey, $tablasMapa, $nombreLog)
- {
- if (array_key_exists($arrayKey, $datosToSet)) {
- $result = array();
- $coleccionMapa = array();
- $countColeccion = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla($tablasMapa[1]);
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapa[] = $dataField->campo_bbdd;
- }
- $countColeccion = count($coleccionMapa);
- foreach ($datosToSet[$arrayKey] as $rowData) {
- if ($rowData != null) {
- if ($countColeccion > count($rowData)) {
- foreach ($coleccionMapa as $dataField) {
- if (!array_key_exists($dataField, $rowData)) {
- $resultFinal[$dataField] = "";
- }
- }
- }
-
- $result[$arrayKey][] = $rowData;
- }
- }
-
- $this->setDatosMultiples($result, $arrayKey, $tablasMapa[0], $nombreLog);
- }
-
- }
-
- private function setInsertArryByArray($datosToSet, $arrayKey, $tablasMapa, $nombreLog)
- {
- if (array_key_exists($arrayKey, $datosToSet)) {
- $result = array();
- $coleccionMapa = array();
- $countColeccion = 0;
- $mapaDatos = $this->CI->Parser_model->getMapaByTabla($tablasMapa[1]);
-
- foreach ($mapaDatos['datos'] as $dataField) {
- $coleccionMapa[] = $dataField->campo_bbdd;
- }
- $countColeccion = count($coleccionMapa);
- foreach ($datosToSet[$arrayKey] as $rowData) {
-
- if ($rowData !== null) {
- foreach ($rowData as $documento) {
-
- $aux = $documento;
- if ($countColeccion > count($documento)) {
- foreach ($coleccionMapa as $dataField) {
- if (!array_key_exists($dataField, $documento)) {
- $aux[$dataField] = "";
- }
- }
- }
- $result[$arrayKey][] = $aux;
- }
- }
-
- }
-
- $this->setDatosMultiples($result, $arrayKey, $tablasMapa[0], $nombreLog);
- }
-
- }
-
- private function setValidNoticeInfo($validNoticeInfo): void
- {
-
- $resultInsert = 0;
-
- if (!empty($validNoticeInfo)) {
- $aux = 0;
- foreach ($validNoticeInfo as $datosArchivo) {
- $setInsert = array();
- $setInsert[$aux] = $datosArchivo;
- $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
-
- unset($setInsert[$aux]['documento']);
- unset($setInsert[$aux]['fechas']);
-
- if (!empty($setInsert)) {
- $resultInsert = insertBucle($setInsert, "BRUTO_valid_notice_info", $this->nombreLog);
-
- if ($resultInsert > 0) {
- $this->setDatosMultiples($datosArchivo, "documento", "BRUTO_valid_notice_info_documento", $resultInsert, "validNoticeInfoFechas", "id_ajena_vni");
-
- $this->setDatosMultiples($datosArchivo, "fechas", "BRUTO_valid_notice_info_fecha", $resultInsert, "validNoticeInfoDocumento", "id_ajena_vni");
- }
- }
- $aux++;
- }
-
- if ($resultInsert) {
- $result = array("result" => true);
- guardar_log($this->nombreLog, "validNoticeInfo Finalizada Inserción", "false");
- } else {
- $result = array("result" => true, "id" => 0);
- guardar_log($this->nombreLog, "validNoticeInfo Fallida", "false", 2);
- }
- } else {
- guardar_log($this->nombreLog, "validNoticeInfo vacio", "false");
- }
- }
-
- private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $nodoLog): void
- {
- $setInsert = array();
- $resultInsert = 0;
-
- if (array_key_exists($arrayKey, $arrayDatos)) {
- if (!empty($arrayDatos[$arrayKey])) {
-
- $resultInsert = insertBucleDuplicateOnKey($arrayDatos[$arrayKey], $tabla, $this->nombreLog);
-
- if ($resultInsert) {
- $result = array("result" => true);
- guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
- } else {
- $result = array("result" => true, "id" => 0);
- guardar_log($this->nombreLog, $nodoLog . " Fallida", "false", 2);
- }
- } else {
- guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
- }
- } else {
- guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
- }
- }
-
- }
-
- /* End of file ParserSetDatabase.php */
- /* Location: ./application/libraries/ParserSetDatabase.php */
|