2
2
3
3
/**
4
4
* @file
5
- * This file describes the MM plugin as implemented by SBSYS
5
+ * This file describes the MM plugin as implemented by eDoc
6
6
*/
7
7
8
8
/**
9
9
* Plugin definition with callbacks
10
10
*/
11
11
$ plugin = array (
12
- 'description ' => t ('SBSYS ESDH MM Backend ' ),
12
+ 'description ' => t ('eDoc ESDH MM Backend ' ),
13
13
'version ' => 1 ,
14
14
'test ' => 'os2web_edoc_esdh_mm_test ' ,
15
15
'get_import_list ' => 'os2web_edoc_esdh_mm_get_import_list ' ,
@@ -32,19 +32,15 @@ function os2web_edoc_esdh_mm_test($stuff) {
32
32
*/
33
33
function os2web_edoc_esdh_mm_get_import_list () {
34
34
/*
35
- * For the sbsys service, we need to miport meetings from xml files.
36
- * We will enumerate the list with the publication-id as parsed from the filename.
35
+ * For the eDoc service, we need to import meetings from xml files.
36
+ * We will enumerate the list with the publication-id
37
+ * as parsed from the dir name of the manifest.
37
38
*/
38
39
$ uris = array ();
39
- foreach (file_scan_directory (variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ), '/\.xml$/i ' , array ('recurse ' => FALSE )) as $ xml_file ) {
40
- $ pub_id = (int ) str_replace ('XML_ ' , '' , $ xml_file ->name );
41
- if (is_numeric ($ pub_id )) {
42
- $ uris [] = array ('id ' => $ pub_id , 'uri ' => $ xml_file ->uri );
43
- }
44
- else {
45
- $ uris [] = array ('id ' => $ xml_file ->name , 'uri ' => $ xml_file ->uri );
46
- }
40
+ foreach (file_scan_directory (variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ), '/\.xml$/i ' , array ('recurse ' => TRUE )) as $ xml_file ) {
41
+ $ uris [] = array ('id ' => dirname ($ xml_file ->uri ), 'uri ' => $ xml_file ->uri );
47
42
}
43
+ error_log (print_r ($ xml_file , 1 ));
48
44
return $ uris ;
49
45
}
50
46
@@ -66,47 +62,69 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
66
62
if (is_file (drupal_realpath ($ file ))) {
67
63
$ manifest = simplexml_load_file (drupal_realpath ($ file ));
68
64
if (is_object ($ manifest )) {
69
- $ agenda_id = (int ) array_shift ($ manifest ->xpath ("/root/table[@name='agenda']/fields/field/@sysid " ));
70
- $ items_xml = $ manifest ->xpath ("//table[@name='producedAgenda']/fields " );
71
- if (empty ($ items_xml )) {
72
- watchdog ('sbsys MM ' , 'Empty list of import items in %file. ' , array ('%file ' => $ file ), WATCHDOG_WARNING );
65
+ $ committee = (string ) array_shift ($ manifest ->xpath ("/Meeting/Committee " ));
66
+ $ meeting_date = (string ) array_shift ($ manifest ->xpath ("/Meeting/MeetingDate " ));
67
+ $ directory_name = dirname (drupal_realpath ($ file ));
68
+
69
+ // Check if the committee is allowed to publish.
70
+ $ publish_committee = array_map ('trim ' , explode (', ' , variable_get ('os2web_meetings_approved_committee ' , MM_DEFAULT_APPROVED )));
71
+ if ($ committee == '' || !in_array ($ committee , $ publish_committee )) {
72
+ watchdog ('eDoc MM ' , 'Ignored agenda from %committee . ' , array ('%committee ' => $ committee ));
73
+ return FALSE ;
73
74
}
74
- foreach ($ items_xml as $ xml_item ) {
75
- $ agendainfo = array (
76
- // 'sysid' => (int) array_shift($xml_item->xpath('field/@sysid')),
77
- 'sysid ' => $ agenda_id ,
78
- 'publish ' => (int ) array_shift ($ xml_item ->xpath ('field/@publish ' )),
79
- 'access ' => (string ) array_shift ($ xml_item ->xpath ('field/@access ' )),
80
- 'filesfolder ' => (string ) array_shift ($ xml_item ->xpath ('field/@filesfolder ' )),
81
- 'xmlfilename ' => (string ) array_shift ($ xml_item ->xpath ('field/@xmlfilename ' )),
82
- 'docfilename ' => (string ) array_shift ($ xml_item ->xpath ('field/@docfilename ' )),
83
- 'type ' => (int ) array_shift ($ xml_item ->xpath ('field/@type ' )),
84
- );
85
- if ($ agendainfo ['publish ' ] === 1 &&
86
- $ agendainfo ['access ' ] !== 'Lukket ' &&
87
- $ agendainfo ['filesfolder ' ] != '' ) {
88
- $ agenda_uri = implode ('/ ' , array (
89
- variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ),
90
- $ agendainfo ['filesfolder ' ],
91
- $ agendainfo ['xmlfilename ' ]));
92
- $ agendainfo ['agenda_uri ' ] = $ agenda_uri ;
93
- $ imported = _os2web_edoc_esdh_import_meeting ($ agendainfo );
94
- if (is_array ($ imported )) {
95
- $ imported ['publish ' ] = TRUE ;
96
- $ meetings [] = $ imported ;
97
- }
98
- }
99
- else {
100
- // Publication not published or public.
101
- $ meetings [] = array (
102
- 'system_id ' => $ agendainfo ['sysid ' ],
103
- 'publish ' => FALSE ,
104
- ) + os2web_esdh_provider_default_meeting ();
75
+
76
+ // Fix dates.
77
+ $ date_obj = date_create ($ meeting_date );
78
+ date_timezone_set ($ date_obj , timezone_open ('UTC ' ));
79
+ $ meeting_date = date_format ($ date_obj , 'Y-m-d H:i ' );
80
+
81
+ // Handle type of meeting.
82
+ // Type:
83
+ // switch ($info['type']) {
84
+ // case 1:
85
+ // $meeting['type'] = 'Dagsorden';
86
+ // break;
87
+
88
+ // case 2:
89
+ // $meeting['type'] = 'Referat';
90
+ // break;
91
+
92
+ // default:
93
+ // $meeting['type'] = 'Anden';
94
+ // watchdog('eDoc MM', 'Unknown meeting type value: %type', array('%type' => $meeting['type']), WATCHDOG_WARNING);
95
+ // }
96
+
97
+ $ meeting = array (
98
+ 'sys_id ' => $ directory_name ,
99
+ 'committee ' => $ committee ,
100
+ 'title ' => $ committee ,
101
+ 'meeting_date ' => $ meeting_date ,
102
+ );
103
+ error_log (print_r (array ('committee ' => $ committee , 'date ' => $ meeting_date ), 1 ));
104
+ $ meeting_agendas = $ manifest ->xpath ("/Meeting/MeetingAgendaTypes " );
105
+ if (empty ($ meeting_agendas )) {
106
+ watchdog ('eDoc MM ' , 'Empty list of import items in %file. ' , array ('%file ' => $ file ), WATCHDOG_WARNING );
107
+ }
108
+
109
+ foreach ($ meeting_agendas as $ meeting_agenda ) {
110
+
111
+ $ imported = _os2web_edoc_esdh_mm_import_meeting_agenda ($ meeting , $ meeting_agenda );
112
+
113
+ if (is_array ($ imported )) {
114
+ $ imported ['publish ' ] = TRUE ;
115
+ $ meetings [] = $ imported ;
105
116
}
117
+ // else {
118
+ // // Publication not published or public.
119
+ // $meetings[] = array(
120
+ // 'system_id' => $agendainfo['sysid'],
121
+ // 'publish' => FALSE,
122
+ // ) + os2web_esdh_provider_default_meeting();
123
+ // }
106
124
}
107
125
}
108
126
else {
109
- watchdog ('sbsys MM ' , 'Failed to parse XML in %file during import. ' , array ('%file ' => $ file ), WATCHDOG_WARNING );
127
+ watchdog ('eDoc MM ' , 'Failed to parse XML in %file during import. ' , array ('%file ' => $ file ), WATCHDOG_WARNING );
110
128
}
111
129
}
112
130
return $ meetings ;
@@ -115,129 +133,108 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
115
133
/**
116
134
* Imports a meeting from filesystem.
117
135
*
118
- * @param array $info
119
- * Meeting info block derived from XML.
136
+ * @param array $meeting
137
+ * Meeting array.
138
+ *
139
+ * @param SimpleXMLElement $agenda_xml
140
+ * Meeting agenda XML object.
120
141
*
121
142
* @return mixed
122
143
* Meeting_struct array for an accepted import, else FALSE
123
144
*/
124
- function _os2web_edoc_esdh_import_meeting ($ info ) {
125
- if (($ real_path = _os2web_edoc_esdh_similar_file_exists (drupal_realpath ($ info ['agenda_uri ' ]))) !== FALSE ) {
126
- $ xml = simplexml_load_file ($ real_path );
127
- $ meeting = array (
128
- 'title ' => (string ) array_shift ($ xml ->xpath ("//table[@name='meeting']/fields/field[@name='name'] " )),
129
- 'meeting_id ' => (string ) array_shift ($ xml ->xpath ("//table[@name='meeting']/fields/field[@name='sysid'] " )),
130
- 'system_id ' => $ info ['sysid ' ],
131
- 'publication_id ' => (string ) array_shift ($ xml ->xpath ("//table[@name='agenda']/fields/field[@name='sysid'] " )),
132
- 'creation_date ' => strtotime ((string ) array_shift ($ xml ->xpath ("//table[@name='agenda']/fields/field[@name='producedate'] " ))),
133
- 'description ' => (string ) array_shift ($ xml ->xpath ("//table[@name='agenda']/fields/field[@name='description'] " )),
134
- 'meeting_date_start ' => (string ) array_shift ($ xml ->xpath ("//table[@name='meeting']/fields/field[@name='date'] " )),
135
- 'meeting_date_finish ' => (string ) array_shift ($ xml ->xpath ("//table[@name='meeting']/fields/field[@name='finish'] " )),
136
- 'committee ' => (string ) array_shift ($ xml ->xpath ("//table[@name='committee']/fields/field[@name='name'] " )),
137
- 'committee_id ' => (string ) array_shift ($ xml ->xpath ("//table[@name='committee']/fields/field[@name='sysid'] " )),
138
- 'location ' => (string ) array_shift ($ xml ->xpath ("//table[@name='location']/fields/field[@name='name'] " )),
139
- 'items ' => array (),
140
- );
141
- $ publish_committee = array_map ('trim ' , explode (', ' , variable_get ('os2web_meetings_approved_committee ' , MM_DEFAULT_APPROVED )));
142
- if ($ meeting ['committee ' ] == '' || !in_array ($ meeting ['committee_id ' ], $ publish_committee )) {
143
- watchdog ('sbsys MM ' , 'Ignored agenda from %committee . ' , array ('%committee ' => $ meeting ['committee ' ]));
144
- return FALSE ;
145
- }
146
-
147
- // Fix dates:
148
- $ date_obj = date_create ($ meeting ['meeting_date_start ' ]);
149
- date_timezone_set ($ date_obj , timezone_open ('UTC ' ));
150
- $ meeting ['meeting_date_start ' ] = date_format ($ date_obj , 'Y-m-d H:i ' );
151
- $ date_obj = date_create ($ meeting ['meeting_date_finish ' ]);
152
- date_timezone_set ($ date_obj , timezone_open ('UTC ' ));
153
- $ meeting ['meeting_date_finish ' ] = date_format ($ date_obj , 'Y-m-d H:i ' );
145
+ function _os2web_edoc_esdh_mm_import_meeting_agenda (&$ meeting , $ agenda_xml ) {
146
+ $ xml_item_pdf = (string ) array_shift ($ agenda_xml ->xpath ('/PDFDocument ' ));
147
+ $ xml_item_type = (string ) array_shift ($ agenda_xml ->xpath ('/AgendaType ' ));
154
148
155
- // Full Doc:
156
- $ meeting ['full_doc ' ] = array (
157
- 'uri ' => implode ('/ ' , array (
158
- variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ),
159
- $ info ['filesfolder ' ],
160
- $ info ['docfilename ' ])),
161
- 'title ' => $ meeting ['title ' ],
162
- );
149
+ $ meeting ['items ' ] = array ();
150
+ $ meeting ['type ' ] = $ xml_item_type ;
163
151
164
- // Type:
165
- switch ($ info ['type ' ]) {
166
- case 1 :
167
- $ meeting ['type ' ] = 'Dagsorden ' ;
168
- break ;
169
152
170
- case 2 :
171
- $ meeting ['type ' ] = 'Referat ' ;
172
- break ;
153
+ $ pdf_uri = implode ('/ ' , array (
154
+ variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ),
155
+ $ meeting ['sys_id ' ],
156
+ $ xml_item_pdf ,
157
+ ));
173
158
174
- default :
175
- $ meeting ['type ' ] = 'Anden ' ;
176
- watchdog ('sbsys MM ' , 'Unknown meeting type value: %type ' , array ('%type ' => $ meeting ['type ' ]), WATCHDOG_WARNING );
177
- }
159
+ error_log (print_r ($ agendainfo , 1 ));
178
160
179
- foreach ($ xml ->xpath ("//table[@name='agendaitemparents'] " ) as $ item_xml ) {
180
- $ item_content_xml = array_shift ($ item_xml ->xpath ("table[@name='agendaitem'] " ));
181
- if (($ item = _os2web_edoc_esdh_import_item ($ info , $ item_content_xml )) !== FALSE ) {
182
- $ meeting ['items ' ][] = $ item ;
161
+ // Only add the agenda if its PDF exists.
162
+ if (file_exists (drupal_realpath ($ pdf_uri ))) {
163
+ $ agenda ['full_doc ' ] = array (
164
+ 'uri ' => $ pdf_uri ,
165
+ 'title ' => $ meeting ['committee ' ],
166
+ );
167
+ // Import all agenda items.
168
+ foreach ($ agenda_xml ->xpath ("/MeetingAgendaItems " ) as $ agenda_item ) {
169
+ if (($ item = _os2web_edoc_esdh_mm_import_meeting_agenda_item ($ meeting , $ agenda_item )) !== FALSE ) {
170
+ $ agenda ['items ' ][] = $ item ;
183
171
}
184
172
}
185
173
// Apply defaults, just in case we missed something.
186
- $ meeting += os2web_esdh_provider_default_meeting ();
187
- return $ meeting ;
188
- }
189
- else {
190
- // Requested file not found.
191
- watchdog ('sbsys MM ' , 'Failed to read agenda manifest file %uri ' , array ('%uri ' => $ info ['agenda_uri ' ]), WATCHDOG_WARNING );
174
+ $ agenda += os2web_esdh_provider_default_meeting ();
175
+ return $ agenda ;
192
176
}
177
+ watchdog ('eDoc MM ' , 'File do not exist in folder. %file ' , array ('%file ' => $ xml_item_pdf ), WATCHDOG_WARNING );
193
178
return FALSE ;
194
179
}
195
180
196
181
/**
197
182
* Imports a single item for an agenda.
198
183
*
199
- * @param array $info
200
- * Import info array
184
+ * @param array $meeting
185
+ * Meeting array.
186
+ *
201
187
* @param SimpleXMLElement $xml
202
188
* Xml segment containing the item
203
189
*
204
190
* @return array
205
191
* The imported item.
206
192
*/
207
- function _os2web_edoc_esdh_import_item ($ info , $ xml ) {
208
- $ id = (int ) array_shift ($ xml ->xpath ("../fields/field[@name='sort'] " ));
209
- $ name = (string ) array_shift ($ xml ->xpath ("fields/field[@name='name'] " ));
193
+ function _os2web_edoc_esdh_mm_import_meeting_agenda_item ($ meeting , $ xml ) {
194
+ $ xml_item_number = (int ) array_shift ($ xml ->xpath ("/AgendaItemNumber " ));
195
+ $ xml_item_pdf = (string ) array_shift ($ agenda_xml ->xpath ('/PDFDocument ' ));
196
+ $ xml_item_name = (string ) array_shift ($ agenda_xml ->xpath ('/Document/NeutralTitle ' ));
197
+ $ document_type = (string ) array_shift ($ agenda_xml ->xpath ('/Document/PublishingType ' ));
198
+
210
199
$ item = array (
211
- 'id ' => $ id ,
212
- 'title ' => 'Punkt ' . $ id . ' ' . $ name ,
213
- 'access ' => ( string ) array_shift ( $ xml -> xpath ( " fields/field[@name='accessname'] " )) ,
200
+ 'id ' => $ xml_item_number ,
201
+ 'title ' => 'Punkt ' . $ xml_item_number . ' ' . $ xml_item_name ,
202
+ 'access ' => $ document_type ,
214
203
'bullets ' => array (),
215
204
'enclosures ' => array (),
205
+ 'doc ' => array (
206
+ 'uri ' => implode ('/ ' , array (
207
+ variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ),
208
+ $ meeting ['sys_id ' ],
209
+ $ xml_item_pdf )),
210
+ 'title ' => $ xml_item_name ,
211
+ ),
216
212
);
217
213
// Deny closed content.
218
- if ($ item [ ' access ' ] !== ' Lukket ' ) {
214
+ if ($ document_type === ' SKAL PUBLICERES ' ) {
219
215
// Process attachments.
220
- foreach ($ xml ->xpath ("table[@name='bullet'] " ) as $ bullet_xml ) {
221
- if (($ bullet = _os2web_edoc_esdh_import_bullet ($ info , $ bullet_xml )) !== FALSE ) {
222
- if (is_int ($ bullet ['sort ' ]) && $ bullet ['sort ' ] > 0 ) {
223
- $ item ['bullets ' ][$ bullet ['sort ' ] - 1 ] = $ bullet ;
224
- }
225
- else {
226
- $ item ['bullets ' ][] = $ bullet ;
227
- }
228
- }
229
- }
230
- // Process enclosures.
231
- foreach ($ xml ->xpath ("table[@name='enclosure'] " ) as $ enclosure ) {
232
- $ filename_in = (string ) array_shift ($ enclosure ->xpath ("fields/field[@name='filename'] " ));
233
- if (strlen ($ filename_in ) > 0 ) {
216
+ // foreach ($xml->xpath("table[@name='bullet']") as $bullet_xml) {
217
+ // if (($bullet = _os2web_edoc_esdh_import_bullet($info, $bullet_xml)) !== FALSE) {
218
+ // if (is_int($bullet['sort']) && $bullet['sort'] > 0) {
219
+ // $item['bullets'][$bullet['sort'] - 1] = $bullet;
220
+ // }
221
+ // else {
222
+ // $item['bullets'][] = $bullet;
223
+ // }
224
+ // }
225
+ // }
226
+ // Process attachments.
227
+ foreach ($ xml ->xpath ("/Document/Attachments'] " ) as $ enclosure ) {
228
+ $ filename_in = (string ) array_shift ($ enclosure ->xpath ("/PDFDocument " ));
229
+ $ access = (string ) array_shift ($ enclosure ->xpath ("/PublishingType " ));
230
+ if (strlen ($ filename_in ) > 0 && $ access === 'SKAL PUBLICERES ' ) {
234
231
$ item ['enclosures ' ][] = array (
235
232
'uri ' => implode ('/ ' , array (
236
233
variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ),
237
234
$ info ['filesfolder ' ],
238
235
$ filename_in )),
239
- 'title ' => trim ((string ) array_shift ($ enclosure ->xpath ("fields/field[@name='name'] " ))),
240
- 'access ' => ( int ) array_shift ( $ enclosure -> xpath ( " fields/field[@name='access'] " )) ,
236
+ 'title ' => trim ((string ) array_shift ($ enclosure ->xpath ("/NeutralTitle " ))),
237
+ 'access ' => TRUE ,
241
238
);
242
239
}
243
240
}
@@ -246,30 +243,6 @@ function _os2web_edoc_esdh_import_item($info, $xml) {
246
243
return $ item ;
247
244
}
248
245
249
- /**
250
- * Imports a single bullet for an agenda item.
251
- *
252
- * @param array $info
253
- * Import info array
254
- * @param SimpleXMLElement $bullet_xml
255
- * Xml segment containing the bullet
256
- *
257
- * @return array
258
- * The imported bullet.
259
- */
260
- function _os2web_edoc_esdh_import_bullet ($ info , $ bullet_xml ) {
261
- $ bullet = array (
262
- 'title ' => (string ) array_shift ($ bullet_xml ->xpath ("fields/field[@name='bulletname'] " )),
263
- 'body ' => (string ) array_shift ($ bullet_xml ->xpath ("fields/field[@name='bulletcontent'] " )),
264
- 'sort ' => (int ) array_shift ($ bullet_xml ->xpath ("fields/field[@name='bulletsortorder'] " )),
265
- );
266
- if ($ bullet ['body ' ] === '' ) {
267
- return FALSE ;
268
- }
269
- $ bullet += os2web_esdh_provider_default_bullet ();
270
- return $ bullet ;
271
- }
272
-
273
246
/**
274
247
* Case insensitive fileexists(). Code from comments on php.net.
275
248
*
@@ -344,7 +317,7 @@ function _os2web_edoc_esdh_mm_order_addenums($drush = FALSE) {
344
317
}
345
318
if (isset ($ meetings [$ meeting_id [0 ]['value ' ]][$ meeting_sub_id [0 ]['value ' ]])) {
346
319
// Duplicate meeting detected.
347
- watchdog ('sbsys MM ' , 'Duplicate import found for meeting %mid. Deleting nid=%nid. ' , array ('%mid ' => $ meeting_id ['value ' ], '%nid ' => $ node ->nid ), WATCHDOG_WARNING );
320
+ watchdog ('eDoc MM ' , 'Duplicate import found for meeting %mid. Deleting nid=%nid. ' , array ('%mid ' => $ meeting_id ['value ' ], '%nid ' => $ node ->nid ), WATCHDOG_WARNING );
348
321
node_delete ($ node ->nid );
349
322
}
350
323
else {
0 commit comments