Subversion Repositories Web Services

Rev

Rev 115056 | Rev 115699 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
82190 hhl 1
<?php
2
/**
3
 *
4
 * This file is part of Open Library System.
5
 * Copyright © 2009, Dansk Bibliotekscenter a/s,
6
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
7
 *
8
 * Open Library System is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * Open Library System is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21
 
22
//==============================================================================
23
 
24
 
25
/**
26
 * ncip - Håndterer kommunication til og fra lokalsystemer, ved brug af ncip protokollen
27
 *
28
 * @author Steen L. Frederiksen
29
 */
30
 
31
require_once("http_wrapper_class.php");
32
 
33
/** \brief ncip klasse
34
*
35
* ncip klassen håndterer opbygning og fortolkning af 5 typer ncip requests:
36
*   LookupUser
37
*   LookupItem
38
*   LookupRequest
39
*   CancelRequestItem
40
*   RenewItem
41
* ... samt opbygning og fortolkning af 5 typer ncip responses:
42
*   LookupUserResponse
43
*   LookupItemResponse
44
*   LookupRequestResponse
45
*   CancelRequestItemResponse
46
*   RenewItemResponse
47
*
48
* Nøjagtig de samme parameterblokke returneres ved fortolkingen af requests/responses.
49
*
50
*/
51
 
