Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 138 lines (124 sloc) 3.622 kb
e436b56e » alxp
2010-11-23 Migration to GitHub
1 <?php
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
2
d705d897 » bwoodhead
2011-10-13 Removed CVS id tags
3
e436b56e » alxp
2010-11-23 Migration to GitHub
4
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
5 /**
6 * @file
e436b56e » alxp
2010-11-23 Migration to GitHub
7 * Implements a simple class for working with Dublin Core data and exporting it
8 * back to XML. Inspiration and design shamelessly stolen from the pyfedora
9 * project at http://pypi.python.org/pypi/pyfedora/0.1.0
10 */
11
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
12 /**
13 * Dublin Core Class
14 */
e436b56e » alxp
2010-11-23 Migration to GitHub
15 class Dublin_Core {
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
16
e436b56e » alxp
2010-11-23 Migration to GitHub
17 public $dc = array(
18 'dc:title' => array(),
19 'dc:creator' => array(),
20 'dc:subject' => array(),
21 'dc:description' => array(),
22 'dc:publisher' => array(),
23 'dc:contributor' => array(),
24 'dc:date' => array(),
25 'dc:type' => array(),
26 'dc:format' => array(),
27 'dc:identifier' => array(),
28 'dc:source' => array(),
29 'dc:language' => array(),
30 'dc:relation' => array(),
31 'dc:coverage' => array(),
32 'dc:rights' => array(),
33 );
34 public $owner;
35
36 /**
37 * Constructs a Dublin_Core object from a Fedora_Item object and populates
38 * the $dc array.
39 * @param <type> $item
40 */
41 function Dublin_Core($item = NULL) {
42 if (!empty($item)) {
43 $this->owner = $item;
44 $dc_xml = $item->get_datastream_dissemination('DC');
45 $this->dc = self::import_from_xml_string($dc_xml)->dc;
46 }
47 }
48
49 /**
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
50 * Add Elements
e436b56e » alxp
2010-11-23 Migration to GitHub
51 * @param <type> $element_name
52 * @param <type> $value
53 */
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
54 function add_element($element_name, $value) {
e436b56e » alxp
2010-11-23 Migration to GitHub
55 if (is_string($value) && is_array($this->dc[$element_name])) {
56 $this->dc[$element_name][] = $value;
57 }
58 }
59
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
60 /**
61 * Replace the given DC element with the values in $values
62 * @param string $elemnt_name
abfc8445 » jonathangreen
2011-06-16 ISLANDORA-278 Initial pass at making the islandora code conform to th…
63 * @param array $values
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
64 */
e436b56e » alxp
2010-11-23 Migration to GitHub
65 function set_element($element_name, $values) {
66 if (is_array($values)) {
67 $this->dc[$element_name] = $values;
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
68 }
e436b56e » alxp
2010-11-23 Migration to GitHub
69 elseif (is_string($values)) {
70 $this->dc[$element_name] = array($values);
71 }
72 }
73
74 /**
75 * Serialize this object to XML and return it.
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
76 * @param type $with_preamble
77 * @return type
e436b56e » alxp
2010-11-23 Migration to GitHub
78 */
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
79 function as_xml($with_preamble = FALSE) {
e436b56e » alxp
2010-11-23 Migration to GitHub
80 $dc_xml = new DomDocument();
81 $oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc');
82 $oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
83 foreach ($this->dc as $dc_element => $values) {
84 if (is_array($values) && !empty($values)) {
85 foreach ($values as $value) {
86 $new_item = $dc_xml->createElement($dc_element, $value);
87 $oai_dc->appendChild($new_item);
88 }
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
89 }
e436b56e » alxp
2010-11-23 Migration to GitHub
90 else {
91 $new_item = $dc_xml->createElement($dc_element);
92 $oai_dc->appendChild($new_item);
93 }
94 }
95 $dc_xml->appendChild($oai_dc);
96 return $dc_xml->saveXML();
97 }
98
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
99 /**
100 * Create dc from dict ( does nothing )
101 */
e436b56e » alxp
2010-11-23 Migration to GitHub
102 static function create_dc_from_dict() {
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
103
e436b56e » alxp
2010-11-23 Migration to GitHub
104 }
105
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
106 /**
107 * Save ??
108 * @param type $alt_owner
109 */
e436b56e » alxp
2010-11-23 Migration to GitHub
110 function save($alt_owner = NULL) {
111 $item_to_update = (!empty($alt_owner) ? $alt_owner : $this->owner);
112 // My Java roots showing, trying to do polymorphism in PHP.
113 if (!empty($item_to_update)) {
114 $item_to_update->modify_datastream_by_value($this->as_xml(), 'DC', 'Default Dublin Core Metadata', 'text/xml');
115 }
116 }
117
118 /**
119 * Creates a new instance of the class by parsing dc_xml
120 * @param string $dc_xml
121 * @return Dublin_Core
122 */
123 static function import_from_xml_string($dc_xml) {
124 $dc_doc = new DomDocument();
125 if ($dc_doc->loadXML($dc_xml)) {
126 $oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*');
127 $new_dc = new Dublin_Core();
128 foreach ($oai_dc as $child) {
129 array_push($new_dc->dc[$child->nodeName], $child->nodeValue);
130 }
131 return $new_dc;
64fac186 » bwoodhead
2011-08-09 Added doc tags to the api
132 }
e436b56e » alxp
2010-11-23 Migration to GitHub
133 else {
134 return NULL;
135 }
136 }
137
138 }
139
Something went wrong with that request. Please try again.