瀏覽代碼

Organizacion de archivos. Administrar descargas y logs por carpetas y fechas. Insercion de varios nodos en bbdd

Nermosis 3 年之前
父節點
當前提交
2bc1f99f44

application/controllers/FileDownload.php → application/controllers/Parser.php 查看文件

@@ -1,13 +1,13 @@
1 1
 <?php
2 2
 defined('BASEPATH') or exit('No direct script access allowed');
3 3
 
4
-class FileDownload extends CI_Controller
4
+class Parser extends CI_Controller
5 5
 {
6 6
 
7 7
     //TODO: Gestionar descarga de archivos por carpeta dia/hora
8
-
8
+    //TODO: PARAMETRIZAR BBDD -> SI EXISTE UN PROCESO EN MARCHA, NO INICIAR SIGUIENTE DESCARGA, AVISAR
9 9
     protected $rutaDiaria = FCPATH . "DOWNLOADS/DAILY/";
10
-    protected $rutaDiariaFormat = FCPATH . "DOWNLOADS/DAILY/format/";
10
+    protected $rutaDiariaFecha = "";
11 11
     protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/";
12 12
     protected $enlaceAtom = "";
13 13
 
@@ -16,19 +16,25 @@ class FileDownload extends CI_Controller
16 16
         parent::__construct();
17 17
         $this->load->helper('file');
18 18
         $this->load->helper('xml');
19
+        $this->load->library('parserfile');
19 20
     }
20 21
 
21 22
     public function index()
22 23
     {
23
-        $this->downloadProcess();
24
+        $fechaCarpeta = date("Y-m-d_H-i-s");
25
+        if ($this->newFolder($this->rutaDiaria . $fechaCarpeta)) {
26
+            $this->rutaDiariaFecha = $this->rutaDiaria . $fechaCarpeta . "/";
27
+            $this->downloadProcess();
28
+            $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta);
29
+        }
24 30
     }
25 31
 
26 32
     private function downloadProcess()
27 33
     {
28 34
         $fileName = basename(URL_DIARIA);
29
-        $this->downloadFile($fileName, URL_DIARIA, $this->rutaDiaria);
35
+        $this->downloadFile($fileName, URL_DIARIA, $this->rutaDiariaFecha);
30 36
 
31
-        $archivoAtom = $this->getFile($this->rutaDiaria . $fileName, $fileName);
37
+        $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName);
32 38
         $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
33 39
 
34 40
         //while ($nuevoAtomAttrNext !== "") {
@@ -36,8 +42,8 @@ class FileDownload extends CI_Controller
36 42
         while ($aux <= 3) {
37 43
 
38 44
             $fileName = basename($nuevoAtomAttrNext);
39
-            $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiaria);
40
-            $archivoAtom = $this->getFile($this->rutaDiaria . $fileName, $fileName);
45
+            $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiariaFecha);
46
+            $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName);
41 47
 
42 48
             $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
43 49
             $aux++;
@@ -56,11 +62,22 @@ class FileDownload extends CI_Controller
56 62
         return $array;
57 63
     }
58 64
 
65
+    private function newFolder($rutaFinal)
66
+    {
67
+        $result = false;
68
+        if (!is_dir($rutaFinal)) {
69
+            $result = mkdir($rutaFinal);
70
+            mkdir($rutaFinal . "/format");
71
+        }
72
+
73
+        return $result;
74
+    }
75
+
59 76
     private function formatXml($xml, $fileName)
60 77
     {
61 78
         $openingFormat = $this->regExIniciosEsquema($xml);
62 79
         $closureFormat = $this->regExFinalesEsquema($openingFormat);
63
-        file_put_contents($this->rutaDiariaFormat . $fileName, $closureFormat);
80
+        file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat);
64 81
     }
65 82
 
66 83
     private function readNextAttribute($archivo)

+ 1 - 1
application/helpers/funciones_helper.php 查看文件

@@ -71,7 +71,7 @@ if (!function_exists("insertBucle")) {
71 71
         }