52
class ncip extends http_wrapper {
53
  private $debug;        // Debug logging boolean
54
  private $parameters;   // Parametre som php array
55
  private $dom;          // DomDocument
56
  private $dom_xml="";   // The XML ncip structure
57
 
58
  private $createMessages =
59
    array( "LookupUser"                => "_create_lookup_user_request",
60
           "LookupUserResponse"        => "_create_lookup_user_response",
61
           "LookupItem"                => "_create_lookup_item_request",
62
           "LookupItemResponse"        => "_create_lookup_item_response",
63
           "LookupRequest"             => "_create_lookup_request_request",
64
           "LookupRequestResponse"     => "_create_lookup_request_response",
65
           "CancelRequestItem"         => "_create_cancel_request_item_request",
66
           "CancelRequestItemResponse" => "_create_cancel_request_item_response",
67
           "RenewItem"                 => "_create_renew_item_request",
68
           "RenewItemResponse"         => "_create_renew_item_response",
69
           "UpdateRequestItem"         => "_create_update_request_item_request",
70
           "UpdateRequestItemResponse" => "_create_update_request_item_response" );
71
  private $parseMessages =
72
    array( "LookupUser"                => "_parse_lookup_user_request",
73
           "LookupUserResponse"        => "_parse_lookup_user_response",
74
           "LookupItem"                => "_parse_lookup_item_request",
75
           "LookupItemResponse"        => "_parse_lookup_item_response",
76
           "LookupRequest"             => "_parse_lookup_request_request",
77
           "LookupRequestResponse"     => "_parse_lookup_request_response",
78
           "CancelRequestItem"         => "_parse_cancel_request_item_request",
79
           "CancelRequestItemResponse" => "_parse_cancel_request_item_response",
80
           "RenewItem"                 => "_parse_renew_item_request",
81
           "RenewItemResponse"         => "_parse_renew_item_response",
82
           "UpdateRequestItem"         => "_parse_update_request_item_request",
83
           "UpdateRequestItemResponse" => "_parse_update_request_item_response" );
84
 
85
 
86
/** \brief Constructor
87
*
88
* Constructoren er tom
89
*
90
*/
91
  public function __construct() {
92
    global $_DEBUG;
93
    parent::__construct();
94
    $this->debug = $_DEBUG;
95
  }
96
 
97
 
98
/** \brief Destructor
99
*
100
* Destructoren er tom
101
*
102
*/
103
  public function __destruct() {
104
    parent::__destruct();
105
  }
106
 
107
 
108
 
109
/** \brief build
110
*
111
* Denne klasse opbygger en ncip request eller en ncip response
112
* Følgende 5 request/response typer understøttes:
113
*   LookupUser / LookupUserResponse
114
*   LookupItem / LookupItemResponse
115
*   LookupRequest / LookupRequestResponse
116
*   CancelRequestItem / CancelRequestItemResponse
117
*   RenewItem / RenewItemResponse
118
* Request/Response typen lægges i $parameters["Ncip"]
119
* Typen skal defineres, og være understøttet
120
*
121
* @param $parameters array  Associativt array indeholdene parametre for requesten/responsen
122
* @retval string Den opbyggede ncip request/response som ren tekst
123
*/
124
  public function build($parameters) {
125
    $this->parameters = $parameters;
126
    $message = $parameters["Ncip"];
127
    if (empty($parameters["Ncip"]) or
128
        !in_array($message, array_keys($this->createMessages)) or
129
        ($this->parameters["Problem"]["Error"] == "UnknownError")) {
130
          return self::_create_version_message();
131
        }
132
    $impl = new DomImplementation;
133
    $dtd = $impl->createDocumentType("NCIPMessage", "-//NISO//NCIP DTD Version 1//EN", "http://www.niso.org/ncip/v1_0/imp1/dtd/ncip_v1_0.dtd");
134
    $this->dom = $impl->createDocument(null, null, $dtd);
135
    $this->dom->version = "1.0";
136
    $this->dom->encoding = "UTF-8";
137
    $ncipMessage = $this->dom->createElement("NCIPMessage");
138
    $ncipMessage->setAttribute("version", "http://ncip.envisionware.com/documentation/ncip_v1_0.dtd");
139
    $ncip_message_element = $this->dom->createElement($message);
140
    if ( method_exists($this, $this->createMessages[$message]) )
141
      call_user_func(array($this, $this->createMessages[$message]), $ncip_message_element);  // Kald den aktuelle build metode
142
    $ncipMessage->appendChild( $ncip_message_element );
143
    $this->dom->appendChild( $ncipMessage );
144
    $this->dom->formatOutput = true;
145
    $this->dom_xml = $this->dom->saveXML();
146
 
147
    if (strtolower($this->debug) == 'ncip') {
148
      echo "<h1>NCIP Request:</h1><pre>" . htmlentities($this->dom_xml) . "</pre>";
149
    }
150
 
151
    return $this->dom_xml;
152
  }
153
 
154
 
155
 
156
 
157
/** \brief parse
158
*
159
* Læser og fortolker input teksten som en ncip request eller response, og opbygger et php array, med de læste data.
160
*
161
* @param $ncip_str string Ncip responsen som xml tekst
162
* @retval array Fortolkede værdier, udtrukket fra ncip responsen
163
*
164
*/
165
  public function parse(&$ncip_str) {
166
    if (strtolower($this->debug) == 'ncip') {
167
      echo "<h1>NCIP Response:</h1><pre>" . htmlentities($ncip_str) . "</pre><hr>";
168
    }
169
 
170
    $this->parameters = array();
171
    $this->dom = DOMDocument::loadXML($ncip_str,  LIBXML_NOERROR);
172
 
173
    $rootTags = self::_get_child_elements($this->dom);
174
    $ncipMessage = $rootTags[0];  // Der bør kun være ét tag som rod-tag, og det skal være NCIPMessage
175
    if ((empty($ncipMessage)) or ($ncipMessage->nodeName != "NCIPMessage")) return self::_problem("MessagingError", "Invalid Message Syntax Error", "NCIPMessage", "NCIP Messaging Error Type Scheme");
176
 
177
    $ncipMessageElements = self::_get_child_elements($ncipMessage);
178
    $message = $ncipMessageElements[0];  // Det første tag i NCIPMessage skal være message type tagget - såhhh det regner vi med at det er
179
    $tag = $message->nodeName;
180
 
181
    $this->parameters["Ncip"] = $tag;
182
    if ( !in_array($tag, array_keys($this->parseMessages)) ) return self::_problem("MessagingError", "Unsupported Service", $tag, "NCIP General Processing Error Scheme");
183
    if ( !method_exists($this, $this->parseMessages[$tag]) ) return self::_problem("MessagingError", "Unsupported Service", $tag, "NCIP General Processing Error Scheme");
184
    $this->parameters = array_merge($this->parameters, call_user_func(array($this, $this->parseMessages[$tag]), $message));  // Kald den aktuelle parsing metode
185
    return $this->parameters;
186
  }
187
 
188
 
189
/** \brief parse_file
190
*
191
* Læser og fortolker indholdet af input filen som en ncip response, og opbygger et php array, med de læste data.
192
*
193
* @param $ncip_file string Fil navnet på den fil, der indeholder ncip responsen
194
* @retval array Fortolkede værdier, udtrukket fra ncip responsen
195
*
196
*/
197
  public function parse_file($ncip_file) {
198
    $file_content = file_get_contents($ncip_file);
199
    return self::parse($file_content);
200
  }
201
 
202
 
203
 
204
 
205
//------------------------------------------------------------------------------
206
// Private metoder
207
//------------------------------------------------------------------------------
208
 
209
 
210
 
211
 
212
/** \brief _get_element
213
*
214
* Hent et navngivet element, og put det ned i et array - men kun hvis det findes
215
*
216
* @param $result array            Det array, hvori resultatet lægges
217
* @param $dom_element DOMElement  DOM Elementet, hvori der ledes
218
* @param $tag_name string         Navnet på tagget, der ledes efter. Hvis dette
219
*                                 er et array af tag navne, ledes efter serien af tag navne
220
* @param $result_name string      Det resulterende tag navn i $result arrayet.
221
*                                 Hvis ikke dette angives, findes navnet som $tag_name -
222
*                                 og hvis $tag_name er et array, bruges det sidste element som navn
223
* @retval string                  Indholdet af det fundne element - hvis ikke det findes, returneres null
224
*                                
225
*/
226
  private function _get_element(&$result, $dom_element, $tag_name, $result_name="") {
227
    if (!is_array($tag_name)) {
228
      $tag_name = array($tag_name);
229
    }
230
    foreach($tag_name as $name) {
231
      $dom_element = $dom_element->getElementsByTagName($name)->item(0);
232
      if (!isset($dom_element)) {
233
        return null;  // Elementet findes ikke, derfor gemmes ikke noget resultat
234
      }
235
    }
236
    if (empty($result_name)) {
237
      return $result[$name] = $dom_element->nodeValue;  // Brug det sidste navn i listen som indeks
238
    } else {
239
      return $result[$result_name] = $dom_element->nodeValue;
240
    }
241
  }
242
 
243
 
244
 
245
/** \brief _create_version_message
246
*
247
* Opbyg en fuldstændig "NCIPVersionMessage" besked
248
*
249
* @retval string Den opbyggede "NCIPVersionMessage" som ren tekst
250
*
251
*/
252
  private function _create_version_message() {
253
    $impl = new DomImplementation;
254
    $dtd = $impl->createDocumentType("NCIPVersionMessage", "-//NISO//NCIP DTD Version 1//EN", "http://www.niso.org/ncip/v1_0/imp1/dtd/ncip_v1_0.dtd");
255
    $this->dom = $impl->createDocument(null, null, $dtd);
256
    $this->dom->version = "1.0";
257
    $this->dom->encoding = "UTF-8";
258
    $ncip_version_message = $this->dom->createElement("NCIPVersionMessage");
259
    $ncip_version_message->setAttribute("version", "http://ncip.envisionware.com/documentation/ncip_v1_0.dtd");
260
    $lookup_version_response = $this->dom->createElement("LookupVersionResponse");
261
    $lookup_version_response->appendChild($this->_create_agency_id("From", $this->parameters["FromAgencyId"]));
262
    $lookup_version_response->appendChild($this->_create_agency_id("To", $this->parameters["ToAgencyId"]));
263
    $lookup_version_response->appendChild($this->dom->createElement("VersionSupported", "http://ncip.envisionware.com/documentation/ncip_v1_0.dtd"));
264
    $ncip_version_message->appendChild( $lookup_version_response );
265
    $this->dom->appendChild($ncip_version_message);
266
    $this->dom->formatOutput = true;
267
    $this->dom_xml = $this->dom->saveXML();
268
    return $this->dom_xml;
269
  }
270
 
271
 
272
/** \brief _create_lookup_user_request
273
*
274
* Opbyg en "LookupUser" ncip request
275
*
276
* Parametrene til ncip beskeden hentes fra $this->parameters.
277
*
278
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
279
*
280
*/
281
  private function _create_lookup_user_request($xml) {
115056 fvs 282
    if (!isset($this->parameters["UserElementTypeName"])) $this->parameters["UserElementTypeName"] = "Name Information";
283
    if (!isset($this->parameters["UserElementTypeAddress"])) $this->parameters["UserElementTypeAddress"] = "User Address Information";
82190 hhl 284
    if (!isset($this->parameters["LoanedItemsDesired"])) $this->parameters["LoanedItemsDesired"] = 1;
285
    if (!isset($this->parameters["RequestedItemsDesired"])) $this->parameters["RequestedItemsDesired"] = 1;
286
    if (!isset($this->parameters["UserFiscalAccountDesired"])) $this->parameters["UserFiscalAccountDesired"] = 1;
287
    $xml->appendChild(self::_create_header("InitiationHeader"));
288
    $xml->appendChild(self::_create_authentication_input($this->parameters["UserId"], "text/plain", "User Id"));
289
    $xml->appendChild(self::_create_authentication_input($this->parameters["UserPIN"], "text/plain", "PIN"));
115056 fvs 290
    $xml->appendChild(self::_create_scheme_value_pair("UserElementType", "http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm", $this->parameters["UserElementTypeName"]));
291
    $xml->appendChild(self::_create_scheme_value_pair("UserElementType", "http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm", $this->parameters["UserElementTypeAddress"]));
82190 hhl 292
    if (!empty($this->parameters["LoanedItemsDesired"])) $xml->appendChild($this->dom->createElement("LoanedItemsDesired"));
293
    if (!empty($this->parameters["RequestedItemsDesired"])) $xml->appendChild($this->dom->createElement("RequestedItemsDesired"));
294
    if (!empty($this->parameters["UserFiscalAccountDesired"])) $xml->appendChild($this->dom->createElement("UserFiscalAccountDesired"));
295
  }
296
 
297
/** \brief _create_lookup_user_response
298
*
299
* Opbyg en "LookupUser" ncip response
300
*
301
* Parametrene til ncip beskeden hentes fra $this->parameters.
302
*
303
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
304
*
305
*/
306
  private function _create_lookup_user_response($xml) {
307
    $xml->appendChild(self::_create_header("ResponseHeader"));
308
    $xml_problem = self::_create_problem();
309
    if (!empty($xml_problem)) {
310
      $xml->appendChild($xml_problem);
311
      return;
312
    }
313
    $xml->appendChild(self::_create_unique_id("User", $this->parameters));
314
    $xml_user_transaction = $this->dom->createElement("UserTransaction");
315
    if (is_array($this->parameters["RequestedItem"]))
316
      foreach ($this->parameters["RequestedItem"] as $item) {
317
        $xml_requested_item = $this->dom->createElement("RequestedItem");
318
        $xml_requested_item->appendChild(self::_create_unique_id("Request", $item));
319
        if (!empty($item["RequestType"])) {
320
          $xml_requested_item->appendChild(self::_create_scheme_value_pair("RequestType", "http://www.niso.org/ncip/v1_0/imp1/schemes/requesttype/requesttype.scm", $item["RequestType"]));
321
        }
322
        if (!empty($item["RequestStatusType"])) {
323
          $xml_requested_item->appendChild(self::_create_scheme_value_pair("RequestStatusType", "http://www.niso.org/ncip/v1_0/imp1/schemes/requeststatustype/requeststatustype.scm", $item["RequestStatusType"]));
324
        }
325
        if (!empty($item["DatePlaced"])) {
326
          $xml_requested_item->appendChild($this->dom->createElement("DatePlaced", $item["DatePlaced"]));
327
        }
328
        if (!empty($item["PickupDate"])) {
329
          $xml_requested_item->appendChild($this->dom->createElement("PickupDate", $item["PickupDate"]));
330
        }
331
        if (!empty($item["PickupExpiryDate"])) {
332
          $xml_requested_item->appendChild($this->dom->createElement("PickupExpiryDate", $item["PickupExpiryDate"]));
333
        }
334
        if (!empty($item["ReminderLevel"])) {
335
          $xml_requested_item->appendChild($this->dom->createElement("ReminderLevel", $item["ReminderLevel"]));
336
        }
337
        if (!empty($item["HoldQueuePosition"])) {
338
          $xml_requested_item->appendChild($this->dom->createElement("HoldQueuePosition", $item["HoldQueuePosition"]));
339
        }
340
        $xml_user_transaction->appendChild($xml_requested_item);
341
      }
342
    if (is_array($this->parameters["LoanedItem"]))
343
      foreach ($this->parameters["LoanedItem"] as $item) {
344
        $xml_loaned_item = $this->dom->createElement("LoanedItem");
345
        $xml_loaned_item->appendChild(self::_create_unique_id("Item", $item));
346
        if (!empty($item["ReminderLevel"])) {
347
          $xml_loaned_item->appendChild($this->dom->createElement("ReminderLevel", $item["ReminderLevel"]));
348
        }
349
        if (!empty($item["DateDue"])) {
350
          $xml_loaned_item->appendChild($this->dom->createElement("DateDue", $item["DateDue"]));
351
        }
352
        if (isset($item["MonetaryValue"])) {
353
          $xml_amount = $this->dom->createElement("Amount");
354
          if (!empty($item["CurrencyCode"])) {
355
            $xml_amount->appendChild(self::_create_scheme_value_pair("CurrencyCode", "http://www.bsi-global.com/Technical+Information/Publications/_Publications/tig90x.doc", $item["CurrencyCode"]));
356
          }
357
          $xml_amount->appendChild($this->dom->createElement("MonetaryValue", $item["MonetaryValue"]));
358
          $xml_loaned_item->appendChild($xml_amount);
359
        }
360
        $xml_user_transaction->appendChild($xml_loaned_item);
361
      }
362
    $xml->appendChild($xml_user_transaction);
363
    if (!empty($this->parameters["GivenName"]) or !empty($this->parameters["Surname"]) or !empty($this->parameters["UnstructuredPersonalUserName"])) {
364
      $xml_user_optional_fields = $this->dom->createElement("UserOptionalFields");
365
      $xml_name_information = $this->dom->createElement("NameInformation");
366
      $xml_personal_name_information = $this->dom->createElement("PersonalNameInformation");
367
      if (!empty($this->parameters["GivenName"]) or !empty($this->parameters["Surname"])) {
368
        $xml_structured_personal_user_name = $this->dom->createElement("StructuredPersonalUserName");
369
        $xml_structured_personal_user_name->appendChild($this->dom->createElement("GivenName", utf8_encode($this->parameters["GivenName"])));
370
        $xml_structured_personal_user_name->appendChild($this->dom->createElement("Surname", utf8_encode($this->parameters["Surname"])));
371
        $xml_personal_name_information->appendChild($xml_structured_personal_user_name);
372
      }
373
      if (!empty($this->parameters["UnstructuredPersonalUserName"])) {
374
        $xml_unstructured_personal_user_name = $this->dom->createElement("UnstructuredPersonalUserName", $this->parameters["UnstructuredPersonalUserName"]);
375
        $xml_personal_name_information->appendChild($xml_unstructured_personal_user_name);
376
      }
377
      $xml_name_information->appendChild($xml_personal_name_information);
378
      $xml_user_optional_fields->appendChild($xml_name_information);
379
      $xml->appendChild($xml_user_optional_fields);
380
    }
381
  }
382
 
383
/** \brief _create_lookup_item_request
384
*
385
* Opbyg en "LookupItem" ncip request
386
*
387
* Parametrene til ncip beskeden hentes fra $this->parameters.
388
*
389
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
390
*
391
*/
392
  private function _create_lookup_item_request($xml) {
393
    if (!isset($this->parameters["ItemElementType"])) $this->parameters["ItemElementType"] = "Bibliographic Description";
394
    $xml->appendChild(self::_create_header("InitiationHeader"));
395
    $xml->appendChild(self::_create_unique_id("Item", $this->parameters));
396
    $xml->appendChild(self::_create_scheme_value_pair("ItemElementType", "http://www.niso.org/ncip/v1_0/schemes/itemelementtype/itemelementtype.scm", $this->parameters["ItemElementType"]));
397
  }
398
 
399
/** \brief _create_lookup_item_response
400
*
401
* Opbyg en "LookupItem" ncip response
402
*
403
* Parametrene til ncip beskeden hentes fra $this->parameters.
404
*
405
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
406
*
407
*/
408
  private function _create_lookup_item_response($xml) {
409
    $xml->appendChild(self::_create_header("ResponseHeader"));
410
    $xml_problem = self::_create_problem();
411
    if (!empty($xml_problem)) {
412
      $xml->appendChild($xml_problem);
413
      return;
414
    }
415
    $xml->appendChild(self::_create_unique_id("Item", $this->parameters));
416
    if (!empty($this->parameters["HoldPickupDate"]))
417
      $xml->appendChild($this->dom->createElement("HoldPickupDate", $this->parameters["HoldPickupDate"]));
418
    if (!empty($this->parameters["DateRecalled"]))
419
      $xml->appendChild($this->dom->createElement("DateRecalled", $this->parameters["DateRecalled"]));
420
    self::_create_item_optional_fields($xml);
421
  }
422
 
423
/** \brief _create_lookup_request_request
424
*
425
* Opbyg en "LookupRequest" ncip request
426
*
427
* Parametrene til ncip beskeden hentes fra $this->parameters.
428
*
429
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
430
*
431
*/
432
  private function _create_lookup_request_request($xml) {
433
    if (!isset($this->parameters["ItemElementType"])) $this->parameters["ItemElementType"] = "Bibliographic Description";
434
    $xml->appendChild(self::_create_header("InitiationHeader"));
435
    $xml->appendChild(self::_create_unique_id("Request", $this->parameters));
436
    $xml->appendChild(self::_create_scheme_value_pair("ItemElementType", "http://www.niso.org/ncip/v1_0/schemes/itemelementtype/itemelementtype.scm", $this->parameters["ItemElementType"]));
437
  }
438
 
439
/** \brief _create_lookup_request_response
440
*
441
* Opbyg en "LookupRequest" ncip response
442
*
443
* Parametrene til ncip beskeden hentes fra $this->parameters.
444
*
445
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
446
*
447
*/
448
  private function _create_lookup_request_response($xml) {
449
    $xml->appendChild(self::_create_header("ResponseHeader"));
450
    $xml_problem = self::_create_problem();
451
    if (!empty($xml_problem)) {
452
      $xml->appendChild($xml_problem);
453
      return;
454
    }
455
    $xml->appendChild(self::_create_unique_id("Request", $this->parameters));
456
    if (!empty($this->parameters["HoldQueuePosition"])) {
457
      $xml->appendChild($this->dom->createElement("HoldQueuePosition", $this->parameters["HoldQueuePosition"]));
458
    }
459
    self::_create_item_optional_fields($xml);
460
  }
461
 
462
/** \brief _create_cancel_request_item_request
463
*
464
* Opbyg en "CancelRequestItem" ncip request
465
*
466
* Parametrene til ncip beskeden hentes fra $this->parameters.
467
*
468
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
469
*
470
*/
471
  private function _create_cancel_request_item_request($xml) {
472
    $xml->appendChild(self::_create_header("InitiationHeader"));
473
    $xml->appendChild(self::_create_unique_id("User", $this->parameters));
474
    $xml->appendChild(self::_create_unique_id("Request", $this->parameters));
475
    $xml->appendChild(self::_create_scheme_value_pair("RequestType", "http://www.niso.org/ncip/v1_0/imp1/schemes/requesttype/requesttype.scm", $this->parameters["RequestType"]));
476
 }
477
 
478
/** \brief _create_cancel_request_item_response
479
*
480
* Opbyg en "CancelRequestItem" ncip response
481
*
482
* Parametrene til ncip beskeden hentes fra $this->parameters.
483
*
484
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
485
*
486
*/
487
  private function _create_cancel_request_item_response($xml) {
488
    $xml->appendChild(self::_create_header("ResponseHeader"));
489
    $xml_problem = self::_create_problem();
490
    if (!empty($xml_problem)) {
491
      $xml->appendChild($xml_problem);
492
      return;
493
    }
494
    $xml->appendChild(self::_create_unique_id("User", $this->parameters));
495
    $xml->appendChild(self::_create_unique_id("Request", $this->parameters));
496
 }
497
 
498
/** \brief _create_renew_item_request
499
*
500
* Opbyg en "RenewItem" ncip request
501
*
502
* Parametrene til ncip beskeden hentes fra $this->parameters.
503
*
504
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
505
*
506
*/
507
  private function _create_renew_item_request($xml) {
508
    $xml->appendChild(self::_create_header("InitiationHeader"));
509
    $xml->appendChild(self::_create_unique_id("User", $this->parameters));
510
    $xml->appendChild(self::_create_unique_id("Item", $this->parameters));
511
  }
512
 
513
/** \brief _create_renew_item_response
514
*
515
* Opbyg en "RenewItem" ncip response
516
*
517
* Parametrene til ncip beskeden hentes fra $this->parameters.
518
*
519
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
520
*
521
*/
522
  private function _create_renew_item_response($xml) {
523
    $xml->appendChild(self::_create_header("ResponseHeader"));
524
    $xml_problem = self::_create_problem();
525
    if (!empty($xml_problem)) {
526
      $xml->appendChild($xml_problem);
527
      return;
528
    }
529
    if (!empty($this->parameters["UniqueItemId"])) {
530
      $xml->appendChild(self::_create_unique_id("Item", $this->parameters));
531
    }
532
    if (!empty($this->parameters["DateDue"])) {
533
      $xml->appendChild($this->dom->createElement("DateDue", $this->parameters["DateDue"]));
534
    }
535
    if (!empty($this->parameters["DateOfExpectedReply"])) {
536
      $xml_pending = $this->dom->createElement("Pending");
537
      $xml_pending->appendChild($this->dom->createElement("DateOfExpectedReply", $this->parameters["DateOfExpectedReply"]));
538
      $xml->appendChild($xml_pending);
539
    }
540
  }
541
 
542
/** \brief _create_update_request_item_request
543
*
544
* Opbyg en "UpdateRequestItem" ncip request
545
* NB: Denne version kan udelukkende opdatere afhentningsstedet
546
* Parametrene til ncip beskeden hentes fra $this->parameters.
547
*
548
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
549
*
550
*/
551
  private function _create_update_request_item_request($xml) {
552
    $xml->appendChild(self::_create_header("InitiationHeader"));
553
    $xml->appendChild(self::_create_unique_id("Request", $this->parameters));
554
  }
555
 
556
/** \brief _create_update_request_item_response
557
*
558
* Opbyg en "UpdateRequestItem" ncip response
559
*
560
* Parametrene til ncip beskeden hentes fra $this->parameters.
561
*
562
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
563
*
564
*/
565
  private function _create_update_request_item_response($xml) {
566
// Endnu ikke implementeret
567
    $xml->appendChild(self::_create_header("ResponseHeader"));
568
    $xml_problem = self::_create_problem();
569
    if (!empty($xml_problem)) {
570
      $xml->appendChild($xml_problem);
571
      return;
572
    }
573
    if (!empty($this->parameters["UniqueItemId"])) {
574
      $xml->appendChild(self::_create_unique_id("Item", $this->parameters));
575
    }
576
    if (!empty($this->parameters["DateDue"])) {
577
      $xml->appendChild($this->dom->createElement("DateDue", $this->parameters["DateDue"]));
578
    }
579
    if (!empty($this->parameters["DateOfExpectedReply"])) {
580
      $xml_pending = $this->dom->createElement("Pending");
581
      $xml_pending->appendChild($this->dom->createElement("DateOfExpectedReply", $this->parameters["DateOfExpectedReply"]));
582
      $xml->appendChild($xml_pending);
583
    }
584
  }
585
 
586
/** \brief _create_scheme_value_pair
587
*
588
* Opbygger et <scheme> / <value> par
589
*
590
* @param $tag string Tag navnet på det scheme/value par, der skal opbygges
591
* @param $scheme string Skema navnet
592
* @param $scheme string Væredien
593
* @retval DOMElement Elementet, indeholdende scheme/value parret
594
*
595
*/
596
  private function _create_scheme_value_pair($tag, $scheme, $value) {
597
    $xml = $this->dom->createElement($tag);
598
    if (!empty($scheme)) $xml->appendChild($this->dom->createElement("Scheme", $scheme));
599
    if (!empty($value)) $xml->appendChild($this->dom->createElement("Value", $value));
600
    return $xml;
601
  }
602
 
603
/** \brief _create_agency_id
604
*
605
* Opbygger et element indeholdende et Unique Agency ID
606
*
607
* @param $what string Hvilket XXXAgencyId element, der skal opbygges, hvor XXX erstattes af $what
608
* @param $agencyId string Værdien for UniqueAgencyId, der puttes ned i det resulterende element
609
* @retval DOMElement Elementet, indeholdende UniqueAgencyId
610
*
611
*/
612
  private function _create_agency_id($what, $agencyId) {
613
    $xml = $this->dom->createElement($what . "AgencyId");
614
    $xml->appendChild(self::_create_scheme_value_pair("UniqueAgencyId", "http://biblstandard.dk/isil/schemes/1.1/", $agencyId));
615
    return $xml;
616
  }
617
 
618
/** \brief _create_header
619
*
620
* Opbygger et header element med tagget: <$header_tag>
621
* Napper parametrene "FromAgencyId", "FromAgencyAuthentication" og "ToAgencyId" fra $this->parameters
622
*
623
* @param $header_tag string Tag navnet for headeren
624
* @retval DOMElement Det resulterende Initiation Header element
625
*
626
*/
627
  private function _create_header($header_tag) {
628
    $xml = $this->dom->createElement($header_tag);
629
    $xml->appendChild(self::_create_agency_id("From", $this->parameters["FromAgencyId"]));
630
    if (!empty($this->parameters["FromAgencyAuthentication"])) {
631
      $xml->appendChild($this->dom->createElement("FromAgencyAuthentication", $this->parameters["FromAgencyAuthentication"]));
632
    }
633
    $xml->appendChild(self::_create_agency_id("To", $this->parameters["ToAgencyId"]));
634
    return $xml;
635
  }
636
 
637
/** \brief _create_item_optional_fields
638
*
639
* Opbyg en "ItemOptionalFields" blok
640
*
641
* Parametrene til ncip beskeden hentes fra $this->parameters.
642
*
643
* @param $xml DOMElement Det element, hvortil den aktuelle xml info skal tilføjes
644
*
645
*/
646
  private function _create_item_optional_fields($xml) {
647
    if (!empty($this->parameters["Author"]) or
648
        !empty($this->parameters["AuthorOfComponent"]) or
649
        !empty($this->parameters["BibliographicItemId"]) or
650
        !empty($this->parameters["BibliographicRecordId"]) or
651
        !empty($this->parameters["ComponentId"]) or
652
        !empty($this->parameters["Edition"]) or
653
        !empty($this->parameters["Pagination"]) or
654
        !empty($this->parameters["PlaceOfPublication"]) or
655
        !empty($this->parameters["PublicationDate"]) or
656
        !empty($this->parameters["PublicationDateOfComponent"]) or
657
        !empty($this->parameters["Publisher"]) or
658
        !empty($this->parameters["SeriesTitleNumber"]) or
659
        !empty($this->parameters["Title"]) or
660
        !empty($this->parameters["TitleOfComponent"]) or
661
        !empty($this->parameters["BibliographicLevel"]) or
662
        !empty($this->parameters["SponsoringBody"]) or
663
        !empty($this->parameters["ElectronicDataFormatType"]) or
664
        !empty($this->parameters["Language"]) or
665
        !empty($this->parameters["MediumType"])) {
666
      $xml_item_optional_fields = $this->dom->createElement("ItemOptionalFields");
667
      $xml_bibliographic_description = $this->dom->createElement("BibliographicDescription");
668
      if (!empty($this->parameters["Author"]))
669
        $xml_bibliographic_description->appendChild($this->dom->createElement("Author", $this->parameters["Author"]));
670
      if (!empty($this->parameters["AuthorOfComponent"]))
671
        $xml_bibliographic_description->appendChild($this->dom->createElement("AuthorOfComponent", $this->parameters["AuthorOfComponent"]));
672
      if (!empty($this->parameters["BibliographicItemId"]))
673
        $xml_bibliographic_description->appendChild($this->dom->createElement("BibliographicItemId", $this->parameters["BibliographicItemId"]));
674
      if (!empty($this->parameters["BibliographicRecordId"]))
675
        $xml_bibliographic_description->appendChild($this->dom->createElement("BibliographicRecordId", $this->parameters["BibliographicRecordId"]));
676
      if (!empty($this->parameters["ComponentId"]))
677
        $xml_bibliographic_description->appendChild($this->dom->createElement("ComponentId", $this->parameters["ComponentId"]));
678
      if (!empty($this->parameters["Edition"]))
679
        $xml_bibliographic_description->appendChild($this->dom->createElement("Edition", $this->parameters["Edition"]));
680
      if (!empty($this->parameters["Pagination"]))
681
        $xml_bibliographic_description->appendChild($this->dom->createElement("Pagination", $this->parameters["Pagination"]));
682
      if (!empty($this->parameters["PlaceOfPublication"]))
683
        $xml_bibliographic_description->appendChild($this->dom->createElement("PlaceOfPublication", $this->parameters["PlaceOfPublication"]));
684
      if (!empty($this->parameters["PublicationDate"]))
685
        $xml_bibliographic_description->appendChild($this->dom->createElement("PublicationDate", $this->parameters["PublicationDate"]));
686
      if (!empty($this->parameters["PublicationDateOfComponent"]))
687
        $xml_bibliographic_description->appendChild($this->dom->createElement("PublicationDateOfComponent", $this->parameters["PublicationDateOfComponent"]));
688
      if (!empty($this->parameters["Publisher"]))
689
        $xml_bibliographic_description->appendChild($this->dom->createElement("Publisher", $this->parameters["Publisher"]));
690
      if (!empty($this->parameters["SeriesTitleNumber"]))
691
        $xml_bibliographic_description->appendChild($this->dom->createElement("SeriesTitleNumber", $this->parameters["SeriesTitleNumber"]));
692
      if (!empty($this->parameters["Title"]))
693
        $xml_bibliographic_description->appendChild($this->dom->createElement("Title", $this->parameters["Title"]));
694
      if (!empty($this->parameters["TitleOfComponent"]))
695
        $xml_bibliographic_description->appendChild($this->dom->createElement("TitleOfComponent", $this->parameters["TitleOfComponent"]));
696
      if (!empty($this->parameters["BibliographicLevel"]))
697
        $xml_bibliographic_description->appendChild($this->dom->createElement("BibliographicLevel", $this->parameters["BibliographicLevel"]));
698
      if (!empty($this->parameters["SponsoringBody"]))
699
        $xml_bibliographic_description->appendChild($this->dom->createElement("SponsoringBody", $this->parameters["SponsoringBody"]));
700
      if (!empty($this->parameters["ElectronicDataFormatType"]))
701
        $xml_bibliographic_description->appendChild($this->dom->createElement("ElectronicDataFormatType", $this->parameters["ElectronicDataFormatType"]));
702
      if (!empty($this->parameters["Language"]))
703
        $xml_bibliographic_description->appendChild($this->dom->createElement("Language", $this->parameters["Language"]));
704
      if (!empty($this->parameters["MediumType"]))
705
        $xml_bibliographic_description->appendChild($this->dom->createElement("MediumType", $this->parameters["MediumType"]));
706
      $xml_item_optional_fields->appendChild($xml_bibliographic_description);
707
      $xml->appendChild($xml_item_optional_fields);
708
    }
709
  }
710
 
711
/** \brief _create_problem
712
*
713
* Opbygger et element med tagget: <Problem>
714
* Napper parameteren "Problem" fra $this->parameters
715
*
716
*  [Problem] array
717
*     [Error] => ProcessingError eller MessagingError
718
*     [Type] => User Authentication Failed
719
*     [Element] => AuthenticationInput
720
*     [Scheme] => "http://www.niso.org/ncip/v1_0/schemes/processingerrortype/lookupuserprocessingerror.scm"
721
*     [Value] => Value
722
*
723
* @retval DOMElement Det resulterende Problem element
724
*
725
*/
726
  private function _create_problem() {
727
    if (empty($this->parameters["Problem"]) or empty($this->parameters["Problem"]["Error"])) {
728
      return null;
729
    }
730
    $xml = $this->dom->createElement("Problem");
731
    $xml_error = $this->dom->createElement($this->parameters["Problem"]["Error"]);
732
    $xml_error->appendChild(self::_create_scheme_value_pair($this->parameters["Problem"]["Error"] . "Type", $this->parameters["Problem"]["Scheme"], $this->parameters["Problem"]["Type"]));
733
    $xml_error_element = $this->dom->createElement($this->parameters["Problem"]["Error"] . "Element");
734
    if (!empty($this->parameters["Problem"]["Element"]))
735
      $xml_error_element->appendChild($this->dom->createElement("ElementName", $this->parameters["Problem"]["Element"]));
736
    if (!empty($this->parameters["Problem"]["Value"]))
737
      $xml_error_element->appendChild($this->dom->createElement($this->parameters["Problem"]["Error"] . "Value", $this->parameters["Problem"]["Value"]));
738
    $xml_error->appendChild($xml_error_element);
739
    $xml->appendChild($xml_error);
740
    return $xml;
741
  }
742
 
743
/** \brief _problem
744
*
745
* Simpel utility rutine, der opbygger et Problem array med de rigtige parametre
746
*
747
*  [Problem] array
748
*     [Error] => ProcessingError eller MessagingError
749
*     [Type] => User Authentication Failed
750
*     [Element] => AuthenticationInput
751
*     [Scheme] => "http://www.niso.org/ncip/v1_0/schemes/processingerrortype/lookupuserprocessingerror.scm"
752
*     [Value] => Value
753
*
754
* @param $error string Error: Enten "ProcessingError" eller "MessagingError"
755
* @param $type string Typen på fejlen - 'fejl beskrivelsen'
756
* @param $element string Elementet, der fejler
757
* @param $scheme string Scheme't på fejlen
758
* @param $value string Hvis der er en værdi, angives den her
759
*
760
* @retval array Det resulterende Problem array
761
*
762
*/
763
  private function _problem($error, $type, $element, $scheme, $value="") {
764
    if ( ($error != "ProcessingError") and ($error != "MessagingError") )
765
      return array( "Problem" => array("Error" => "MessagingError", "Type" => "Invalid Message Syntax Error", "Element" => $element, "Scheme" => "NCIP Messaging Error Type Scheme"));
766
    $ret_array = array( "Error" => $error, "Type" => $type, "Element" => $element, "Scheme" => $scheme);
767
    if (!empty($value)) $ret_array["Value"] = $value;
768
    return array( "Problem" => $ret_array);
769
  }
770
 
771
 
772
/** \brief _create_authentication_input
773
*
774
* Opbygger et <AuthenticationInput> element
775
*
776
* @param $inputData string Authentication Input string
777
* @param dataFormatType string Data Format Typen for Authentication inputtet
778
* @param $inputType string Input Typen for Authentication inputtet
779
* @retval DOMElement Det resulterende AuthenticationInput element
780
*
781
*/
782
  private function _create_authentication_input($inputData, $dataFormatType, $inputType) {
783
    $xml = $this->dom->createElement("AuthenticationInput");
784
    $xml->appendChild($this->dom->createElement("AuthenticationInputData", $inputData));
785
    $xml->appendChild(self::_create_scheme_value_pair("AuthenticationDataFormatType", "http://www.iana.org/assignments/media-types", $dataFormatType));
786
    $xml->appendChild(self::_create_scheme_value_pair("AuthenticationInputType", "http://www.niso.org/ncip/v1_0/imp1/schemes/authenticationinputtype/authenticationinputtype.scm", $inputType));
787
    return $xml;
788
  }
789
 
790
/** \brief _create_unique_id
791
*
792
* Opbygger et <UniqueXXXId> element
793
*
794
* @param $what string Hvilket UniqueXXXId element, der skal opbygges, hvor XXX erstattes af $what
795
* @param $uniqueXxxId array hvorfra parametrene hentes på formen:
796
*                $uniqueXxxId["UniqueXXXId"]["XXXIdentifierValue"] og
797
*                $uniqueXxxId["UniqueXXXId"]["UniqueAgencyId"]
798
*        
799
* @retval DOMElement Det resulterende UniqueXXXId element
800
*
801
*/
802
  private function _create_unique_id($what, $uniqueXxxId) {
803
    $xml = $this->dom->createElement("Unique" . $what . "Id");
804
    $xml->appendChild(self::_create_scheme_value_pair("UniqueAgencyId", "http://biblstandard.dk/isil/schemes/1.1/", $uniqueXxxId["Unique" . $what . "Id"]["UniqueAgencyId"]));
805
    $xml->appendChild($this->dom->createElement($what . "IdentifierValue", $uniqueXxxId["Unique" . $what . "Id"][$what . "IdentifierValue"]));
806
    return $xml;
807
  }
808
 
809
 
810
//==============================================================================
811
 
812
 
813
/** \brief _parse_lookup_user_request
814
*
815
* Fortolker LookupUser request, og returnerer et array med resultatet
816
*
817
* @param $lookupRequest DOMElement DOM Elementet med indholdet af LookupUserRequest
818
* @retval array De fortolkede værdier
819
*
820
*/
821
  private function _parse_lookup_user_request($lookupRequest) {
822
    $user = self::_parse_header("InitiationHeader", $lookupRequest);
823
    if (!empty($user["Problem"])) return $user;
824
    $user["UserId"] = self::_parse_authentication_input("User Id", $lookupRequest);
825
    $user["UserPIN"] = self::_parse_authentication_input("PIN", $lookupRequest);
826
    self::_get_element($user, $lookupRequest, array("UserElementType", "Value"), "UserElementType");
827
    if (empty($user["UserElementType"])) return self::_problem("MessagingError", "Invalid Message Syntax Error", "UserElementType", "NCIP Messaging Error Type Scheme");
828
    $loaned_items = $lookupRequest->getElementsByTagName("LoanedItemsDesired");
829
    if (is_object($loaned_items) and ($loaned_items->length>0)) $user["LoanedItemsDesired"] = 1;
830
    $requested_items = $lookupRequest->getElementsByTagName("RequestedItemsDesired");
831
    if (is_object($requested_items) and ($requested_items->length>0)) $user["RequestedItemsDesired"] = 1;
832
    $user_fiscal_account_items = $lookupRequest->getElementsByTagName("UserFiscalAccountDesired");
833
    if (is_object($user_fiscal_account_items) and ($user_fiscal_account_items->length>0)) $user["UserFiscalAccountDesired"] = 1;
834
    return $user;
835
  }
836
 
837
 
838
/** \brief _parse_lookup_user_response
839
*
840
* Fortolker LookupUser response, og returnerer et array med resultatet
841
*
842
* @param $lookupResponse DOMElement DOM Elementet med indholdet af LookupUserResponse
843
* @retval array De fortolkede værdier
844
*
845
*/
846
  private function _parse_lookup_user_response($lookupResponse) {
847
    $user = self::_parse_header("ResponseHeader", $lookupResponse);
848
    if (!empty($user["Problem"])) return $user;
849
    $user = array_merge($user, self::_parse_unique_id_header($lookupResponse, "User"));
850
    unset($user["Problem"]);  // UniqueIdHeader behover ikke at vaere der - saa undertryk fejl
115647 fvs 851
    //$userFiscalAccount = $lookupResponse->getElementsByTagName("UserFiscalAccount")->item(0);
852
    $fiscalAccountBalance = 0;
853
    foreach ($lookupResponse->getElementsByTagName("UserFiscalAccount") as $userFiscalAccount) {
854
      if (!empty($userFiscalAccount)) {
855
        self::_get_element($user["UserFiscalAccount"], $userFiscalAccount, array("AccountBalance", "CurrencyCode",  "Value"), "AccountBalanceCurrency");
856
        self::_get_element($user["UserFiscalAccount"], $userFiscalAccount, array("AccountBalance", "MonetaryValue"), "AccountBalanceValue");
857
        $fiscalValue = $user["UserFiscalAccount"]["AccountBalanceValue"];
858
        $fiscalAccountBalance += $fiscalValue;
859
        $fiscalCurrency = $user["UserFiscalAccount"]["AccountBalanceCurrency"];
860
        if ($userFiscalAccount->getElementsByTagName("AccountDetails")->length) {
861
          foreach ( $userFiscalAccount->getElementsByTagName("AccountDetails") as $detail ) {
862
            $fiscal = array();
863
            self::_get_element($fiscal, $detail, "AccrualDate");
864
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "FiscalTransactionType",  "Value"), "FiscalTransactionType");
865
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "Amount",  "CurrencyCode", "Value"), "CurrencyCode");
866
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "Amount",  "MonetaryValue"));
867
            self::_get_element($fiscal['UniqueItemId'], $detail, array("FiscalTransactionInformation", "ItemDetails",  "UniqueItemId", "UniqueAgencyId", "Value"), "UniqueAgencyId");
