This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
forked from ppound/content_model_viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectProperties.inc
192 lines (178 loc) · 4.31 KB
/
ObjectProperties.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
// $Id$
/**
* @file
*
*/
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
/**
* This class is used to get/set a fedora object's properties.
*/
class ObjectProperties {
/**
* The given objects PID.
*
* @var string
*/
protected $pid;
/**
* The object.
*
* @var Fedora_Item
*/
protected $item;
/**
* Object's Label.
*
* @var string
*/
protected $label;
/**
* Object's Owner.
*
* @var string
*/
protected $owner;
/**
* Object's State.
*
* Either Active (A), Inactive (I) or Deleted (D)
*
* @var string
*/
protected $state;
/**
* The date that this object was created.
*
* @var string
*/
protected $created;
/**
* The date in which this object was last modified.
*
* @var string
*/
protected $modified;
/**
* Creates an object that fetchs the properties of the object identified by $PID.
* These properties can be changed, and committed back to fedora.
*
* @param string $pid
*/
public function __construct($pid) {
$this->pid = $pid;
$this->item = new Fedora_Item($pid);
$this->label = $this->getLabel();
$this->owner = $this->getOwner();
$this->state = $this->getState();
$this->created = $this->getCreationDate();
$this->modified = $this->getLastModifiedDate();
}
/**
* Gets the object's label from fedora.
*
* @return string
*/
private function getLabel() {
return $this->item->objectProfile->objLabel;
}
/**
* Gets the object's owner from fedora.
*
* @return string
*/
private function getOwner() {
$foxml = $this->item->export_as_foxml();
$doc = new DOMDocument();
$doc->loadXML($foxml);
$xpath = new DOMXPath($doc);
$result = $xpath->query("/*[local-name()='digitalObject']/*[local-name()='objectProperties']/*[local-name()='property'][@NAME='info:fedora/fedora-system:def/model#ownerId']/@VALUE");
if ($result && $result->length == 1) {
return $result->item(0)->value;
}
return '';
}
/**
* Gets the object's state from fedora.
*
* @return string
*/
private function getState() {
$foxml = $this->item->export_as_foxml();
$doc = new DOMDocument();
$doc->loadXML($foxml);
$xpath = new DOMXPath($doc);
$result = $xpath->query("/*[local-name()='digitalObject']/*[local-name()='objectProperties']/*[local-name()='property'][@NAME='info:fedora/fedora-system:def/model#state']/@VALUE");
if ($result && $result->length == 1) {
$convert = array(
'Active' => 'A',
'Inactive' => 'I',
'Deleted' => 'D',
);
$value = $result->item(0)->value;
return isset($convert[$value]) ? $convert[$value] : $value;
}
return 'I'; // Default...
}
/**
* Gets the object's creation date from fedora.
*
* @return string
*/
private function getCreationDate() {
return $this->item->objectProfile->objCreateDate;
}
/**
* Gets the object's last modified date from fedora.
*
* @return string
*/
private function getLastModifiedDate() {
return $this->item->objectProfile->objLastModDate;
}
/**
* Checks to see if the given object state is valid.
*
* @param string $state
*
* @return boolean
*/
private function validState($state) {
return $state == "A" || $state == "I" || $state == "D";
}
/**
* Propagates the given properties to this fedora object.
*
* @param string $label
* @param string $owner
* @param string $state (Expected to be "A", "I", "D")
*/
public function setProperties($label, $owner, $state) {
if (!$this->validState($state)) {
throw new Exception("'$state' is an invalid value for a fedora object's state.");
}
if ($this->item->modify_object($label, $state, $owner)) {
$this->label = $label;
$this->owner = $owner;
$this->state = $state;
return TRUE;
}
return FALSE;
}
/**
* Gets the properties associated with this object as an array with the following properties.
*
* label, owner, state, created, modified
*
* @return array
*/
public function getProperties() {
return array(
'label' => $this->label,
'owner' => $this->owner,
'state' => $this->state,
'created' => $this->created,
'modified' => $this->modified
);
}
}