72 72
 
73 73
         if (count($conjunto) > 0) {
74
-
74
+            guardar_log($nombreLog, count($conjunto));
75 75
             $CI->db->insert_batch($nombreTabla, $conjunto);
76 76
         }
77 77
 

+ 117 - 34
application/libraries/ParserDatabase.php 查看文件

@@ -7,6 +7,7 @@ class ParserDatabase
7 7
     //TODO: Functions return void
8 8
 
9 9
     protected $idLicitacion = 0;
10
+    protected $fechaInicioParser = "";
10 11
 
11 12
     public function __construct()
12 13
     {
@@ -14,12 +15,13 @@ class ParserDatabase
14 15
         $this->CI->load->model("Parser_model");
15 16
     }
16 17
 
17
-    public function setDatosParser($arrayDatosSucios)
18
+    public function setDatosParser($arrayDatosSucios, $fecha)
18 19
     {
20
+        $this->fechaInicioParser = $fecha;
19 21
         if (!empty($arrayDatosSucios)) {
20 22
 
21 23
             foreach ($arrayDatosSucios as $nombreArchivo => $datosArchivo) {
22
-                guardar_log("setLicitacion", "ARCHIVO ---" . $nombreArchivo, false);
24
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "ARCHIVO ---" . $nombreArchivo, false);
23 25
 
24 26
                 foreach ($datosArchivo as $row) {
25 27
                     $idLicitacion = $this->setInicioLicitacion($row['general']);
@@ -27,6 +29,12 @@ class ParserDatabase
27 29
                     if ($idLicitacion['result']) {
28 30
                         $this->idLicitacion = $idLicitacion['id'];
29 31
 
32
+                        $this->setContractInfo($row['contractInfo']);
33
+
34
+                        $this->setLocatedContractingParty($row['locatedContractingParty']);
35
+
36
+                        $this->setParty($row['party']);
37
+
30 38
                         $this->setLegalDocs($row['legalDocs']);
31 39
 
32 40
                         $this->setTechnicalDocs($row['technicalDocs']);
@@ -49,18 +57,102 @@ class ParserDatabase
49 57
 
50 58
         if ($insertLicitacion) {
51 59
             $result = array("result" => true, "id" => $insertLicitacion);
52
-            guardar_log("setLicitacion", "Licitacion ID " . $datosInicioLicitacion['id_licitacion'] . " - BBDD Licitación ID " . $insertLicitacion, "false");
60
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'] . " - BBDD Licitación ID " . $insertLicitacion, "false");
53 61
         } else {
54 62
             $result = array("result" => true, "id" => 0);
55
-            guardar_log("setLicitacion", "Licitacion ID " . $datosInicioLicitacion['id_licitacion'], "false", 2);
63
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'], "false", 2);
56 64
         }
57 65
 
58 66
         return $result;
59 67
     }
60 68
 
61
-    private function setLegalDocs($legalDocs): array
69
+    private function setContractInfo($contractInfo): void
70
+    {
71
+        $setInsert = array();
72
+        $resultInsert = 0;
73
+
74
+        if (!empty($contractInfo)) {
75
+
76
+            $contractInfo['id_ajena_licitacion'] = $this->idLicitacion;
77
+
78
+            if ($resultInsert) {
79
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "ContractInfo Finalizada Inserción", "false");
80
+            } else {
81
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "ContractInfo Fallida", "false", 2);
82
+            }
83
+        } else {
84
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "ContractInfo vacio", "false");
85
+        }
86
+    }
87
+
88
+    private function setLocatedContractingParty($contractInfo): void
89
+    {
90
+        $setInsert = array();
91
+        $contractInfoInsert = 0;
92
+
93
+        if (!empty($contractInfo)) {
94
+
95
+            $contractInfo['locatedContractingParty']['id_ajena_licitacion'] = $this->idLicitacion;
96
+
97
+            $contractInfoInsert = $this->CI->Parser_model->setLocatedContractInfo($contractInfo['locatedContractingParty']);
98
+
99
+            if ($contractInfoInsert) {
100
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "locatedContractingParty Finalizada Inserción", "false");
101
+
102
+                if (!empty($contractInfo['activity'])) {
103
+                    $activityArr = array();
104
+
105
+                    foreach ($contractInfo['activity'] as $clave => $row) {
106
+                        $activityArr[$clave] = $row;
107
+                        $activityArr[$clave]['id_ajena_located_contracting_party'] = $contractInfoInsert;
108
+                    }
109
+                    $activityInsert = insertBucle($activityArr, 'BRUTO_located_contracting_party_activity', "setLicitacion_" . $this->fechaInicioParser);
110
+                } else {
111
+                    guardar_log("setLicitacion_" . $this->fechaInicioParser, "locatedContractingParty_Activity vacio", "false");
112
+                }
113
+            } else {
114
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "locatedContractingParty Fallida", "false", 2);
115
+            }
116
+        } else {
117
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "locatedContractingParty vacio", "false");
118
+        }
119
+    }
120
+
121
+    private function setParty($partyInfo): void
122
+    {
123
+        $setInsert = array();
124
+        $partyInfoInsert = 0;
125
+
126
+        if (!empty($partyInfo)) {
127
+
128
+            $partyInfo['party']['id_ajena_licitacion'] = $this->idLicitacion;
129
+
130
+            $partyInfoInsert = $this->CI->Parser_model->setParty($partyInfo['party']);
131
+
132
+            if ($partyInfoInsert) {
133
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "PartyInfo Finalizada Inserción", "false");
134
+
135
+                if (!empty($partyInfo['partyIdentification'])) {
136
+                    $partyIdentificationArr = array();
137
+
138
+                    foreach ($partyInfo['partyIdentification'] as $clave => $row) {
139
+                        $partyIdentificationArr[$clave] = $row;
140
+                        $partyIdentificationArr[$clave]['id_ajena_party'] = $partyInfoInsert;
141
+                    }
142
+                    $activityInsert = insertBucle($partyIdentificationArr, 'BRUTO_party_party_idenfitication', "setLicitacion_" . $this->fechaInicioParser);
143
+                } else {
144
+                    guardar_log("setLicitacion_" . $this->fechaInicioParser, "PartyInfo_PartyIdentification vacio", "false");
145
+                }
146
+            } else {
147
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "PartyInfo Fallida", "false", 2);
148
+            }
149
+        } else {
150
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "PartyInfo vacio", "false");
151
+        }
152
+    }
153
+
154
+    private function setLegalDocs($legalDocs): void
62 155
     {
63
-        $result = array("result" => false, "id" => 0);
64 156
         $setInsert = array();
65 157
         $resultInsert = 0;
66 158
 
@@ -73,26 +165,24 @@ class ParserDatabase
73 165
             }