868
            self::_get_element($fiscal['UniqueItemId'], $detail, array("FiscalTransactionInformation", "ItemDetails",  "UniqueItemId", "ItemIdentifierValue"));
869
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "ItemDetails",  "BibliographicDescription", "Author"));
870
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "ItemDetails",  "BibliographicDescription", "Title"));
871
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "ItemDetails",  "BibliographicDescription", "PublicationDate"));
872
            self::_get_element($fiscal, $detail, array("FiscalTransactionInformation", "ItemDetails",  "BibliographicDescription", "BibliographicRecordId", "BibliographicRecordIdentifier"), "BibliographicRecordId");
873
            if (!empty($fiscal)) $user["UserFiscalAccount"][] = $fiscal;
874
          }
875
        }
876
        else {
877
          $user["UserFiscalAccount"][] = array("CurrencyCode" => $fiscalCurrency, "MonetaryValue" => $fiscalValue);
878
        }
82190 hhl 879
      }
115647 fvs 880
      $user["UserFiscalAccount"]["AccountBalanceValue"] = $fiscalAccountBalance;
82190 hhl 881
    }
882
    $userTransaction = $lookupResponse->getElementsByTagName("UserTransaction")->item(0);
883
    if (!empty($userTransaction)) {
884
      foreach ( $userTransaction->getElementsByTagName("RequestedItem") as $item ) {
885
        $req = self::_parse_unique_id_header($item, "Request");  // Parse "UniqueRequestId"
886
        if (isset($req)) {
887
          $req["RequestType"] = $item->getElementsByTagName("RequestType")->item(0)->getElementsByTagName("Value")->item(0)->nodeValue;
888
          $req["RequestStatusType"] = $item->getElementsByTagName("RequestStatusType")->item(0)->getElementsByTagName("Value")->item(0)->nodeValue;
889
          $req["DatePlaced"] = $item->getElementsByTagName("DatePlaced")->item(0)->nodeValue;
890
          $pickupDate = $item->getElementsByTagName("PickupDate")->item(0)->nodeValue;
891
          if (isset($pickupDate)) $req["PickupDate"] = $pickupDate;
892
          $pickupExpiryDate = $item->getElementsByTagName("PickupExpiryDate")->item(0)->nodeValue;
893
          if (isset($pickupExpiryDate)) $req["PickupExpiryDate"] = $pickupExpiryDate;
894
          $reminderLevel = $item->getElementsByTagName("ReminderLevel")->item(0)->nodeValue;
895
          if (isset($reminderLevel)) $req["PickupReminderLevelDate"] = $reminderLevel;
896
          $holdQueuePosition = $item->getElementsByTagName("HoldQueuePosition")->item(0)->nodeValue;
897
          if (isset($holdQueuePosition)) $req["HoldQueuePosition"] = $holdQueuePosition;
898
          $user["RequestedItem"][] = $req;
899
        }
900
      }
901
      foreach ( $userTransaction->getElementsByTagName("LoanedItem") as $item ) {
902
        $loan = self::_parse_unique_id_header($item, "Item");  // Parse "UniqueItemId"
903
        if (isset($loan)) {
904
          $loan["ReminderLevel"] = $item->getElementsByTagName("ReminderLevel")->item(0)->nodeValue;
905
          $dateDue = $item->getElementsByTagName("DateDue")->item(0)->nodeValue;
906
          if (isset($dateDue)) $loan["DateDue"] = $dateDue;
907
          $amount = $item->getElementsByTagName("Amount")->item(0);
908
          if (isset($amount)) {
909
            $currencyCode = $amount->getElementsByTagName("CurrencyCode")->item(0);
910
            if (isset($currencyCode)) {
911
              $loan["CurrencyCode"] = $currencyCode->getElementsByTagName("Value")->item(0)->nodeValue;
912
            }
913
            $loan["MonetaryValue"] = $amount->getElementsByTagName("MonetaryValue")->item(0)->nodeValue;
914
          }
915
          $user["LoanedItem"][] = $loan;                                                                                                                          
916
        }
917
      }
918
    }
