Skip to content

Commit fe1258c

Browse files
committed
Rewrite from acadre XML to eDox XML.
1 parent 1474d7b commit fe1258c

File tree

1 file changed

+133
-160
lines changed

1 file changed

+133
-160
lines changed

plugins/mm/os2web_edoc_esdh_mm.inc

Lines changed: 133 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
/**
44
* @file
5-
* This file describes the MM plugin as implemented by SBSYS
5+
* This file describes the MM plugin as implemented by eDoc
66
*/
77

88
/**
99
* Plugin definition with callbacks
1010
*/
1111
$plugin = array(
12-
'description' => t('SBSYS ESDH MM Backend'),
12+
'description' => t('eDoc ESDH MM Backend'),
1313
'version' => 1,
1414
'test' => 'os2web_edoc_esdh_mm_test',
1515
'get_import_list' => 'os2web_edoc_esdh_mm_get_import_list',
@@ -32,19 +32,15 @@ function os2web_edoc_esdh_mm_test($stuff) {
3232
*/
3333
function os2web_edoc_esdh_mm_get_import_list() {
3434
/*
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.
3738
*/
3839
$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);
4742
}
43+
error_log(print_r($xml_file, 1 ));
4844
return $uris;
4945
}
5046

@@ -66,47 +62,69 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
6662
if (is_file(drupal_realpath($file))) {
6763
$manifest = simplexml_load_file(drupal_realpath($file));
6864
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;
7374
}
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;
105116
}
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+
// }
106124
}
107125
}
108126
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);
110128
}
111129
}
112130
return $meetings;
@@ -115,129 +133,108 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
115133
/**
116134
* Imports a meeting from filesystem.
117135
*
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.
120141
*
121142
* @return mixed
122143
* Meeting_struct array for an accepted import, else FALSE
123144
*/
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'));
154148

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;
163151

164-
// Type:
165-
switch ($info['type']) {
166-
case 1:
167-
$meeting['type'] = 'Dagsorden';
168-
break;
169152

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+
));
173158

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));
178160

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;
183171
}
184172
}
185173
// 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;
192176
}
177+
watchdog('eDoc MM', 'File do not exist in folder. %file', array('%file' => $xml_item_pdf), WATCHDOG_WARNING);
193178
return FALSE;
194179
}
195180

196181
/**
197182
* Imports a single item for an agenda.
198183
*
199-
* @param array $info
200-
* Import info array
184+
* @param array $meeting
185+
* Meeting array.
186+
*
201187
* @param SimpleXMLElement $xml
202188
* Xml segment containing the item
203189
*
204190
* @return array
205191
* The imported item.
206192
*/
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+
210199
$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,
214203
'bullets' => array(),
215204
'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+
),
216212
);
217213
// Deny closed content.
218-
if ($item['access'] !== 'Lukket') {
214+
if ($document_type === 'SKAL PUBLICERES') {
219215
// 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') {
234231
$item['enclosures'][] = array(
235232
'uri' => implode('/', array(
236233
variable_get('os2web_edoc_esdh_mm_path', MM_IMPORT_DIR),
237234
$info['filesfolder'],
238235
$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,
241238
);
242239
}
243240
}
@@ -246,30 +243,6 @@ function _os2web_edoc_esdh_import_item($info, $xml) {
246243
return $item;
247244
}
248245

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-
273246
/**
274247
* Case insensitive fileexists(). Code from comments on php.net.
275248
*
@@ -344,7 +317,7 @@ function _os2web_edoc_esdh_mm_order_addenums($drush = FALSE) {
344317
}
345318
if (isset($meetings[$meeting_id[0]['value']][$meeting_sub_id[0]['value']])) {
346319
// 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);
348321
node_delete($node->nid);
349322
}
350323
else {

0 commit comments

Comments
 (0)