74 166
 
75 167
             if (!empty($setInsert)) {
76
-                $resultInsert = insertBucle($setInsert, 'BRUTO_legal_documents', 'setLicitacion');
168
+                $resultInsert = insertBucle($setInsert, 'BRUTO_legal_documents', "setLicitacion_" . $this->fechaInicioParser);
77 169
             }
78 170
 
79 171
             if ($resultInsert) {
80 172
                 $result = array("result" => true);
81
-                guardar_log("setLicitacion", "LegalDocs Finalizada Inserción", "false");
173
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "LegalDocs Finalizada Inserción", "false");
82 174
             } else {
83 175
                 $result = array("result" => true, "id" => 0);
84
-                guardar_log("setLicitacion", "LegalDocs Fallida", "false", 2);
176
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "LegalDocs Fallida", "false", 2);
85 177
             }
86 178
         } else {
87
-            guardar_log("setLicitacion", "LegalDocs vacio", "false");
179
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "LegalDocs vacio", "false");
88 180
         }
89 181
 
90
-        return $result;
91 182
     }
92 183
 
93
-    private function setGeneralDocs($generalDocs): array
184
+    private function setGeneralDocs($generalDocs): void
94 185
     {
95
-        $result = array("result" => false, "id" => 0);
96 186
         $setInsert = array();
97 187
         $resultInsert = 0;
98 188
         if (!empty($generalDocs)) {
@@ -104,26 +194,24 @@ class ParserDatabase
104 194
             }
105 195
 
106 196
             if (!empty($setInsert)) {
107
-                $resultInsert = insertBucle($setInsert, 'BRUTO_general_documents', 'setLicitacion');
197
+                $resultInsert = insertBucle($setInsert, 'BRUTO_general_documents', "setLicitacion_" . $this->fechaInicioParser);
108 198
             }
109 199
 
110 200
             if ($resultInsert) {
111 201
                 $result = array("result" => true);
112
-                guardar_log("setLicitacion", "GeneralDocs Finalizada Inserción", "false");
202
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "GeneralDocs Finalizada Inserción", "false");
113 203
             } else {
114 204
                 $result = array("result" => true, "id" => 0);
115
-                guardar_log("setLicitacion", "GeneralDocs Fallida", "false", 2);
205
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "GeneralDocs Fallida", "false", 2);
116 206
             }