919
    $userOptionalFields = $lookupResponse->getElementsByTagName("UserOptionalFields")->item(0);
920
    if (isset($userOptionalFields)) {
921
      $structuredPersonalUserName = $userOptionalFields->getElementsByTagName("StructuredPersonalUserName")->item(0);
922
      if (isset($structuredPersonalUserName)) {
923
        $user["GivenName"] = $structuredPersonalUserName->getElementsByTagName("GivenName")->item(0)->nodeValue;
924
        $user["Surname"] = $structuredPersonalUserName->getElementsByTagName("Surname")->item(0)->nodeValue;
925
      }
926
      $unstructuredPersonalUserName = $userOptionalFields->getElementsByTagName("UnstructuredPersonalUserName")->item(0);
927
      if (isset($unstructuredPersonalUserName)) {
928
        $user["UnstructuredPersonalUserName"] = $unstructuredPersonalUserName->nodeValue;
929
      }
115056 fvs 930
      $electronicAddressData = $userOptionalFields->getElementsByTagName("ElectronicAddressData")->item(0);
931
      if (isset($electronicAddressData)) {
932
        $user["ElectronicAddressData"] = $electronicAddressData->nodeValue;
933
      }
934
      $structuredAddress = $userOptionalFields->getElementsByTagName("StructuredAddress")->item(0);
935
      if (isset($structuredAddress)) {
936
        $user["Street"] = $structuredAddress->getElementsByTagName("Street")->item(0)->nodeValue;
937
        $user["District"] = $structuredAddress->getElementsByTagName("District")->item(0)->nodeValue;
938
        $user["Country"] = $structuredAddress->getElementsByTagName("Country")->item(0)->nodeValue;
939
        $user["PostalCode"] = $structuredAddress->getElementsByTagName("PostalCode")->item(0)->nodeValue;
940
      }
82190 hhl 941
    }
