Skip to content

Commit 82475b1

Browse files
committed
Add holdings 852 parser
1 parent 7aa315e commit 82475b1

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

src/Fields/Location.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Scriptotek\Marc\Fields;
4+
5+
use Scriptotek\Marc\Record;
6+
7+
/**
8+
* Location (852) field
9+
*
10+
* @property string location $a : Institution or person holding the item or from which access is given.
11+
* @property string sublocation $b : Sublocation or collection - Specific department, library, etc., within the holding organization in which the item is located or from which it is available.
12+
* @property string shelvingLocation $c : Description of the shelving location of the item within the collection of the holding organization.
13+
* @property string callCode Call number, including prefix and suffix.
14+
* @property string nonpublicNote $x
15+
* @property string publicNote $z
16+
*
17+
*/
18+
class Location extends Field implements FieldInterface
19+
{
20+
public static function get(Record $record)
21+
{
22+
return parent::makeFieldObjects($record, '852');
23+
}
24+
25+
public function getLocation()
26+
{
27+
return $this->sf('a');
28+
}
29+
30+
public function getSublocation()
31+
{
32+
return $this->sf('b');
33+
}
34+
35+
public function getShelvingLocation()
36+
{
37+
return $this->sf('c');
38+
}
39+
40+
public function getCallCode()
41+
{
42+
return $this->toString([
43+
'k', // Call number prefix
44+
'l', // Shelving form of title
45+
'h', // Classification portion of the call number
46+
'm', // Call number suffix
47+
]);
48+
}
49+
50+
public function getNonpublicNote()
51+
{
52+
return $this->sf('x');
53+
}
54+
55+
public function getPublicNote()
56+
{
57+
return $this->sf('x');
58+
}
59+
60+
public function __toString()
61+
{
62+
return $this->toString(['a', 'b', 'c', 'k', 'l', 'h', 'm']);
63+
}
64+
65+
}

src/HoldingsRecord.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,40 @@
22

33
namespace Scriptotek\Marc;
44

5+
use Scriptotek\Marc\Fields\Location;
6+
7+
/**
8+
* Holdings record
9+
*
10+
* @property Location[] locations
11+
* @property Location location
12+
*/
513
class HoldingsRecord extends Record
614
{
15+
/*************************************************************************
16+
* Helper methods for specific fields. Each of these are supported by
17+
* a class in src/Fields/
18+
*************************************************************************/
19+
20+
/**
21+
* Get an array of the 852 fields as `Location` objects.
22+
*
23+
* @return Location[]
24+
*/
25+
public function getLocations()
26+
{
27+
return Location::get($this);
28+
}
29+
30+
/**
31+
* Get the first 852 field as a `Location` object.
32+
*
33+
* @return Location
34+
*/
35+
public function getLocation()
36+
{
37+
$locations = $this->getLocations();
738

39+
return count($locations) ? $locations[0] : null;
40+
}
841
}

tests/RecordTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public function testRecordTypeHoldings()
9595

9696
$this->assertInstanceOf(Record::class, $record);
9797
$this->assertInstanceOf(HoldingsRecord::class, $record);
98+
99+
$this->assertEquals('1030310', $record->location->sublocation);
100+
$this->assertEquals('k00473', $record->location->shelvingLocation);
101+
$this->assertEquals('Plv 157', $record->location->callCode);
98102
}
99103

100104
public function testRecordTypeDescriptiveCatalogingForm()

0 commit comments

Comments
 (0)