117 207
         } else {
118
-            guardar_log("setLicitacion", "GeneralDocs vacio", "false");
208
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "GeneralDocs vacio", "false");
119 209
         }
120 210
 
121
-        return $result;
122 211
     }
123 212
 
124
-    private function setAdditionalDocs($additionalDocs): array
213
+    private function setAdditionalDocs($additionalDocs): void
125 214
     {
126
-        $result = array("result" => false, "id" => 0);
127 215
         $setInsert = array();
128 216
         $resultInsert = 0;
129 217
         if (!empty($additionalDocs)) {
@@ -135,26 +223,23 @@ class ParserDatabase
135 223
             }
136 224
 
137 225
             if (!empty($setInsert)) {
138
-                $resultInsert = insertBucle($setInsert, 'BRUTO_additional_documents', 'setLicitacion');
226
+                $resultInsert = insertBucle($setInsert, 'BRUTO_additional_documents', "setLicitacion_" . $this->fechaInicioParser);
139 227
             }
140 228
 
141 229
             if ($resultInsert) {
142 230
                 $result = array("result" => true);
143
-                guardar_log("setLicitacion", "AdditionalDocs Finalizada Inserción", "false");
231
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "AdditionalDocs Finalizada Inserción", "false");
144 232
             } else {
145 233
                 $result = array("result" => true, "id" => 0);
146
-                guardar_log("setLicitacion", "AdditionalDocs Fallida", "false", 2);
234
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "AdditionalDocs Fallida", "false", 2);
147 235
             }
148 236
         } else {
149
-            guardar_log("setLicitacion", "AdditionalDocs vacio", "false");
237
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "AdditionalDocs vacio", "false");
150 238
         }
151
-
152
-        return $result;
153 239
     }
154 240
 
155
-    private function setTechnicalDocs($technicalDocs): array
241
+    private function setTechnicalDocs($technicalDocs): void
156 242
     {
157
-        $result = array("result" => false, "id" => 0);
158 243
         $setInsert = array();
159 244
         $resultInsert = 0;
160 245
         if (!empty($technicalDocs)) {
@@ -166,21 +251,19 @@ class ParserDatabase
166 251
             }
167 252
 
168 253
             if (!empty($setInsert)) {
169
-                $resultInsert = insertBucle($setInsert, 'BRUTO_technical_documents', 'setLicitacion');
254
+                $resultInsert = insertBucle($setInsert, 'BRUTO_technical_documents', "setLicitacion_" . $this->fechaInicioParser);
170 255
             }
171 256
 
172 257
             if ($resultInsert) {
173 258
                 $result = array("result" => true);
174
-                guardar_log("setLicitacion", "TechnicalDocs Finalizada Inserción", "false");
259
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "TechnicalDocs Finalizada Inserción", "false");
175 260
             } else {
176 261
                 $result = array("result" => true, "id" => 0);
177
-                guardar_log("setLicitacion", "TechnicalDocs Fallida", "false", 2);
262
+                guardar_log("setLicitacion_" . $this->fechaInicioParser, "TechnicalDocs Fallida", "false", 2);
178 263
             }