942
    return $user;
943
  }
944
 
945
 
946
/** \brief _parse_lookup_item_request
947
*
948
* Fortolker LookupItem request, og returnerer et array med resultatet
949
*
950
* @param $lookupRequest DOMElement DOM Elementet med indholdet af LookupItemRequest
951
* @retval array De fortolkede værdier
952
*
953
*/
954
  private function _parse_lookup_item_request($lookupRequest) {
955
    $item = self::_parse_header("InitiationHeader", $lookupRequest);
956
    if (!empty($item["Problem"])) return $item;
957
    $item = array_merge($item, self::_parse_unique_id_header($lookupRequest, "Item"));
958
    if (!empty($item["Problem"])) return $item;
959
    self::_get_element($item, $lookupRequest, array("ItemElementType", "Value"), "ItemElementType");
960
    if (empty($item["ItemElementType"])) return self::_problem("MessagingError", "Invalid Message Syntax Error", "ItemElementType", "NCIP Messaging Error Type Scheme");
961
    return $item;
962
  }
963
 
964
 
965
/** \brief _parse_lookup_item_response
966
*
967
* Fortolker LookupItem response, og returnerer et array med resultatet
968
*
969
* @param $lookupResponse DOMElement DOM Elementet med indholdet af LookupItemResponse
970
* @retval array De fortolkede værdier
971
*
972
*/
973
  private function _parse_lookup_item_response($lookupResponse) {
974
    $item = self::_parse_header("ResponseHeader", $lookupResponse);
975
    if (!empty($item["Problem"])) return $item;
976
    $item = array_merge($item, self::_parse_unique_id_header($lookupResponse, "Request"));  // Optional
977
    $item = array_merge($item, self::_parse_unique_id_header($lookupResponse, "Item"));  // Optional
978
    unset($item['Problem']); // Neither of these headers need to be there, so if not - clear the error
979
    self::_get_element($item, $lookupResponse, "HoldPickupDate");  // Optional
980
    if (isset($item["HoldPickupDate"])) $item["HoldPickupDate"] = $item["HoldPickupDate"];
981
    self::_get_element($item, $lookupResponse, "DateRecalled");  // Optional
982
    if (isset($item["DateRecalled"])) $item["DateRecalled"] = $item["DateRecalled"];
983
    $item = array_merge($item, self::_parse_item_transaction($lookupResponse));
984
    $item = array_merge($item, self::_parse_item_optional_fields($lookupResponse));
985
    return $item;
986
  }
