Open Journal Systems  3.3.0
swordappstatement.php
1 <?php
2 
3 require_once('swordappstatemententry.php');
4 require_once('utils.php');
5 
7 
8  // The XML returned by the deposit
9  public $sac_xml;
10 
11  // The state of the item
13 
14  // A description of the state of the item
16 
17  // An array of entries
18  public $sac_entries;
19 
20  // Construct a new SWORD statement by passing in the http status code
21  function __construct($sac_newstatus, $sac_thexml = '') {
22  // Store the xml
23  $this->sac_xml = $sac_thexml;
24 
25  // Initalise entries
26  $this->sac_entries = array();
27 
28  // Parse the xml if there is some
29  if ($sac_thexml != '') {
30  $sac_statement = @new SimpleXMLElement($sac_thexml);
31  $sac_ns = $sac_statement->getNamespaces(true);
32  if (!array_key_exists('atom', $sac_ns)) $sac_ns['atom'] = 'http://www.w3.org/2005/Atom';
33  if (!array_key_exists('sword', $sac_ns)) $sac_ns['sword'] = 'http://purl.org/net/sword/';
34  $sac_state = $sac_statement->children($sac_ns['sword'])->state;
35  if (!empty($sac_state)) {
36  $sac_state_attributes = $sac_state->attributes();
37  $this->sac_state_href = $sac_state_attributes['href'];
38  $this->sac_state_description = $sac_state->children($sac_ns['sword'])->stateDescription;
39  }
40  foreach ($sac_statement->children($sac_ns['atom'])->entry as $sac_entry) {
41  $sac_entry_scheme = $sac_entry_term = $sac_entry_label = '';
42  $sac_category = $sac_entry->children($sac_ns['atom'])->category;
43  if (!empty($sac_category)) {
44  $sac_category_attributes = $sac_category->attributes();
45  $sac_entry_scheme = $sac_category_attributes['scheme'];
46  $sac_entry_term = $sac_category_attributes['term'];
47  $sac_entry_label = $sac_category_attributes['label'];
48  }
49  // TODO: Fix this - it currently works against the ss.py, but not against the spec
50  $sac_theentry = new SWORDAPPStatementEntry($sac_entry_scheme, $sac_entry_term, $sac_entry_label);
51 
52  $sac_content = $sac_entry->children($sac_ns['atom'])->content;
53  $sac_content_attributes = $sac_content->attributes();
54  $sac_theentry->addContent($sac_content_attributes['type'],
55  $sac_content_attributes['src']);
56 
57  $sac_theentry->setPackaging($sac_entry->children($sac_ns['sword'])->packaging);
58 
59  $sac_theentry->setDepositedOn($sac_entry->children($sac_ns['sword'])->depositedOn);
60 
61  $sac_theentry->setDepositedBy($sac_entry->children($sac_ns['sword'])->depositedBy);
62 
63  array_push($this->sac_entries, $sac_theentry);
64  }
65  }
66  }
67 
68  function toString() {
69  print ' - State href: ' . $this->sac_state_href . "\n";
70  print ' - State description: ' . $this->sac_state_description . "\n";
71  foreach ($this->sac_entries as $sac_entry) {
72  $sac_entry->toString();
73  }
74  }
75 }
SWORDAPPStatement\__construct
__construct($sac_newstatus, $sac_thexml='')
Definition: swordappstatement.php:21
SWORDAPPStatement\$sac_xml
$sac_xml
Definition: swordappstatement.php:9
SWORDAPPStatement
Definition: swordappstatement.php:6
SWORDAPPStatement\$sac_state_href
$sac_state_href
Definition: swordappstatement.php:12
SWORDAPPStatement\$sac_entries
$sac_entries
Definition: swordappstatement.php:18
SWORDAPPStatement\$sac_state_description
$sac_state_description
Definition: swordappstatement.php:15
SWORDAPPStatement\toString
toString()
Definition: swordappstatement.php:68