Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit ab6017a

Browse files
committed
Add vendor and collection names to uploaded XML files
1 parent 381610b commit ab6017a

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

classes/class.adjust_xml.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Class to adjust the XML file
4+
*
5+
* @author Jared Howland <[email protected]>
6+
* @version 2013-10-08
7+
* @since 2013-10-08
8+
*
9+
*/
10+
11+
class adjust_xml {
12+
public function add_vendor($resource_id) {
13+
$file = config::UPLOAD_DIRECTORY . '/' . $resource_id . '.xml';
14+
$xml_str = file_get_contents($file);
15+
$xml = new SimpleXMLElement($xml_str);
16+
// MARC namespace
17+
$marc = $xml->children('http://www.loc.gov/MARC21/slim');
18+
foreach($marc->record AS $record) {
19+
$vendor_name = $record->vendor_name;
20+
if($vendor_name) {
21+
break;
22+
} else {
23+
$field_583 = $this->get_583($resource_id);
24+
$vendor_name = $field_583[0]['vendor_name'];
25+
$collection_name = $field_583[0]['resource_name'];
26+
$vendor->addChild('vendor_name', $vendor_name);
27+
$vendor->addChild('collection_name', $collection_name);
28+
}
29+
}
30+
$xml->asXML($file);
31+
}
32+
33+
private function get_583($resource_id) {
34+
$database = new db;
35+
$db = $database->connect();
36+
$sql = 'SELECT r.resource_name, v.name AS vendor_name FROM records r INNER JOIN vendors v ON r.vendor_id = v.id WHERE r.id = :resource_id';
37+
$query = $db->prepare($sql);
38+
$query->bindParam(':resource_id', $resource_id);
39+
$query->execute();
40+
$results = $query->fetchAll(PDO::FETCH_ASSOC);
41+
$db = null;
42+
return $results;
43+
}
44+
45+
}
46+
?>

upload.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
// Upload new MARC records
1010
if($frequency) {
1111
$import_file = new import();
12-
$success = $import_file->upload( $resource_id, $frequency, $num_records, $_FILES );
13-
if( $success ) {
14-
$html = '<p>File ' . $type . ' successfully uploaded!</p>';
12+
$success = $import_file->upload($resource_id, $frequency, $num_records, $_FILES);
13+
if($success) {
14+
$adjust_xml = new adjust_xml();
15+
$add_vendor = $adjust_xml->add_vendor($resource_id);
16+
$html = '<p>File ' . $type . ' successfully uploaded!</p>';
1517
} else {
1618
$html = '<p>File ' . $type . ' was not successfully uploaded. Please try again.</p>';
1719
}
1820
// Update next load date to be 2 workdays from now
1921
} else {
20-
$update = new update();
21-
$success = $update->next_load( $resource_id );
22-
if( $success ) {
22+
$update = new update();
23+
$success = $update->next_load($resource_id);
24+
if($success) {
2325
$html = '<p>Date successfully updated. <a href="' . config::URL . '">Return home</a>.</p>';
2426
} else {
2527
$html = '<p>Date was not successfully updated. Please go back and try again.</p>';
@@ -28,4 +30,4 @@
2830

2931
$html = array('title' => 'Message', 'html' => $html);
3032
template::display('generic.tmpl', $html, 'Message');
31-
?>
33+
?>

0 commit comments

Comments
 (0)