987
 
988
 
989
/** \brief _parse_lookup_request_request
990
*
991
* Fortolker LookupRequest request, og returnerer et array med resultatet
992
*
993
* @param $lookupRequest DOMElement DOM Elementet med indholdet af LookupRequestRequest
994
* @retval array De fortolkede værdier
995
*
996
*/
997
  private function _parse_lookup_request_request($lookupRequest) {
998
    $request = self::_parse_header("InitiationHeader", $lookupRequest);
999
    if (!empty($request["Problem"])) return $request;
1000
    $request = array_merge($request, self::_parse_unique_id_header($lookupRequest, "Request"));
1001
    if (!empty($request["Problem"])) return $request;
1002
    self::_get_element($request, $lookupRequest, array("ItemElementType", "Value"), "ItemElementType");
1003
    return $request;
1004
  }
1005
 
1006
 
1007
/** \brief _parse_lookup_request_response
1008
*
1009
* Fortolker LookupRequest response, og returnerer et array med resultatet
1010
*
1011
* @param $lookupResponse DOMElement DOM Elementet med indholdet af LookupRequestResponse
1012
* @retval array De fortolkede værdier
1013
*
1014
*/
1015
  private function _parse_lookup_request_response($lookupResponse) {
1016
    $request = self::_parse_header("ResponseHeader", $lookupResponse);
1017
    if (!empty($request["Problem"])) return $request;
1018
    $request = array_merge($request, self::_parse_unique_id_header($lookupResponse, "Request"));  // Optional
1019
    $request = array_merge($request, self::_parse_unique_id_header($lookupResponse, "Item"));  // Optional
1020
    $request = array_merge($request, self::_parse_unique_id_header($lookupResponse, "User"));  // Optional
1021
    unset($request['Problem']);  // UniqueRequestId, UniqueItemId and UniqueUserId are optional
1022
    self::_get_element($request, $lookupResponse, array("RequestType", "Value"), "RequestType");  // Optional
1023
    self::_get_element($request, $lookupResponse, array("RequestScopeType", "Value"), "RequestScopeType");  // Optional
1024
    self::_get_element($request, $lookupResponse, array("RequestStatusType", "Value"), "RequestStatusType");  // Optional
1025
    self::_get_element($request, $lookupResponse, "HoldQueuePosition");  // Optional
1026
    $request = array_merge($request, self::_parse_shipping_information($lookupResponse));
1027
    self::_get_element($request, $lookupResponse, "EarliestDateNeeded");  // Optional
1028
    if (isset($request["EarliestDateNeeded"])) $request["EarliestDateNeeded"] = $request["EarliestDateNeeded"];
1029
    self::_get_element($request, $lookupResponse, "NeedBeforeDate");  // Optional
1030
    if (isset($request["NeedBeforeDate"])) $request["NeedBeforeDate"] = $request["NeedBeforeDate"];
1031
    self::_get_element($request, $lookupResponse, "PickupDate");  // Optional
1032
    if (isset($request["PickupDate"])) $request["PickupDate"] = $request["PickupDate"];
1033
    self::_get_element($request, $lookupResponse, "PickupExpiryDate");  // Optional
1034
    if (isset($request["PickupExpiryDate"])) $request["PickupExpiryDate"] = $request["PickupExpiryDate"];
1035
    self::_get_element($request, $lookupResponse, "DateOfUserRequest");  // Optional
1036
    if (isset($request["DateOfUserRequest"])) $request["DateOfUserRequest"] = $request["DateOfUserRequest"];
1037
    self::_get_element($request, $lookupResponse, "DateAvailable");  // Optional
1038
    if (isset($request["DateAvailable"])) $request["DateAvailable"] = $request["DateAvailable"];
1039
    $request = array_merge($request, self::_parse_amount($lookupResponse, 'AcknowledgedFeeAmount'));
1040
    $request = array_merge($request, self::_parse_amount($lookupResponse, 'PaidFeeAmount'));
1041
    $request = array_merge($request, self::_parse_item_optional_fields($lookupResponse));   // Optional
1042
    $request = array_merge($request, self::_parse_user_optional_fields($lookupResponse));   // Optional
1043
    return $request;
1044
  }
1045
 
1046
 
1047
/** \brief _parse_cancel_request_item_request
1048
*
1049
* Fortolker CancelRequestItem request, og returnerer et array med resultatet
1050
*
1051
* @param $cancelRequest DOMElement DOM Elementet med indholdet af CancelRequestItemRequest
1052
* @retval array De fortolkede værdier
1053
*
1054
*/
1055
  private function _parse_cancel_request_item_request($cancelRequest) {
1056
    $request = self::_parse_header("InitiationHeader", $cancelRequest);
1057
    if (!empty($request["Problem"])) return $request;
1058
    $request = array_merge($request, self::_parse_unique_id_header($cancelRequest, "User"));
1059
    if (!empty($request["Problem"])) return $request;
1060
    $request = array_merge($request, self::_parse_unique_id_header($cancelRequest, "Request"));
1061
    self::_get_element($request, $cancelRequest, array("RequestType", "Value"), "RequestType");
1062
    return $request;
1063
  }
1064
 
1065
 
1066
/** \brief _parse_cancel_request_item_response
1067
*
1068
* Fortolker CancelRequestItem response, og returnerer et array med resultatet
1069
*
1070
* @param $cancelResponse DOMElement DOM Elementet med indholdet af CancelRequestItemResponse
1071
* @retval array De fortolkede værdier
1072
*
1073
*/
1074
  private function _parse_cancel_request_item_response($cancelResponse) {
1075
    $request = self::_parse_header("ResponseHeader", $cancelResponse);
1076
    if (!empty($request["Problem"])) return $request;
1077
    $request = array_merge($request, self::_parse_unique_id_header($cancelResponse, "User"));
1078
    if (!empty($request["Problem"])) return $request;
1079
    $request = array_merge($request, self::_parse_unique_id_header($cancelResponse, "Request"));
1080
    return $request;
1081
  }
1082
 
1083
 
1084
/** \brief _parse_renew_item_request
1085
*
1086
* Fortolker RenewItem request, og returnerer et array med resultatet
1087
*
1088
* @param $renewRequest DOMElement DOM Elementet med indholdet af RenewItemRequest
1089
* @retval array De fortolkede værdier
1090
*
1091
*/
1092
  private function _parse_renew_item_request($renewRequest) {
1093
    $request = self::_parse_header("InitiationHeader", $renewRequest);
1094
    if (!empty($request["Problem"])) return $request;
1095
    $request = array_merge($request, self::_parse_unique_id_header($renewRequest, "User"));
1096
    if (!empty($request["Problem"])) return $request;
1097
    $request = array_merge($request, self::_parse_unique_id_header($renewRequest, "Item"));
1098
    return $request;
1099
  }
1100
 
1101
 
1102
/** \brief _parse_renew_item_response
1103
*
1104
* Fortolker RenewItem response, og returnerer et array med resultatet
1105
*
1106
* @param $renewResponse DOMElement DOM Elementet med indholdet af RenewItemResponse
1107
* @retval array De fortolkede værdier
1108
*
1109
*/
1110
  private function _parse_renew_item_response($renewResponse) {
1111
    $request = self::_parse_header("ResponseHeader", $renewResponse);
1112
    if (!empty($request["Problem"])) return $request;
1113
 
1114
    $pending = $renewResponse->getElementsByTagName("Pending")->item(0);
1115
    if (isset($pending)) {
1116
      $dateOfExpectedReply = $pending->getElementsByTagName("DateOfExpectedReply")->item(0)->nodeValue;
1117
      if (isset($dateOfExpectedReply)) $request["DateOfExpectedReply"] = $dateOfExpectedReply;
1118
      return $request;
1119
    }
1120
    $request = array_merge($request, self::_parse_unique_id_header($renewResponse, "Item"));
1121
    if (!empty($request["Problem"])) return $request;
1122
    $dateDue = $renewResponse->getElementsByTagName("DateDue")->item(0)->nodeValue;
1123
    if (isset($dateDue)) $request["DateDue"] = $dateDue;
1124
    return $request;
1125
  }