179 264
         } else {
180
-            guardar_log("setLicitacion", "TechnicalDocs vacio", "false");
265
+            guardar_log("setLicitacion_" . $this->fechaInicioParser, "TechnicalDocs vacio", "false");
181 266
         }
182
-
183
-        return $result;
184 267
     }
185 268
 
186 269
 }

application/controllers/ParserFile.php → application/libraries/ParserFile.php 查看文件

@@ -1,28 +1,28 @@
1 1
 <?php
2 2
 defined('BASEPATH') or exit('No direct script access allowed');
3 3
 
4
-class ParserFile extends CI_Controller
4
+class ParserFile
5 5
 {
6
-    protected $rutaDiaria = FCPATH . "DOWNLOADS/DAILY/format";
6
+
7
+    protected $rutaDiaria = "";
7 8
     protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/format";
8 9
     protected $esquema = array('cbc-place-ext', 'cac-place-ext', 'cbc', 'cac', 'ns1');
9 10
 
10 11
     //TODO: Añadir los nodos que falten mirando la libreria de java
11
-    //TODO: Crear log por dia y hora
12
-    //TODO: Log de la carpeta seleccionada
12
+
13 13
     public function __construct()
14 14
     {
15
-        parent::__construct();
16
-        $this->load->helper('file');
17
-        $this->load->library('parserdatabase');
15
+        $this->CI = &get_instance();
16
+        $this->CI->load->helper('file');
17
+        $this->CI->load->library('parserdatabase');
18 18
     }
19 19
 
20
-    public function index()
20
+    public function index($rutaDiariaDownloader, $fechaInicioParser)
21 21
     {
22
+        $this->rutaDiaria = $rutaDiariaDownloader . "/format/";
22 23
         $files = get_filenames($this->rutaDiaria, true);
23 24
 
24
-        guardar_log("setLicitacion", "----------------------------------", false);
25
-        guardar_log("setLicitacion", "Licitaciones de fecha " . date("Y-m-d H:i:s"), false);
25
+        guardar_log("setLicitacion_" . $fechaInicioParser, "----------------------------------", false);
26 26
 
27 27
         $resultEntries = array();
28 28
         foreach ($files as $file) {
@@ -36,11 +36,11 @@ class ParserFile extends CI_Controller
36 36
 
37 37
                 $resultEntries[$filename][$aux]['general'] = $this->nodoEntry($row);
38 38
 
39
-                $resultEntries[$filename][$aux]['contractInfo'] = $this->nodoContractFolderStatus($row);
39
+                $resultEntries[$filename][$aux]['contractInfo'] = $this->nodoContractFolderStatus($row); //
40 40
 
41
-                $resultEntries[$filename][$aux]['locatedContractingParty'] = $this->nodoLocatedContractingParty($row);
41
+                $resultEntries[$filename][$aux]['locatedContractingParty'] = $this->nodoLocatedContractingParty($row); //
42 42
 
43
-                $resultEntries[$filename][$aux]['party'] = $this->nodoParty($row);
43
+                $resultEntries[$filename][$aux]['party'] = $this->nodoParty($row); //
44 44
 
45 45
                 $resultEntries[$filename][$aux]['procurementProject'] = $this->nodoPresupuesto($row);
46 46
 
@@ -54,13 +54,13 @@ class ParserFile extends CI_Controller
54 54
 
55 55
                 $resultEntries[$filename][$aux]['validNoticeInfo'] = $this->nodoValidNoticeInfo($row);
56 56
 
57
-                $resultEntries[$filename][$aux]['legalDocs'] = $this->nodoLegalDoc($row);
57
+                $resultEntries[$filename][$aux]['legalDocs'] = $this->nodoLegalDoc($row); //
58 58
 
59
-                $resultEntries[$filename][$aux]['technicalDocs'] = $this->nodoTechnicalDocumentReference($row);
59
+                $resultEntries[$filename][$aux]['technicalDocs'] = $this->nodoTechnicalDocumentReference($row); //
60 60
 
61
-                $resultEntries[$filename][$aux]['generalDocs'] = $this->nodoGeneralDocuments($row);
61
+                $resultEntries[$filename][$aux]['generalDocs'] = $this->nodoGeneralDocuments($row); //
62 62
 
63
-                $resultEntries[$filename][$aux]['additionalDocs'] = $this->nodoAdditionalDocumentReference($row);
63
+                $resultEntries[$filename][$aux]['additionalDocs'] = $this->nodoAdditionalDocumentReference($row); //
64 64
 
65 65
                 $aux++;
66 66
             }
@@ -70,7 +70,7 @@ class ParserFile extends CI_Controller
70 70
             file_put_contents($this->rutaDiaria . "/text_" . $filename . ".txt", $str);
71 71
         }
72 72
 
73
-        $this->parserdatabase->setDatosParser($resultEntries);
73
+        $this->CI->parserdatabase->setDatosParser($resultEntries, $fechaInicioParser);
74 74
     }