1126
 
1127
/** \brief _parse_update_request_item_request
1128
*
1129
* Fortolker UpdateRequestItem request, og returnerer et array med resultatet
1130
*
1131
* @param $updateRequestItem DOMElement DOM Elementet med indholdet af UpdateRequestItem
1132
* @retval array De fortolkede værdier
1133
*
1134
*/
1135
  private function _parse_update_request_item_request($updateRequestItem) {
1136
// Endnu ikke implementeret
1137
    $request = self::_parse_header("InitiationHeader", $updateRequestItem);
1138
    if (!empty($request["Problem"])) return $request;
1139
    $request = array_merge($request, self::_parse_unique_id_header($updateRequestItem, "Request"));
1140
    return $request;
1141
  }
1142
 
1143
/** \brief _parse_update_request_item_response
1144
*
1145
* Fortolker UpdateRequestItem response, og returnerer et array med resultatet
1146
*
1147
* @param $updateRequestItemResponse DOMElement DOM Elementet med indholdet af RenewItemResponse
1148
* @retval array De fortolkede værdier
1149
*
1150
*/
1151
  private function _parse_update_request_item_response($updateRequestItemResponse) {
1152
    $response = self::_parse_header("ResponseHeader", $updateRequestItemResponse);
1153
    if (!empty($response["Problem"])) return $response;
1154
    $response = array_merge($response, self::_parse_problem($updateRequestItemResponse));
1155
    if (!empty($response["Problem"])) return $response;
1156
//    $response = array_merge($response, self::_parse_unique_id_header($updateRequestItemResponse, "Item"));
1157
//    if (!empty($response["Problem"])) return $response;
1158
//    $response = array_merge($response, self::_parse_unique_id_header($updateRequestItemResponse, "User"));
1159
//    if (!empty($response["Problem"])) return $response;
1160
 
1161
    return $response;
1162
  }
1163
 
1164
/** \brief _get_child_elements
1165
*
1166
* Ren XML forespørgsels metode, der henter listen af child - DOMElements
1167
*
1168
* @param $node DOMNode Parent node, hvor alle børne elementer ønskes
1169
* @retval DOMNode array af DOMElement's
1170
*
1171
*/
1172
  private function _get_child_elements($node) {
1173
    $tags = array();
1174
    for ($i=0; $i<$node->childNodes->length; $i++) {
1175
      if ($node->childNodes->item($i)->nodeType == XML_ELEMENT_NODE) {
1176
        $tags[] = $node->childNodes->item($i);
1177
      }
1178
    }
1179
  return $tags;
1180
  }
1181
 
1182
/** \brief _parse_header
1183
*
1184
* Fortolker et DOMElement, og henter response header info ud af den
1185
* Tjekker osse om der findes et Problem tag i elementet, og returnerer dette sammen med header info
1186
*
1187
* @param $header_tag string Navnet på header tag elementet
1188
* @param $xml DOMElement Det element, hvorfra header info ønskes læst
1189
* @retval array Header info
1190
*
1191
*/
1192
  private function _parse_header($header_tag, $xml) {
1193
    $ret = array();
1194
    if (!isset($xml)) return self::_problem("MessagingError", "Invalid Message Syntax Error", $header_tag, "NCIP Messaging Error Type Scheme");
1195
    self::_get_element($ret, $xml, array($header_tag, "FromSystemId", "Value"), "FromSystemId");  // Optional
1196
    self::_get_element($ret, $xml, array($header_tag, "FromSystemAuthentication"));  // Optional
1197
    self::_get_element($ret, $xml, array($header_tag, "FromAgencyId", "UniqueAgencyId", "Value"), "FromAgencyId");  // Mandatory
1198
    if (empty($ret["FromAgencyId"])) return self::_problem("MessagingError", "Invalid Message Syntax Error", "FromAgencyId", "NCIP Messaging Error Type Scheme");
1199
    self::_get_element($ret, $xml, array($header_tag, "FromAgencyAuthentication"));  // Optional
1200
    self::_get_element($ret, $xml, array($header_tag, "OnBehalfOfAgency", "UniqueAgencyId", "Value"), "OnBehalfOfAgency");  // Optional
1201
    self::_get_element($ret, $xml, array($header_tag, "ToSystemId", "Value"), "ToSystemId");  // Optional
1202
    self::_get_element($ret, $xml, array($header_tag, "ToAgencyId", "UniqueAgencyId", "Value"), "ToAgencyId");  //  Mandatory
1203
    if (empty($ret["ToAgencyId"])) return self::_problem("MessagingError", "Invalid Message Syntax Error", "ToAgencyId", "NCIP Messaging Error Type Scheme");
1204
    self::_get_element($ret, $xml, array($header_tag, "ApplicationProfileType", "Value"), "ApplicationProfileType");  // Optional
1205
    return array_merge($ret, self::_parse_problem($xml));
1206
  }
1207
 
1208
 
1209
/** \brief _parse_unique_id_header
1210
*
1211
* Fortolker et DOMElement, og henter Unique ID Headeren info ud af det
1212
*
1213
* @param $response DOMElement Det element, hvorfra response header info ønskes læst
1214
* @param $par string Navnet på den Unique ID, der ønskes info om ("UniqueXXXID")
1215
* @retval array Unique ID info
1216
*
1217
*/
1218
  private function _parse_unique_id_header($response, $par) {
1219
    if (!isset($response)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "Unique" . $par . "Id", "NCIP Messaging Error Type Scheme");
1220
    $uniqueId = $response->getElementsByTagName("Unique" . $par . "Id")->item(0);
1221
    if (!isset($uniqueId)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "Unique" . $par . "Id", "NCIP Messaging Error Type Scheme");
1222
    $identifierValue = $uniqueId->getElementsByTagName($par . "IdentifierValue")->item(0);
1223
    if (!isset($identifierValue)) return self::_problem("MessagingError", "Invalid Message Syntax Error", $par . "IdentifierValue", "NCIP Messaging Error Type Scheme");
1224
    $uniqueAgencyId = $uniqueId->getElementsByTagName("UniqueAgencyId")->item(0);
1225
    if (!isset($uniqueAgencyId)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "UniqueAgencyId", "NCIP Messaging Error Type Scheme");
1226
    $value = $uniqueAgencyId->getElementsByTagName("Value")->item(0);
1227
    if (!isset($value)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "Value", "NCIP Messaging Error Type Scheme");
1228
    return array( "Unique" . $par . "Id" => array($par . "IdentifierValue" => $identifierValue->nodeValue, "UniqueAgencyId" => $value->nodeValue) );
1229
  }
1230
 
1231
 
1232
/** \brief _parse_shipping_information
1233
*
1234
* Fortolker et DOMElement, og henter Shipping Information info ud af det
1235
*
1236
* @param $lookupResponse DOMElement Det element, hvorfra Item Optional Fields info ønskes læst
1237
* @retval array Item Optional Fields info
1238
*
1239
*/
1240
  private function _parse_shipping_information($lookupResponse) {
1241
    $ret = array();
1242
    $shippingInformation = $lookupResponse->getElementsByTagName("ShippingInformation")->item(0);
1243
    if (isset($shippingInformation)) {
1244
      self::_get_element($ret, $lookupResponse, 'ShippingInstructions');
1245
      self::_get_element($ret, $lookupResponse, 'ShippingNote');
1246
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'LocationWithinBuilding'));
1247
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'HouseName'));
1248
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'Street'));
1249
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'PostOfficeBox'));
1250
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'District'));
1251
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'Line1'));
1252
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'Line2'));
1253
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'Locality'));
1254
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'Region'));
1255
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'Country'));
1256
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'PostalCode'));
1257
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'StructuredAddress', 'CareOf'));
1258
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'UnstructuredAddress', 'UnstructuredAddressType', 'Value'), 'UnstructuredAddressType');
1259
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'UnstructuredAddress', 'UnstructuredAddressData'));
1260
      self::_get_element($ret, $lookupResponse, array('PhysicalAddress', 'PhysicalAddressType', 'Value'), 'PhysicalAddressType');
1261
    }
1262
    return $ret;
1263
  }
1264
 
1265
 
1266
/** \brief _parse_item_transaction
1267
*
1268
* Fortolker et DOMElement, og henter Item Transaction info ud af det
1269
*
1270
* @param $lookupResponse DOMElement Det element, hvorfra Item Transaction info ønskes læst
1271
* @retval array Item Transaction info
1272
*
1273
*/
1274
  private function _parse_item_transaction($lookupResponse) {
1275
    $ret = array();
1276
    $itemTransaction = $lookupResponse->getElementsByTagName("ItemTransaction")->item(0);
1277
    if (isset($itemTransaction)) {
1278
      $currentBorrower = $itemTransaction->getElementsByTagName("CurrentBorrower")->item(0);
1279
      if (isset($currentBorrower)) {
1280
        self::_get_element($ret['CurrentBorrower'], $currentBorrower, array('UniqueUserId', 'UserIdentifierValue'));
1281
        self::_get_element($ret['CurrentBorrower'], $currentBorrower, array('UniqueUserId', 'UniqueAgencyId', 'Value'), 'UniqueAgencyId');
1282
      }
1283
      $currentRequesters = $itemTransaction->getElementsByTagName("CurrentRequester");
1284
      foreach ($currentRequesters as $currentRequester) {
1285
        $element = array();
1286
        self::_get_element($element, $currentRequester, array('UniqueUserId', 'UserIdentifierValue'));
1287
        self::_get_element($element, $currentRequester, array('UniqueUserId', 'UniqueAgencyId', 'Value'), 'UniqueAgencyId');
1288
        $ret['CurrentRequester'][] = $element;
1289
      }
1290
    }
1291
    return $ret;
1292
  }
1293
 
1294
 
1295
 