75 75
 
76 76
     private function nodoEntry($xml)
@@ -84,7 +84,7 @@ class ParserFile extends CI_Controller
84 84
         $resultEntries['summary'] = (string) $xml->summary;
85 85
         $resultEntries['title'] = (string) $xml->title;
86 86
         $resultEntries['updated'] = (string) $xml->updated;
87
-
87
+        $resultEntries['tipo_perfil_licitacion'] = 1;
88 88
         return $resultEntries;
89 89
     }
90 90
 
@@ -106,23 +106,23 @@ class ParserFile extends CI_Controller
106 106
         if (isset($xml->ContractFolderStatus->LocatedContractingParty)) {
107 107
             $LocatedContractingParty = $xml->ContractFolderStatus->LocatedContractingParty;
108 108
 
109
-            $resultEntries['contractingPartyTypeCode'] = $this->existNodo($LocatedContractingParty, "ContractingPartyTypeCode", 'string');
110
-            $resultEntries['contractingPartyTypeCodeUri'] = $this->existAttribute($LocatedContractingParty, "ContractingPartyTypeCode", 'string', 'listURI');
109
+            $resultEntries['locatedContractingParty']['contractingPartyTypeCode'] = $this->existNodo($LocatedContractingParty, "ContractingPartyTypeCode", 'string');
110
+            $resultEntries['locatedContractingParty']['contractingPartyTypeCodeUri'] = $this->existAttribute($LocatedContractingParty, "ContractingPartyTypeCode", 'string', 'listURI');
111 111
 
112 112
             if (isset($LocatedContractingParty->ActivityCode)) {
113 113
                 if (count($LocatedContractingParty->ActivityCode) > 1) {
114 114
                     for ($i = 0; $i < count($LocatedContractingParty->ActivityCode); $i++) {
115
-                        $resultEntries['activityCode'][$i] = (string) $LocatedContractingParty->ActivityCode[$i];
115
+                        $resultEntries['activity'][$i]['activityCode'] = (string) $LocatedContractingParty->ActivityCode[$i];
116
+                        $resultEntries['activity'][$i]['activityCodeUri'] = (string) $LocatedContractingParty->ActivityCode[$i]->attributes()['listURI'];
116 117
                     }
117 118
                 } else {
118
-                    $resultEntries['activityCode'][0] = $this->existNodo($LocatedContractingParty, "ActivityCode", 'string');
119
-                    $resultEntries['activityCodeUri'][0] = $this->existAttribute($LocatedContractingParty, "ActivityCode", 'string', 'listURI');
119
+                    $resultEntries['activity'][0]['activityCode'] = $this->existNodo($LocatedContractingParty, "ActivityCode", 'string');
120
+                    $resultEntries['activity'][0]['activityCodeUri'] = $this->existAttribute($LocatedContractingParty, "ActivityCode", 'string', 'listURI');
120 121
 
121 122
                 }
122
-
123 123
             }
124 124
 
125
-            $resultEntries['buyerProfileURIID'] = $this->existNodo($LocatedContractingParty, "BuyerProfileURIID", 'string');
125
+            $resultEntries['locatedContractingParty']['buyerProfileURIID'] = $this->existNodo($LocatedContractingParty, "BuyerProfileURIID", 'string');
126 126
 
127 127
             if (isset($LocatedContractingParty->ParentLocatedParty)) {
128 128
                 $this->RecurseXML($LocatedContractingParty->ParentLocatedParty);
@@ -141,22 +141,22 @@ class ParserFile extends CI_Controller
141 141
             //Datos Empresa -> direccion,nif, etc
142 142
             //LocatedContractingParty->Party
143 143
             $party = $contractFolder->Party;
144
-            $resultEntries['websiteURI'] = $this->existNodo($party, "WebsiteURI", 'string');
144
+            $resultEntries['party']['websiteURI'] = $this->existNodo($party, "WebsiteURI", 'string');
145 145
 
146
-            if (isset($party->PartyIdentification)) {
147
-                for ($i = 0; $i < $party->PartyIdentification; $i++) {
148
-                    $resultEntries['partyIdentification'][$i]['id'] = $this->existNodo($party->PartyIdentification, "ID", 'string');
149
-                    $resultEntries['partyIdentification'][$i]['attr'] = $this->existAttribute($party, "PartyIdentification", "string", 'schemeName');
146
+            if (isset($party->PartyIdentification) && !empty($party->PartyIdentification)) {
147
+                for ($i = 0; $i < count($party->PartyIdentification); $i++) {
148
+                    $resultEntries['partyIdentification'][$i]['idPartyIdent'] = $this->existNodo($party->PartyIdentification[$i], "ID", 'string');
149
+                    $resultEntries['partyIdentification'][$i]['attr'] = $this->existAttribute($party, $party->PartyIdentification[$i], "string", 'schemeName');
150 150
                 }
151 151
             }
152 152
 
153
-            $resultEntries['partyName'] = $this->existNodo($party->PartyName, "Name", 'string');
154
-            $resultEntries['city'] = $this->existNodo($party->PostalAddress, "CityName", 'string');
155
-            $resultEntries['codpostal'] = $this->existNodo($party->PostalAddress, "PostalZone", 'string');
156
-            $resultEntries['direccion'] = $this->existNodo($party->PostalAddress->AddressLine, "Line", 'string');
157
-            $resultEntries['country'] = $this->existNodo($party->PostalAddress->Country, "Name", 'string');
158
-            $resultEntries['contact_name'] = $this->existNodo($party->Contact, "Name", 'string');
159
-            $resultEntries['contact_email'] = $this->existNodo($party->Contact, "ElectronicMail", 'string');
153
+            $resultEntries['party']['partyName'] = $this->existNodo($party->PartyName, "Name", 'string');
154
+            $resultEntries['party']['city'] = $this->existNodo($party->PostalAddress, "CityName", 'string');
155
+            $resultEntries['party']['codpostal'] = $this->existNodo($party->PostalAddress, "PostalZone", 'string');
156
+            $resultEntries['party']['direccion'] = $this->existNodo($party->PostalAddress->AddressLine, "Line", 'string');
157
+            $resultEntries['party']['country'] = $this->existNodo($party->PostalAddress->Country, "Name", 'string');
158
+            $resultEntries['party']['contact_name'] = $this->existNodo($party->Contact, "Name", 'string');
159
+            $resultEntries['party']['contact_email'] = $this->existNodo($party->Contact, "ElectronicMail", 'string');
160 160
         }
161 161
         $resultFinal = $this->array_remove_empty($resultEntries);
162 162
         return $resultFinal;
@@ -555,82 +555,7 @@ class ParserFile extends CI_Controller
555 555
         return $haystack;
556 556
     }
557 557
 
558
-    /* public function xml2array($xml)
559
-{
560
-$arr = array();
561
-
562
-foreach ($xml->getNamespaces() + array(null) as $prefix => $namespace) {
563
-foreach ($xml->attributes($namespace) as $key => $value) {
564
-// Add prefixes to prefixed attributes
565
-if (is_string($prefix)) {
566
-$key = $prefix . '.' . $key;
567
-}
568
-$arr['@attributes'][$key] = (string) $value;
569
-}
570
-}
571
-
572
-foreach ($xml as $name => $element) {
573
-$value = $element->children() ? $this->xml2array($element) : trim($element);
574
-if ($value) {
575
-if (!isset($arr[$name])) {
576
-$arr[$name] = $value;
577
-} else {
578
-foreach ((array) $value as $k => $v) {
579
-if (is_numeric($k)) {
580
-$arr[$name][] = $v;
581
-} else {
582
-$arr[$name][$k] = array_merge(
583
-(array) $arr[$name][$k],
584
-(array) $v
585
-);
586
-}
587
-}
588
-}
589
-}
590
-}
591
-
592
-if ($content = trim((string) $xml)) {
593
-$arr[] = $content;
594
-}
595
-
596
-return $arr;
597
-}
598
-$reader = new \XMLReader;
599
-$reader->open($file); // where $path is the file path to the xml file
600
-
601
-// using a dirty trick to skip most of the xml that is irrelevant where $nodeName is the node im looking for
602
-// then in the next while loop i skip to the next node
603
-$data = array();
604
-while ($reader->read() && $reader->name !== "data");
605
-while ($reader->name === "data") {
606
-$doc = new \DOMDocument;
607
-$dom = $doc->importNode($reader->expand(), true);
608
-$data = $this->processDom($dom);
609
-$reader->next($dom->localName);
610
-}
611
-
612
-public function processDom(\DOMNode $node)
613
-{
614
-$data = [];
615
-/** @var \DomNode $childNode
616
-foreach ($node->childNodes as $childNode) {
617
-// child nodes include of a lot of #text nodes which are irrelevant for me, so i just skip them
618
-if ($childNode->nodeName === '#text') {
619
-continue;
620
-}
621
-$childData = $this->processDom($childNode);
622
-if ($childData === null || $childData === []) {
623
-$data[$childNode->localName] = $childNode->nodeValue;
624
-} else {
625
-$data[$childNode->localName] = $childData;
626
-}
627
-}
628
-return $data;
629
-}
630
-
631
- */
632
-
633 558
 }
634 559
 
635 560
 /* End of file ParserFile.php */
636
-/* Location: ./application/controllers/ParserFile.php */
561
+/* Location: ./application/libraries/ParserFile.php */

+ 0 - 11
application/libraries/index.html 查看文件

@@ -1,11 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-<head>
4
-	<title>403 Forbidden</title>
5
-</head>
6
-<body>
7
-
8
-<p>Directory access is forbidden.</p>
9
-
10
-</body>
11
-</html>

+ 12 - 0
application/models/Parser_model.php 查看文件

@@ -32,6 +32,18 @@ class Parser_model extends CI_Model
32 32
         return $this->db->insert_id();
33 33
     }
34 34
 
35
+    public function setLocatedContractInfo($locatedContractArr)
36
+    {
37
+        $this->db->insert('BRUTO_located_contracting_party', $locatedContractArr);
38
+        return $this->db->insert_id();
39
+    }
40
+
41
+    public function setParty($partyArr)
42
+    {
43
+        $this->db->insert('BRUTO_party', $partyArr);
44
+        return $this->db->insert_id();
45
+    }
46
+
35 47
 }
36 48
 
37 49
 /* End of file Parser_model.php */

+ 0 - 11
application/models/index.html 查看文件

@@ -1,11 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-<head>
4
-	<title>403 Forbidden</title>
5
-</head>
6
-<body>
7
-
8
-<p>Directory access is forbidden.</p>
9
-
10
-</body>
11
-</html>