1296
/** \brief _parse_item_optional_fields
1297
*
1298
* Fortolker et DOMElement, og henter Item Optional Fields info ud af det
1299
*
1300
* @param $lookupResponse DOMElement Det element, hvorfra Item Optional Fields info ønskes læst
1301
* @retval array Item Optional Fields info
1302
*
1303
*/
1304
  private function _parse_item_optional_fields($lookupResponse) {
1305
    $ret = array();
1306
    $itemOptionalFields = $lookupResponse->getElementsByTagName("ItemOptionalFields")->item(0);
1307
    if (isset($itemOptionalFields)) {
1308
      $bibliographicDescription = $itemOptionalFields->getElementsByTagName("BibliographicDescription")->item(0);
1309
      if (isset($bibliographicDescription)) {
1310
        self::_get_element($ret, $bibliographicDescription, 'Author');
1311
        self::_get_element($ret, $bibliographicDescription, 'AuthorOfComponent');
1312
        self::_get_element($ret, $bibliographicDescription, array('BibliographicItemId', 'BibliographicItemIdentifier'));
1313
        self::_get_element($ret, $bibliographicDescription, array('BibliographicItemId', 'BibliographicItemIdentifierCode', 'Value'), 'BibliographicItemIdentifierCode');
1314
        self::_get_element($ret, $bibliographicDescription, array('BibliographicRecordId', 'BibliographicRecordIdentifier'));
1315
        self::_get_element($ret, $bibliographicDescription, array('BibliographicRecordId', 'UniqueAgencyId', 'Value'), 'BibliographicUniqueAgencyId');
1316
        self::_get_element($ret, $bibliographicDescription, array('BibliographicRecordId', 'BibliographicRecordIdentifierCode', 'Value'), 'BibliographicRecordIdentifierCode');
1317
        self::_get_element($ret, $bibliographicDescription, array('ComponentId', 'ComponentIdentifierType', 'Value'), 'ComponentIdentifierType');
1318
        self::_get_element($ret, $bibliographicDescription, array('ComponentId', 'ComponentIdentifier'));
1319
        self::_get_element($ret, $bibliographicDescription, 'Edition');
1320
        self::_get_element($ret, $bibliographicDescription, 'Pagination');
1321
        self::_get_element($ret, $bibliographicDescription, 'PlaceOfPublication');
1322
        self::_get_element($ret, $bibliographicDescription, 'PublicationDate');
1323
        self::_get_element($ret, $bibliographicDescription, 'PublicationDateOfComponent');
1324
        self::_get_element($ret, $bibliographicDescription, 'Publisher');
1325
        self::_get_element($ret, $bibliographicDescription, 'SeriesTitleNumber');
1326
        self::_get_element($ret, $bibliographicDescription, 'Title');
1327
        self::_get_element($ret, $bibliographicDescription, 'TitleOfComponent');
1328
        self::_get_element($ret, $bibliographicDescription, array('BibliographicLevel', 'Value'), 'BibliographicLevel');
1329
        self::_get_element($ret, $bibliographicDescription, 'SponsoringBody');
1330
        self::_get_element($ret, $bibliographicDescription, array('ElectronicDataFormatType', 'Value'), 'ElectronicDataFormatType');
1331
        self::_get_element($ret, $bibliographicDescription, array('Language', 'Value'), 'Language');
1332
        self::_get_element($ret, $bibliographicDescription, array('MediumType', 'Value'), 'MediumType');
1333
      }
1334
      // Eneste understøttede tag i <ItemOptionalFields> er <BibliographicDescription>, alle resterende tags understøttes ikke i denne version
1335
    }    
1336
    return $ret;
1337
  }
1338
 
1339
 
1340
 
1341
/** \brief _parse_user_optional_fields
1342
*
1343
* Fortolker et DOMElement, og henter Item Optional Fields info ud af det
1344
*
1345
* @param $lookupResponse DOMElement Det element, hvorfra Item Optional Fields info ønskes læst
1346
* @retvlrn array Item Optional Fields info
1347
*
1348
*/
1349
  private function _parse_user_optional_fields($lookupResponse) {
1350
    $ret = array();
1351
    // Ingen support - endnu
1352
    return $ret;
1353
  }
1354
 
1355
 
1356
 
1357
/** \brief _parse_authentication_input
1358
*
1359
* Fortolker et DOMElement, og henter Authentication Input ud af det
1360
*
1361
* @param $authentication_input_type_name string Typen på det Authentication Input elementet, der ønskes udvalgt
1362
* @param $lookupResponse DOMElement Det element, hvorfra Authentication Input ønskes læst
1363
* @retval string Værdien af AuthenticationInputData tagget i det givne elementet
1364
*
1365
*/
1366
  private function _parse_authentication_input($authentication_input_type_name, $xml) {
1367
    if (empty($xml)) return null;
1368
    $authentication_input_tags = $xml->getElementsByTagName("AuthenticationInput");
1369
    if (empty($authentication_input_tags)) return null;
1370
    foreach ($authentication_input_tags as $item) {
1371
      $type = self::_get_element($dummy, $item, array("AuthenticationInputType", "Value"), "AuthenticationInputType");
1372
      if ($type == $authentication_input_type_name) {
1373
        return self::_get_element($dummy, $item, "AuthenticationInputData");
1374
      }
1375
    }
1376
    return null;
1377
  }
1378
 
1379
 
1380
/** \brief _parse_amount
1381
*
1382
* Fortolker et DOMElement, og henter amount ud af det
1383
*
1384
* @param $dom DOMElement Det element, hvorfra amount ønskes læst
1385
* @param $tag string Navnet på det tag, der ønskes læst
1386
* @retval array Det resulterende array
1387
*
1388
*/
1389
  private function _parse_amount($dom, $tag) {
1390
    if (!isset($dom)) return array();
1391
    $ret = array();
1392
    $amount = $dom->getElementsByTagName($tag)->item(0);
1393
    if (empty($amount)) return array();
1394
    self::_get_element($ret[$tag], $amount, array('CurrencyCode', 'Value'), 'CurrencyCode');
1395
    self::_get_element($ret[$tag], $amount, 'MonetaryValue');
1396
    return $ret;
1397
  }
1398
 
1399
 
1400
/** \brief _parse_problem
1401
*
1402
* Fortolker et DOMElement, og henter Problem info ud af det
1403
*
1404
*  [Problem] array
1405
*     [Error] => ProcessingError eller MessagingError
1406
*     [Type] => User Authentication Failed
1407
*     [Element] => AuthenticationInput
1408
*     [Scheme] => "http://www.niso.org/ncip/v1_0/schemes/processingerrortype/lookupuserprocessingerror.scm"
1409
*     [Value] => Value
1410
*    
1411
* @param $xml DOMElement Det element, hvorfra Problem info ønskes læst
1412
* @retval array Problem info
1413
*
1414
*/
1415
  private function _parse_problem($xml) {
1416
    if (!isset($xml)) return self::_problem();
1417
    $problem = $xml->getElementsByTagName("Problem")->item(0);
1418
    if (!isset($problem)) return array();  // No problem detected
1419
 
1420
    $ret_value = array();
1421
 
1422
    $processingError = $problem->getElementsByTagName("ProcessingError")->item(0);
1423
    if (isset($processingError)) {
1424
      $ret_value["Error"] = "ProcessingError";
1425
 
1426
      $processingErrorType = $processingError->getElementsByTagName("ProcessingErrorType")->item(0);
1427
      if (!isset($processingErrorType)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "ProcessingErrorType", "NCIP Messaging Error Type Scheme");
1428
      $ret_value["Scheme"] = $processingErrorType->getElementsByTagName("Scheme")->item(0)->nodeValue;
1429
      if (empty($ret_value["Scheme"])) unset($ret_value["Scheme"]);
1430
      $ret_value["Type"] = $processingErrorType->getElementsByTagName("Value")->item(0)->nodeValue;
1431
      if (empty($ret_value["Type"])) unset($ret_value["Type"]);
1432
 
1433
      $processingErrorElement = $processingError->getElementsByTagName("ProcessingErrorElement")->item(0);
1434
//      if (!isset($processingErrorElement)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "ProcessingErrorElement", "NCIP Messaging Error Type Scheme");
1435
      if (isset($processingErrorElement)) {
1436
        $ret_value["Element"] = $processingErrorElement->getElementsByTagName("ElementName")->item(0)->nodeValue;
1437
        if (empty($ret_value["Element"])) unset($ret_value["Element"]);
1438
        $ret_value["Value"] = $processingErrorElement->getElementsByTagName("ProcessingErrorValue")->item(0)->nodeValue;
1439
        if (empty($ret_value["Value"])) unset($ret_value["Value"]);
1440
      }
1441
 
1442
      return array("Problem" => $ret_value);
1443
    }
1444
 
1445
    $messagingError = $problem->getElementsByTagName("MessagingError")->item(0);
1446
    if (isset($messagingError)) {
1447
      $ret_value["Error"] = "MessagingError";
1448
 
1449
      $messagingErrorType = $messagingError->getElementsByTagName("MessagingErrorType")->item(0);
1450
      if (!isset($messagingErrorType)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "MessagingErrorType", "NCIP Messaging Error Type Scheme");
1451
      $ret_value["Scheme"] = $messagingErrorType->getElementsByTagName("Scheme")->item(0)->nodeValue;
1452
      if (empty($ret_value["Scheme"])) unset($ret_value["Scheme"]);
1453
      $ret_value["Type"] = $messagingErrorType->getElementsByTagName("Value")->item(0)->nodeValue;
1454
      if (empty($ret_value["Type"])) unset($ret_value["Type"]);
1455
 
1456
      $messagingErrorElement = $messagingError->getElementsByTagName("MessagingErrorElement")->item(0);
1457
      if (!isset($messagingErrorElement)) return self::_problem("MessagingError", "Invalid Message Syntax Error", "MessagingErrorElement", "NCIP Messaging Error Type Scheme");
1458
      $ret_value["Element"] = $messagingErrorElement->getElementsByTagName("ElementName")->item(0)->nodeValue;
1459
      if (empty($ret_value["Element"])) unset($ret_value["Element"]);
1460
      $ret_value["Value"] = $messagingErrorElement->getElementsByTagName("MessagingErrorValue")->item(0)->nodeValue;
1461
      if (empty($ret_value["Value"])) unset($ret_value["Value"]);
1462
 
1463
      return array("Problem" => $ret_value);
1464
    }
1465
  return self::_problem("MessagingError", "Invalid Message Syntax Error", "", "NCIP Messaging Error Type Scheme");
1466
  }
1467
 
1468
}
1469
 
1470
?>